Linux Test Project
 help / color / mirror / Atom feed
From: Wake Liu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Wake Liu <wakel@google.com>, Grzegorz Jaszczyk <jaszczyk@google.com>
Subject: [LTP] [PATCH] cpufreq_intel: Check for per-CPU online file presence before reading
Date: Fri, 28 Aug 2026 23:09:24 +0000	[thread overview]
Message-ID: <20260828230924.2635548-1-wakel@google.com> (raw)

From: Grzegorz Jaszczyk <jaszczyk@google.com>

In setup(), the test assumes that all secondary CPUs (cpu1..cpuN-1)
expose '/sys/devices/system/cpu/cpu<N>/online' and attempts to read
their status using SAFE_FILE_SCANF().

However, on systems where CPU hotplugging is disabled (e.g. kernels
built without CONFIG_HOTPLUG_CPU or platforms where CPUs are not
hotpluggable), the per-CPU 'online' sysfs attributes are not created.
Calling SAFE_FILE_SCANF() on a non-existent file results in ENOENT
and breaks test setup with TBROK.

Check for the existence of the per-CPU 'online' file with access()
first. If the file exists, read the status via SAFE_FILE_SCANF(); if
it does not exist, assume the CPU is not hotpluggable and is
permanently online.

Signed-off-by: Grzegorz Jaszczyk <jaszczyk@google.com>
Signed-off-by: Wake Liu <wakel@google.com>
---
 testcases/kernel/power_management/cpufreq_intel.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/power_management/cpufreq_intel.c b/testcases/kernel/power_management/cpufreq_intel.c
index 11896258e..a2a3f3475 100644
--- a/testcases/kernel/power_management/cpufreq_intel.c
+++ b/testcases/kernel/power_management/cpufreq_intel.c
@@ -94,8 +94,16 @@ static void setup(void)
 		int tmp;
 
 		snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/online", i);
-		SAFE_FILE_SCANF(path, "%d", &tmp);
-		online[i] = (bool)tmp;
+		if (access(path, F_OK) == 0) {
+			SAFE_FILE_SCANF(path, "%d", &tmp);
+			online[i] = (bool)tmp;
+		} else {
+			/*
+			 * If the 'online' file is missing, the CPU is not
+			 * hotpluggable and is permanently online.
+			 */
+			online[i] = true;
+		}
 	}
 
 	SAFE_FILE_PRINTF("/sys/devices/system/cpu/intel_pstate/status", "active");
-- 
2.55.0.897.gb25b4bd76c-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2026-08-28 23:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 23:09 Wake Liu via ltp [this message]
2026-08-29  3:33 ` [LTP] cpufreq_intel: Check for per-CPU online file presence before reading linuxtestproject.agent
2026-08-31  9:58 ` [LTP] [PATCH] " Kubaj, Piotr
2026-08-31 10:49 ` Andrea Cervesato via ltp
2026-08-31 10:50 ` Andrea Cervesato via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260828230924.2635548-1-wakel@google.com \
    --to=ltp@lists.linux.it \
    --cc=jaszczyk@google.com \
    --cc=wakel@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox