Introduction to Linux power management system structure, do you know?

The operation of any system requires energy. The computer system runs on electrical energy. The acquisition of energy is costly. Therefore, if the energy consumption can be saved as much as possible on the basis of ensuring the operation of the system, the survival competitiveness of the system will be greatly improved. In this regard, nature has already done a good job, such as the fall of leaves of plants, the hibernation of animals, and so on. In the world of computers (here, an embedded system running Linux OS is taken as an example), it is called Power Management.

The operation of any system requires energy. The computer system runs on electrical energy. The acquisition of energy is costly. Therefore, if the energy consumption can be saved as much as possible on the basis of ensuring the operation of the system, the survival competitiveness of the system will be greatly improved. In this regard, nature has already done a good job, such as the fall of leaves of plants, the hibernation of animals, and so on. In the world of computers (here, an embedded system running Linux OS is taken as an example), it is called Power Management.

In layman’s terms, power management is: “I want horses to run, but horses don’t want to eat grass.” However, from the perspective of energy conservation, if you want a horse to run as fast and for a long time, you must let it eat the corresponding amount of grass. Then we will go back and forth: “Let the horse eat grass only when it needs to run.” This is the core idea of ​​power management. What about the method? It can be like this:

Method 1: Kill the horse when it is not needed to run, so that it will not eat grass. Raise another horse when you need it to run.

In the real world, no one except fools should use this method. Because it takes time to re-raise a horse-where can I wait, we need grass-it may take more than raising a free horse.

Method 2: When the horse is not needed to run, let it sleep without opening its eyes, moving, or barking.

Let’s not talk about whether the horse is willing to sleep all the time. This method can only reduce the amount of grass the horse eats, because its heart is still beating and blood is still circulating, which also consumes energy. But fortunately, when the horse needs to run, it shouldn’t need to wait too long.

Method 3: Doesn’t it mean that the heartbeat and blood circulation consume energy? Then stop these as well. How much can be saved.

It’s really a good way. You don’t have to ask the veterinarian first if you can get it done. However, with the current medical level, it is estimated that this will not be possible.

In the computer world, the above methods are commonplace, and the control is much more refined than these. Because the computer was designed by humans, but the horse is by the hand of God. But through the horse example, we can summarize the basic behavior of power management:

a, Real-time shutdown of temporarily unused parts (can be called “transfer from working state to non-working state”). For example, when the mobile phone is in the pocket, the screen does not need to be bright.

b. When it is necessary to reuse those closed parts (which can be called “transfer from non-working state to working state”), there can be no too long waiting, and the transfer process can not consume too much energy. The above method 1 is a negative teaching material, but in the computer world, the situation will be much better.

2. The composition of Linux power management

Power Management (Power Management) is a relatively large subsystem in Linux Kernel, involving power supply (Power Supply), charging (Charger), clock (Clock), frequency (Frequency), voltage (Voltage), sleep/wake-up (Suspend /Resume) and other aspects (as shown in the figure below), Wowo will describe them one by one in a series of articles on Linux power management.

Introduction to Linux power management system structure, do you know?

Note 1: The picture is only a schematic diagram, and does not divide the software hierarchy, so the relationship between the modules is not necessarily the real relationship.

Before describing these components (also called Framework) in the picture in detail, let’s first understand the basic concepts here.

Note 2: Framework is a middle-tier software that provides a framework for software development. The purpose is threefold: one is to shield the specific implementation details and fix the corresponding interface, which can facilitate the development and maintenance of upper-level software; the second is to abstract the common logic as much as possible and implement it in the Framework to improve reusability and reduce the amount of development ; The third is to provide a series of callback functions to the lower layer. The lower layer software may face a very different reality, but as long as these callback functions are filled, all the logic can be completed, which reduces the difficulty of development.

Power Supply is a class for user space programs to monitor the power supply status of the system (battery power supply, USB power supply, AC power supply, etc.). In layman’s terms, it is a Framework driven by Battery&Charger

Clock Framework, a Clock-driven Framework, used to uniformly manage the clock resources of the system

Regulator Framework, Framework driven by Voltage/Current Regulator.This driver is used to adjust the voltage and current values ​​of CPU and other modules

Dynamic Tick/Clock Event, in the traditional Linux Kernel, the system Tick is a fixed period (such as 10ms), so every other Tick, a Timer interrupt will be generated. This will wake up the CPU in the Idle or Sleep state, and in many cases this wake-up is meaningless.Therefore, the new Kernel puts forward the concept of Dynamic Tick. Tick is no longer periodic, but irregularly generated according to the timer in the system, which can reduce a lot of useless Timer interrupts.

CPU Idle, Framework used to control the state of CPU Idle

Generic PM, Power Management in the traditional sense, such as Power Off, Suspend to RAM, Suspend to Disk, Hibernate, etc.

Runtime PM and Wakelock, Power Management at runtime, no longer need user program interference, unified scheduling by Kernel, real-time shutdown or opening of the device, in order to find the best balance between performance and power saving performance

Note 3: Runtime PM is the runtime power management mechanism of Linux Kernel, and Wakelock is a mechanism proposed by Android. The purpose of these two mechanisms is the same, so only one needs to be supported. In addition, because the Wakelock mechanism is too wild and has been despised by the Linux community, we will not describe the mechanism too much.

CPU Freq/Device Freq, Framework used to adjust the frequency of CPU and Device

OPP (Operating Performance Point) refers to the voltage and frequency combination that can make SOCs or Devices work normally.The kernel provides this Layer in order to filter out some relatively fixed combinations among many voltage and frequency combinations, so as to make things easier.

PM QOS, the so-called PM QOS, refers to the working quality of the system in a specified operating state (different voltage, frequency, switching between different modes, etc.), including three parameters of latency, timeout, and throughput, and the units are respectively us , Us and kb/s.Through QOS parameters, you can analyze and improve the performance of the system

3. Source code compilation related to power management in Kernel

In the Linux 3.10.29 version of the kernel used by Wowo, the source codes related to power management are located at:

kernel/power/ *

drivers/power/

drivers/base/power/*

drivers/cpuidle/*

drivers/cpufreq/*

drivers/devfreq/*

include/linux/power_supply.h

include/linux/cpuidle.h

include/linux/cpufreq.h

include/linux/cpu_pm.h

include/linux/device.h

include/linux/pm.h

include/linux/pm domain.h

include/linux/pm runtime.h

include/linux/pm wakeup.h

include/linux/suspend.h

Documentation/power/*.txt

After reading the above content, how much do you know about the structure of the Linux power management system?

The Links:   MT506SV4CN PK200HB160

Related Posts