How to use the command 'cpupower' (with examples)

How to use the command 'cpupower' (with examples)

The ‘cpupower’ command is a tool that provides options for managing CPU power and tuning. It allows users to control CPU frequency scaling, manage power-saving governors, and retrieve information about CPU cores and their available options.

Use case 1: List CPUs

Code:

sudo cpupower --cpu all info

Motivation: This command is used to retrieve information about all available CPUs in the system. It can be helpful for monitoring and troubleshooting purposes.

Explanation:

  • sudo: This command requires administrative privileges to retrieve system-level information.
  • cpupower: Invokes the ‘cpupower’ command.
  • --cpu all: Specifies that information should be provided for all available CPUs.
  • info: Instructs ‘cpupower’ to display the information.

Example output:

CPU 0:
          analyzing CPU 0:
          Intel P-state, schedutil, performance
          available cpufreq governors: performance, powersave
          hardware limits: 1.20 GHz - 3.60 GHz
          available frequency steps: 3.60 GHz, 3.50 GHz, 3.40 GHz, 3.30 GHz, 3.20 GHz, 3.10 GHz, 3.00 GHz, 2.90 GHz ...

Use case 2: Print information about all cores

Code:

sudo cpupower --cpu all info

Motivation: This command is used to retrieve detailed information about all CPU cores in the system. It can be useful for understanding the capabilities and configurations of each core.

Explanation:

  • sudo: This command requires administrative privileges to retrieve system-level information.
  • cpupower: Invokes the ‘cpupower’ command.
  • --cpu all: Specifies that information should be provided for all available CPUs.
  • info: Instructs ‘cpupower’ to display the information.

Example output:

analyzing CPU 0:
          Intel P-state, schedutil, performance
          available cpufreq governors: performance, powersave
          hardware limits: 1.20 GHz - 3.60 GHz
          available frequency steps: 3.60 GHz, 3.50 GHz, 3.40 GHz, 3.30 GHz, 3.20 GHz, 3.10 GHz, 3.00 GHz, 2.90 GHz ...

analyzing CPU 1:
          Intel P-state, schedutil, performance
          available cpufreq governors: performance, powersave
          hardware limits: 1.20 GHz - 3.60 GHz
          available frequency steps: 3.60 GHz, 3.50 GHz, 3.40 GHz, 3.30 GHz, 3.20 GHz, 3.10 GHz, 3.00 GHz, 2.90 GHz ...

Use case 3: Set all CPUs to a power-saving frequency governor

Code:

sudo cpupower --cpu all frequency-set --governor powersave

Motivation: This command is useful when you want to conserve power by setting all CPUs to a power-saving frequency governor. This can help reduce energy consumption and prolong battery life on laptops.

Explanation:

  • sudo: This command requires administrative privileges to make changes to system settings.
  • cpupower: Invokes the ‘cpupower’ command.
  • --cpu all: Specifies that the action should be performed on all available CPUs.
  • frequency-set: Instructs ‘cpupower’ to change the CPU frequency settings.
  • --governor powersave: Sets the governor for all CPUs to ‘powersave’, which prioritizes power saving over performance.

Example output: No output is displayed if the command is executed successfully. The changes take effect immediately.

Use case 4: Print CPU 0’s available frequency governors

Code:

sudo cpupower --cpu 0 frequency-info g | grep "analyzing\|governors"

Motivation: This command is used to retrieve information about the available frequency governors for a specific CPU. It can be helpful for analyzing and selecting the appropriate governor based on specific requirements.

Explanation:

  • sudo: This command requires administrative privileges to retrieve system-level information.
  • cpupower: Invokes the ‘cpupower’ command.
  • --cpu 0: Specifies that the information should be retrieved for CPU 0.
  • frequency-info: Instructs ‘cpupower’ to display frequency-related information.
  • g: Specifies that only the governor-related information should be displayed.
  • grep "analyzing\|governors": Filters the output to include only lines containing the words “analyzing” or “governors”.

Example output:

analyzing CPU 0:
          available cpufreq governors: performance, powersave

Use case 5: Print CPU 4’s frequency from the hardware, in a human-readable format

Code:

sudo cpupower --cpu 4 frequency-info --hwfreq --human

Motivation: This command is used to retrieve the current frequency of a specific CPU (CPU 4 in this case) directly from the hardware. It provides the frequency information in a human-readable format.

Explanation:

  • sudo: This command requires administrative privileges to retrieve system-level information.
  • cpupower: Invokes the ‘cpupower’ command.
  • --cpu 4: Specifies that the information should be retrieved for CPU 4.
  • frequency-info: Instructs ‘cpupower’ to display frequency-related information.
  • --hwfreq: Specifies that the frequency information should be obtained from the hardware.
  • --human: Formats the output in a human-readable format.

Example output:

current CPU frequency: 2.30 GHz (asserted by BIOS)

Conclusion:

The ‘cpupower’ command is a versatile tool for managing CPU power and tuning options. It allows users to retrieve information about CPUs, set power-saving governors, and monitor frequency-related details. By using the various options and arguments provided by ‘cpupower’, users can efficiently manage CPU performance and power consumption according to their specific requirements.

Related Posts

How to use the command 'tlmgr' (with examples)

How to use the command 'tlmgr' (with examples)

The command ’tlmgr’ is used to manage packages and configuration options of an existing TeX Live installation.

Read More
How to use the command "is-up" (with examples)

How to use the command "is-up" (with examples)

The command “is-up” is a CLI tool that allows you to check whether a website is up or down.

Read More
How to use the command 'git reflog' (with examples)

How to use the command 'git reflog' (with examples)

Git reflog is a command that shows a log of changes to local references like HEAD, branches, or tags.

Read More