Linux Foundation Wiki

project collaboration site

User Tools

Site Tools


realtime:documentation:howto:debugging:no-cpu-idle

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
realtime:documentation:howto:debugging:no-cpu-idle [2018/07/16 11:04]
ebugden Specify that there are two different methods of modifying the kernel param
realtime:documentation:howto:debugging:no-cpu-idle [2018/08/27 09:56]
ebugden Make kernel parameter changing method explanation more general
Line 27: Line 27:
 </​code>​ </​code>​
  
-After compilation,​ an instance of the program can be pinned to each CPU using the //taskset// program. For example, below is a script that will make sure that a system with 4 CPUs will never go idle using a simple program called cpu-no-idle:​+After compilation,​ an instance of the program can be pinned to each CPU using the [[realtime:​documentation:​howto:​tools:​cpu-partitioning:​taskset|taskset]] ​program. For example, below is a script that will make sure that a system with 4 CPUs will never go idle using a simple program called cpu-no-idle:​
  
 <code bash> <code bash>
Line 44: Line 44:
 </​code>​ </​code>​
  
-===== Kernel ​boot parameter: idle =====+===== Kernel ​command-line ​parameter =====
  
-Another way to make sure that the CPUs never go idle is to change the value of the Linux kernel boot parameter "​idle"​. This technique does not prevent the idle task from executing, but it prevents the idle task from putting the CPUs in low power idle stateThis method is permanent for the duration of the system'​s executionSo, to allow the system to go idle again the parameter ​must be modified and the system must be restarted.+Another way to make sure that the CPUs never go idle is to change the value of a [[https://​www.kernel.org/​doc/​html/​latest/​admin-guide/​kernel-parameters.html|kernel command-line ​parameter]]. A couple of options of parameters that can be used to prevent deeper CPU sleep states are presented below.
  
-To prevent the CPUs from going idle using the technique, the option idle=poll must be added to the command-line parameters passed to the kernel when it is executed on startup. This option forces the processor to poll when it has nothing to do instead of going into a low power idle state. More details about the "​idle"​ option can be found in the Linux documentation about kernel parameters. ​Two methods ​for changing ​the "idle" ​are presented below, a method where the new kernel parameter value is permanent until explicitly changed ​and a method where the kernel parameter applies ​for a single execution ​of the kernel.+These methods are permanent for the duration of the system'​s execution. So, to allow the system to resume its original behavior the parameter must be modified and the system must be restarted. Two methods for changing parameters are presented, a method where the new kernel parameter value is permanent until explicitly changed and a method where the kernel parameter applies for a single execution of the kernel. The idle parameter is used as an example to aid in the explanation of these methods, but the techniques below apply for any kernel command-line parameter. 
 + 
 +==== idle parameter ==== 
 + 
 +A parameter that can be used to prevent a system'​s CPUs from idling is the boot parameter "​idle"​. Changing this parameter does not prevent the idle task from executing, but it prevents the idle task from putting the CPUs in a low power idle state.  
 + 
 +To prevent the CPUs from going idle using the technique, the option idle=poll must be added to the command-line parameters passed to the kernel when it is executed on startup. This option forces the processor to poll when it has nothing to do instead of going into a low power idle state. More details about the "​idle"​ option can be found in the Linux documentation about [[https://​www.kernel.org/​doc/​html/​latest/​admin-guide/​kernel-parameters.html|kernel parameters]]. 
 + 
 +==== max_cstate parameters ==== 
 + 
 +One common motivation ​for wanting to prevent CPU idling is avoiding gaps in kernel function traces that can be mistaken for unusual firmware or hardware caused latencies. The max_cstate parameters //cannot be used to prevent CPU idling//, but they can be used to prevent gaps in function traces. 
 + 
 +A max_cstate kernel parameter can be used to limit the maximum C-State. Limiting the maximum C-State to 1 will prevent having noticeable gaps in full function traces. Briefly, C-States are different power saving ​idle states. C-States 1 and up are progressively deeper processor sleep states. C-State zero represents a processor that is not idle. C-State 1 is an idle statebut it is very "​shallow"​ idle state so it takes almost no time for the processor to enter and exit C-State 1 (around 1 us). This means that going in and out of C-State 1 will not create noticeable gaps in trace. 
 + 
 +There are two max_cstate boot parameters that can be used for this, processor.max_cstate (which limits ​the maximum C-State ​for the acpi_idle driver) and intel_idle.max_cstate (which limits the maximum C-state for the intel_idle driver). The value of one of these parameters must be set to 1 (e.g. intel_idle.max_cstate=1). Only one of these boot parameters needs to be specified in the command-line depending on which idle driver is used by the kernel. The idle driver that is currently loaded can be checked via sysfs: 
 + 
 +<code bash> 
 +# cat /​sys/​devices/​system/​cpu/​cpuidle/​current_driver 
 +</​code>​ 
 + 
 +However, there is also no harm in covering all possibilities and specifying a limit for both intel_idle and acpi_idle. 
 + 
 +Using a max_cstate parameter to prevent trace gaps is better than using the idle parameter because allowing the CPUs to enter C-State 1 will save power compared to forcing them to poll when they have nothing to do.
  
 ==== Change parameter permanently ==== ==== Change parameter permanently ====
  
-To make the option changes persistent when the system is restarted, add idle=poll to the contents of the GRUB_CMDLINE_LINUX field in the /​etc/​default/​grub file. The user must be root or use sudo to modify this file. Here is an example of what the line in the file could look like after being modified:+To make the option changes persistent when the system is restarted, add the parameter and its desired value (e.g. idle=pollto the contents of the GRUB_CMDLINE_LINUX field in the /​etc/​default/​grub file. The user must be root or use sudo to modify this file. Here is an example of what the line in the file could look like after being modified:
  
 <​code>​ <​code>​
Line 72: Line 94:
 </​code>​ </​code>​
  
-To make the temporary change, add idle=poll to the end of the line so that it looks like this:+To make the temporary change, add the kernel parameter and its value (e.g. idle=pollto the end of the line so that it looks like this:
  
 <​code>​ <​code>​
Line 88: Line 110:
 </​code>​ </​code>​
  
-and make sure that idle=poll is somewhere in the output.+and make sure that the kernel parameter and its value (e.g. idle=pollis somewhere in the output.
realtime/documentation/howto/debugging/no-cpu-idle.txt · Last modified: 2018/08/27 09:56 by ebugden