[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howtos:hardware:cpu_frequency_scaling [2013/12/16 22:22 (UTC)] – [Overview] metaschimahowtos:hardware:cpu_frequency_scaling [2023/12/11 10:43 (UTC)] (current) – [Introduction] zeebra
Line 3: Line 3:
 ====== CPU-frequency scaling on Slackware ====== ====== CPU-frequency scaling on Slackware ======
  
-===== Overview ===== +===== Introduction ===== 
-CPU frequency scaling is carried out by the kernel, but requires that the relevant UEFI/BIOS options be enabled (such as Intel (EnhancedSpeedstep). Slackware comes with all requirements necessary to use this feature+CPU frequency scaling is carried out by the kernel, there are currently two main ways of thinking about CPU Frequency Scaling, and these are based on the frequency scaling driver which is in use. By default "p-states" implements CPU Frequency Scaling and cannot be compiled out of the Kernel. This has been the case for Intel for quite some time, and recently (as of 2023) "p-states" are also implemented for AMD (but is not the default driver). It is however possible to disable p-states, which will set the controlling driver to "acpi-cpufreq".\\ 
 +\\  
 +"P-states" use the default scaling mechanisms of the CPU and in many cases leave more decisions to the CPU ("hardware managed p-states" aka __HPW__). There are two frequency scaling "governors" for this mode, "performance" and "powersave". If your CPU does not support HWP it is put into "passive" mode, which you can also do manually. If you change the scaling driver to acpi-cpufreq, you can disable the p-states of the CPU. ACPI is an "industry standard" and related to this topic you can use it to scale your CPU in a different way by using the acpi-cpufreq driver and scaling governors. Until somewhat recently there were 5 scaling governors for acpi-cpufreq, **"performance"**, **"powersave"**, **"userspace"**, **"ondemand"** and **"conservative"**, with "ondemand" often being the default. A 6th governor **"schedutil"** was added and made the default option in the Kernel and Slackware. It might seem complicated, but you only really have to consider the two main modes of CPU Frequency Scaling, which is __p-state__ and __acpi-cpufreq__. Slackware by default comes with all requirements necessary to use these features\\ 
 +\\ 
 +For older computers with "legacy" scaling implementations and with a new Kernel, these functions have been incorporated into acpi-cpufreq, and alongside AMD it should be your default choice. For very old and new AMD CPU's (zen2 onwards), other options exists and should be considered. 
 +\\
  
-===== Requirements ===== +**Available governors** and the **currently used driver** can be seen by using the cpufreq command 
-The kernel options for CPU frequency scaling are as follows. You need both a governor (one set to default) and a driver. +<code>cpufreq-info</code> 
-  Power management and ACPI options +\\ 
-    CPU Frequency scaling +===== Kernel Configuration =====
-      CPU Frequency scaling (CPU_FREQ [=y]) +
-        'performance' governor (CONFIG_CPU_FREQ_GOV_PERFORMANCE) This sets CPU frequency to the maximum available. +
-        'powersave' governor (CONFIG_CPU_FREQ_GOV_POWERSAVE) This sets CPU frequency to the minimum available. +
-        'userspace' governor for userspace frequency scaling (CONFIG_CPU_FREQ_GOV_USERSPACE) This allows userspace programs to set the CPU frequency. +
-        * 'ondemand' cpufreq policy governor (CONFIG_CPU_FREQ_GOV_ONDEMAND) This governor is recommended for desktops. +
-        * 'conservative' cpufreq governor (CONFIG_CPU_FREQ_GOV_CONSERVATIVE) This governor is recommended for laptops/netbooks. Although similar to the 'ondemand' governor, frequency is gracefully increased and decreased rather than jumping to 100% when speed is required. +
-        * x86 CPU frequency scaling drivers +
-          * Intel P state control (X86_INTEL_PSTATE [=n]) This driver is mutually exclusive with CONFIG_X86_ACPI_CPUFREQ. It is a newer driver for Sandy Bridge processors and [[https://www.linuxquestions.org/questions/slackware-14/slackware-64bit-14-1-rc-kernel-3-10-16-and-virtualbox-4175481316/|may cause problems]]. +
-          * Processor Clocking Control interface driver (CONFIG_X86_PCC_CPUFREQ) This is only required for HP ProLiant servers, which using this interface. Otherwise, disable it. +
-          * ACPI Processor P-States driver (CONFIG_X86_ACPI_CPUFREQ [=y]) This is the recommended driver for newer CPUs Intel (Enhanced) Speedstep enabled and AMD K10 and newer. +
-          * AMD Opteron/Athlon64 PowerNow! (CONFIG_X86_POWERNOW_K8) This is for K8/early Opteron/Athlon64 processors. +
-          * Intel Enhanced SpeedStep (deprecated) (CONFIG_X86_SPEEDSTEP_CENTRINO [=n] This is a deprecated option that has been superseded by CONFIG_X86_ACPI_CPUFREQ, so leave this disabled. +
-          * Intel Pentium 4 clock modulation (CONFIG_X86_P4_CLOCKMOD [=n]) This is a hack for Pentium 4s that may cause severe slowdowns and noticeable latencies, so disable it.+
  
-<note important>It is recommended that the drivers be built-in to the kernel. If they are not, they may load automatically or you may have to load them yourself.</note>+Both Kernels (huge/generic) for Slackware 15 includes the necessary modules for all the CPU Frequency Scaling functions.\\ 
 +If you want to use a newer Kernel series or your own Kernel, the relevant options are found in the section **"Power management and ACPI options" under "CPU Frequency scaling"**.\\
  
-===== Configuring the kernel ===== +With AMD you should normally use the acpi-cpufreq driverbut exceptions applyWith Intel you will expose 3 different drivers: **intel_pstate****intel_cpufreq** (passive/acpi) and **acpi-cpufreq**.   
-Cpu frequency scaling can be done automatically by a so-called governoror manuallyThe governors available are "conservative""ondemand", "powersave" and "performance"When you build your own kernel, you can choose one of these governors or "userspace" which allows for configuring cpu frequency in userspace+Generally speaking you could say that Intel P-state is performance biased in general and that acpi-cpufreq gives you the maximum control (including performance bias)There are several options you can pass to the Kernel at bootbut if you want to disable p-states and use the acpi-cpufreq driver you pass **intel_pstate=disable** to the Kernel at boot time. These two options are the safe options, while other options could prevent a boot with certain CPU's. However, you might want to use another option depending on your cpu. \\ 
-The stock Slackware kernels are configured for "userspace" by default.+\\ 
 +You can pass these options at boot time to the Kernel command line with the bootloader, like Grub2, you add it after the Kernel line, the standard way of passing Kernel parameters at boot. 
 +\\
  
 +<!-- This section was a huge mess, so I removed the content and just added a snip of information here to keep the section. If it needs to be added, it is probably better to add it towards the end of the article to make it look less overwhelming  --- //[[wiki:user:zeebra|zeebra]] 2023/12/10 13:08 (UTC)//-->
  
-===== Checking the cpu frequency settings on your computer =====+===== /etc/rc.d/rc.cpufreq and /etc/default/cpufreq =====
  
-Slackware comes with the cpufrequtils package which helps to configure frequency scaling in an appropriate mannerYou can check the settings on your system with the command  +The main way to adjust frequency scaling in Slackware is to do so at boot time by making /etc/rc.d/rc.cpufreq executable.  
-<code>cpufreq-info</code>+<code>chmod +x /etc/rc.d/rc.cpufreq</code>  
 +And by selecting the governor to use by editing the file /etc/default/cpufreq. 
 +<code>nano /etc/default/cpufreq</code> 
 +<code># To select a particular CPU governor option for /etc/rc.d/rc.cpufreq, 
 +# uncomment the line below and edit it to select your choice: 
 +#SCALING_GOVERNOR=ondemand 
 +</code>
  
-Or using sysfs: +<note important>The necessary setup is done in /etc/rc.d/rc.cpufreq and it reads /etc/default/cpufreq to select the governor. These things do depend on what options are available to it, and those options depend on what choice you make at boot time and which driver is in use. If you use the acpi-cpufreq driver, you can select any of the available scaling governors, if intel_pstate is in use, it will ignore the choice if it cannot be parsed.</note>
-<code>cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor</code> +
-where "cpu*" per cpu subdir.+
  
 +After the initial setup of CPU frequency scaling at boot, scaling can also be controlled manually in a variety of ways, as described below.\\
 +\\
  
-===== The configuration ===== +====== Handling of CPU frequency scaling with cpufrequtils and /sys ====== 
-The cpufrequtils package provides two commands. With ''cpufreq-info'' you can find out which governor is configured and also some other information, for examplethe available frequencies for your processor.+Slackware comes with the ''cpufrequtils'' package which helps to configure frequency scaling in an appropriate manner. 
 + 
 +===== Checking the CPU frequency settings ===== 
 + 
 +You can check the settings on your system with the command  
 +<code bash>cpufreq-info</code> 
 + 
 +Or if you don't have the package installed: 
 +<code bash>cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 
 +cat /proc/cpuinfo</code> 
 +where "cpu*" is the CPU you want the info on, for example cpu0. 
 + 
 + 
 + 
 +===== Setting the CPU frequency settings ===== 
 +<!-- This section is still outdated and should be worked into how to use /sys and cpufrequtils insted --- //[[wiki:user:zeebra|zeebra]] 2023/12/10 15:53 (UTC)//-->
 The ''cpufreq-set'' command can be used to set the appropriate governor. The ''cpufreq-set'' command can be used to set the appropriate governor.
  
-===== Example ===== +You can set the scaling governor manually if you want, per cpu core.
-On my laptop I have the following lines in my ''/etc/rc.d/rc.local'' file+
 <code bash> <code bash>
-# CPU-frequency scaling 
 cpufreq-set --cpu 0 --governor conservative cpufreq-set --cpu 0 --governor conservative
 cpufreq-set --cpu 1 --governor conservative cpufreq-set --cpu 1 --governor conservative
 </code> </code>
  
-If using sysfs:+The same can be done using sysfs:
 <code bash> <code bash>
 echo "conservative" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor echo "conservative" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
Line 65: Line 80:
 as long as the interface exists. as long as the interface exists.
 ===== Further reading ===== ===== Further reading =====
-I recommend reading the manpages for cpufreq-info and cpufreq-set. Also you can read the relevant documentation in the kernel sources.+The manpages for ''cpufreq-info'' and ''cpufreq-set'' are useful 
 + 
 +The kernel ''Documentation/cpu-freq'' directory contains detailed explanations of CPU frequency drivers, governors, and other settings.
  
 A decent explanation of P states and how they are handled in the kernel: https://plus.google.com/+ArjanvandeVen/posts/dLn9T4ehywL A decent explanation of P states and how they are handled in the kernel: https://plus.google.com/+ArjanvandeVen/posts/dLn9T4ehywL
Line 75: Line 92:
   * Originally written by [[wiki:user:markush|Markus Hutmacher]]   * Originally written by [[wiki:user:markush|Markus Hutmacher]]
   * Updated by [[wiki:user:metaschima]]   * Updated by [[wiki:user:metaschima]]
 +  * Updated by [[wiki:user:zeebra]]
 <!-- * Contributions by [[wiki:user:yyy | User Y]] --> <!-- * Contributions by [[wiki:user:yyy | User Y]] -->
 +* Additional resources and sources: [[https://www.kernel.org/doc/html/v4.12/admin-guide/pm/intel_pstate.html]]\\
 +* Additional resources and sources: [[https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt]]\\
 +* Additional resources and sources: [[https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt]]\\
  
 <!-- Please do not modify anything below, except adding new tags.--> <!-- Please do not modify anything below, except adding new tags.-->
 <!-- You must remove the tag-word "template" below before saving your new page --> <!-- You must remove the tag-word "template" below before saving your new page -->
-{{tag>howtos CPU frequency Laptop}}+<!-- Some updates done, more will follow. Specifically a section about /etc/rc.d/ is high priority  --- //[[wiki:user:zeebra|zeebra]] 2023/12/10 13:34 (UTC)// --> 
 +{{tag>howtos CPU frequency Laptop cpu_frequency_scaling}}
 howtos:hardware:cpu_frequency_scaling ()