In Linux, hibernation is divided into three main steps: (1) Freeze user-mode processes and kernel-mode tasks; (2) Call the suspend callback function of registered devices; (3) Hibernate core devices and enable the CPU according to the registration order. Enter dormant state.
Freezing a process means that the kernel sets the status of all processes in the process list to stopped and saves the context of all processes. When these processes are unfrozen, they are unaware that they have been frozen and simply continue execution. How to put Linux into hibernation? Users can control the system to enter hibernation by reading and writing the sys file /sys /power/state. For example: # echo standby > /sys/power/state commands the system to enter sleep mode. You can also use # cat /sys/power/state to get which sleep modes the kernel supports.
Linux Suspend process. Paths to related files: linux_soruce/kernel/power/main.c linux_source/kernel/arch/xxx/mach-xxx/pm.c
linux_source/driver/base/power/main.c (1) Next, let us take a detailed look at how Linux sleeps/wakes up.
Users' reading and writing of /sys/power/state will call state_store() in main.c. Users can write strings defined in const char * const pm_state[], such as "mem" and "standby". Then state_store() will call enter_state(), which will first check some state parameters and then synchronize the file system. (2) Prepare to freeze the process.
When entering suspend_prepare(), it allocates a virtual terminal to suspend to output information, then broadcasts a Notify that the system wants to enter suspend, closes the user-mode helper process, and then calls suspend_freeze_processes() at once to freeze all processes. The current status of all processes will be saved here. There may be some processes that refuse to enter the frozen state. When such processes exist, the freezing will fail. This function will give up the frozen process and unfreeze all the processes that were just frozen.
(3) Let the peripherals go to sleep.
Now, all processes (including workqueue/kthread) have stopped. The kernel mode task may hold some semaphores when stopped, so if you unlock the semaphore in the peripheral at this time, a deadlock may occur. , so be very careful when locking/unlocking in the peripheral's suspend() function. It is recommended not to wait for the lock in suspend() when designing.
Finally, suspend_devices_and_enter() will be called to put all peripherals to sleep. In this function, if the platform registers suspend_pos (usually defined and registered in the board-level definition), suspend_ops->begin() will be called here, and then the driver device_suspend()->dpm_suspend() in /base/power/main.c will be called, and they will call the driver's suspend() callback in turn to sleep all devices. When all devices go to sleep, suspend_ops->prepare() will be called. This function usually does some preparation work to put the board into sleep. Next, in Linux, non-starting CPUs in multi-core CPUs will be turned off. As you can see from the comments, this is to prevent these other CPUs from causing race condion. From now on, only one CPU will be running. suspend_ops is a board-level power management operation, usually registered in the file arch/xxx/mach-xxx/pm.c. Next, suspend_enter() will be called. This function will close the arch irq and call device_power_down(). It will call the suspend_late() function. This function is the last function called when the system actually enters sleep. It is usually the last function in this function. inspection. If the check is OK, then sleep all system devices and buses, and call suspend_pos->enter() to put the CPU into a power saving state. At this time, it has gone to sleep, and the execution of the code stops here.
(4) Resume.
If the system is awakened by an interrupt or other event during sleep, the next code will begin to execute. The order of wake-up is reverse to the order of sleep, so the system devices and buses will wake up first, enable system interrupts, and enable sleep. When stopping the non-starting CPU, and calling suspend_ops->finish(), and in the suspend_devices_and_enter() function, it will continue to wake up each device and enable the virtual terminal. Finally call suspend_ops->end(). Return to the enter_state() function. When suspend_devices_and_enter() returns, the peripherals have woken up, but the processes and tasks are still frozen. Here, suspend_finish() will be called to unfreeze these processes and tasks, and a Notify will be issued to indicate this. The system has exited from the suspend state and woke up the terminal. At this point, all sleeping and waking up have been completed, and the system continues to run.
Previous article:Analysis of the standard Linux sleep and wake-up mechanism of power management of Linux driver (1)
Next article:Regulator mechanism process of power management of Linux driver (1)
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Vicor high-performance power modules enable the development of low-altitude avionics and EVTOL
- Chuangshi Technology's first appearance at electronica 2024: accelerating the overseas expansion of domestic distributors
- Chuangshi Technology's first appearance at electronica 2024: accelerating the overseas expansion of domestic distributors
- "Cross-chip" quantum entanglement helps build more powerful quantum computing capabilities
- Ultrasound patch can continuously and noninvasively monitor blood pressure
- Ultrasound patch can continuously and noninvasively monitor blood pressure
- Europe's three largest chip giants re-examine their supply chains
- Europe's three largest chip giants re-examine their supply chains
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Correctly understand the phase difference caused by capacitance and inductance
- 【SoC】Realize Ethernet interaction function
- Can anyone provide a download link for the AD package library (with 3D effects)? It's quite complete. Thank you.
- Simple Microphone Amplifier
- [ESP32-Korvo Review] (1) Development Board Circuit Connection
- What to do if ESP32-WROOM-32 has high power consumption when connected to the Internet
- Use the hal library to drive ra8875 using the Red Bull development board
- Download: Qorvo Ultra-Wideband (UWB) For Dummies
- EEWORLD University Hall----MCU Principles and Applications Harbin Institute of Technology
- Learning Machine Solution