Skip to contentSkip to conversation

cpufreq.c: add new test for cpufreq sysfs interface validation

PATCH In review Piotr Kubaj 3 participants 4 messages Jun 11 – Jul 31

lore
Share & tools
lore
#0 lore raw

PATCH v9 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.

---
Addresses review from Andrea:
1. Single goto instead of duplicating free().
2. .save_restore for intel_pstate/status and intel_pstate/no_turbo.
3. TCONF is necessary, because even with the driver loaded, the sysfs interface may not be available - e.g. when running on a VM, when using unsupported CPU or when intel_pstate=disable is appended to the kernel cmdline.
4. Replace strstr.
5. Use single quotes instead of escaping double quotes.
6. Add CONFIG_CPU_FREQ_GOV_SCHEDUTIL and CONFIG_CPU_FREQ_GOV_PERFORMANCE to required kconfigs.

 runtest/power_management_tests               |   1 +
 testcases/kernel/power_management/.gitignore |   1 +
 testcases/kernel/power_management/cpufreq.c  | 424 +++++++++++++++++++
 3 files changed, 426 insertions(+)
 create mode 100644 testcases/kernel/power_management/.gitignore
 create mode 100644 testcases/kernel/power_management/cpufreq.c
runtest/power_management_tests +1 -0
index b670da6ec..0bc7dd0c8 100644
@@ -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
new file mode 100644
index 000000000..7f34e4c2f
@@ -0,0 +1 @@
+cpufreq
testcases/kernel/power_management/cpufreq.c new file +424 -0

424 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
#1 lore raw

Hi Piotr,

testcases/kernel/power_management/cpufreq.c line 335

Quoted 9 lines · Piotr Kubaj

cpufreq.c: add new test for cpufreq sysfs interface validation

testcases/kernel/power_management/cpufreq.c new file +7 -0
+		if (cpuinfo_max_freq < scaling_max_freq) {
+			tst_res(TINFO, "cpuinfo_max_freq: %ld", cpuinfo_max_freq);
+			tst_res(TINFO, "scaling_max_freq: %ld", scaling_max_freq);
+			tst_res(TFAIL, "Failure setting %s", path);
+		} else {
+			tst_res(TPASS, "Successfully set up %s", path);
+		}

The frequency write-back checks throughout run() use one-directional comparisons. Here the test writes cpuinfo_max_freq to scaling_max_freq and reads it back, but only fails when the read value is *higher* than what was written. If the kernel rounded the value *down* (or the write silently failed to a lower value), the test would still report TPASS with "Successfully set up".

The same pattern applies to the scaling_min_freq checks further down, which only fail when the read value is *lower* than what was written.

Since the purpose of these checks is to validate that exact boundary values can be written, would it not be more correct to use != instead of < / > here?

testcases/kernel/power_management/cpufreq.c line 341

Quoted 1 line
testcases/kernel/power_management/cpufreq.c new file +1 -0
+		if (cpuinfo_max_freq < scaling_min_freq) {

Same issue: only catches upward deviations.

testcases/kernel/power_management/cpufreq.c line 371

Quoted 1 line
testcases/kernel/power_management/cpufreq.c new file +1 -0
+		if (cpuinfo_min_freq > scaling_min_freq) {

Same issue: only catches downward deviations.

testcases/kernel/power_management/cpufreq.c line 383

Quoted 1 line
testcases/kernel/power_management/cpufreq.c new file +1 -0
+		if (cpuinfo_min_freq > scaling_max_freq) {

Same issue: only catches downward deviations.

Verdict: Needs revision

---
Note:

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
#2 lore raw

The current check is correct. This is exactly the way our architect suggested. This is because the values written by the user are not written raw, but kernel uses them only as a suggestion and can be lower or higher than specified, but need to always abide the values of scaling_min_freq and scaling_max_freq - which is exactly what this test checks.

2026-06-11 (木) の 12:32 +0000 に [email protected] さんは書きました:

Quoted 49 lines

Hi Piotr,

Review

Quoted 13 lines · Piotr Kubaj

cpufreq.c: add new test for cpufreq sysfs interface validation

(quoted diff) +2 -0
+		if (cpuinfo_max_freq < scaling_max_freq) {
+			tst_res(TINFO, "cpuinfo_max_freq: %ld",

cpuinfo_max_freq);

(quoted diff) +1 -0
+			tst_res(TINFO, "scaling_max_freq: %ld",

scaling_max_freq);

(quoted diff) +1 -0
+			tst_res(TFAIL, "Failure setting %s",

path);

(quoted diff) +2 -0
+		} else {
+			tst_res(TPASS, "Successfully set up %s",

path);

(quoted diff) +1 -0
+		}

The frequency write-back checks throughout run() use one-directional comparisons. Here the test writes cpuinfo_max_freq to scaling_max_freq
and reads it back, but only fails when the read value is *higher* than what was written. If the kernel rounded the value *down* (or the write silently failed to a lower value), the test would still report TPASS with "Successfully set up".

The same pattern applies to the scaling_min_freq checks further down, which only fail when the read value is *lower* than what was written.

Since the purpose of these checks is to validate that exact boundary values can be written, would it not be more correct to use != instead of < / > here?

testcases/kernel/power_management/cpufreq.c line 341

Quoted 1 line
testcases/kernel/power_management/cpufreq.c new file +1 -0
+		if (cpuinfo_max_freq < scaling_min_freq) {

Same issue: only catches upward deviations.

testcases/kernel/power_management/cpufreq.c line 371

Quoted 1 line
testcases/kernel/power_management/cpufreq.c new file +1 -0
+		if (cpuinfo_min_freq > scaling_min_freq) {

Same issue: only catches downward deviations.

testcases/kernel/power_management/cpufreq.c line 383

Quoted 1 line
testcases/kernel/power_management/cpufreq.c new file +1 -0
+		if (cpuinfo_min_freq > scaling_max_freq) {

Same issue: only catches downward deviations.

Verdict: Needs revision

---
Note:

Quoted 6 lines

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

---------------------------------------------------------------------
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