Skip to content

Commit b6b42a6

Browse files
committed
tools/power x86_energy_perf_policy: Enhance HWP enabled check
Verify that all CPUs have HWP enabled, not just cpu0. Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 6212765 commit b6b42a6

1 file changed

Lines changed: 36 additions & 8 deletions

File tree

tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* policy preference bias on recent X86 processors.
55
*/
66
/*
7-
* Copyright (c) 2010 - 2017 Intel Corporation.
7+
* Copyright (c) 2010 - 2025 Intel Corporation.
88
* Len Brown <len.brown@intel.com>
99
*/
1010

@@ -517,7 +517,7 @@ void for_packages(unsigned long long pkg_set, int (func)(int))
517517

518518
void print_version(void)
519519
{
520-
printf("x86_energy_perf_policy 17.05.11 (C) Len Brown <len.brown@intel.com>\n");
520+
printf("x86_energy_perf_policy 2025.9.19 Len Brown <lenb@kernel.org>\n");
521521
}
522522

523523
void cmdline(int argc, char **argv)
@@ -1312,6 +1312,17 @@ void for_all_cpus_in_set(size_t set_size, cpu_set_t *cpu_set, int (func)(int))
13121312
if (CPU_ISSET_S(cpu_num, set_size, cpu_set))
13131313
func(cpu_num);
13141314
}
1315+
int for_all_cpus_in_set_and(size_t set_size, cpu_set_t *cpu_set, int (func)(int))
1316+
{
1317+
int cpu_num;
1318+
int retval = 1;
1319+
1320+
for (cpu_num = 0; cpu_num <= max_cpu_num; ++cpu_num)
1321+
if (CPU_ISSET_S(cpu_num, set_size, cpu_set))
1322+
retval &= func(cpu_num);
1323+
1324+
return retval;
1325+
}
13151326

13161327
void init_data_structures(void)
13171328
{
@@ -1326,21 +1337,38 @@ void init_data_structures(void)
13261337
for_all_proc_cpus(mark_cpu_present);
13271338
}
13281339

1329-
/* clear has_hwp if it is not enable (or being enabled) */
1340+
int is_hwp_enabled_on_cpu(int cpu_num)
1341+
{
1342+
unsigned long long msr;
1343+
int retval;
1344+
1345+
/* MSR_PM_ENABLE[1] == 1 if HWP is enabled and MSRs visible */
1346+
get_msr(cpu_num, MSR_PM_ENABLE, &msr);
1347+
retval = (msr & 1);
13301348

1349+
if (verbose)
1350+
fprintf(stderr, "cpu%d: %sHWP\n", cpu_num, retval ? "" : "No-");
1351+
1352+
return retval;
1353+
}
1354+
1355+
/*
1356+
* verify_hwp_is_enabled()
1357+
*
1358+
* Set (has_hwp=0) if no HWP feature or any of selected CPU set does not have HWP enabled
1359+
*/
13311360
void verify_hwp_is_enabled(void)
13321361
{
1333-
unsigned long long msr;
1362+
int retval;
13341363

13351364
if (!has_hwp) /* set in early_cpuid() */
13361365
return;
13371366

1338-
/* MSR_PM_ENABLE[1] == 1 if HWP is enabled and MSRs visible */
1339-
get_msr(base_cpu, MSR_PM_ENABLE, &msr);
1340-
if ((msr & 1) == 0) {
1367+
retval = for_all_cpus_in_set_and(cpu_setsize, cpu_selected_set, is_hwp_enabled_on_cpu);
1368+
1369+
if (retval == 0) {
13411370
fprintf(stderr, "HWP can be enabled using '--hwp-enable'\n");
13421371
has_hwp = 0;
1343-
return;
13441372
}
13451373
}
13461374

0 commit comments

Comments
 (0)