From: Len Brown <lenb@kernel.org>
To: linux-pm@vger.kernel.org
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>,
Len Brown <len.brown@intel.com>
Subject: [PATCH 02/18] x86_energy_perf_policy: Enhance MSR probe
Date: Mon, 19 Oct 2026 12:43:23 -0400 [thread overview]
Message-ID: <8a047427531a00a7ceeaa389657c2d7bd1e2dbf4.1792428130.git.len.brown@intel.com> (raw)
In-Reply-To: <e160a0ae497702e1c32ab163faa63c0043ea9298.1792428130.git.len.brown@intel.com>
From: Len Brown <len.brown@intel.com>
If Linux MSR driver isn't running,
modprobe and try the Linux path again.
If still no joy, try Android path.
Signed-off-by: Len Brown <len.brown@intel.com>
---
.../x86_energy_perf_policy.c | 40 ++++++++++++-------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
index a963c0430794..abd3cf2fdd39 100644
--- a/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
+++ b/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
@@ -15,6 +15,7 @@
#include <sys/types.h>
#include <sched.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <sys/resource.h>
#include <getopt.h>
#include <err.h>
@@ -1611,30 +1612,41 @@ void set_base_cpu(void)
err(-ENODEV, "No valid cpus found");
}
-static void probe_android_msr_path(void)
+/* return 0 if path exists */
+static int check_msr_path(void)
{
struct stat sb;
- set_msr_path(base_cpu); /* called with use_android_path = 0, to probe Linux path */
- if (stat(msr_path, &sb))
- use_android_msr_path = 1;
+ return stat(msr_path, &sb);
}
+/*
+ * Check Linux MSR path
+ * If it fails, try modprobe and check it again
+ * If still no joy, enable Android path and try again
+ */
void probe_dev_msr(void)
{
- struct stat sb;
+ int retval;
+
+ use_android_msr_path = 0;
+ set_msr_path(base_cpu);
+ if (check_msr_path() == 0)
+ return;
- probe_android_msr_path();
+ retval = system("/sbin/modprobe msr > /dev/null 2>&1");
+ if (check_msr_path() == 0)
+ return;
+
+ use_android_msr_path = 1;
set_msr_path(base_cpu);
- if (stat(msr_path, &sb)) {
- if (system("/sbin/modprobe msr > /dev/null 2>&1")) {
- if (use_android_msr_path)
- err(-5, "no /dev/msr0, Try \"# modprobe msr\" ");
- else
- err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" ");
- }
- }
+ if (check_msr_path() == 0)
+ return;
+
+ if (WIFEXITED(retval))
+ retval = WEXITSTATUS(retval);
+ err(-1, "\"msr\" driver support required, modprobe msr returned %d", retval);
}
static void get_cpuid_or_exit(unsigned int leaf, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
--
2.45.2
next prev parent reply other threads:[~2026-10-19 16:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 16:43 [PATCH 0/18] x86_energy_perf_policy cleanups Len Brown
2026-10-19 16:43 ` [PATCH 01/18] x86_energy_perf_policy: Create msr_path helper Len Brown
2026-10-19 16:43 ` Len Brown [this message]
2026-10-20 9:44 ` [PATCH 02/18] x86_energy_perf_policy: Enhance MSR probe Andy Shevchenko
2026-10-19 16:43 ` [PATCH 03/18] x86_energy_perf_policy: Prevent unlikely buffer overflow Len Brown
2026-10-20 9:46 ` Andy Shevchenko
2026-10-19 16:43 ` [PATCH 04/18] x86_energy_perf_policy: Cleanup: Harden with strtol() Len Brown
2026-10-19 16:43 ` [PATCH 05/18] x86_energy_perf_policy: Cleanup: Use snprintf() for platform-profile Len Brown
2026-10-19 16:43 ` [PATCH 06/18] x86_energy_perf_policy: Fix optarg keyword matching Len Brown
2026-10-19 16:43 ` [PATCH 07/18] x86_energy_perf_policy: Cleanup: Fix potential ratio overflow Len Brown
2026-10-19 16:43 ` [PATCH 08/18] x86_energy_perf_policy: Bound package iteration Len Brown
2026-10-19 16:43 ` [PATCH 09/18] x86_energy_perf_policy: Cleanup: Define HWP window max Len Brown
2026-10-19 16:43 ` [PATCH 10/18] x86_energy_perf_policy: Cleanup: Define BCLK_MHZ Len Brown
2026-10-19 16:43 ` [PATCH 11/18] x86_energy_perf_policy: Cleanup: Check fseek() in VM path Len Brown
2026-10-19 16:43 ` [PATCH 12/18] x86_energy_perf_policy: Document MSRHEADER Len Brown
2026-10-19 16:43 ` [PATCH 13/18] x86_energy_perf_policy: Cleanup: Drop unused signal.h Len Brown
2026-10-19 16:43 ` [PATCH 14/18] x86_energy_perf_policy: Cleanup: Constify profile name arg Len Brown
2026-10-19 16:43 ` [PATCH 15/18] x86_energy_perf_policy: Cleanup: Constify HWP strings Len Brown
2026-10-19 16:43 ` [PATCH 16/18] x86_energy_perf_policy: Fix use-after-free in err_on_hypervisor() Len Brown
2026-10-19 16:43 ` [PATCH 17/18] x86_energy_perf_policy: Fix write_sysfs() return type Len Brown
2026-10-19 16:43 ` [PATCH 18/18] MAINTAINERS: Add x86_energy_perf_policy Len Brown
2026-10-19 18:33 ` [PATCH 01/18] x86_energy_perf_policy: Create msr_path helper Andy Shevchenko
2026-10-20 9:35 ` Andy Shevchenko
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=8a047427531a00a7ceeaa389657c2d7bd1e2dbf4.1792428130.git.len.brown@intel.com \
--to=lenb@kernel.org \
--cc=andriy.shevchenko@intel.com \
--cc=len.brown@intel.com \
--cc=linux-pm@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.