From 7043a9f77c2ad8e937850fce6f95ab66592d624a Mon Sep 17 00:00:00 2001 From: Tor Vic Date: Tue, 24 Sep 2024 16:17:47 +0200 Subject: [PATCH 1/6] tools/power/cpupower: Add documentation for some recently introduced options The 'cpupower-set' tool has been enhanced with new features: commit f2ab5557119a ("cpupower: Add EPP value change support") commit df8776b03689 ("cpupower: Add support for amd_pstate mode change") commit eb426fc6bdd6 ("cpupower: Add turbo-boost support in cpupower") However, the corresponding manpage was never updated. Add a basic description of these new options to the existing manpage. Commit description updated to fix checkpatch errors: Shuah Khan Signed-off-by: Tor Vic Signed-off-by: Shuah Khan --- tools/power/cpupower/man/cpupower-set.1 | 38 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tools/power/cpupower/man/cpupower-set.1 b/tools/power/cpupower/man/cpupower-set.1 index 2bcc696f44969..500653ef98c77 100644 --- a/tools/power/cpupower/man/cpupower-set.1 +++ b/tools/power/cpupower/man/cpupower-set.1 @@ -3,7 +3,7 @@ cpupower\-set \- Set processor power related kernel or hardware configurations .SH SYNOPSIS .ft B -.B cpupower set [ \-b VAL ] +.B cpupower set [ \-b VAL | \-e POLICY | \-m MODE | \-t BOOL ] .SH DESCRIPTION @@ -19,7 +19,7 @@ described in the Options sections. Use \fBcpupower info \fP to read out current settings and whether they are supported on the system at all. -.SH Options +.SH OPTIONS .PP \-\-perf-bias, \-b .RS 4 @@ -56,6 +56,40 @@ Use \fBcpupower -c all info -b\fP to verify. This options needs the msr kernel driver (CONFIG_X86_MSR) loaded. .RE +.PP +\-\-epp, \-e +.RS 4 +Sets the energy performance policy preference on supported Intel or AMD +processors which use the Intel or AMD P-State cpufreq driver respectively. + +Available policies can be found with +\fBcat /sys/devices/system/cpu/cpufreq/policy0/energy_performance_available_preferences\fP : +.RS 4 +default performance balance_performance balance_power power +.RE + +.RE + +.PP +\-\-amd\-pstate\-mode, \-m +.RS 4 +Sets the AMD P-State mode for supported AMD processors. +Available modes are "active", "guided" or "passive". + +Refer to the AMD P-State kernel documentation for further information. + +.RE + +.PP +\-\-turbo\-boost, \-t +.RS 4 +This option is used to enable or disable the turbo boost feature on +supported Intel and AMD processors. + +This option takes as parameter either \fB1\fP to enable, or \fB0\fP to disable the feature. + +.RE + .SH "SEE ALSO" cpupower-info(1), cpupower-monitor(1), powertop(1) .PP From c0dd6507ab20066f39993065a73d2687b97a848d Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Thu, 19 Sep 2024 20:08:11 +0800 Subject: [PATCH 2/6] pm: cpupower: bench: print config file path when open cpufreq-bench.conf fails Print out the config file path when fopen failed. It will be easy for users to know where to create the file. Since we are here, use strerror to drop the usage of perror. Signed-off-by: Peng Fan Signed-off-by: Shuah Khan --- tools/power/cpupower/bench/parse.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c index e63dc11fa3a53..080678d9d74e2 100644 --- a/tools/power/cpupower/bench/parse.c +++ b/tools/power/cpupower/bench/parse.c @@ -4,6 +4,7 @@ * Copyright (C) 2008 Christian Kornacker */ +#include #include #include #include @@ -165,8 +166,8 @@ int prepare_config(const char *path, struct config *config) configfile = fopen(path, "r"); if (configfile == NULL) { - perror("fopen"); - fprintf(stderr, "error: unable to read configfile\n"); + fprintf(stderr, "error: unable to read configfile: %s, %s\n", + path, strerror(errno)); free(config); return 1; } From f79473ed922023942407da25cb00843ac28b981c Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Thu, 19 Sep 2024 20:08:12 +0800 Subject: [PATCH 3/6] pm: cpupower: Makefile: Allow overriding cross-compiling env params Allow overriding the cross-comple env parameters to make it easier for Yocto users. Then cross-compiler toolchains to build cpupower with only two steps: - source (toolchain path)/environment-setup-armv8a-poky-linux - make Signed-off-by: Peng Fan Signed-off-by: Shuah Khan --- tools/power/cpupower/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile index 6c02f401069ec..e2a48af6fa2a5 100644 --- a/tools/power/cpupower/Makefile +++ b/tools/power/cpupower/Makefile @@ -86,12 +86,12 @@ INSTALL_SCRIPT = ${INSTALL} -m 644 # If you are running a cross compiler, you may want to set this # to something more interesting, like "arm-linux-". If you want # to compile vs uClibc, that can be done here as well. -CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- -CC = $(CROSS)gcc -LD = $(CROSS)gcc -AR = $(CROSS)ar -STRIP = $(CROSS)strip -RANLIB = $(CROSS)ranlib +CROSS ?= #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- +CC ?= $(CROSS)gcc +LD ?= $(CROSS)gcc +AR ?= $(CROSS)ar +STRIP ?= $(CROSS)strip +RANLIB ?= $(CROSS)ranlib HOSTCC = gcc MKDIR = mkdir From 08a26a15a4cdf5f2ca801dd0fbd6806233fbd6b6 Mon Sep 17 00:00:00 2001 From: "John B. Wyatt IV" Date: Mon, 30 Sep 2024 13:22:55 -0400 Subject: [PATCH 4/6] pm: cpupower: gitignore: Add compile_commands.json A compile_commands.json file is used by the LSP in tools like VSCode and Neovim to look up function and type information. The file is specific to the state of the current system; add it to the gitignore. Note: the kernel root's gitignore has a similar entry: /compile_commands.json I am not sure why they use '/' for a file as it is used for directories. Signed-off-by: "John B. Wyatt IV" Signed-off-by: "John B. Wyatt IV" Signed-off-by: Shuah Khan --- tools/power/cpupower/.gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/power/cpupower/.gitignore b/tools/power/cpupower/.gitignore index 7677329c42a64..5113d5a7aee0f 100644 --- a/tools/power/cpupower/.gitignore +++ b/tools/power/cpupower/.gitignore @@ -27,3 +27,6 @@ debug/i386/intel_gsic debug/i386/powernow-k8-decode debug/x86_64/centrino-decode debug/x86_64/powernow-k8-decode + +# Clang's compilation database file +compile_commands.json From 2314dca1b36629f352b0f919cdab16ca3fcaea42 Mon Sep 17 00:00:00 2001 From: "John B. Wyatt IV" Date: Mon, 30 Sep 2024 19:21:54 -0400 Subject: [PATCH 5/6] pm: cpupower: bindings: Improve disable c_state block This commit fixes a bad comment, removes an unneeded code block, and catches a few more states that cpuidle_state_disable with the test script. Part of the motivation for this commit was I kept forgetting to use sudo. Signed-off-by: "John B. Wyatt IV" Signed-off-by: "John B. Wyatt IV" Signed-off-by: Shuah Khan --- .../bindings/python/test_raw_pylibcpupower.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py b/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py index 3d6f62b9556ad..bb2b26db8b107 100755 --- a/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py +++ b/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py @@ -15,21 +15,21 @@ print(f"cstate count error: return code: {cpu_cstates_count}") """ -Disable cstate (will fail if the above is 0, ex: a virtual machine) +Disable cstate (will fail if the above returns is under 1, ex: a virtual machine) """ cstate_disabled = p.cpuidle_state_disable(0, 0, 1) -if cpu_cstates_count == 0: - print(f"CPU 0 has {cpu_cstates_count} c-states") -else: - print(f"cstate count error: return code: {cpu_cstates_count}") match cstate_disabled: case 0: print(f"CPU state disabled") case -1: print(f"Idlestate not available") + case -2: + print(f"Disabling is not supported by the kernel") + case -3: + print(f"No write access to disable/enable C-states: try using sudo") case _: - print(f"Not documented") + print(f"Not documented: {cstate_disabled}") # Pointer example From b6a2dbf88aa793a288f77e0eddb395f79594908f Mon Sep 17 00:00:00 2001 From: "John B. Wyatt IV" Date: Mon, 30 Sep 2024 19:21:55 -0400 Subject: [PATCH 6/6] pm: cpupower: bindings: Add test to confirm cpu state is disabled Add a simple test to confirm and print out the cpu state. Signed-off-by: "John B. Wyatt IV" Signed-off-by: "John B. Wyatt IV" Signed-off-by: Shuah Khan --- .../bindings/python/test_raw_pylibcpupower.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py b/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py index bb2b26db8b107..ca5aa46c9b207 100755 --- a/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py +++ b/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py @@ -31,6 +31,22 @@ case _: print(f"Not documented: {cstate_disabled}") +""" +Test cstate is disabled +""" +is_cstate_disabled = p.cpuidle_is_state_disabled(0, 0) + +match is_cstate_disabled: + case 1: + print(f"CPU is disabled") + case 0: + print(f"CPU is enabled") + case -1: + print(f"Idlestate not available") + case -2: + print(f"Disabling is not supported by kernel") + case _: + print(f"Not documented: {is_cstate_disabled}") # Pointer example