In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you the example analysis of the cpufreq mechanism in Linux, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Starting with the 2.6.0 Linux kernel, you can dynamically adjust the processor frequency through the CPUfreq subsystem. When processors run at lower clock speeds, they consume less electricity and generate less heat. This scaling of the clock speed can control the system to consume less power when it is not running at full capacity.
Overview of cpufreq
The core function of cpufreq is to adjust the voltage and frequency of CPU to take into account the performance and power consumption of the system. When high performance is not needed, reduce voltage and frequency to reduce power consumption; when high performance is needed, increase voltage and frequency to improve performance.
Cpufreq software framework
Cpufreq realizes the control of frequency and voltage based on clock, regulator, pmu and other modules. Cpufreq provides frequency query and control interfaces to user space in the form of sysfs through cpufreq core, cpufreq governor, cpufreq stats and other modules. Inside, cpufreq is divided into core, governor, drivers and other modules.
Cpufreq FM Strategy Performance
Performance is a priority, and CPU fixed works at the highest frequency it supports.
Powersave
Power consumption is given priority, and CPU works at the lowest frequency it supports.
Userspace
The system gives the decision-making power of the frequency conversion strategy to the user-mode application program, and provides the corresponding interface for the user-mode program to set the CPU frequency.
Ondemand
Adjust the CPU frequency dynamically as needed. As soon as the CPU load exceeds the threshold, up_threshold will be set to the maximum frequency, and the appropriate frequency will be calculated according to the load at other times.
Conservative
Unlike ondemand, Conservative does not blindly pursue the highest frequency, but smoothly adjusts the CPU frequency. The rise and fall of the frequency is gradual.
Interactive
Trigger FM callback based on kernel task scheduling. In the callback function, the time when CPU is in idle and busy between two schedules is calculated, and the load frequency modulation and then frequency modulation of CPU are calculated.
Schedutil
Schedutil also triggers FM callback based on kernel task scheduling. Unlike interactive, the load used by schedutil comes from the load estimated by the kernel using task load tracking technology (PELT/WALT).
Cpufreq Test Command query
The following file nodes can be displayed through the cat command
# ls / sys/devices/system/cpu/cpu0/cpufreq/
Affected_cpus / / which online corecpuinfo_cur_freq / / current CPU hardware frequency cpuinfo_max_freq / / CPU hardware supported lowest frequency cpuinfo_min_freq / / CPU hardware supported highest frequency cpuinfo_transition_latency / / hardware supported minimum switching frequency interval related_cpus / / online and offline corescaling_available_frequencies / / software supported frequency list scaling_available_governors / / supported policy columns Table scaling_cur_freq / / current frequency of software settings Usually the same as cpuinfo_cpus, if there is a hardware problem, it may lead to inconsistency of scaling_driver / / currently used driverscaling_governor / / currently used governorscaling_max_freq / / Software governor set the highest frequency scaling_min_freq / / Software governor set the lowest frequency scaling_setspeed / / you need to switch the governor type to userspace before it will appear. If you modify the value through echo, the main frequency will be switched.
Set up
You can configure scaling_governor,scaling_max_freq,scaling_min_freq through echo for example: echo 1400 > / sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
Cpufreq compilation configuration
# CPU Frequency scalingCONFIG_CPU_FREQ=y # main switch # CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y # default gov you can choose a macro to turn on, which determines the governor used for cpufreq initialization. Later, you can modify the file node # CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y#CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=yCONFIG_CPU_FREQ_STAT=y # dimensional test switch in init.rc to view cpufreq statistics: / sys/devices/system/cpu/cpu0/cpufreq/stats.
Cpufreq module initialization
The initialization of cpufreq can be divided into three stages: core layer, governor layer and driverslayer.
Core layer
Initialize FM notification linked list, pure_initcall (init_cpufreq_transition_notifier_list) create cpufreq file node, core_initcall (cpufreq_core_init)
Governor layer
Use the cpufreq_register_governor interface to register each governor to the linked list, for example:
Fs_initcall (cpufreq_gov_performance_init); fs_initcall (cpufreq_gov_powersave_init); fs_initcall (cpufreq_gov_userspace_init); fs_initcall (cpufreq_gov_dbs_init); fs_initcall (sugov_register)
Drivers layer
The drivers layer is initialized in the device_initcall or late_initcall phase. The following main tasks need to be completed:
Call the init callback of the cpufreq_register_driver registered driver to complete the initialization of the hardware layer, including the control cpufreq_register_driver interfaces of clk, regulator, and pmu to complete the settings of policy and governor. These are all the contents of the article "sample Analysis of cpufreq Mechanism in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.