[Exchange and share] deepin Platform Power Strategy
Tofloor
poster avatar
longlong
deepin
Developer
2024-06-26 17:04
Author

Background

Recently, we received feedback from users experiencing high CPU power consumption leading to device overheating and poor battery life while using the deepin system. Despite low CPU usage in these scenarios, power consumption remained high. To address this issue, the Open Source Community Center has established a special project to optimize power management for deepin. This article aims to analyze and explain the root cause of this issue.

Before optimizing power management, we conducted an in-depth investigation and analysis of the deepin system to understand its actual performance under load conditions. Through monitoring CPU usage and power consumption, we discovered a surprising fact: although CPU usage was low under high load conditions, power consumption continued to rise, ultimately causing device overheating and affecting battery life. This means that our previous power-saving optimization efforts were not only ineffective but counterproductive (the specific situation will be explained in detail below).

Issue

Kernel

The problem was first discovered in the kernel. Users comparing our kernel with Ubuntu's kernel found that although our system's performance was similar to Ubuntu's, we lagged significantly in terms of heat dissipation and battery life. Users compiling the kernel on the deepin system using configuration files from Ubuntu and other open-source Linux distributions discovered that the main issue with deepin was in heat control. Our testing colleagues took this community feedback seriously and reproduced the problem, confirming this phenomenon.

To address this issue, we immediately contacted colleagues in the kernel development department and invited community users with some knowledge of kernel configuration to participate. Through joint troubleshooting, we found that the HWE kernel provided in deepin v23 had some debug and unnecessary kernel options enabled, and some power-saving functions were not effectively activated, which contributed to the poor battery performance of deepin v23.

System

At the system level, I re-examined the power scheduling module provided by dde-daemon and compared it with the file interfaces provided by the kernel documentation. By analyzing the power modes used by our users, I found room for optimization. This will be one of the main focuses of this article.

  1. Prerequisite Knowledge: ACPI

ACPI stands for Advanced Configuration and Power Interface. It is an interface standard for exchanging power-related information between computer hardware and the operating system. It defines the power-related information of computer hardware, such as the power state of the power supply, device power consumption, and device power factor. ACPI is a standard for operating system control of computer hardware power management and also a standard for communication between hardware manufacturers and operating systems.

In the deepin system, ACPI is responsible for handling the power management of computer hardware. It interacts with the deepin system's power management module to achieve power management of computer hardware.

When analyzing system-level issues, we need to understand the role and functions of ACPI and the power management module and how they work together. This article will explain the working principles of ACPI and the power scheduling module in the deepin system in detail and propose feasible optimization suggestions.

First, let's understand the working principle of ACPI. When a power change occurs in the computer hardware, ACPI collects hardware information and sends a power request to the operating system. Upon receiving the power request, the operating system automatically adjusts the power strategy of each hardware according to user configuration. The power module of the deepin system helps users generate configurations to adjust ACPI behavior. Therefore, in this regard, we can provide reasonable power strategies to ACPI to ensure performance while reducing device temperature and improving battery life.

  1. Platform Power Configuration

Relevant Kernel Documentation: https://docs.kernel.org/userspace-api/sysfs-platform_profile.html

UEFI ACPI Documentation: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/index.html

Platform power configuration is an important part of the power management module. It is used to manage the power state of computer platform hardware (referring to all devices that support ACPI), and the CPU is also part of ACPI devices. However, since the CPU is the main heat generator in a computer, platform power management might be too coarse-grained for it. Therefore, ACPI introduces some CPU-specific performance management methods, which will be explained in detail in the next section.

Platform power configuration provides three selectable modes: performance, balance, and low-power. Generally, users can use the balance mode. The performance mode is the default for desktop and mini PCs (which have no requirements for power consumption and heat). The balance mode is the default for laptops and other mobile devices. The low-power mode is not provided by default because some ACPI devices may experience "sleep death" in low-power mode. Therefore, to avoid this issue, low-power mode is not provided by default.

  1. CPU Power Configuration

Traditional Power Modes (SCalling) Kernel Documentation: https://www.kernel.org/doc/html/v6.1/admin-guide/pm/cpufreq.html

Intel PState Kernel Documentation: https://www.kernel.org/doc/html/v6.1/admin-guide/pm/intel_pstate.html

AMD PState Kernel Documentation: https://docs.kernel.org/admin-guide/pm/amd-pstate.html

If you have time, you can easily understand the content related to CPU power configuration by studying the above power documentation. In this explanation, I will ignore a lot of technical details and implementation methods, just telling you how to adjust the CPU's power mode.

In the /sys/devices/system/cpu/cpufreq directory, there are many files named policy (where x represents the core number). These files correspond to the CPU cores on your computer, and the power scheduling details of the CPU are in these folders. In the policy directory, there is a file called scaling_driver. Access it using cat or other methods to get the current scheduler:

  1. intel_cpufreq / acpi_cpufreq: Uses scaling freq scheduling
  2. intel_pstate: Uses Intel Pstate scheduling
  3. amd-pstate: Uses AMD Pstate scheduling
  4. Scaling Freq Scheduling

This is the most traditional CPU scheduling method. In the policy folder, the scaling_available_governors file lists the available power modes:

English Chinese Meaning
performance 性能模式 The highest performance, the hottest CPU temperature, and the shortest battery life
powersave 节能模式 Contribute to a greener earth
balance 平衡模式 Balance performance and battery life, having the best of both worlds
schedutil 平衡模式 A type of balance mode, using different algorithms for scheduling
ondemand 平衡模式 A type of balance mode, dynamically adjusting frequency based on current CPU load
conservative 平衡模式 A type of balance mode, dynamically adjusting frequency based on current CPU load
userspace 用户模式 Runs the CPU at a user-specified frequency, configurable via /sys/devices/system/cpu/cpuX/cpufreq/scaling_setspeed

You might wonder why there are so many balance modes. These balance modes aim to balance performance and battery life, though they use different algorithms. I won't go into detail here, but I found some detailed resources online for reference. Interested friends can look them up:

  1. Oppo Kernel Team: Schedutil Governor Scenario Analysis: http://www.wowotech.net/process_management/schedutil_governor.html
  2. Linux Kernel Documentation: Schedutil Governor: https://www.kernel.org/doc/html/next/translations/zh_CN/scheduler/schedutil.html
  3. Arch Wiki: https://wiki.archlinux.org/title/CPU_frequency_scaling

We can change the scaling_governors to alter this core's power scheduling (note that it can only be changed to the power schedulers listed in the scaling_available_governors file, which may vary by computer).

  1. Intel Pstate

This is exclusive to recent Intel CPUs. With the kernel's Intel Pstate enabled (default in V23), you'll find several additional files in the policy folder. We only need to focus on:

  1. Benergy_performance_available_perference: Available Pstate power scheduling
  2. energy_performance_perference: The currently selected Pstate power scheduling, which can be changed by modifying this file

Intel Pstate introduces two new scheduling schemes:

  1. balance_performance: Balanced towards performance, with low working frequency but quick response under load
  2. balance_power: Balanced towards power-saving, with a more conservative power strategy.

On some computers, there's also a default scheme, which is an optimized balance strategy. For the specific black magic used by Pstate and the scheduling strategies of active and passive modes, refer to the kernel documentation.

  1. AMD Pstate

This is exclusive to AMD ZEN2 and newer users, and those using kernel 6.4.x. AMD has supported Pstate in kernel 6.1, though it was passive mode.

  1. Active Mode

Active Mode is available only with kernel versions greater than 6.4, and the AMD Pstate option enabled. You may need to add the amd_pstate=active boot parameter in grub to enable this feature or modify files accordingly. The power strategy of Active Mode is similar to Intel Pstate.

  1. Passive Mode

Passive Mode is available only with kernel versions greater than 6.1, and the AMD Pstate option enabled. You may need to add the amd_pstate=passive boot parameter in grub to enable this feature or modify files accordingly.

Passive Mode provides two power modes, adjustable in the /sys/device/system/cpu/cpufreq/scaling_governor file:

  • performance: Configured using platform_profile, with high scheduling aggressiveness
  • schedutil: Adjusts scheduling granularity (the interval time between two schedules) in the /sys/device/system/cpu/cpufreq/schedutil/rate_limit_us file, similar to ACPI's schedutil class in /sys/device/system/cpu/cpufreq/scaling_governor
  1. Guided Mode

Guided Mode is available only with kernel versions greater than 6.1, and the AMD Pstate option enabled. You may need to add the amd_pstate=guided boot parameter in grub to enable this feature or modify files accordingly.

It works like an automatic transmission in a car, where the driver requests the minimum and maximum performance levels, and the platform automatically selects the appropriate performance level within this range based on the current workload.

GPU Power Management

  1. AMD GPU

For AMD GPU, two files need to be modified (using the tee command for writing):

  • /sys/class/drm/card0/device/power_dpm_state (a legacy interface for backward compatibility)
  • performance: High-performance mode
  • balance: Balanced mode
  • battery: Power-saving mode
  • /sys/class/drm/card0/device/power_dpm_force_performance_level

The following settings are from the AMD official driver documentation:

* auto: The device dynamically selects the best power curve based on current conditions in the driver

* low: Forces the GPU to the lowest power state

* high: Forces the GPU to the highest power state

* manual: Allows users to manually adjust the enabled power states for each clock domain via sysfs pp_dpm_mclk, pp_dpm_sclk, and pp_dpm_pcie files, and adjust power state transitions via the pp_power_profile_mode sysfs file

* profile_standard: Fixed clock level analysis mode. This mode sets the clocks to a fixed level, which varies by ASIC. Useful for analyzing specific workloads (rarely used)

* profile_min_sclk: Minimum sclk analysis mode. This mode forces sclk to the lowest level. Useful for analyzing minimal power consumption scenarios (rarely used)

* profile_min_mclk: Minimum mclk analysis mode. This mode forces mclk to the lowest level. Useful for analyzing minimal power consumption scenarios (rarely used)

* profile_peak: Peak analysis mode. This mode sets all clocks (mclk, sclk, pcie) to the highest level. Useful for analyzing maximum performance scenarios (rarely used)

  • AMD Integrated Graphics AnTuTu Verification Data

Set to low mode, GPU score: 12144

Set to auto mode, GPU score: 88544

Set to high mode, GPU score: 89575

  1. Intel GPU

Intel GPUs use the i915 driver, which does not encourage manual adjustments since its built-in power strategies are already optimized. However, you can use intel-gpu-tools to adjust and obtain information:sudo apt install intel-gpu-tools

Then use:sudo intel_gpu_frequencyto get the current frequency (currently using Intel A750). The Intel GPU driver dynamically adjusts between 600 MHz and 2400 MHz.

Test results on a laptop with an Intel integrated graphics card:

  1. Nvidia

No comments. Use the driver settings.

Acknowledgments

The author of this article is longlong from the deepin Open Source Community Center. This article is distributed under the CC-BY-NC-SA-4.0 license: https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh

Thanks to the deepin community kernel team, the community testing team, @fslong, and other community users who participated in the V23 kernel battery life testing.

Reply Favorite View the author
All Replies
pzm9012
Moderator
2024-06-26 17:36
#1

It seems that the pictures attatched can't load properly.

Reply View the author