cpufreq.c: add new test for cpufreq sysfs interface validation
PATCH v8 1/1 cpufreq.c: add new test for cpufreq sysfs interface validation
Runs various sanity checks for intel_pstate cpufreq sysfs interface.
Checks whether intel_pstate driver is used, whether it is possible to switch scaling_governor to powersave and performance, whether it is possible to disable turbo frequency and whether it is possible to change scaling_min_freq and scaling_max_freq to its minimal valid and maximal valid values.
Requires root to write to /sys/devices/system/cpu/intel_pstate/ (status, no_turbo) and per-CPU /sys/devices/system/cpu/cpu*\/cpufreq/ attributes (scaling_governor, scaling_min_freq, scaling_max_freq).
Motivation: LTP has no regression coverage for the intel_pstate cpufreq sysfs interface, so breakage in any of these attributes (driver exposure, governor switching, active/passive mode transitions, no_turbo toggling or scaling_{min,max}_freq writes) can reach users undetected. This test exercises the interface end-to-end to catch such regressions.
---
Address further review:
1. better commit message.
2. drop SAFE_READ().
3. reset setup_done.
runtest/power_management_tests | 1 + testcases/kernel/power_management/.gitignore | 1 + testcases/kernel/power_management/cpufreq.c | 410 +++++++++++++++++++ 3 files changed, 412 insertions(+) create mode 100644 testcases/kernel/power_management/.gitignore create mode 100644 testcases/kernel/power_management/cpufreq.c
runtest/power_management_tests +1 -0
@@ -1,4 +1,5 @@ #POWER_MANAGEMENT +cpufreq cpufreq runpwtests03 runpwtests03.sh runpwtests04 runpwtests04.sh runpwtests06 runpwtests06.sh
testcases/kernel/power_management/.gitignore new file +1 -0
@@ -0,0 +1 @@ +cpufreq
testcases/kernel/power_management/cpufreq.c new file +410 -0
410 lines not on this page · raw message
Signature · 13 lines
2.47.3 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Piotr,
Quoted 1 line · Piotr Kubaj
cpufreq.c: add new test for cpufreq sysfs interface validation
---
Note:
Our agent completed the review of the patch. The full review can be found at: https://patchwork.ozlabs.org/project/ltp/list/?series=503158
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Ping. AI bot says it's ok, no other review. I guess it's ready to merge?
2026-05-07 (木) の 13:11 +0200 に Piotr Kubaj さんは書きました:
Quoted 595 lines
Runs various sanity checks for
intel_pstatecpufreq sysfs interface.Checks whether
intel_pstatedriver is used, whether it is possible to switchscaling_governorto powersave and performance, whether it is possible to disable turbo frequency and whether it is possible to changescaling_min_freqandscaling_max_freqto its minimal valid and maximal
valid values.Requires root to write to
/sys/devices/system/cpu/intel_pstate/(status,no_turbo) and per-CPU /sys/devices/system/cpu/cpu*\/cpufreq/ attributes
(scaling_governor,scaling_min_freq,scaling_max_freq).Motivation: LTP has no regression coverage for the
intel_pstatecpufreq
sysfs interface, so breakage in any of these attributes (driver exposure, governor switching, active/passive mode transitions,no_turbo
toggling or scaling_{min,max}_freq writes) can reach users undetected.
This test exercises the interface end-to-end to catch such regressions.Signed-off-by Piotr Kubaj <[email protected]>---
Address further review:
1. better commit message.
2. dropSAFE_READ().
3. resetsetup_done. runtest/power_management_tests | 1 + testcases/kernel/power_management/.gitignore | 1 + testcases/kernel/power_management/cpufreq.c | 410
+++++++++++++++++++3 files changed, 412 insertions(+)create mode 100644 testcases/kernel/power_management/.gitignore create mode 100644
testcases/kernel/power_management/cpufreq.cruntest/power_management_tests +1
-0@@ -1,4 +1,5 @@ #POWER_MANAGEMENT +cpufreq cpufreqrunpwtests03
runpwtests03.sh
runpwtests04runpwtests04.sh
runpwtests06runpwtests06.shtestcases/kernel/power_management/.gitignore new file +1
-0@@ -0,0 +1 @@ +cpufreqtestcases/kernel/power_management/cpufreq.c new file +7
-0@@ -0,0 +1,410 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2026 Piotr Kubaj <[email protected]> +*/ + +/*\ +* Runs various sanity checks for intel_pstate cpufreq sysfs interface.
+ *
+ * Checks whetherintel_pstatedriver is used, whether it is possible to switch
+ *scaling_governorto powersave and performance, whether it is possible
+ * to disable turbo frequency and whether it is possible to change
+ *scaling_min_freqandscaling_max_freqto its minimal valid and maximal valid
+ * values.
+ *
+ * Requires root to write to/sys/devices/system/cpu/intel_pstate/(status,
+ *no_turbo) and per-CPU /sys/devices/system/cpu/cpu*\/cpufreq/ attributes
+ * (scaling_governor,scaling_min_freq,scaling_max_freq).
+ *
+ * Motivation: LTP has no regression coverage for theintel_pstatecpufreq
+ * sysfs interface, so breakage in any of these attributes (driver exposure,
+ * governor switching, active/passive mode transitions,no_turbotoggling or
+ * scaling_{min,max}_freq writes) can reach users undetected. This test
+ * exercises the interface end-to-end to catch such regressions.
+ */testcases/kernel/power_management/cpufreq.c new file +23
-0+ +#include "tst_test.h" + +static bool *online; +static bool setup_done; +static char intel_pstate_status[16 ]; +static char (*previous_scaling_governor)[16 ]; +static int no_turbo, nproc; +static long *previous_scaling_max_freq, *previous_scaling_min_freq; + +static void cleanup (void ) +{ +char path[PATH_MAX ]; + +if (!setup_done) { +free (online); +free (previous_scaling_max_freq); +free (previous_scaling_min_freq); +free (previous_scaling_governor); +return ; + } + + SAFE_FILE_PRINTF("/sys/devices/system/cpu/intel_pstate/status", "%s",
intel_pstate_status);testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_PRINTF("/sys/devices/system/cpu/intel_pstate/no_turbo", "%d",
no_turbo);testcases/kernel/power_management/cpufreq.c new file +6
-0+ +for (int i =0 ; i < nproc; i++) { +if (!online[i]) +continue ; + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_PRINTF(path, "%s",previous_scaling_governor[i]);
testcases/kernel/power_management/cpufreq.c new file +2
-0+ + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_PRINTF(path, "%ld",previous_scaling_max_freq[i]);
testcases/kernel/power_management/cpufreq.c new file +2
-0+ + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_PRINTF(path, "%ld",previous_scaling_min_freq[i]);
testcases/kernel/power_management/cpufreq.c new file +14
-0+ } + +free (online); +free (previous_scaling_max_freq); +free (previous_scaling_min_freq); +free (previous_scaling_governor); + setup_done = false; +} + +static void setup (void ) +{ +char path[PATH_MAX ]; + + if (access("/sys/devices/system/cpu/intel_pstate/status",
F_OK) == -1)testcases/kernel/power_management/cpufreq.c new file +3
-0+tst_brk (TCONF ,"intel_pstate driver not active" ); + + SAFE_FILE_SCANF("/sys/devices/system/cpu/intel_pstate/no_turbo", "%d",
&no_turbo);testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_SCANF("/sys/devices/system/cpu/intel_pstate/status", "%15s",
intel_pstate_status);testcases/kernel/power_management/cpufreq.c new file +4
-0+ + nproc =tst_ncpus_conf (); + online =SAFE_CALLOC (nproc,sizeof (*online)); + previous_scaling_max_freq = SAFE_CALLOC(nproc,
sizeof(*previous_scaling_max_freq));testcases/kernel/power_management/cpufreq.c new file +1
-0+ previous_scaling_min_freq = SAFE_CALLOC(nproc,
sizeof(*previous_scaling_min_freq));testcases/kernel/power_management/cpufreq.c new file +1
-0+ previous_scaling_governor = SAFE_CALLOC(nproc,
sizeof(*previous_scaling_governor));testcases/kernel/power_management/cpufreq.c new file +5
-0+ online[0 ] = true; +for (int i =1 ; i < nproc; i++) { +int tmp; + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/online", i);
testcases/kernel/power_management/cpufreq.c new file +8
-0+SAFE_FILE_SCANF (path,"%d" , &tmp); + online[i] = (bool )tmp; + } +for (int i =0 ; i < nproc; i++) { +if (!online[i]) +continue ; + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_SCANF(path, "%15s",previous_scaling_governor[i]);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_SCANF(path, "%ld",&previous_scaling_max_freq[i]);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_SCANF(path, "%ld",&previous_scaling_min_freq[i]);
testcases/kernel/power_management/cpufreq.c new file +3
-0+ } + + SAFE_FILE_PRINTF("/sys/devices/system/cpu/intel_pstate/status", "active");
testcases/kernel/power_management/cpufreq.c new file +22
-0+ + setup_done = true; +} + +static void run (void ) +{ +const char *const cpufreq_nodes[] = { +"affected_cpus" , +"cpuinfo_max_freq" , +"cpuinfo_min_freq" , +"cpuinfo_transition_latency" , +"related_cpus" , +"scaling_available_governors" , +"scaling_cur_freq" , +"scaling_driver" , +"scaling_governor" , +"scaling_max_freq" , +"scaling_min_freq" , +"scaling_setspeed" , +NULL + }; + char contents[256] = {0}, path[PATH_MAX],path_cpuinfo_min_freq[PATH_MAX];
testcases/kernel/power_management/cpufreq.c new file +2
-0+int no_turbo_val; + long cpuinfo_max_freq = 0, cpuinfo_min_freq = 0,
scaling_max_freq,scaling_min_freq;testcases/kernel/power_management/cpufreq.c new file +6
-0+ +for (int i =0 ; i < nproc; i++) { +if (!online[i]) +continue ; + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_driver", i);
testcases/kernel/power_management/cpufreq.c new file +3
-0+ +SAFE_FILE_SCANF (path,"%255s" , contents); + tst_res(TDEBUG, "Checking whether %s is\"intel_pstate\"", path);
testcases/kernel/power_management/cpufreq.c new file +4
-0+if (strstr (contents,"intel_pstate" )) { +tst_res (TPASS ,"%s is intel_pstate" , path); + }else { + tst_res(TINFO, "%s contains: %s", path,contents);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TFAIL, "%s is not intel_pstate",path);
testcases/kernel/power_management/cpufreq.c new file +6
-0+ } + +for (int j =0 ; cpufreq_nodes[j]; j++) { +struct stat stats; + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/%s", i, cpufreq_nodes[j]);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TDEBUG, "Checking whether %s is aregular file", path);
testcases/kernel/power_management/cpufreq.c new file +3
-0+SAFE_STAT (path, &stats); +if (!S_ISREG (stats.st_mode)) { + tst_res(TINFO, "%s mode: %o", path,stats.st_mode);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TFAIL, "%s is not a regularfile", path);
testcases/kernel/power_management/cpufreq.c new file +2
-0+ }else { + tst_res(TPASS, "%s is a regularfile", path);
testcases/kernel/power_management/cpufreq.c new file +4
-0+ } + } + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_governors", i);
testcases/kernel/power_management/cpufreq.c new file +4
-0+memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255[^\n]" , contents); + + tst_res(TDEBUG, "Checking whether %s contains\"performance\" and \"powersave\"", path);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ if (strstr(contents, "performance") &&
strstr(contents, "powersave")) {testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TPASS, "%s contains: %s", path,contents);
testcases/kernel/power_management/cpufreq.c new file +2
-0+ }else { + tst_res(TINFO, "%s contains: %s", path,contents);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TFAIL, "%s is not \"performancepowersave\"", path);
testcases/kernel/power_management/cpufreq.c new file +3
-0+ } + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", i);
testcases/kernel/power_management/cpufreq.c new file +5
-0+tst_res (TDEBUG ,"Checking %s" , path); +memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255s" , contents); +if (strstr (contents,"performance" )) { + tst_res(TDEBUG, "%s is \"performance\"",path);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TDEBUG, "Checking whether %s can beswitched to \"powersave\"", path);
testcases/kernel/power_management/cpufreq.c new file +5
-0+SAFE_FILE_PRINTF (path,"powersave" ); +memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255s" , contents); +if (strstr (contents,"powersave" )) + tst_res(TPASS, "Changing
scaling_governorfrom performance to powersave succeeded");testcases/kernel/power_management/cpufreq.c new file +2
-0+else + tst_res(TFAIL, "%s: failed to change
scaling_governorfrom performance to powersave, currentscaling_governor: %s", path, contents);testcases/kernel/power_management/cpufreq.c new file +3
-0+ + }else if (strstr (contents,"powersave" )) { + tst_res(TDEBUG, "%s is \"powersave\"",path);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TDEBUG, "Checking whether %s can beswitched to \"performance\"", path);
testcases/kernel/power_management/cpufreq.c new file +5
-0+SAFE_FILE_PRINTF (path,"performance" ); +memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255s" , contents); +if (strstr (contents,"performance" )) + tst_res(TPASS, "Changing
scaling_governorfrom powersave to performance succeeded");testcases/kernel/power_management/cpufreq.c new file +2
-0+else + tst_res(TFAIL, "%s: failed to change
scaling_governorfrom powersave to performance, currentscaling_governor: %s", path, contents);testcases/kernel/power_management/cpufreq.c new file +3
-0+ + }else { + tst_brk(TBROK, "Unknown scaling_governor:%s", contents);
testcases/kernel/power_management/cpufreq.c new file +3
-0+ } + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ snprintf(path_cpuinfo_min_freq,
sizeof(path_cpuinfo_min_freq), "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", i);testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TDEBUG, "Checking whether %s is bigger than
cpuinfo_min_freq", path);testcases/kernel/power_management/cpufreq.c new file +3
-0+SAFE_FILE_SCANF (path,"%ld" , &cpuinfo_max_freq); + + SAFE_FILE_SCANF(path_cpuinfo_min_freq, "%ld",
&cpuinfo_min_freq);testcases/kernel/power_management/cpufreq.c new file +3
-0+ +if (cpuinfo_min_freq > cpuinfo_max_freq) + tst_res(TFAIL, "Value in %s: %ld, should bebigger than
cpuinfo_min_freq: %ld", path,cpuinfo_max_freq,cpuinfo_min_freq);testcases/kernel/power_management/cpufreq.c new file +2
-0+else + tst_res(TPASS, "Value in %s: %ld, is biggerthan
cpuinfo_min_freq: %ld", path,cpuinfo_max_freq,cpuinfo_min_freq);testcases/kernel/power_management/cpufreq.c new file +3
-0+ } + + snprintf(path, sizeof(path),"
/sys/devices/system/cpu/intel_pstate/status");testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TDEBUG, "Checking whether %s contains \"active\"",path);
testcases/kernel/power_management/cpufreq.c new file +7
-0+memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255s" , contents); + +if (strstr (contents,"active" )) +tst_res (TPASS ,"%s is \"active\"" , path); +else + tst_res(TFAIL, "%s is not \"active\", but %s", path,contents);
testcases/kernel/power_management/cpufreq.c new file +2
-0+ + tst_res(TDEBUG, "Checking whether %s can be switched to\"passive\"", path);
testcases/kernel/power_management/cpufreq.c new file +8
-0+SAFE_FILE_PRINTF (path,"passive" ); +memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255s" , contents); + +if (strstr (contents,"passive" )) +tst_res (TPASS ,"%s is \"passive\"" , path); +else + tst_res(TFAIL, "%s is not \"passive\", but %s",path, contents);
testcases/kernel/power_management/cpufreq.c new file +2
-0+ + tst_res(TDEBUG, "Checking whether %s can be switched back to\"active\"", path);
testcases/kernel/power_management/cpufreq.c new file +8
-0+SAFE_FILE_PRINTF (path,"active" ); +memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255s" , contents); + +if (strstr (contents,"active" )) +tst_res (TPASS ,"%s is \"active\"" , path); +else + tst_res(TFAIL, "%s is not \"active\", but %s", path,contents);
testcases/kernel/power_management/cpufreq.c new file +2
-0+ + snprintf(path, sizeof(path),"
/sys/devices/system/cpu/intel_pstate/no_turbo");testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TDEBUG, "Checking whether %s can be switched to 1",path);
testcases/kernel/power_management/cpufreq.c new file +7
-0+SAFE_FILE_PRINTF (path,"1" ); +SAFE_FILE_SCANF (path,"%d" , &no_turbo_val); + +if (no_turbo_val ==1 ) +tst_res (TPASS ,"%s is \"1\"" , path); +else + tst_res(TFAIL, "%s is not \"1\", but %d", path,
no_turbo_val);testcases/kernel/power_management/cpufreq.c new file +2
-0+ + tst_res(TDEBUG, "Checking whether %s can be switched back to0", path);
testcases/kernel/power_management/cpufreq.c new file +7
-0+SAFE_FILE_PRINTF (path,"0" ); +SAFE_FILE_SCANF (path,"%d" , &no_turbo_val); + +if (no_turbo_val ==0 ) +tst_res (TPASS ,"%s is \"0\"" , path); +else + tst_res(TFAIL, "%s is not \"0\", but %d", path,
no_turbo_val);testcases/kernel/power_management/cpufreq.c new file +2
-0+ + tst_res(TDEBUG, "Checking whether
scaling_available_governorscontains \"performance\" and \"schedutil\" after switching/sys/devices/system/cpu/intel_pstate/statusto \"passive\"");testcases/kernel/power_management/cpufreq.c new file +1
-0+ snprintf(path, sizeof(path),"
/sys/devices/system/cpu/intel_pstate/status");testcases/kernel/power_management/cpufreq.c new file +7
-0+SAFE_FILE_PRINTF (path,"passive" ); + +for (int i =0 ; i < nproc; i++) { +if (!online[i]) +continue ; + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_governors", i);
testcases/kernel/power_management/cpufreq.c new file +4
-0+memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255[^\n]" , contents); + + tst_res(TDEBUG, "Checking whether %s contains\"performance\" and \"schedutil\"", path);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ if (strstr(contents, "performance") &&
strstr(contents, "schedutil")) {testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TPASS, "%s contains: %s", path,contents);
testcases/kernel/power_management/cpufreq.c new file +2
-0+ }else { + tst_res(TINFO, "%s contains: %s", path,contents);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TFAIL, "%s does not contain\"performance\" and \"schedutil\"", path);
testcases/kernel/power_management/cpufreq.c new file +3
-0+ } + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TDEBUG, "Checking whether %s can be changedto performance", path);
testcases/kernel/power_management/cpufreq.c new file +6
-0+SAFE_FILE_PRINTF (path,"performance" ); +memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255s" , contents); + +if (strstr (contents,"performance" )) + tst_res(TPASS, "%s is \"performance\"",path);
testcases/kernel/power_management/cpufreq.c new file +2
-0+else + tst_res(TFAIL, "%s is not \"performance\",but %s", path, contents);
testcases/kernel/power_management/cpufreq.c new file +2
-0+ + tst_res(TDEBUG, "Checking whether %s can be changedto schedutil", path);
testcases/kernel/power_management/cpufreq.c new file +8
-0+SAFE_FILE_PRINTF (path,"schedutil" ); +memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255s" , contents); + +if (strstr (contents,"schedutil" )) +tst_res (TPASS ,"%s is \"schedutil\"" , path); +else + tst_res(TFAIL, "%s is not \"schedutil\", but%s", path, contents);
testcases/kernel/power_management/cpufreq.c new file +7
-0+ } + +for (int i =0 ; i < nproc; i++) { +if (!online[i]) +continue ; + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TDEBUG, "Checking whether %s can be assignedto
scaling_max_freqandscaling_min_freq", path);testcases/kernel/power_management/cpufreq.c new file +3
-0+SAFE_FILE_SCANF (path,"%ld" , &cpuinfo_max_freq); + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", i);
testcases/kernel/power_management/cpufreq.c new file +3
-0+SAFE_FILE_SCANF (path,"%ld" , &cpuinfo_min_freq); + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i);
testcases/kernel/power_management/cpufreq.c new file +5
-0+SAFE_FILE_PRINTF (path,"%ld" , cpuinfo_max_freq); +SAFE_FILE_SCANF (path,"%ld" , &scaling_max_freq); + +if (cpuinfo_max_freq < scaling_max_freq) { + tst_res(TINFO, "cpuinfo_max_freq: %ld",
cpuinfo_max_freq);testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TINFO, "scaling_max_freq: %ld",
scaling_max_freq);testcases/kernel/power_management/cpufreq.c new file +3
-0+tst_res (TFAIL ,"Failure setting %s" , path); + }else { + tst_res(TPASS, "Successfully set up %s",path);
testcases/kernel/power_management/cpufreq.c new file +3
-0+ } + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", i);
testcases/kernel/power_management/cpufreq.c new file +5
-0+SAFE_FILE_PRINTF (path,"%ld" , cpuinfo_max_freq); +SAFE_FILE_SCANF (path,"%ld" , &scaling_min_freq); + +if (cpuinfo_max_freq < scaling_min_freq) { + tst_res(TINFO, "cpuinfo_max_freq: %ld",
cpuinfo_max_freq);testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TINFO, "scaling_min_freq: %ld",
scaling_min_freq);testcases/kernel/power_management/cpufreq.c new file +3
-0+tst_res (TFAIL ,"Failure setting %s" , path); + }else { + tst_res(TPASS, "Successfully set up %s",path);
testcases/kernel/power_management/cpufreq.c new file +3
-0+ } + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_PRINTF(path, "%ld",previous_scaling_min_freq[i]);
testcases/kernel/power_management/cpufreq.c new file +2
-0+ + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_PRINTF(path, "%ld",previous_scaling_max_freq[i]);
testcases/kernel/power_management/cpufreq.c new file +7
-0+ } + +for (int i =0 ; i < nproc; i++) { +if (!online[i]) +continue ; + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TDEBUG, "Checking whether %s can be assignedto
scaling_max_freqandscaling_min_freq", path);testcases/kernel/power_management/cpufreq.c new file +3
-0+SAFE_FILE_SCANF (path,"%ld" , &cpuinfo_max_freq); + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_min_freq", i);
testcases/kernel/power_management/cpufreq.c new file +3
-0+SAFE_FILE_SCANF (path,"%ld" , &cpuinfo_min_freq); + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", i);
testcases/kernel/power_management/cpufreq.c new file +5
-0+SAFE_FILE_PRINTF (path,"%ld" , cpuinfo_min_freq); +SAFE_FILE_SCANF (path,"%ld" , &scaling_min_freq); + +if (cpuinfo_min_freq > scaling_min_freq) { + tst_res(TINFO, "cpuinfo_min_freq: %ld",
cpuinfo_min_freq);testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TINFO, "scaling_min_freq: %ld",
scaling_min_freq);testcases/kernel/power_management/cpufreq.c new file +3
-0+tst_res (TFAIL ,"Failure setting %s" , path); + }else { + tst_res(TPASS, "Successfully set up %s",path);
testcases/kernel/power_management/cpufreq.c new file +3
-0+ } + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", i);
testcases/kernel/power_management/cpufreq.c new file +5
-0+SAFE_FILE_PRINTF (path,"%ld" , cpuinfo_min_freq); +SAFE_FILE_SCANF (path,"%ld" , &scaling_max_freq); + +if (cpuinfo_min_freq > scaling_max_freq) { + tst_res(TINFO, "cpuinfo_min_freq: %ld",
cpuinfo_min_freq);testcases/kernel/power_management/cpufreq.c new file +1
-0+ tst_res(TINFO, "scaling_max_freq: %ld",
scaling_max_freq);testcases/kernel/power_management/cpufreq.c new file +3
-0+tst_res (TFAIL ,"Failure setting %s" , path); + }else { + tst_res(TPASS, "Successfully set up %s",path);
testcases/kernel/power_management/cpufreq.c new file +4
-0+ } + } + + SAFE_FILE_PRINTF("/sys/devices/system/cpu/intel_pstate/status", "active");
testcases/kernel/power_management/cpufreq.c new file +6
-0+ +for (int i =0 ; i < nproc; i++) { +if (!online[i]) +continue ; + + snprintf(path, sizeof(path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", i);
testcases/kernel/power_management/cpufreq.c new file +1
-0+ SAFE_FILE_PRINTF(path, "%s",previous_scaling_governor[i]);
testcases/kernel/power_management/cpufreq.c new file +8
-0+ } +} + +static struct tst_test test = { + .cleanup = cleanup, + .needs_kconfigs = (const char *const []) { +"CONFIG_X86_INTEL_PSTATE" , +NULL
testcases/kernel/power_management/cpufreq.c line 410
Quoted 10 lines
testcases/kernel/power_management/cpufreq.c new file +10
-0+ }, + .needs_root = 1, + .setup = setup, + .supported_archs = (const char *const []) { +"x86" , +"x86_64" , +NULL + }, + .test_all = run +};
---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN. Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
testcases/kernel/power_management/cpufreq.c line 139
Quoted 2 lines
testcases/kernel/power_management/cpufreq.c new file +2
-0+SAFE_FILE_SCANF (path,"%255s" , contents); +tst_res (TDEBUG ,"Checking whether %s is \"intel_pstate\"" , path);
I slightly prefer single quotes inside double quotes e.g. " ... 'intel_pstate'" since they does not need to be escaped. And maybe the run() could have been split into functions so that it's not that long. But both of these are very minor.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Piotr,
testcases/kernel/power_management/cpufreq.c line 43
Quoted 9 lines
testcases/kernel/power_management/cpufreq.c new file +9
-0+static void cleanup (void ) +{ +char path[PATH_MAX ]; + +if (!setup_done) { +free (online); +free (previous_scaling_max_freq); +free (previous_scaling_min_freq); +free (previous_scaling_governor);
Better to use goto at the end of the cleanup() function, instead of defining free() in two different parts and duplicating code.
testcases/kernel/power_management/cpufreq.c line 48
Quoted 5 lines
testcases/kernel/power_management/cpufreq.c new file +5
-0+return ; + } + +SAFE_FILE_PRINTF ("/sys/devices/system/cpu/intel_pstate/status" ,"%s" , intel_pstate_status); +SAFE_FILE_PRINTF ("/sys/devices/system/cpu/intel_pstate/no_turbo" ,"%d" , no_turbo);
For fixed sysfs files that we need to modify and restore, we should use .save_restore instead.
testcases/kernel/power_management/cpufreq.c line 76
Quoted 6 lines
testcases/kernel/power_management/cpufreq.c new file +6
-0+static void setup (void ) +{ +char path[PATH_MAX ]; + +if (access ("/sys/devices/system/cpu/intel_pstate/status" ,F_OK ) ==-1 ) +tst_brk (TCONF ,"intel_pstate driver not active" );
Are you sure it's not a TBROK/TFAIL? We are checking for the driver configuration inside the kernel at tst_test level. I expect that .../cpu/intel_pstate/status is present at this point. If it's not, we are probably facing a bug in the driver, isnt it?
[..]
testcases/kernel/power_management/cpufreq.c line 79
Quoted 3 lines
testcases/kernel/power_management/cpufreq.c new file +3
-0+ +SAFE_FILE_SCANF ("/sys/devices/system/cpu/intel_pstate/no_turbo" ,"%d" , &no_turbo); +SAFE_FILE_SCANF ("/sys/devices/system/cpu/intel_pstate/status" ,"%15s" , intel_pstate_status);
And since we are scanning the status value later on, we probably don't need the access(.../cpu/intel_pstate/status) verification. The test will TBROK anyway here.
We should probably use .save_restore at this point, since we can safely guard the test from having drivers issues at configuration level. In particular, we should use .save_restore with TST_SR_TBROK (or TST_SR_TCONF if you confirm that driver might not initialize the sysfs under certain circumstances).
testcases/kernel/power_management/cpufreq.c line 277
Quoted 5 lines
testcases/kernel/power_management/cpufreq.c new file +5
-0+snprintf (path,sizeof (path),"/sys/devices/system/cpu/cpu%d/cpufreq/scaling_available_governors" , i); +memset (contents,0 ,sizeof (contents)); +SAFE_FILE_SCANF (path,"%255[^\n]" , contents); + +tst_res (TDEBUG ,"Checking whether %s contains \"performance\" and \"schedutil\"" , path);
Please change all of these double quotes inside tst_res() message parameter single quotes (as Cyril mentioned already).
testcases/kernel/power_management/cpufreq.c line 301
Quoted 3 lines
testcases/kernel/power_management/cpufreq.c new file +3
-0+SAFE_FILE_SCANF (path,"%255s" , contents); + +if (strstr (contents,"schedutil" ))
Also, I'm a bit concern for the massive use of strstr() patterns. Again, if drivers are bugged and show a string with garbage data matching one of the "supposed" correct string, we pass the test while drivers are still bugged.
You are also missing these two configurations which are needed by the test:
- CONFIG_CPU_FREQ_GOV_SCHEDUTIL
- CONFIG_CPU_FREQ_GOV_PERFORMANCE
Otherwise, it's not possible to run:
Quoted 1 line
+
SAFE_FILE_PRINTF(path, "schedutil");
or setting CPU governor to performance.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp