]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/power turbostat: Validate APERF access for VMWARE
authorLen Brown <len.brown@intel.com>
Tue, 2 Dec 2025 16:29:27 +0000 (11:29 -0500)
committerLen Brown <len.brown@intel.com>
Tue, 2 Dec 2025 21:11:14 +0000 (16:11 -0500)
VMWARE correctly enumerates lack of APERF and MPERF in CPUID,
but turbostat didn't consult that before attempting to access them.

Since VMWARE allows access, but always returns 0, turbostat
got confusd into an infinite reset loop.

Head this off by listening to CPUID.6.APERF_MPERF
(and rename the existing variable to make this more clear)

Reported-by: David Arcari <darcari@redhat.com>
Tested-by: David Arcari <darcari@redhat.com>
Signed-off-by: Len Brown <len.brown@intel.com>
tools/power/x86/turbostat/turbostat.c

index ab28ac6e74b63496d53080799c6909cd1f1bd2e4..0064f9091c7f0e076aca7fcb9094983e6d721346 100644 (file)
@@ -497,7 +497,7 @@ unsigned int summary_only;
 unsigned int list_header_only;
 unsigned int dump_only;
 unsigned int force_load;
-unsigned int has_aperf;
+unsigned int cpuid_has_aperf_mperf;
 unsigned int has_aperf_access;
 unsigned int has_epb;
 unsigned int has_turbo;
@@ -8404,7 +8404,7 @@ void linux_perf_init(void)
        if (access("/proc/sys/kernel/perf_event_paranoid", F_OK))
                return;
 
-       if (BIC_IS_ENABLED(BIC_IPC) && has_aperf) {
+       if (BIC_IS_ENABLED(BIC_IPC) && cpuid_has_aperf_mperf) {
                fd_instr_count_percpu = calloc(topo.max_cpu_num + 1, sizeof(int));
                if (fd_instr_count_percpu == NULL)
                        err(-1, "calloc fd_instr_count_percpu");
@@ -8524,7 +8524,7 @@ void rapl_perf_init(void)
 /* Assumes msr_counter_info is populated */
 static int has_amperf_access(void)
 {
-       return msr_counter_arch_infos[MSR_ARCH_INFO_APERF_INDEX].present &&
+       return cpuid_has_aperf_mperf && msr_counter_arch_infos[MSR_ARCH_INFO_APERF_INDEX].present &&
            msr_counter_arch_infos[MSR_ARCH_INFO_MPERF_INDEX].present;
 }
 
@@ -8936,7 +8936,7 @@ void process_cpuid()
         */
 
        __cpuid(0x6, eax, ebx, ecx, edx);
-       has_aperf = ecx & (1 << 0);
+       cpuid_has_aperf_mperf = ecx & (1 << 0);
        do_dts = eax & (1 << 0);
        if (do_dts)
                BIC_PRESENT(BIC_CoreTmp);
@@ -8954,7 +8954,7 @@ void process_cpuid()
        if (!quiet)
                fprintf(outf, "CPUID(6): %sAPERF, %sTURBO, %sDTS, %sPTM, %sHWP, "
                        "%sHWPnotify, %sHWPwindow, %sHWPepp, %sHWPpkg, %sEPB\n",
-                       has_aperf ? "" : "No-",
+                       cpuid_has_aperf_mperf ? "" : "No-",
                        has_turbo ? "" : "No-",
                        do_dts ? "" : "No-",
                        do_ptm ? "" : "No-",
@@ -9032,7 +9032,7 @@ void process_cpuid()
                                base_mhz, max_mhz, bus_mhz);
        }
 
-       if (has_aperf)
+       if (cpuid_has_aperf_mperf)
                aperf_mperf_multiplier = platform->need_perf_multiplier ? 1024 : 1;
 
        BIC_PRESENT(BIC_IRQ);
@@ -10231,7 +10231,7 @@ int get_and_dump_counters(void)
 
 void print_version()
 {
-       fprintf(outf, "turbostat version 2025.12.01 - Len Brown <lenb@kernel.org>\n");
+       fprintf(outf, "turbostat version 2025.12.02 - Len Brown <lenb@kernel.org>\n");
 }
 
 #define COMMAND_LINE_SIZE 2048