Research on Low Power strategy of Embedded Linux

Source: Internet
Author: User
Tags apm
Research on Low Power strategy of Embedded Linux

Abstract: Power consumption is a very important performance indicator for embedded devices. After the hardware design and selection, the power consumption level depends greatly on the software design. In view of the increasing application of lioux in embedded devices, several software programming strategies are proposed in embedded Linux. These software compilation methods can effectively reduce the power consumption of the final product.
Keywords: Embedded Linux power consumption policy

Introduction
Linux has many characteristics that are required by embedded operating systems, such as adaptability to multiple CPUs and multiple hardware platforms, stable performance, good cropping ability, open source code, simple development and use. At present, the number of embedded devices based on Linux applications is increasing, and Linux is playing an increasingly important role in the embedded field.

For embedded devices, especially mobile devices, power consumption is an important indicator of the system. One of the important objectives of system design is to minimize power consumption. At present, the research on power consumption is mainly focused on hardware solutions, and there is little research on software. Practice has proved that after the hardware design and selection are determined, the power consumption is highly correlated with the software design. The quality of software design and programming greatly affects the power consumption of final products. To reduce power consumption, several software programming strategies are proposed in embedded Linux.

1. Problem Analysis
Because the final energy consumption is hardware, when considering the use of software methods to reduce power consumption, we should fully consider the features and performance of the hardware, that is, how to organize hardware operations to reduce power consumption on the basis of ensuring system implementation. Full-speed execution, standby, and sleep all use the inherent capabilities of the CPU to reduce power consumption by reducing the operating voltage or frequency. In addition, if most users do not notice it, the actual power management can gradually change the system status according to the load status. Sometimes this situation can be generated several hundred times within 1 s.

In addition, you may encounter such a situation when writing a program, such as recording the Status Register content and waiting for the set mark to appear; check the FIFO status mark of the serial port to see if the data is received; monitor a dual-port memory to check whether another CPU has written a variable in the system to control shared resources. On the surface, there is no problem with such code, but recording register status continuously during each clock cycle will not be able to effectively prolong the battery life of the device.

Based on these problems, several strategies are proposed below to effectively reduce the power consumption of the final product.

2. Use Linux kernel Power Management
The basis of the power management policy is to adjust the operating voltage and frequency of the processor kernel. However, the modern embedded CPU has a very high power efficiency, so that the CPU is not always the most important energy-consuming component. Other high-energy-consuming components include high-performance memory, display, and RF interfaces. Therefore, if the power management system can only adjust the voltage and frequency of the CPU kernel, its usage will be limited. A truly effective power management solution should be able to coordinate or be independent of CPU kernel execution, supporting fast adjustment of a series of voltages and frequencies.

Linux supports two power management standards: APM (advancedpower managemim) and ACPI (Advanced configtlationand p0wer interface ). APM is a traditional advanced power management solution that is still used in many Linus-based portable devices, while ACPI provides more flexible interfaces for computer and device management. These two standards cannot run simultaneously. By default, Linux runs ACPI. APM can enable the server to be In the suspend or standby status and check the battery capacity. ACPI can also enable independent power outages for peripherals (such as monitors and PCI, more control over power saving. To make the power management function take effect, you need to enable it in the Linux kernel and load necessary application software in Linux.

Power Management activities require special intervention on the operating system kernel and device drivers. In Embedded Linux, although the low-level power management reside in the operating system kernel, the power management policies and mechanisms come from the intermediary software and user application code, as shown in L.

The power management mechanism in Linux kernel is responsible for maintaining the power status of the entire system. It can be seen as an element that provides services for drivers, intermediary software, and applications.

By implementing the power management interface in the driver, the driver can closely monitor the system status. Driven by external events, they reflect the work of devices by setting different states. To implement the device power management interface, perform the following operations:
① Use pm_register to register each instance of the device;
② Call pm_access before operating the hardware (this ensures that the device has been awakened and is in ready state );
③ The user's own pnl_callback function will be called when the system enters the suspend state or recovers from the suspend state;
④ Call the pm_dev_idle function when the device is not in use (this operation is optional to enhance the monitoring capability of the device's idle status );
⑤ When unioad is used, use pm_unreggister to cancel the registration of the device.

The intermediary allows you to pre-define certain policies, track power status, and perform specific operations.

In an application, you can use the APIS provided by the intermediary program to set basic constraints and force the power management mechanism to make changes that match the execution requirements. Linix power management implementation mechanisms include the following APIs, such as dpm_set_ OS () (kernel), assert_constraint (), remove_constraint () and set_operatInK-state () (kernel and driver), set_policy () and set_task_state () (called by the System user) and/proc interface.

3. Wait for the event in idle mode
Many embedded CPUs have a power working mode that can reduce power consumption. The most common mode is the idle mode. At this time, the CPU kernel command execution is partially disabled, and all peripherals and interrupt signals are still working. Since the idle mode consumes much less power than the CPU command execution, you can, as long as Linux detects that all threads are in a blocking state (such as waiting for interruption, event, or scheduled time), it can place the CPU in idle mode. Any interruptions (such as touch screen events and pressing key events) can wake up the CPU from idle mode and continue executing the subsequent code. If the event cannot be directly connected to an external interrupt, you can also use a system timer to regularly wake up the CPU. For example, if you wait for an event and know that the event can be detected within 10 ms, you can start the lo Ms timer and place the CPU in idle mode. Check the event status when processing scheduled interruptions. If the status does not change, the system immediately returns to idle mode.

4. Reduce events
Usually the scheduled interrupt interval of the CPU is 1 MS, Linux will frequently place the CPU in idle mode, and remain until it is interrupted to wake up. In this case, the most likely thing to wake up is the timer interrupt itself. Even if all other threads are blocked, the timer interrupt will wake up the CPU from idle mode at an interval of 1 00 () times per second before other interruptions, internal events, and long delays, to run the scheduler. Even if the scheduler determines that all lines are blocked and the CPU is quickly switched back to idle mode, frequent operations will waste a lot of power. Therefore, the CPU should be put in idle mode as long as possible, and reducing the event is an effective way to solve this problem. Analyze the code and system requirements to determine whether the interrupt handling method can be changed. For example, you can disable the time slot interruption signal before entering the idle mode and wake up only when the interruption signal appears again. However, this approach is usually not suitable. Although most blocked threads can directly or indirectly wait for external interruptions, some also rely on timed interruptions, such as a drive that will sleep 500 MS while waiting for peripherals, if the system timer is completely disabled in idle mode, it may mean that the line cannot be resumed on time.

In Linux, it is best to set variable timeout for the scheduler. Lintux knows that each thread cannot determine whether to wait for an external or internal event, or plans to run it again at a specific time. In Linux, you can determine when the first thread is scheduled to run and set the timer to work before the CPU is in idle mode. Variable timeout settings do not impose a great deal of burden on the scheduler, but can save power and processing time.

Variable plan timeout limit is only one way to reduce events. Direct Memory Access (DMA) can also leave the CPU in idle mode for a long time, even if data is being sent to or received from peripherals. As long as possible, DMA should be used in the peripheral drive, the power saving effect is quite satisfactory.

For example, when the Intel strongarm CPU serial port receives listen 0, an interruption occurs every eight bytes at 115 2OO bps. at a high speed, the 11 kb pulse data sent to this port will cause the CPU kernel to interrupt 500 times per second, which is likely to wake up from idle mode; however, if you don't actually need to process data in these small 8-byte devices, the waste is amazing. It is best to use DMA with a large-capacity buffer to make the interrupt level easier to manage, maybe 10 times per second or l00 times, so that the CPU is idle between two interrupts. It turns out that using DMA in these cases can reduce the usage rate by 20%, reduce CPU power consumption, and increase the CPU bandwidth used by other threads.

5. Control CPU Performance
The latest progress in CPU power consumption reduction shows that the CPU energy consumption is proportional to the clock frequency of the CPU driver and the voltage square on the kernel.

The CPU allows dynamic clock speed reduction. If the clock speed is reduced by half, the power consumption will decrease proportionally. However, using this technology only saves energy requires some skills, because the execution of the Code may take two times to complete, and even this will not save power. For example, the on-board LCD controller needs to use a frame cache stored in the off-chip SDRAM. When the LCD controller is working, a high enough memory bus frequency needs to be specified to meet the display refresh rate. When the LCD does not work (for example, when the PDA is used only as an MP3 player), the frequency of the SDRAM bus can be reduced, saving the power consumption of the entire system.

Dynamic voltage reduction is another approach. More and more CPUs are allowed to reduce the voltage to adapt to the CPU clock speed drop, which can also reduce power consumption when the clock speed is reduced. In fact, as long as the CPU is not saturated, the frequency and voltage can be continuously reduced, so that the work can still be completed, while the power consumption is relatively low.

Considering that not all threads consume the same amount of CPU bandwidth, these methods can be improved. Threads that effectively apply CPU bandwidth can take longer to complete as the CPU clock speed drops. These threads are allocated to each cycle. On the other hand, the I/O thread uses all the CPU cycles allocated to it, even if the CPU clock rate drops, it will take the same time to complete. For example, when data writers flash the memory card, the system bottleneck is not the CPU speed, instead, physical bus interfaces and card firmware are the time it takes to erase and re-program flash memory. Ideally, the wait event technology discussed earlier can be used here to minimize power consumption, but the wait time often changes greatly, far less than the operating system time, this will affect the performance. These drivers often detect status registers, reducing the clock speed will save some of the power, but will have a slight impact on the time of Data writing to the card.

Using a policy that controls CPU performance, you need to know when the clock frequency and voltage can be reduced without significantly affecting performance. It is difficult to consider when the clock speed of the drive and application can be reduced. This is more skillful in multitasking environments.

Conclusion 6
In recent years, with the accelerated development of computer and network communication and consumer electronics, embedded products have become the mainstream of the information industry. Linux has developed into one of the most powerful and well-designed operating systems in just over a decade, it can run on x86, Alpha, iSCSI, MIPS, PPC, Motorola, NEC, arm, and other hardware platforms. It is also open source code and can be customized, more and more enterprises and R & D institutions are turning to the development and research of embedded Linux. On the basis of system analysis, this paper studies a method to reduce the power consumption level of the final product by optimizing the software writing mechanism in the embedded Linux system, which has a strong practical application significance. With the in-depth research, embedded Linux will certainly show its superiority in low power consumption, and more embedded devices will be popularized in Linux applications.

(Comprehensive e-forum)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.