From 962d0202306072651ef459abf1f7240c73afaee1 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Thu, 8 Oct 2026 21:42:11 -0400 Subject: tools/power turbostat: Decode Uncore Frequency Agent Types Newer platforms export Uncore Frequency agent_types: $ cat /sys/devices/system/cpu/intel_uncore_frequency/uncore03/agent_types memory Update the previous system configuration header lines: Uncore Frequency package0 domain4 cluster1: 800 - 2100 MHz (800 - 2100 MHz) 2100 MHz With (more concise) lines that include this (agent type) description: pkg0: UMHz4.1(memory): 800 - 2100 MHz (800 - 2100 MHz) 2100 MHz The actual measurement column header is unchanged: UMHz4.1 Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 44 ++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index cb3d571f121e..4a16d12dc842 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -7144,6 +7144,36 @@ static int read_sysfs_int(char *path) return (retval); } +/* + * read_sysfs_line(char *path, char **buf) + * + * fail silently if open fails + * err() if open works, but read fails + * Replace \n with \0 in buffer and return byte count accordingly. + * + * n.b. caller owns freeing buf + */ +static int read_sysfs_line(char *path, char **buf) +{ + FILE *fp; + size_t size = 0; + int bytes_read; + + fp = fopen(path, "r"); + if (!fp) + return 0; + + bytes_read = getline(buf, &size, fp); + if (bytes_read < 0) + err(1, "%s: file read failed", path); + + fclose(fp); + + assert((*buf)[bytes_read - 1] == '\n'); + (*buf)[bytes_read - 1] = '\0'; + return bytes_read - 1; +} + static void dump_sysfs_file(char *path) { FILE *input; @@ -7260,11 +7290,23 @@ static void probe_intel_uncore_frequency_cluster(void) if (quiet) continue; + char *agent_types = NULL; + int agent_bytes; + + sprintf(path, "%s/agent_types", path_base); + agent_bytes = read_sysfs_line(path, &agent_types); + + if (agent_bytes > 0) + fprintf(outf, "pkg%d: %s(%s):", unc_pkg_id, name_buf, agent_types); + else + fprintf(outf, "pkg%d: %s:", unc_pkg_id, name_buf); + free(agent_types); + sprintf(path, "%s/min_freq_khz", path_base); k = read_sysfs_int(path); sprintf(path, "%s/max_freq_khz", path_base); l = read_sysfs_int(path); - fprintf(outf, "Uncore Frequency package%d domain%d cluster%d: %d - %d MHz ", unc_pkg_id, domain_id, cluster_id, k / 1000, l / 1000); + fprintf(outf, " %d - %d MHz ", k / 1000, l / 1000); sprintf(path, "%s/initial_min_freq_khz", path_base); k = read_sysfs_int(path); -- cgit v1.2.3 From acadea13ed2f8ade79b3f1813b008ed89fab7abe Mon Sep 17 00:00:00 2001 From: Len Brown Date: Tue, 28 Apr 2026 18:02:39 -0400 Subject: tools/power turbostat: Cleanup: Delete unused flags No functional change. Assisted-by: Claude:claude-haiku-4-5 Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 4a16d12dc842..8054716207b0 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -138,8 +138,6 @@ struct msr_counter { enum counter_format format; struct msr_counter *next; unsigned int flags; -#define FLAGS_HIDE (1 << 0) -#define FLAGS_SHOW (1 << 1) #define SYSFS_PERCPU (1 << 1) }; static int use_android_msr_path; -- cgit v1.2.3 From afa7b0f63a7bf59c0db0abc91df5c11544a6ab91 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Tue, 28 Apr 2026 20:48:56 -0400 Subject: tools/power turbostat: Rename: Differentiate counter and CPU sets Sets of Built-In-Counters (BICs) are implemented using cpu_set_t. Since cpu_set_t is also used for sets of CPUs, invent the name "bic_set_t" to make it more clear which is which. typedef is discouraged by kernel coding checkers, but is appropriate here -- and better than #define. No functional change. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 8054716207b0..b4403b4ed2c8 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -290,7 +290,9 @@ enum bic_names { MAX_BIC }; -void print_bic_set(char *s, cpu_set_t *set) +typedef cpu_set_t bic_set_t; /* implement bic_set_t using cpu_set_t */ + +void print_bic_set(char *s, bic_set_t *set) { int i; @@ -306,17 +308,17 @@ void print_bic_set(char *s, cpu_set_t *set) putchar('\n'); } -static cpu_set_t bic_group_topology; -static cpu_set_t bic_group_thermal_pwr; -static cpu_set_t bic_group_frequency; -static cpu_set_t bic_group_hw_idle; -static cpu_set_t bic_group_sw_idle; -static cpu_set_t bic_group_idle; -static cpu_set_t bic_group_cache; -static cpu_set_t bic_group_other; -static cpu_set_t bic_group_disabled_by_default; -static cpu_set_t bic_enabled; -static cpu_set_t bic_present; +static bic_set_t bic_group_topology; +static bic_set_t bic_group_thermal_pwr; +static bic_set_t bic_group_frequency; +static bic_set_t bic_group_hw_idle; +static bic_set_t bic_group_sw_idle; +static bic_set_t bic_group_idle; +static bic_set_t bic_group_cache; +static bic_set_t bic_group_other; +static bic_set_t bic_group_disabled_by_default; +static bic_set_t bic_enabled; +static bic_set_t bic_present; /* modify */ #define BIC_INIT(set) CPU_ZERO(set) @@ -332,7 +334,7 @@ static cpu_set_t bic_present; #define DO_BIC_READ(COUNTER_NUMBER) CPU_ISSET(COUNTER_NUMBER, &bic_present) #define DO_BIC(COUNTER_NUMBER) (CPU_ISSET(COUNTER_NUMBER, &bic_enabled) && CPU_ISSET(COUNTER_NUMBER, &bic_present)) -static void bic_set_all(cpu_set_t *set) +static void bic_set_all(bic_set_t *set) { int i; @@ -346,7 +348,7 @@ static void bic_set_all(cpu_set_t *set) * bic_clear_bits() * clear all the bits from "clr" in "dst" */ -static void bic_clear_bits(cpu_set_t *dst, cpu_set_t *clr) +static void bic_clear_bits(bic_set_t *dst, bic_set_t *clr) { int i; @@ -2783,7 +2785,7 @@ void help(void) * for all the strings in comma separate name_list, * set the approprate bit in return value. */ -void bic_lookup(cpu_set_t *ret_set, char *name_list, enum show_hide_mode mode) +void bic_lookup(bic_set_t *ret_set, char *name_list, enum show_hide_mode mode) { unsigned int i; @@ -11620,7 +11622,7 @@ void cmdline(int argc, char **argv) * multiple invocations simply clear more bits in enabled mask */ { - cpu_set_t bic_group_hide; + bic_set_t bic_group_hide; BIC_INIT(&bic_group_hide); -- cgit v1.2.3 From c1165c0db999a201110a2affb05115bc0169ca2b Mon Sep 17 00:00:00 2001 From: Len Brown Date: Tue, 28 Apr 2026 21:49:46 -0400 Subject: tools/power turbostat: Cleanup: Remove hard-coded 8192 CPU limit The --cpu cmdline option was parsed before topology_probe() set max_cpu_num, and so it used a hard-coded CPU limit of 8192. Probe max_cpu_num earlier and allocate the set for --cpu using the same size as all other CPU sets, large enough to hold max possible (but not bigger). No functional change, unless you count fixing some error paths. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 75 ++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 31 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index b4403b4ed2c8..70e272447511 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -1407,7 +1407,6 @@ void init_perf_model_support(unsigned int family, unsigned int model) int backwards_count; char *progname; -#define CPU_SUBSET_MAXCPUS 8192 /* need to use before probe... */ cpu_set_t *cpu_present_set, *cpu_possible_set, *cpu_effective_set, *cpu_allowed_set, *cpu_affinity_set, *cpu_subset; cpu_set_t *perf_pcore_set, *perf_ecore_set, *perf_lcore_set; size_t cpu_present_setsize, cpu_possible_setsize, cpu_effective_setsize, cpu_allowed_setsize, cpu_affinity_setsize, cpu_subset_size; @@ -6170,7 +6169,7 @@ int get_physical_node_id(struct cpu_topology *thiscpu) static int parse_cpu_str(char *cpu_str, cpu_set_t *cpu_set, int cpu_set_size) { - unsigned int start, end; + int start, end; char *next = cpu_str; while (next && *next) { @@ -6183,7 +6182,7 @@ static int parse_cpu_str(char *cpu_str, cpu_set_t *cpu_set, int cpu_set_size) start = strtoul(next, &next, 10); - if (start >= CPU_SUBSET_MAXCPUS) + if (start > topo.max_cpu_num) return 1; CPU_SET_S(start, cpu_set_size, cpu_set); @@ -6210,7 +6209,7 @@ static int parse_cpu_str(char *cpu_str, cpu_set_t *cpu_set, int cpu_set_size) return 1; while (++start <= end) { - if (start >= CPU_SUBSET_MAXCPUS) + if (start > topo.max_cpu_num) return 1; CPU_SET_S(start, cpu_set_size, cpu_set); } @@ -6380,26 +6379,6 @@ void re_initialize(void) fprintf(outf, "turbostat: re-initialized with num_cpus %d, allowed_cpus %d\n", topo.num_cpus, topo.allowed_cpus); } -void set_max_cpu_num(void) -{ - FILE *filep; - int current_cpu; - unsigned long dummy; - char pathname[64]; - - current_cpu = sched_getcpu(); - if (current_cpu < 0) - err(1, "cannot find calling cpu ID"); - sprintf(pathname, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", current_cpu); - - filep = fopen_or_die(pathname, "r"); - topo.max_cpu_num = 0; - while (fscanf(filep, "%lx,", &dummy) == 1) - topo.max_cpu_num += BITMASK_SIZE; - fclose(filep); - topo.max_cpu_num--; /* 0 based */ -} - /* * count_cpus() * remember the last one seen, it will be the max @@ -9578,6 +9557,35 @@ int set_thread_siblings(struct cpu_topology *thiscpu) return (ht_id - 1); } +/* + * get_max_cpu_num(path) + * return the last number of the cpu list in this file + */ +static int get_max_cpu_num(char *path) +{ + FILE *filep; + int retval, num; + char c; + + filep = fopen(path, "r"); + if (filep == NULL) { + warn("%s", path); + return 255; + } + + while ((retval = fscanf(filep, "%d%c", &num, &c)) == 2) { + if (c == '\n') + break; + if (c != ',' && c != '-') + errx(1, "Bad Format '%s'", path); + } + if (retval != 2) + errx(1, "Bad format '%s'", path); + + fclose(filep); + return num; +} + void topology_probe(bool startup) { int i; @@ -9585,8 +9593,7 @@ void topology_probe(bool startup) int max_package_id = 0; int max_siblings = 0; - /* Initialize num_cpus, max_cpu_num */ - set_max_cpu_num(); + /* Initialize num_cpus */ topo.num_cpus = 0; for_all_proc_cpus(count_cpus); if (!summary_only) @@ -9653,7 +9660,7 @@ void topology_probe(bool startup) * * cpu_allowed_set is the intersection of cpu_present_set/cpu_effective_set/cpu_subset. */ - for (i = 0; i < CPU_SUBSET_MAXCPUS; ++i) { + for (i = 0; i <= topo.max_cpu_num; ++i) { if (cpu_subset && !CPU_ISSET_S(i, cpu_subset_size, cpu_subset)) continue; @@ -9661,7 +9668,7 @@ void topology_probe(bool startup) if (cpu_subset) { /* cpus in cpu_subset must be in cpu_present_set during startup */ if (startup) - err(1, "cpu%d not present", i); + errx(1, "cpu%d not present", i); else fprintf(stderr, "cpu%d not present\n", i); } @@ -9681,7 +9688,7 @@ void topology_probe(bool startup) print_cpu_set("allowed set", cpu_allowed_set); if (!CPU_COUNT_S(cpu_allowed_setsize, cpu_allowed_set)) - err(-ENODEV, "No valid cpus found"); + errx(-ENODEV, "No valid cpus found"); sched_setaffinity(0, cpu_allowed_setsize, cpu_allowed_set); /* @@ -11520,15 +11527,17 @@ void parse_cpu_command(char *optarg) if (show_core_only || show_pkg_only) goto error; - cpu_subset = CPU_ALLOC(CPU_SUBSET_MAXCPUS); + cpu_subset = CPU_ALLOC(topo.max_cpu_num + 1); if (cpu_subset == NULL) err(3, "CPU_ALLOC"); - cpu_subset_size = CPU_ALLOC_SIZE(CPU_SUBSET_MAXCPUS); + cpu_subset_size = CPU_ALLOC_SIZE(topo.max_cpu_num + 1); CPU_ZERO_S(cpu_subset_size, cpu_subset); if (parse_cpu_str(optarg, cpu_subset, cpu_subset_size)) goto error; + if (debug) + print_cpu_set("cpu subsetset", cpu_subset); return; @@ -11740,6 +11749,10 @@ int main(int argc, char **argv) close(fd); skip_cgroup_setting: + + /* probe max_cpu_num early for use by cmdline() */ + topo.max_cpu_num = get_max_cpu_num("/sys/devices/system/cpu/possible"); + outf = stderr; cmdline(argc, argv); -- cgit v1.2.3 From 244cc1e3022b8644693caa47d2f5b9b449c3d056 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Tue, 28 Apr 2026 19:39:40 -0400 Subject: tools/power turbostat: Cleanup: Delete duplicate table entry No functional change. Assisted-by: Claude:claude-haiku-4-5 Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 1 - 1 file changed, 1 deletion(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 70e272447511..03b72616673b 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -1312,7 +1312,6 @@ static struct perf_model_support turbostat_perf_model_support[] = { { INTEL_ATOM_CRESTMONT, { PCE(0x00, 0x00), PCE(0x00, 0x02)}, {}, {} }, /* GRR */ { INTEL_ATOM_DARKMONT_X, { PCE(0x01, 0xFF), PCE(0x01, 0xBF)}, {}, {} }, /* CWF */ - { INTEL_ALDERLAKE, { PCE(0x00, 0xFF), PCE(0x00, 0xDF)}, { PCE(0x00, 0x00), PCE(0x00, 0x02)}, {} }, { INTEL_ALDERLAKE, { PCE(0x00, 0xFF), PCE(0x00, 0xDF)}, { PCE(0x00, 0x00), PCE(0x00, 0x02)}, {} }, { INTEL_ALDERLAKE_L, { PCE(0x00, 0xFF), PCE(0x00, 0xDF)}, { PCE(0x00, 0x00), PCE(0x00, 0x02)}, {} }, { INTEL_RAPTORLAKE, { PCE(0x00, 0xFF), PCE(0x00, 0xDF)}, { PCE(0x00, 0x00), PCE(0x00, 0x02)}, {} }, -- cgit v1.2.3 From 91aa566a7ec32cc2d1401a2680cd71f250cba5af Mon Sep 17 00:00:00 2001 From: Len Brown Date: Tue, 28 Apr 2026 23:24:24 -0400 Subject: tools/power turbostat: Cleanup: Remove useless assert() No functional change. Assisted-by: Claude:claude-haiku-4-5 Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 03b72616673b..7b872bb82172 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -3283,8 +3283,6 @@ int dump_counters(PER_THREAD_PARAMS) double rapl_counter_get_value(const struct rapl_counter *c, enum rapl_unit desired_unit, double interval) { - assert(desired_unit != RAPL_UNIT_INVALID); - /* * For now we don't expect anything other than joules, * so just simplify the logic. -- cgit v1.2.3 From b1dc956189b1974e59ea08199657eb48e23f2806 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Thu, 30 Apr 2026 21:47:43 -0400 Subject: tools/power turbostat: Cleanup: Unify comparisons to max_cpu_num Unify the syntax of loops over all CPUs for consistency, since we just fixed two off-by-one bugs. No functional change. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 7b872bb82172..ac28a9953bf1 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -5834,7 +5834,7 @@ void free_fd_percpu(void) if (!fd_percpu) return; - for (i = 0; i < topo.max_cpu_num + 1; ++i) { + for (i = 0; i <= topo.max_cpu_num; ++i) { if (fd_percpu[i] != 0) close(fd_percpu[i]); } @@ -5848,7 +5848,7 @@ void free_fd_instr_count_percpu(void) if (!fd_instr_count_percpu) return; - for (int i = 0; i < topo.max_cpu_num + 1; ++i) { + for (int i = 0; i <= topo.max_cpu_num; ++i) { if (fd_instr_count_percpu[i] != 0) close(fd_instr_count_percpu[i]); } @@ -5862,7 +5862,7 @@ void free_fd_llc_percpu(void) if (!fd_llc_percpu) return; - for (int i = 0; i < topo.max_cpu_num + 1; ++i) { + for (int i = 0; i <= topo.max_cpu_num; ++i) { if (fd_llc_percpu[i] != 0) close(fd_llc_percpu[i]); } @@ -5879,7 +5879,7 @@ void free_fd_l2_percpu(void) if (!fd_l2_percpu) return; - for (int i = 0; i < topo.max_cpu_num + 1; ++i) { + for (int i = 0; i <= topo.max_cpu_num; ++i) { if (fd_l2_percpu[i] != 0) close(fd_l2_percpu[i]); } @@ -8722,7 +8722,7 @@ void rapl_perf_init(void) memset(domain_visited, 0, num_domains * sizeof(*domain_visited)); - for (int cpu = 0; cpu < topo.max_cpu_num + 1; ++cpu) { + for (int cpu = 0; cpu <= topo.max_cpu_num; ++cpu) { if (cpu_is_not_allowed(cpu)) continue; @@ -9843,7 +9843,7 @@ void allocate_counters(struct counters *counters) if (counters->threads == NULL) goto error; - for (i = 0; i < topo.max_cpu_num + 1; i++) + for (i = 0; i <= topo.max_cpu_num; i++) (counters->threads)[i].cpu_id = -1; counters->cores = calloc(num_cores, sizeof(struct core_data)); @@ -9972,7 +9972,7 @@ void set_master_cpu(void) { int i; - for (i = 0; i < topo.max_cpu_num + 1; ++i) { + for (i = 0; i <= topo.max_cpu_num; ++i) { if (cpu_is_not_allowed(i)) continue; master_cpu = i; @@ -10091,7 +10091,7 @@ int added_perf_counters_init_(struct perf_counter_info *pinfo) memset(domain_visited, 0, max_num_domains * sizeof(*domain_visited)); - for (int cpu = 0; cpu < topo.max_cpu_num + 1; ++cpu) { + for (int cpu = 0; cpu <= topo.max_cpu_num; ++cpu) { next_domain = cpu_to_domain(pinfo, cpu); -- cgit v1.2.3 From 6389a3ed1abdc00b00e3f79e3722d99ed119fab5 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sun, 3 May 2026 13:13:50 -0400 Subject: tools/power turbostat: Cleanup counter sets debug code When the debug "--Dump" option is used to dump counter values, also dump the counter sets. Update that counter counter-set debug code to pass code review. Assisted-by: Claude:claude-sonnet-4.6 Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index ac28a9953bf1..c63aa2ec7426 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -98,6 +98,8 @@ #define ROUND_UP_TO_PAGE_SIZE(n) (((n) + 0x1000UL-1UL) & ~(0x1000UL-1UL)) +FILE *outf; + enum counter_scope { SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE }; enum counter_type { COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC, COUNTER_K2M }; enum counter_format { FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT, FORMAT_AVERAGE }; @@ -292,20 +294,23 @@ enum bic_names { typedef cpu_set_t bic_set_t; /* implement bic_set_t using cpu_set_t */ -void print_bic_set(char *s, bic_set_t *set) +/* + * debug helper + */ +static void print_bic_set(const char *s, const bic_set_t *set) { int i; assert(MAX_BIC < CPU_SETSIZE); - printf("%s:", s); + fprintf(outf, "%s:", s); for (i = 0; i < MAX_BIC; ++i) { if (CPU_ISSET(i, set)) - printf(" %s", bic[i].name); + fprintf(outf, " %s", bic[i].name); } - putchar('\n'); + fputc('\n', outf); } static bic_set_t bic_group_topology; @@ -320,6 +325,21 @@ static bic_set_t bic_group_disabled_by_default; static bic_set_t bic_enabled; static bic_set_t bic_present; +static void dump_bic_sets(void) +{ + print_bic_set("bic_enabled", &bic_enabled); + print_bic_set("bic_present", &bic_present); + print_bic_set("bic_group_topology", &bic_group_topology); + print_bic_set("bic_group_thermal_pwr", &bic_group_thermal_pwr); + print_bic_set("bic_group_frequency", &bic_group_frequency); + print_bic_set("bic_group_hw_idle", &bic_group_hw_idle); + print_bic_set("bic_group_sw_idle", &bic_group_sw_idle); + print_bic_set("bic_group_idle", &bic_group_idle); + print_bic_set("bic_group_cache", &bic_group_cache); + print_bic_set("bic_group_other", &bic_group_other); + print_bic_set("bic_group_disabled_by_default", &bic_group_disabled_by_default); +} + /* modify */ #define BIC_INIT(set) CPU_ZERO(set) @@ -485,7 +505,6 @@ static void bic_groups_init(void) #define PCLUNL 15 /* Unlimited */ char *proc_stat = "/proc/stat"; -FILE *outf; int *fd_percpu; int *fd_instr_count_percpu; int *fd_llc_percpu; @@ -11772,8 +11791,10 @@ skip_cgroup_setting: msr_sum_record(); /* dump counters and exit */ - if (dump_only) + if (dump_only) { + dump_bic_sets(); return get_and_dump_counters(); + } /* list header and exit */ if (list_header_only) { -- cgit v1.2.3 From 12f841ec7b8943923f04fc438cb2883b9f9a773e Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sun, 3 May 2026 13:27:29 -0400 Subject: tools/power turbostat: Cleanup add_counter declaration Declaration and definition parameter name mismatch was confusing. Some params can be 'const'. No functional change. Assisted-by: Claude:claude-sonnet-4.6 Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index c63aa2ec7426..a005ac6942b5 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -590,8 +590,8 @@ struct gfx_sysfs_info { static struct gfx_sysfs_info gfx_info[GFX_MAX]; int get_msr(int cpu, off_t offset, unsigned long long *msr); -int add_counter(unsigned int msr_num, char *path, char *name, - unsigned int width, enum counter_scope scope, enum counter_type type, enum counter_format format, int flags, int package_num); +int add_counter(unsigned int msr_num, const char *path, const char *name, + unsigned int width, enum counter_scope scope, enum counter_type type, enum counter_format format, int flags, int id); /* Model specific support Start */ @@ -10718,7 +10718,7 @@ void print_bootcmd(void) fclose(fp); } -struct msr_counter *find_msrp_by_name(struct msr_counter *head, char *name) +struct msr_counter *find_msrp_by_name(struct msr_counter *head, const char *name) { struct msr_counter *mp; @@ -10731,7 +10731,7 @@ struct msr_counter *find_msrp_by_name(struct msr_counter *head, char *name) return NULL; } -int add_counter(unsigned int msr_num, char *path, char *name, +int add_counter(unsigned int msr_num, const char *path, const char *name, unsigned int width, enum counter_scope scope, enum counter_type type, enum counter_format format, int flags, int id) { struct msr_counter *msrp; -- cgit v1.2.3 From 3bbe42ac516d3f0ea43aaaa6dbf98f174f3f8a1b Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sun, 3 May 2026 14:29:40 -0400 Subject: tools/power turbostat: Cleanup: consistently use warn/err, not perror Acknowledge that get_msr() always errs out on failure by returning void and deleting checks for its return value. Replace all perror() with warn(). Replace all perror()/exit() with err(). No functional change, unless you count the uniform return value of -1 on calloc failure. Assisted-by: Claude:claude-sonnet-4.6 Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 254 ++++++++++++---------------------- 1 file changed, 87 insertions(+), 167 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index a005ac6942b5..cab144d1d5ec 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -589,7 +589,7 @@ struct gfx_sysfs_info { static struct gfx_sysfs_info gfx_info[GFX_MAX]; -int get_msr(int cpu, off_t offset, unsigned long long *msr); +void get_msr(int cpu, off_t offset, unsigned long long *msr); int add_counter(unsigned int msr_num, const char *path, const char *name, unsigned int width, enum counter_scope scope, enum counter_type type, enum counter_format format, int flags, int id); @@ -648,8 +648,7 @@ double slm_bclk(void) unsigned int i; double freq; - if (get_msr(master_cpu, MSR_FSB_FREQ, &msr)) - fprintf(outf, "SLM BCLK: unknown\n"); + get_msr(master_cpu, MSR_FSB_FREQ, &msr); i = msr & 0xf; if (i >= SLM_BCLK_FREQS) { @@ -2647,18 +2646,12 @@ int get_instr_count_fd(int cpu) return fd_instr_count_percpu[cpu]; } -int get_msr(int cpu, off_t offset, unsigned long long *msr) +void get_msr(int cpu, off_t offset, unsigned long long *msr) { - ssize_t retval; - assert(!no_msr); - retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); - - if (retval != sizeof *msr) + if (pread(get_msr_fd(cpu), msr, sizeof(*msr), offset) != sizeof(*msr)) err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset); - - return 0; } int add_msr_counter(int cpu, off_t offset) @@ -4552,8 +4545,7 @@ int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp, char * { if (mp->msr_num != 0) { assert(!no_msr); - if (get_msr(cpu, mp->msr_num, counterp)) - return -1; + get_msr(cpu, mp->msr_num, counterp); } else { char path[128 + PATH_BYTES]; @@ -4917,13 +4909,10 @@ int get_rapl_counters(int cpu, unsigned int domain, struct core_data *c, struct fprintf(stderr, "Reading rapl counter via msr at %u\n", i); assert(!no_msr); - if (rci->flags[i] & RAPL_COUNTER_FLAG_USE_MSR_SUM) { - if (get_msr_sum(cpu, rci->msr[i], &rci->data[i])) - return -13 - i; - } else { - if (get_msr(cpu, rci->msr[i], &rci->data[i])) - return -13 - i; - } + if (rci->flags[i] & RAPL_COUNTER_FLAG_USE_MSR_SUM) + get_msr_sum(cpu, rci->msr[i], &rci->data[i]); + else + get_msr(cpu, rci->msr[i], &rci->data[i]); rci->data[i] &= rci->msr_mask[i]; if (rci->msr_shift[i] >= 0) @@ -5052,8 +5041,7 @@ int get_cstate_counters(unsigned int cpu, PER_THREAD_PARAMS) case COUNTER_SOURCE_MSR: assert(!no_msr); - if (get_msr(cpu, cci->msr[i], &cci->data[i])) - return -13 - i; + get_msr(cpu, cci->msr[i], &cci->data[i]); if (debug >= 2) fprintf(stderr, "cstate via %s0x%llx %u: %llu\n", "msr", cci->msr[i], i, cci->data[i]); @@ -5151,8 +5139,7 @@ int get_smi_aperf_mperf(unsigned int cpu, struct thread_data *t) case COUNTER_SOURCE_MSR: assert(!no_msr); - if (get_msr(cpu, mci->msr[i], &mci->data[i])) - return -2 - i; + get_msr(cpu, mci->msr[i], &mci->data[i]); mci->data[i] &= mci->msr_mask[i]; @@ -5317,12 +5304,10 @@ int get_counters(PER_THREAD_PARAMS) } if (DO_BIC(BIC_Mod_c6)) - if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) - return -8; + get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us); if (DO_BIC(BIC_CoreTmp)) { - if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) - return -9; + get_msr(cpu, MSR_IA32_THERM_STATUS, &msr); c->core_temp_c = tj_max - ((msr >> 16) & 0x7F); } @@ -5344,22 +5329,14 @@ int get_counters(PER_THREAD_PARAMS) if (!is_cpu_first_core_in_package(t, p)) goto done; - if (DO_BIC(BIC_Totl_c0)) { - if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) - return -10; - } - if (DO_BIC(BIC_Any_c0)) { - if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) - return -11; - } - if (DO_BIC(BIC_GFX_c0)) { - if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) - return -12; - } - if (DO_BIC(BIC_CPUGFX)) { - if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) - return -13; - } + if (DO_BIC(BIC_Totl_c0)) + get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0); + if (DO_BIC(BIC_Any_c0)) + get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0); + if (DO_BIC(BIC_GFX_c0)) + get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0); + if (DO_BIC(BIC_CPUGFX)) + get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0); if (DO_BIC(BIC_CPU_LPI)) p->cpu_lpi = cpuidle_cur_cpu_lpi_us; @@ -5373,8 +5350,7 @@ int get_counters(PER_THREAD_PARAMS) } if (DO_BIC(BIC_PkgTmp)) { - if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) - return -17; + get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr); p->pkg_temp_c = tj_max - ((msr >> 16) & 0x7F); } @@ -6712,7 +6688,7 @@ void do_sleep(void) int get_msr_sum(int cpu, off_t offset, unsigned long long *msr) { - int ret, idx; + int idx; unsigned long long msr_cur, msr_last; assert(!no_msr); @@ -6724,9 +6700,7 @@ int get_msr_sum(int cpu, off_t offset, unsigned long long *msr) if (idx < 0) return idx; /* get_msr_sum() = sum + (get_msr() - last) */ - ret = get_msr(cpu, offset, &msr_cur); - if (ret) - return ret; + get_msr(cpu, offset, &msr_cur); msr_last = per_cpu_msr_sum[cpu].entries[idx].last; DELTA_WRAP32(msr_cur, msr_last); *msr = msr_last + per_cpu_msr_sum[cpu].entries[idx].sum; @@ -6739,7 +6713,7 @@ timer_t timerid; /* Timer callback, update the sum of MSRs periodically. */ static int update_msr_sum(PER_THREAD_PARAMS) { - int i, ret; + int i; int cpu = t->cpu_id; UNUSED(c); @@ -6756,11 +6730,7 @@ static int update_msr_sum(PER_THREAD_PARAMS) offset = idx_to_offset(i); if (offset < 0) continue; - ret = get_msr(cpu, offset, &msr_cur); - if (ret) { - fprintf(outf, "Can not update msr(0x%llx)\n", (unsigned long long)offset); - continue; - } + get_msr(cpu, offset, &msr_cur); msr_last = per_cpu_msr_sum[cpu].entries[i].last; per_cpu_msr_sum[cpu].entries[i].last = msr_cur & 0xffffffff; @@ -7612,27 +7582,21 @@ int print_hwp(PER_THREAD_PARAMS) return -1; } - if (get_msr(cpu, MSR_PM_ENABLE, &msr)) - return 0; - + get_msr(cpu, MSR_PM_ENABLE, &msr); fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", cpu, msr, (msr & (1 << 0)) ? "" : "No-"); /* MSR_PM_ENABLE[1] == 1 if HWP is enabled and MSRs visible */ if ((msr & (1 << 0)) == 0) return 0; - if (get_msr(cpu, MSR_HWP_CAPABILITIES, &msr)) - return 0; - + get_msr(cpu, MSR_HWP_CAPABILITIES, &msr); fprintf(outf, "cpu%d: MSR_HWP_CAPABILITIES: 0x%08llx " "(high %d guar %d eff %d low %d)\n", cpu, msr, (unsigned int)HWP_HIGHEST_PERF(msr), (unsigned int)HWP_GUARANTEED_PERF(msr), (unsigned int)HWP_MOSTEFFICIENT_PERF(msr), (unsigned int)HWP_LOWEST_PERF(msr)); - if (get_msr(cpu, MSR_HWP_REQUEST, &msr)) - return 0; - + get_msr(cpu, MSR_HWP_REQUEST, &msr); fprintf(outf, "cpu%d: MSR_HWP_REQUEST: 0x%08llx " "(min %d max %d des %d epp 0x%x window 0x%x pkg 0x%x)\n", cpu, msr, @@ -7642,9 +7606,7 @@ int print_hwp(PER_THREAD_PARAMS) (unsigned int)(((msr) >> 24) & 0xff), (unsigned int)(((msr) >> 32) & 0xff3), (unsigned int)(((msr) >> 42) & 0x1)); if (has_hwp_pkg) { - if (get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr)) - return 0; - + get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr); fprintf(outf, "cpu%d: MSR_HWP_REQUEST_PKG: 0x%08llx " "(min %d max %d des %d epp 0x%x window 0x%x)\n", cpu, msr, @@ -7653,15 +7615,11 @@ int print_hwp(PER_THREAD_PARAMS) (unsigned int)(((msr) >> 16) & 0xff), (unsigned int)(((msr) >> 24) & 0xff), (unsigned int)(((msr) >> 32) & 0xff3)); } if (has_hwp_notify) { - if (get_msr(cpu, MSR_HWP_INTERRUPT, &msr)) - return 0; - + get_msr(cpu, MSR_HWP_INTERRUPT, &msr); fprintf(outf, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx " "(%s_Guaranteed_Perf_Change, %s_Excursion_Min)\n", cpu, msr, ((msr) & 0x1) ? "EN" : "Dis", ((msr) & 0x2) ? "EN" : "Dis"); } - if (get_msr(cpu, MSR_HWP_STATUS, &msr)) - return 0; - + get_msr(cpu, MSR_HWP_STATUS, &msr); fprintf(outf, "cpu%d: MSR_HWP_STATUS: 0x%08llx " "(%sGuaranteed_Perf_Change, %sExcursion_Min)\n", cpu, msr, ((msr) & 0x1) ? "" : "No-", ((msr) & 0x4) ? "" : "No-"); @@ -7774,9 +7732,10 @@ double get_tdp_intel(void) { unsigned long long msr; - if (valid_rapl_msrs & RAPL_PKG_POWER_INFO) - if (!get_msr(master_cpu, MSR_PKG_POWER_INFO, &msr)) - return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; + if (valid_rapl_msrs & RAPL_PKG_POWER_INFO) { + get_msr(master_cpu, MSR_PKG_POWER_INFO, &msr); + return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; + } return get_quirk_tdp(); } @@ -7814,8 +7773,7 @@ void rapl_probe_intel(void) CLR_BIC(BIC_RAM__, &bic_enabled); /* units on package 0, verify later other packages match */ - if (get_msr(master_cpu, MSR_RAPL_POWER_UNIT, &msr)) - return; + get_msr(master_cpu, MSR_RAPL_POWER_UNIT, &msr); rapl_power_units = 1.0 / (1 << (msr & 0xF)); if (platform->has_rapl_divisor) @@ -7862,9 +7820,7 @@ void rapl_probe_amd(void) if (!valid_rapl_msrs || no_msr) return; - if (get_msr(master_cpu, MSR_RAPL_PWR_UNIT, &msr)) - return; - + get_msr(master_cpu, MSR_RAPL_PWR_UNIT, &msr); rapl_time_units = ldexp(1.0, -(msr >> 16 & 0xf)); rapl_energy_units = ldexp(1.0, -(msr >> 8 & 0x1f)); rapl_power_units = ldexp(1.0, -(msr & 0xf)); @@ -8020,7 +7976,7 @@ static int print_rapl_sysfs(void) snprintf(path, PATH_MAX, "%s/%s", PATH_RAPL_SYSFS, entry->d_name); if ((cdir = opendir(path)) == NULL) { - perror("opendir() error"); + warn("%s", path); return 1; } @@ -8063,21 +8019,17 @@ int print_rapl(PER_THREAD_PARAMS) if (valid_rapl_msrs & RAPL_AMD_F17H) { msr_name = "MSR_RAPL_PWR_UNIT"; - if (get_msr(cpu, MSR_RAPL_PWR_UNIT, &msr)) - return -1; + get_msr(cpu, MSR_RAPL_PWR_UNIT, &msr); } else { msr_name = "MSR_RAPL_POWER_UNIT"; - if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) - return -1; + get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr); } fprintf(outf, "cpu%d: %s: 0x%08llx (%f Watts, %f Joules, %f sec.)\n", cpu, msr_name, msr, rapl_power_units, rapl_energy_units, rapl_time_units); if (valid_rapl_msrs & RAPL_PKG_POWER_INFO) { - if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr)) - return -5; - + get_msr(cpu, MSR_PKG_POWER_INFO, &msr); fprintf(outf, "cpu%d: MSR_PKG_POWER_INFO: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", cpu, msr, ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, @@ -8087,9 +8039,7 @@ int print_rapl(PER_THREAD_PARAMS) } if (valid_rapl_msrs & RAPL_PKG) { - if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr)) - return -9; - + get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr); fprintf(outf, "cpu%d: MSR_PKG_POWER_LIMIT: 0x%08llx (%slocked)\n", cpu, msr, (msr >> 63) & 1 ? "" : "UN"); print_power_limit_msr(cpu, msr, "PKG Limit #1"); @@ -8099,17 +8049,13 @@ int print_rapl(PER_THREAD_PARAMS) ((msr >> 32) & 0x7FFF) * rapl_power_units, (1.0 + (((msr >> 54) & 0x3) / 4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, ((msr >> 48) & 1) ? "EN" : "DIS"); - if (get_msr(cpu, MSR_VR_CURRENT_CONFIG, &msr)) - return -9; - + get_msr(cpu, MSR_VR_CURRENT_CONFIG, &msr); fprintf(outf, "cpu%d: MSR_VR_CURRENT_CONFIG: 0x%08llx\n", cpu, msr); fprintf(outf, "cpu%d: PKG Limit #4: %f Watts (%slocked)\n", cpu, ((msr >> 0) & 0x1FFF) * rapl_power_units, (msr >> 31) & 1 ? "" : "UN"); } if (valid_rapl_msrs & RAPL_DRAM_POWER_INFO) { - if (get_msr(cpu, MSR_DRAM_POWER_INFO, &msr)) - return -6; - + get_msr(cpu, MSR_DRAM_POWER_INFO, &msr); fprintf(outf, "cpu%d: MSR_DRAM_POWER_INFO,: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", cpu, msr, ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, @@ -8117,32 +8063,25 @@ int print_rapl(PER_THREAD_PARAMS) ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); } if (valid_rapl_msrs & RAPL_DRAM) { - if (get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr)) - return -9; + get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr); fprintf(outf, "cpu%d: MSR_DRAM_POWER_LIMIT: 0x%08llx (%slocked)\n", cpu, msr, (msr >> 31) & 1 ? "" : "UN"); print_power_limit_msr(cpu, msr, "DRAM Limit"); } if (valid_rapl_msrs & RAPL_CORE_POLICY) { - if (get_msr(cpu, MSR_PP0_POLICY, &msr)) - return -7; - + get_msr(cpu, MSR_PP0_POLICY, &msr); fprintf(outf, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF); } if (valid_rapl_msrs & RAPL_CORE_POWER_LIMIT) { - if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr)) - return -9; + get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr); fprintf(outf, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n", cpu, msr, (msr >> 31) & 1 ? "" : "UN"); print_power_limit_msr(cpu, msr, "Cores Limit"); } if (valid_rapl_msrs & RAPL_GFX) { - if (get_msr(cpu, MSR_PP1_POLICY, &msr)) - return -8; - + get_msr(cpu, MSR_PP1_POLICY, &msr); fprintf(outf, "cpu%d: MSR_PP1_POLICY: %lld\n", cpu, msr & 0xF); - if (get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr)) - return -9; + get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr); fprintf(outf, "cpu%d: MSR_PP1_POWER_LIMIT: 0x%08llx (%slocked)\n", cpu, msr, (msr >> 31) & 1 ? "" : "UN"); print_power_limit_msr(cpu, msr, "GFX Limit"); } @@ -8157,7 +8096,6 @@ int print_rapl(PER_THREAD_PARAMS) */ void probe_rapl_msrs(void) { - int ret; off_t offset; unsigned long long msr_value; @@ -8171,12 +8109,7 @@ void probe_rapl_msrs(void) if (offset < 0) return; - ret = get_msr(master_cpu, offset, &msr_value); - if (ret) { - if (debug) - fprintf(outf, "Can not read RAPL_PKG_ENERGY MSR(0x%llx)\n", (unsigned long long)offset); - return; - } + get_msr(master_cpu, offset, &msr_value); if (msr_value == 0) { if (debug) fprintf(outf, "RAPL_PKG_ENERGY MSR(0x%llx) == ZERO: disabling all RAPL MSRs\n", (unsigned long long)offset); @@ -8256,17 +8189,17 @@ int set_temperature_target(PER_THREAD_PARAMS) if (!platform->has_nhm_msrs || no_msr) goto guess; - if (get_msr(master_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr)) - goto guess; - + get_msr(master_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr); tcc_default = (msr >> 16) & 0xFF; if (!quiet) { int bits = platform->tcc_offset_bits; unsigned long long enabled = 0; - if (bits && !get_msr(master_cpu, MSR_PLATFORM_INFO, &enabled)) + if (bits) { + get_msr(master_cpu, MSR_PLATFORM_INFO, &enabled); enabled = (enabled >> 30) & 1; + } if (bits && enabled) { tcc_offset = (msr >> 24) & GENMASK(bits - 1, 0); @@ -8318,15 +8251,11 @@ int print_thermal(PER_THREAD_PARAMS) } if (do_ptm && is_cpu_first_core_in_package(t, p)) { - if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) - return 0; - + get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr); dts = (msr >> 16) & 0x7F; fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_STATUS: 0x%08llx (%d C)\n", cpu, msr, tj_max - dts); - if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr)) - return 0; - + get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr); dts = (msr >> 16) & 0x7F; dts2 = (msr >> 8) & 0x7F; fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n", cpu, msr, tj_max - dts, tj_max - dts2); @@ -8335,16 +8264,12 @@ int print_thermal(PER_THREAD_PARAMS) if (do_dts && debug) { unsigned int resolution; - if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) - return 0; - + get_msr(cpu, MSR_IA32_THERM_STATUS, &msr); dts = (msr >> 16) & 0x7F; resolution = (msr >> 27) & 0xF; fprintf(outf, "cpu%d: MSR_IA32_THERM_STATUS: 0x%08llx (%d C +/- %d)\n", cpu, msr, tj_max - dts, resolution); - if (get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr)) - return 0; - + get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr); dts = (msr >> 16) & 0x7F; dts2 = (msr >> 8) & 0x7F; fprintf(outf, "cpu%d: MSR_IA32_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n", cpu, msr, tj_max - dts, tj_max - dts2); @@ -8403,9 +8328,9 @@ void decode_feature_control_msr(void) if (quiet) return; - if (!get_msr(master_cpu, MSR_IA32_FEAT_CTL, &msr)) - fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", - master_cpu, msr, msr & FEAT_CTL_LOCKED ? "" : "UN-", msr & (1 << 18) ? "SGX" : ""); + get_msr(master_cpu, MSR_IA32_FEAT_CTL, &msr); + fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", + master_cpu, msr, msr & FEAT_CTL_LOCKED ? "" : "UN-", msr & (1 << 18) ? "SGX" : ""); } void decode_misc_enable_msr(void) @@ -8418,13 +8343,13 @@ void decode_misc_enable_msr(void) if (!genuine_intel) return; - if (!get_msr(master_cpu, MSR_IA32_MISC_ENABLE, &msr)) - fprintf(outf, "cpu%d: MSR_IA32_MISC_ENABLE: 0x%08llx (%sTCC %sEIST %sMWAIT %sPREFETCH %sTURBO)\n", - master_cpu, msr, - msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", - msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", - msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", - msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); + get_msr(master_cpu, MSR_IA32_MISC_ENABLE, &msr); + fprintf(outf, "cpu%d: MSR_IA32_MISC_ENABLE: 0x%08llx (%sTCC %sEIST %sMWAIT %sPREFETCH %sTURBO)\n", + master_cpu, msr, + msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", + msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", + msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", + msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); } void decode_misc_feature_control(void) @@ -8437,10 +8362,10 @@ void decode_misc_feature_control(void) if (!platform->has_msr_misc_feature_control) return; - if (!get_msr(master_cpu, MSR_MISC_FEATURE_CONTROL, &msr)) - fprintf(outf, - "cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP-Prefetch)\n", - master_cpu, msr, msr & (0 << 0) ? "No-" : "", msr & (1 << 0) ? "No-" : "", msr & (2 << 0) ? "No-" : "", msr & (3 << 0) ? "No-" : ""); + get_msr(master_cpu, MSR_MISC_FEATURE_CONTROL, &msr); + fprintf(outf, + "cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP-Prefetch)\n", + master_cpu, msr, msr & (0 << 0) ? "No-" : "", msr & (1 << 0) ? "No-" : "", msr & (2 << 0) ? "No-" : "", msr & (3 << 0) ? "No-" : ""); } /* @@ -8460,9 +8385,9 @@ void decode_misc_pwr_mgmt_msr(void) if (!platform->has_msr_misc_pwr_mgmt) return; - if (!get_msr(master_cpu, MSR_MISC_PWR_MGMT, &msr)) - fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB %sable-OOB)\n", - master_cpu, msr, msr & (1 << 0) ? "DIS" : "EN", msr & (1 << 1) ? "EN" : "DIS", msr & (1 << 8) ? "EN" : "DIS"); + get_msr(master_cpu, MSR_MISC_PWR_MGMT, &msr); + fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB %sable-OOB)\n", + master_cpu, msr, msr & (1 << 0) ? "DIS" : "EN", msr & (1 << 1) ? "EN" : "DIS", msr & (1 << 8) ? "EN" : "DIS"); } /* @@ -8481,11 +8406,11 @@ void decode_c6_demotion_policy_msr(void) if (!platform->has_msr_c6_demotion_policy_config) return; - if (!get_msr(master_cpu, MSR_CC6_DEMOTION_POLICY_CONFIG, &msr)) - fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", master_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); + get_msr(master_cpu, MSR_CC6_DEMOTION_POLICY_CONFIG, &msr); + fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", master_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); - if (!get_msr(master_cpu, MSR_MC6_DEMOTION_POLICY_CONFIG, &msr)) - fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", master_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); + get_msr(master_cpu, MSR_MC6_DEMOTION_POLICY_CONFIG, &msr); + fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", master_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); } void print_dev_latency(void) @@ -9186,13 +9111,10 @@ void process_cpuid() cpuid_has_hv = ecx_flags & (1 << 31); if (!no_msr) { - if (get_msr(sched_getcpu(), MSR_IA32_UCODE_REV, &ucode_patch)) { - warnx("get_msr(UCODE)"); - } else { - ucode_patch_valid = true; - if (!authentic_amd && !hygon_genuine) - ucode_patch >>= 32; - } + get_msr(sched_getcpu(), MSR_IA32_UCODE_REV, &ucode_patch); + ucode_patch_valid = true; + if (!authentic_amd && !hygon_genuine) + ucode_patch >>= 32; } /* @@ -10821,10 +10743,8 @@ int add_counter(unsigned int msr_num, const char *path, const char *name, struct sysfs_path *sp; sp = calloc(1, sizeof(struct sysfs_path)); - if (sp == NULL) { - perror("calloc"); - exit(1); - } + if (sp == NULL) + err(-1, "%s", path); strncpy(sp->path, path, PATH_BYTES - 1); sp->id = id; sp->next = msrp->sp; @@ -11760,7 +11680,7 @@ int main(int argc, char **argv) ret = write(fd, "0\n", 2); if (ret == -1) - perror("Can't update cgroup\n"); + warn("/sys/fs/cgroup/cgroup.procs"); close(fd); -- cgit v1.2.3 From 501c340739775ae01139b02ff50d392d0ca20e6f Mon Sep 17 00:00:00 2001 From: Len Brown Date: Mon, 4 May 2026 15:27:12 -0400 Subject: tools/power turbostat: Fix typo: MHz, not Mhz The SI symbol for megahertz capitalizes both the SI prefix ('M') and the unit symbol ('Hz'). Assisted-by: Claude:claude-sonnet-4.6 Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.8 | 4 ++-- tools/power/x86/turbostat/turbostat.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8 index 344ede2f8546..830c9f094765 100644 --- a/tools/power/x86/turbostat/turbostat.8 +++ b/tools/power/x86/turbostat/turbostat.8 @@ -269,7 +269,7 @@ Periodic output goes to stdout, by default, unless --out is used to specify an o The 5-second interval can be changed with the "-i sec" option. .nf sudo turbostat --quiet --show CPU,frequency - Core CPU Avg_MHz Busy% Bzy_MHz TSC_MHz CPU%c7 UncMhz + Core CPU Avg_MHz Busy% Bzy_MHz TSC_MHz CPU%c7 UncMHz - - 524 12.48 4198 3096 74.53 3800 0 0 4 0.09 4081 3096 98.88 3800 0 4 1 0.02 4063 3096 @@ -279,7 +279,7 @@ sudo turbostat --quiet --show CPU,frequency 2 6 3 0.08 4159 3096 3 3 1 0.04 4046 3096 99.66 3 7 0 0.01 3989 3096 - Core CPU Avg_MHz Busy% Bzy_MHz TSC_MHz CPU%c7 UncMhz + Core CPU Avg_MHz Busy% Bzy_MHz TSC_MHz CPU%c7 UncMHz - - 525 12.52 4198 3096 74.54 3800 0 0 4 0.10 4051 3096 99.49 3800 0 4 2 0.04 3993 3096 diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index cab144d1d5ec..3248a6a60732 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -658,7 +658,7 @@ double slm_bclk(void) freq = slm_freq_table[i]; if (!quiet) - fprintf(outf, "SLM BCLK: %.1f Mhz\n", freq); + fprintf(outf, "SLM BCLK: %.1f MHz\n", freq); return freq; } -- cgit v1.2.3 From e1708e514a368ca2cb05a5c6e122919005027bad Mon Sep 17 00:00:00 2001 From: Len Brown Date: Mon, 4 May 2026 15:32:12 -0400 Subject: tools/power turbostat: Cleanup: bool force_load It is confusing to increment what is effectively a bool value. Define force_load as bool, and access it accordingly. Assisted-by: Claude:claude-sonnet-4.6 Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 3248a6a60732..dbbaa737342d 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -523,7 +523,7 @@ unsigned int valid_rapl_msrs; unsigned int summary_only; unsigned int list_header_only; unsigned int dump_only; -unsigned int force_load; +bool force_load; unsigned int cpuid_has_aperf_mperf; unsigned int cpuid_has_hv; unsigned int has_aperf_access; @@ -1360,7 +1360,7 @@ void probe_platform_features(unsigned int family, unsigned int model) if (authentic_amd || hygon_genuine) { /* fallback to default features on unsupported models */ - force_load++; + force_load = true; if (max_extended_level >= 0x80000007) { unsigned int eax, ebx, ecx, edx; @@ -1383,7 +1383,7 @@ void probe_platform_features(unsigned int family, unsigned int model) } end: - if (force_load && !platform) { + if ((force_load == true) && !platform) { fprintf(outf, "Forced to run on unsupported platform!\n"); platform = &default_features; } @@ -11555,7 +11555,7 @@ void cmdline(int argc, char **argv) bic_lookup(&bic_enabled, optarg, SHOW_LIST); break; case 'f': - force_load++; + force_load = true; break; case 'd': debug++; -- cgit v1.2.3 From e817a533bbc0aef5a9cb6255153941ed968d2fb1 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Mon, 4 May 2026 15:38:34 -0400 Subject: tools/power turbostat: pmt: Improve sscanf() hygiene Explicitly check sscanf() return values for number of matches, and handle EOF (-1). Defensive programming -- not an issue actively seen by users. Fixes: 4265a86582ea ("tools/power turbostat: Add PMT directory iterator helper") Assisted-by: Claude:claude-sonnet-4.6 Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index dbbaa737342d..cacdf4c9c5d7 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -2011,15 +2011,17 @@ int pmt_telemdir_filter(const struct dirent *e) { unsigned int dummy; - return sscanf(e->d_name, "telem%u", &dummy); + return (sscanf(e->d_name, "telem%u", &dummy) == 1); } int pmt_telemdir_sort(const struct dirent **a, const struct dirent **b) { unsigned int aidx = 0, bidx = 0; - sscanf((*a)->d_name, "telem%u", &aidx); - sscanf((*b)->d_name, "telem%u", &bidx); + if (sscanf((*a)->d_name, "telem%u", &aidx) != 1) + aidx = 0; + if (sscanf((*b)->d_name, "telem%u", &bidx) != 1) + bidx = 0; return (aidx > bidx) ? 1 : (aidx < bidx) ? -1 : 0; } -- cgit v1.2.3 From 890265c019317ce56219013d41cb73d4e664d623 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sun, 24 May 2026 10:41:42 -0400 Subject: tools/power turbostat: Dump RDT CPUID.7 Support Show both Symmetric and Asymmetric RDT bits. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index cacdf4c9c5d7..02d566f0de1a 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -8327,9 +8327,6 @@ void decode_feature_control_msr(void) if (no_msr) return; - if (quiet) - return; - get_msr(master_cpu, MSR_IA32_FEAT_CTL, &msr); fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", master_cpu, msr, msr & FEAT_CTL_LOCKED ? "" : "UN-", msr & (1 << 18) ? "SGX" : ""); @@ -9200,21 +9197,31 @@ void process_cpuid() decode_misc_enable_msr(); if (max_level >= 0x7) { - int has_sgx; + eax = ebx = ecx = edx = 0; + __cpuid_count(0x7, 0, eax, ebx, ecx, edx); - ecx = 0; + is_hybrid = !!(edx & (1 << 15)); - __cpuid_count(0x7, 0, eax, ebx, ecx, edx); + if (!quiet) { + int has_sgx, has_rdt_m, has_rdt_a, has_ardt_m, has_ardt_a; - has_sgx = ebx & (1 << 2); + has_sgx = ebx & (1 << 2); + has_rdt_m = ebx & (1 << 12); + has_rdt_a = ebx & (1 << 15); - is_hybrid = !!(edx & (1 << 15)); + eax = ebx = ecx = edx = 0; + __cpuid_count(0x7, 1, eax, ebx, ecx, edx); - if (!quiet) - fprintf(outf, "CPUID(7): %sSGX %sHybrid\n", has_sgx ? "" : "No-", is_hybrid ? "" : "No-"); + has_ardt_m = ecx & (1 << 0); + has_ardt_a = ecx & (1 << 1); - if (has_sgx) - decode_feature_control_msr(); + fprintf(outf, "CPUID(7): %sSGX %sRDT_M %sRDT_A %sARDT_M %sARDT_A %sHybrid\n", + has_sgx ? "" : "No-", has_rdt_m ? "" : "No-", has_rdt_a ? "" : "No-", has_ardt_m ? "" : "No-", has_ardt_a ? "" : "No-", + is_hybrid ? "" : "No-"); + + if (has_sgx) + decode_feature_control_msr(); + } } if (max_level >= 0x15) { -- cgit v1.2.3 From e48d77302b85bdf80765a6eb3b34c4b5b20f5cb6 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sun, 24 May 2026 13:42:24 -0400 Subject: tools/power turbostat: Dump RDT CPUID.0xF,0x10,0x27,0x28 Support If Asymmetric RDT is supported, dump it on every CPU. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 02d566f0de1a..d897c48d85aa 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -9076,6 +9076,65 @@ void dump_cpuid_hypervisor(void) fprintf(outf, "\n"); } +void dump_rdt_m_leaf(int leaf) +{ + unsigned int eax, ebx, ecx, edx; + int cpu = sched_getcpu(); + + __cpuid_count(leaf, 0, eax, ebx, ecx, edx); + + fprintf(outf, "cpu%d: CPUID(0x%x).0: MAX_RMID:%d %sL3_MON\n", cpu, leaf, ebx, edx & 0x1 ? "" : "No-"); +} + +#define RDT_CAT_L3_INDEX 1 +#define RDT_CAT_L2_INDEX 2 +#define RDT_MBA_INDEX 3 +#define RDT_CBA_INDEX 5 +#define RDT_RP_INDEX 6 + +void dump_rdt_a_leaf(int leaf) +{ + unsigned int eax, ebx, ecx, edx; + int cpu = sched_getcpu(); + unsigned int has_cat_l3, has_cat_l2, has_mba, has_cba, has_rp; + + __cpuid_count(leaf, 0, eax, ebx, ecx, edx); + + has_cat_l3 = ebx & (1 << RDT_CAT_L3_INDEX); + has_cat_l2 = ebx & (1 << RDT_CAT_L2_INDEX); + has_mba = ebx & (1 << RDT_MBA_INDEX); + has_cba = ebx & (1 << RDT_CBA_INDEX); + has_rp = ebx & (1 << RDT_RP_INDEX); + + fprintf(outf, "cpu%d: CPUID(0x%x).0: %sCATL3, %sCATL2, %sMBA, %sCBA, %sRP\n", cpu, leaf, + has_cat_l3 ? "" : "No-", has_cat_l2 ? "" : "No-", has_mba ? "" : "No-", has_cba ? "" : "No-", has_rp ? "" : "No-"); + if (has_rp) { + unsigned int has_rp_thread, has_rp_package; + + __cpuid_count(leaf, RDT_RP_INDEX, eax, ebx, ecx, edx); + + has_rp_thread = eax & (1 << 0); + has_rp_package = eax & (1 << 1); + + fprintf(outf, "cpu%d: CPUID(0x%x).%d: %sRP_THREAD, %sRP_PKG\n", + cpu, leaf, RDT_RP_INDEX, has_rp_thread ? "" : "No-", has_rp_package ? "" : "No-"); + } +} + +int dump_ardt_m(int cpu) +{ + cpu_migrate(cpu); + dump_rdt_m_leaf(0x27); + return 0; +} + +int dump_ardt_a(int cpu) +{ + cpu_migrate(cpu); + dump_rdt_a_leaf(0x28); + return 0; +} + void process_cpuid() { unsigned int eax, ebx, ecx, edx; @@ -9221,6 +9280,15 @@ void process_cpuid() if (has_sgx) decode_feature_control_msr(); + + if (has_rdt_m && max_level >= 0xF) + dump_rdt_m_leaf(0xF); + if (has_rdt_a && max_level >= 0x10) + dump_rdt_a_leaf(0x10); + if (has_ardt_m && max_level >= 0x27) + for_all_proc_cpus(dump_ardt_m); + if (has_ardt_a && max_level >= 0x28) + for_all_proc_cpus(dump_ardt_a); } } -- cgit v1.2.3 From 7aa84b0a2c76be971e925f8e41cd7cffe1571869 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sun, 24 May 2026 17:02:13 -0400 Subject: tools/power turbostat: Dump RP-Enable MSRs To reduce verbosity, put the Enable MSRs on the same output line as the CPUID info that shows they exist. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index d897c48d85aa..7eefaf021ea8 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -9092,6 +9092,14 @@ void dump_rdt_m_leaf(int leaf) #define RDT_CBA_INDEX 5 #define RDT_RP_INDEX 6 +#ifndef MSR_IA32_RESOURCE_PRIORITY +#define MSR_IA32_RESOURCE_PRIORITY 0xc88 +#endif + +#ifndef MSR_IA32_RESOURCE_PRIORITY_PKG +#define MSR_IA32_RESOURCE_PRIORITY_PKG 0xc89 +#endif + void dump_rdt_a_leaf(int leaf) { unsigned int eax, ebx, ecx, edx; @@ -9116,8 +9124,21 @@ void dump_rdt_a_leaf(int leaf) has_rp_thread = eax & (1 << 0); has_rp_package = eax & (1 << 1); - fprintf(outf, "cpu%d: CPUID(0x%x).%d: %sRP_THREAD, %sRP_PKG\n", + fprintf(outf, "cpu%d: CPUID(0x%x).%d: %sRP_THREAD, %sRP_PKG", cpu, leaf, RDT_RP_INDEX, has_rp_thread ? "" : "No-", has_rp_package ? "" : "No-"); + if (has_rp_thread && !no_msr) { + unsigned long long msr; + + get_msr(cpu, MSR_IA32_RESOURCE_PRIORITY, &msr); + fprintf(outf, " MSR_RP_THREAD_EN:%llu", msr); + } + if (has_rp_package && !no_msr) { + unsigned long long msr; + + get_msr(cpu, MSR_IA32_RESOURCE_PRIORITY_PKG, &msr); + fprintf(outf, " MSR_RP_PKG_EN:%llu", msr); + } + fprintf(outf, "\n"); } } -- cgit v1.2.3 From d895f1596d6e41c14dc50ef72a1c78715232b85b Mon Sep 17 00:00:00 2001 From: Len Brown Date: Tue, 28 Apr 2026 22:19:41 -0400 Subject: tools/power turbostat: Cleanup: Use one cpu_setsize for all purposes Use a single cpu_setsize to describe every cpu_set_t. Size it based on the maximum possible cpu number. No functional change. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 77 ++++++++++++++++------------------- 1 file changed, 34 insertions(+), 43 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 7eefaf021ea8..d7e68363e4dc 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -1426,7 +1426,7 @@ char *progname; cpu_set_t *cpu_present_set, *cpu_possible_set, *cpu_effective_set, *cpu_allowed_set, *cpu_affinity_set, *cpu_subset; cpu_set_t *perf_pcore_set, *perf_ecore_set, *perf_lcore_set; -size_t cpu_present_setsize, cpu_possible_setsize, cpu_effective_setsize, cpu_allowed_setsize, cpu_affinity_setsize, cpu_subset_size; +size_t cpu_setsize; #define MAX_ADDED_THREAD_COUNTERS 24 #define MAX_ADDED_CORE_COUNTERS 8 #define MAX_ADDED_PACKAGE_COUNTERS 16 @@ -2459,7 +2459,7 @@ int cpu_is_not_present(int cpu) if (cpu < 0) return 1; - return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set); + return !CPU_ISSET_S(cpu, cpu_setsize, cpu_present_set); } int cpu_is_not_allowed(int cpu) @@ -2467,7 +2467,7 @@ int cpu_is_not_allowed(int cpu) if (cpu < 0) return 1; - return !CPU_ISSET_S(cpu, cpu_allowed_setsize, cpu_allowed_set); + return !CPU_ISSET_S(cpu, cpu_setsize, cpu_allowed_set); } #define GLOBAL_CORE_ID(core_id, pkg_id) (core_id + pkg_id * (topo.max_core_id + 1)) @@ -2560,9 +2560,9 @@ int is_cpu_first_thread_in_package(struct thread_data *t, struct core_data *c, s int cpu_migrate(int cpu) { - CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); - CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); - if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) + CPU_ZERO_S(cpu_setsize, cpu_affinity_set); + CPU_SET_S(cpu, cpu_setsize, cpu_affinity_set); + if (sched_setaffinity(0, cpu_setsize, cpu_affinity_set) == -1) return -1; else return 0; @@ -3382,7 +3382,7 @@ int format_counters(PER_THREAD_PARAMS) return 0; /*if not summary line and --cpu is used */ - if ((t != average.threads) && (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset))) + if ((t != average.threads) && (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_setsize, cpu_subset))) return 0; if (DO_BIC(BIC_USEC)) { @@ -5976,19 +5976,15 @@ void free_all_buffers(void) CPU_FREE(cpu_present_set); cpu_present_set = NULL; - cpu_present_setsize = 0; CPU_FREE(cpu_effective_set); cpu_effective_set = NULL; - cpu_effective_setsize = 0; CPU_FREE(cpu_allowed_set); cpu_allowed_set = NULL; - cpu_allowed_setsize = 0; CPU_FREE(cpu_affinity_set); cpu_affinity_set = NULL; - cpu_affinity_setsize = 0; if (perf_pcore_set) { CPU_FREE(perf_pcore_set); @@ -6345,7 +6341,7 @@ static void update_effective_set(bool startup) { update_effective_str(startup); - if (parse_cpu_str(cpu_effective_str, cpu_effective_set, cpu_effective_setsize)) + if (parse_cpu_str(cpu_effective_str, cpu_effective_set, cpu_setsize)) err(1, "%s: cpu str malformat %s", PATH_EFFECTIVE_CPUS, cpu_effective_str); } @@ -6387,7 +6383,7 @@ int count_cpus(int cpu) int mark_cpu_present(int cpu) { - CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); + CPU_SET_S(cpu, cpu_setsize, cpu_present_set); return 0; } @@ -8518,7 +8514,7 @@ int initialize_cpu_set_from_sysfs(cpu_set_t *cpu_set, const char *sysfs_path, warn("read %s", sysfs_path); goto out; } - if (parse_cpu_str(cpuset_buf, cpu_set, cpu_possible_setsize)) { + if (parse_cpu_str(cpuset_buf, cpu_set, cpu_setsize)) { warnx("%s: cpu str malformat %s\n", sysfs_path, cpuset_buf); goto out; } @@ -8555,7 +8551,7 @@ void linux_perf_init_hybrid_cpus(void) perf_pcore_set = CPU_ALLOC((topo.max_cpu_num + 1)); if (perf_pcore_set == NULL) err(3, "CPU_ALLOC"); - CPU_ZERO_S(cpu_possible_setsize, perf_pcore_set); + CPU_ZERO_S(cpu_setsize, perf_pcore_set); initialize_cpu_set_from_sysfs(perf_pcore_set, perf_cpu_pcore_path, "cpus"); if (debug) print_cpu_set("perf pcores", perf_pcore_set); @@ -8567,7 +8563,7 @@ void linux_perf_init_hybrid_cpus(void) perf_ecore_set = CPU_ALLOC((topo.max_cpu_num + 1)); if (perf_ecore_set == NULL) err(3, "CPU_ALLOC"); - CPU_ZERO_S(cpu_possible_setsize, perf_ecore_set); + CPU_ZERO_S(cpu_setsize, perf_ecore_set); initialize_cpu_set_from_sysfs(perf_ecore_set, perf_cpu_ecore_path, "cpus"); if (debug) print_cpu_set("perf ecores", perf_ecore_set); @@ -8579,7 +8575,7 @@ void linux_perf_init_hybrid_cpus(void) perf_lcore_set = CPU_ALLOC((topo.max_cpu_num + 1)); if (perf_lcore_set == NULL) err(3, "CPU_ALLOC"); - CPU_ZERO_S(cpu_possible_setsize, perf_lcore_set); + CPU_ZERO_S(cpu_setsize, perf_lcore_set); initialize_cpu_set_from_sysfs(perf_lcore_set, perf_cpu_lcore_path, "cpus"); if (debug) print_cpu_set("perf lcores", perf_lcore_set); @@ -9502,7 +9498,7 @@ void perf_l2_init(void) } continue; } - if (perf_pcore_set && CPU_ISSET_S(cpu, cpu_possible_setsize, perf_pcore_set)) { + if (perf_pcore_set && CPU_ISSET_S(cpu, cpu_setsize, perf_pcore_set)) { fd_l2_percpu[cpu] = open_perf_counter(cpu, perf_pmu_types.pcore, perf_model_support->first.refs, -1, PERF_FORMAT_GROUP); if (fd_l2_percpu[cpu] == -1) { warnx("%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.pcore, perf_model_support->first.refs); @@ -9515,7 +9511,7 @@ void perf_l2_init(void) free_fd_l2_percpu(); return; } - } else if (perf_ecore_set && CPU_ISSET_S(cpu, cpu_possible_setsize, perf_ecore_set)) { + } else if (perf_ecore_set && CPU_ISSET_S(cpu, cpu_setsize, perf_ecore_set)) { fd_l2_percpu[cpu] = open_perf_counter(cpu, perf_pmu_types.ecore, perf_model_support->second.refs, -1, PERF_FORMAT_GROUP); if (fd_l2_percpu[cpu] == -1) { warnx("%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.ecore, perf_model_support->second.refs); @@ -9528,7 +9524,7 @@ void perf_l2_init(void) free_fd_l2_percpu(); return; } - } else if (perf_lcore_set && CPU_ISSET_S(cpu, cpu_possible_setsize, perf_lcore_set)) { + } else if (perf_lcore_set && CPU_ISSET_S(cpu, cpu_setsize, perf_lcore_set)) { fd_l2_percpu[cpu] = open_perf_counter(cpu, perf_pmu_types.lcore, perf_model_support->third.refs, -1, PERF_FORMAT_GROUP); if (fd_l2_percpu[cpu] == -1) { warnx("%s(cpu%d, 0x%x, 0x%llx) REFS", __func__, cpu, perf_pmu_types.lcore, perf_model_support->third.refs); @@ -9648,8 +9644,7 @@ void topology_probe(bool startup) cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); if (cpu_present_set == NULL) err(3, "CPU_ALLOC"); - cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); - CPU_ZERO_S(cpu_present_setsize, cpu_present_set); + CPU_ZERO_S(cpu_setsize, cpu_present_set); for_all_proc_cpus(mark_cpu_present); if (debug) print_cpu_set("present set", cpu_present_set); @@ -9660,8 +9655,7 @@ void topology_probe(bool startup) cpu_possible_set = CPU_ALLOC((topo.max_cpu_num + 1)); if (cpu_possible_set == NULL) err(3, "CPU_ALLOC"); - cpu_possible_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); - CPU_ZERO_S(cpu_possible_setsize, cpu_possible_set); + CPU_ZERO_S(cpu_setsize, cpu_possible_set); initialize_cpu_set_from_sysfs(cpu_possible_set, "/sys/devices/system/cpu", "possible"); if (debug) print_cpu_set("possible set", cpu_possible_set); @@ -9672,8 +9666,7 @@ void topology_probe(bool startup) cpu_effective_set = CPU_ALLOC((topo.max_cpu_num + 1)); if (cpu_effective_set == NULL) err(3, "CPU_ALLOC"); - cpu_effective_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); - CPU_ZERO_S(cpu_effective_setsize, cpu_effective_set); + CPU_ZERO_S(cpu_setsize, cpu_effective_set); update_effective_set(startup); if (debug) print_cpu_set("effective set", cpu_effective_set); @@ -9684,8 +9677,7 @@ void topology_probe(bool startup) cpu_allowed_set = CPU_ALLOC((topo.max_cpu_num + 1)); if (cpu_allowed_set == NULL) err(3, "CPU_ALLOC"); - cpu_allowed_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); - CPU_ZERO_S(cpu_allowed_setsize, cpu_allowed_set); + CPU_ZERO_S(cpu_setsize, cpu_allowed_set); /* * Validate and update cpu_allowed_set. @@ -9697,10 +9689,10 @@ void topology_probe(bool startup) * cpu_allowed_set is the intersection of cpu_present_set/cpu_effective_set/cpu_subset. */ for (i = 0; i <= topo.max_cpu_num; ++i) { - if (cpu_subset && !CPU_ISSET_S(i, cpu_subset_size, cpu_subset)) + if (cpu_subset && !CPU_ISSET_S(i, cpu_setsize, cpu_subset)) continue; - if (!CPU_ISSET_S(i, cpu_present_setsize, cpu_present_set)) { + if (!CPU_ISSET_S(i, cpu_setsize, cpu_present_set)) { if (cpu_subset) { /* cpus in cpu_subset must be in cpu_present_set during startup */ if (startup) @@ -9711,21 +9703,21 @@ void topology_probe(bool startup) continue; } - if (CPU_COUNT_S(cpu_effective_setsize, cpu_effective_set)) { - if (!CPU_ISSET_S(i, cpu_effective_setsize, cpu_effective_set)) { + if (CPU_COUNT_S(cpu_setsize, cpu_effective_set)) { + if (!CPU_ISSET_S(i, cpu_setsize, cpu_effective_set)) { fprintf(stderr, "cpu%d not effective\n", i); continue; } } - CPU_SET_S(i, cpu_allowed_setsize, cpu_allowed_set); + CPU_SET_S(i, cpu_setsize, cpu_allowed_set); } if (debug) print_cpu_set("allowed set", cpu_allowed_set); - if (!CPU_COUNT_S(cpu_allowed_setsize, cpu_allowed_set)) + if (!CPU_COUNT_S(cpu_setsize, cpu_allowed_set)) errx(-ENODEV, "No valid cpus found"); - sched_setaffinity(0, cpu_allowed_setsize, cpu_allowed_set); + sched_setaffinity(0, cpu_setsize, cpu_allowed_set); /* * Allocate and initialize cpu_affinity_set @@ -9733,8 +9725,7 @@ void topology_probe(bool startup) cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); if (cpu_affinity_set == NULL) err(3, "CPU_ALLOC"); - cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); - CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); + CPU_ZERO_S(cpu_setsize, cpu_affinity_set); for_all_proc_cpus(clear_ht_id); @@ -10629,11 +10620,11 @@ void turbostat_init() void affinitize_child(void) { /* Prefer cpu_possible_set, if available */ - if (sched_setaffinity(0, cpu_possible_setsize, cpu_possible_set)) { + if (sched_setaffinity(0, cpu_setsize, cpu_possible_set)) { warn("sched_setaffinity cpu_possible_set"); /* Otherwise, allow child to run on same cpu set as turbostat */ - if (sched_setaffinity(0, cpu_allowed_setsize, cpu_allowed_set)) + if (sched_setaffinity(0, cpu_setsize, cpu_allowed_set)) warn("sched_setaffinity cpu_allowed_set"); } } @@ -11564,11 +11555,10 @@ void parse_cpu_command(char *optarg) cpu_subset = CPU_ALLOC(topo.max_cpu_num + 1); if (cpu_subset == NULL) err(3, "CPU_ALLOC"); - cpu_subset_size = CPU_ALLOC_SIZE(topo.max_cpu_num + 1); - CPU_ZERO_S(cpu_subset_size, cpu_subset); + CPU_ZERO_S(cpu_setsize, cpu_subset); - if (parse_cpu_str(optarg, cpu_subset, cpu_subset_size)) + if (parse_cpu_str(optarg, cpu_subset, cpu_setsize)) goto error; if (debug) print_cpu_set("cpu subsetset", cpu_subset); @@ -11784,8 +11774,9 @@ int main(int argc, char **argv) skip_cgroup_setting: - /* probe max_cpu_num early for use by cmdline() */ + /* probe max_cpu_num and set cpu_setsize early for use by cmdline() */ topo.max_cpu_num = get_max_cpu_num("/sys/devices/system/cpu/possible"); + cpu_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); outf = stderr; cmdline(argc, argv); -- cgit v1.2.3 From 1a0bd1bfad43d151f813d77fb8b1b16ecc9f949b Mon Sep 17 00:00:00 2001 From: Len Brown Date: Tue, 28 Apr 2026 22:53:38 -0400 Subject: tools/power turbostat: Allow multiple --cpu on cmdline If --cpu is on the cmdline more than once, previous invocations are forgotten (and their cpu_set is leaked). Allow multiple invocations of --cpu on the cmdline. OR them together, reusing the same cpu_set. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.8 | 2 +- tools/power/x86/turbostat/turbostat.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8 index 830c9f094765..c905198d0501 100644 --- a/tools/power/x86/turbostat/turbostat.8 +++ b/tools/power/x86/turbostat/turbostat.8 @@ -92,7 +92,7 @@ name as necessary to disambiguate it from others is necessary. Note that option '%x' hex identifier of the PMT MMIO region. .fi .PP -\fB--cpu cpu-set\fP limit output to system summary plus the specified cpu-set. If cpu-set is the string "core", then the system summary plus the first CPU in each core are printed -- eg. subsequent HT siblings are not printed. Or if cpu-set is the string "package", then the system summary plus the first CPU in each package is printed. Otherwise, the system summary plus the specified set of CPUs are printed. The cpu-set is ordered from low to high, comma delimited with ".." and "-" permitted to denote a range. eg. 1,2,8,14..17,21-44 +\fB--cpu cpu-set\fP limit output to system summary plus the specified cpu-set. If cpu-set is the string "core", then the system summary plus the first CPU in each core are printed -- eg. subsequent HT siblings are not printed. Or if cpu-set is the string "package", then the system summary plus the first CPU in each package is printed. Otherwise, the system summary plus the specified set of CPUs are printed. The cpu-set is ordered from low to high, comma delimited with ".." and "-" permitted to denote a range. eg. 1,2,8,14..17,21-44 Multiple invocations of --cpu are OR'd together. .PP \fB--hide column\fP do not show the specified built-in columns. May be invoked multiple times, or with a comma-separated list of column names. .PP diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index d7e68363e4dc..58a8a61bac7b 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -11552,16 +11552,18 @@ void parse_cpu_command(char *optarg) if (show_core_only || show_pkg_only) goto error; - cpu_subset = CPU_ALLOC(topo.max_cpu_num + 1); - if (cpu_subset == NULL) - err(3, "CPU_ALLOC"); + if (!cpu_subset) { + cpu_subset = CPU_ALLOC(topo.max_cpu_num + 1); + if (cpu_subset == NULL) + err(3, "CPU_ALLOC"); - CPU_ZERO_S(cpu_setsize, cpu_subset); + CPU_ZERO_S(cpu_setsize, cpu_subset); + } if (parse_cpu_str(optarg, cpu_subset, cpu_setsize)) goto error; if (debug) - print_cpu_set("cpu subsetset", cpu_subset); + print_cpu_set("--cpu", cpu_subset); return; -- cgit v1.2.3 From 065c85e4799e1fb7f46d3c5fe2463631ca61f0d2 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Tue, 28 Apr 2026 22:57:34 -0400 Subject: tools/power turbostat: Rename cpu_subset to cpuset_cmdline The cpu_set supporting "--cpu" on the cmdline is special. Unlike all other cpu_sets, it is allocated, re-used, and never freed. Add a comment noting this and name it "cpuset_cmdline" to clarify its use. No functional change. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 39 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 58a8a61bac7b..3d6082484add 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -1424,7 +1424,7 @@ void init_perf_model_support(unsigned int family, unsigned int model) int backwards_count; char *progname; -cpu_set_t *cpu_present_set, *cpu_possible_set, *cpu_effective_set, *cpu_allowed_set, *cpu_affinity_set, *cpu_subset; +cpu_set_t *cpu_present_set, *cpu_possible_set, *cpu_effective_set, *cpu_allowed_set, *cpu_affinity_set, *cpuset_cmdline; cpu_set_t *perf_pcore_set, *perf_ecore_set, *perf_lcore_set; size_t cpu_setsize; #define MAX_ADDED_THREAD_COUNTERS 24 @@ -3382,7 +3382,7 @@ int format_counters(PER_THREAD_PARAMS) return 0; /*if not summary line and --cpu is used */ - if ((t != average.threads) && (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_setsize, cpu_subset))) + if ((t != average.threads) && (cpuset_cmdline && !CPU_ISSET_S(t->cpu_id, cpu_setsize, cpuset_cmdline))) return 0; if (DO_BIC(BIC_USEC)) { @@ -9682,19 +9682,19 @@ void topology_probe(bool startup) /* * Validate and update cpu_allowed_set. * - * Make sure all cpus in cpu_subset are also in cpu_present_set during startup. - * Give a warning when cpus in cpu_subset become unavailable at runtime. + * Make sure all cpus in cpuset_cmdline are also in cpu_present_set during startup. + * Give a warning when cpus in cpuset_cmdline become unavailable at runtime. * Give a warning when cpus are not effective because of cgroup setting. * - * cpu_allowed_set is the intersection of cpu_present_set/cpu_effective_set/cpu_subset. + * cpu_allowed_set is the intersection of cpu_present_set/cpu_effective_set/cpuset_cmdline. */ for (i = 0; i <= topo.max_cpu_num; ++i) { - if (cpu_subset && !CPU_ISSET_S(i, cpu_setsize, cpu_subset)) + if (cpuset_cmdline && !CPU_ISSET_S(i, cpu_setsize, cpuset_cmdline)) continue; if (!CPU_ISSET_S(i, cpu_setsize, cpu_present_set)) { - if (cpu_subset) { - /* cpus in cpu_subset must be in cpu_present_set during startup */ + if (cpuset_cmdline) { + /* cpus in cpuset_cmdline must be in cpu_present_set during startup */ if (startup) errx(1, "cpu%d not present", i); else @@ -11533,18 +11533,18 @@ void probe_cpuidle_counts(void) /* * parse cpuset with following syntax - * 1,2,4..6,8-10 and set bits in cpu_subset + * 1,2,4..6,8-10 and set bits in cpuset_cmdline */ void parse_cpu_command(char *optarg) { if (!strcmp(optarg, "core")) { - if (cpu_subset) + if (cpuset_cmdline) goto error; show_core_only++; return; } if (!strcmp(optarg, "package")) { - if (cpu_subset) + if (cpuset_cmdline) goto error; show_pkg_only++; return; @@ -11552,18 +11552,23 @@ void parse_cpu_command(char *optarg) if (show_core_only || show_pkg_only) goto error; - if (!cpu_subset) { - cpu_subset = CPU_ALLOC(topo.max_cpu_num + 1); - if (cpu_subset == NULL) + /* + * cpuset_cmdline is allocated on the first invocation of --cpu + * It is re-used for subsequent invocations. + * It is never freed. + */ + if (!cpuset_cmdline) { + cpuset_cmdline = CPU_ALLOC(topo.max_cpu_num + 1); + if (cpuset_cmdline == NULL) err(3, "CPU_ALLOC"); - CPU_ZERO_S(cpu_setsize, cpu_subset); + CPU_ZERO_S(cpu_setsize, cpuset_cmdline); } - if (parse_cpu_str(optarg, cpu_subset, cpu_setsize)) + if (parse_cpu_str(optarg, cpuset_cmdline, cpu_setsize)) goto error; if (debug) - print_cpu_set("--cpu", cpu_subset); + print_cpu_set("--cpu", cpuset_cmdline); return; -- cgit v1.2.3 From 24d277a547611b998c451bf9ee135011fcfc6276 Mon Sep 17 00:00:00 2001 From: Hemanth Selam Date: Fri, 4 Sep 2026 18:00:17 +0530 Subject: tools/power turbostat: Fix comment typo Spell "instead" properly in comment. Assisted-by: Cursor:claude-opus-5 Signed-off-by: Hemanth Selam Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 3d6082484add..d80ce73e73d7 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -10543,7 +10543,7 @@ void pmt_init(void) * Set the scope to CPU, even though CWF report the counter per module. * CPUs inside the same module will read from the same location, instead of reporting zeros. * - * CWF with newer firmware might require a PMT_TYPE_XTAL_TIME intead of PMT_TYPE_TCORE_CLOCK. + * CWF with newer firmware might require a PMT_TYPE_XTAL_TIME instead of PMT_TYPE_TCORE_CLOCK. */ pmt_add_counter(PMT_CWF_MC1E_GUID, seq, "CPU%c1e", PMT_TYPE_TCORE_CLOCK, PMT_COUNTER_CWF_MC1E_LSB, PMT_COUNTER_CWF_MC1E_MSB, offset, SCOPE_CPU, FORMAT_DELTA, cpu_num, PMT_OPEN_TRY); -- cgit v1.2.3 From 00eae75a3baa8a551b6c86a63bd0eed5b0bd4f7c Mon Sep 17 00:00:00 2001 From: Kuppuswamy Sathyanarayanan Date: Thu, 1 Oct 2026 10:30:39 -0700 Subject: tools/power turbostat: Add rugged Panther Lake support Add CPU model for rugged Panther Lake to the platform and perf model tables. It uses the same cores as Panther Lake, so use the same settings. Signed-off-by: Kuppuswamy Sathyanarayanan Co-developed-by: Srinivas Pandruvada Signed-off-by: Srinivas Pandruvada Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index d80ce73e73d7..50efbc3ca012 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -1247,6 +1247,7 @@ static const struct platform_data turbostat_pdata[] = { { INTEL_ARROWLAKE, &adl_features }, { INTEL_LUNARLAKE_M, &lnl_features }, { INTEL_PANTHERLAKE_L, &lnl_features }, + { INTEL_PANTHERLAKE_R, &lnl_features }, { INTEL_NOVALAKE, &lnl_features }, { INTEL_NOVALAKE_L, &lnl_features }, { INTEL_WILDCATLAKE_L, &lnl_features }, @@ -1344,6 +1345,7 @@ static struct perf_model_support turbostat_perf_model_support[] = { { INTEL_ARROWLAKE, { PCE(0x00, 0xFF), PCE(0x00, 0x5F)}, { PCE(0x00, 0x07), PCE(0x00, 0x02)}, {} }, { INTEL_PANTHERLAKE_L, { PCE(0x00, 0xFF), PCE(0x00, 0x5F)}, { PCE(0x01, 0xFF), PCE(0x01, 0xBF)}, {} }, + { INTEL_PANTHERLAKE_R, { PCE(0x00, 0xFF), PCE(0x00, 0x5F)}, { PCE(0x01, 0xFF), PCE(0x01, 0xBF)}, {} }, { INTEL_WILDCATLAKE_L, { PCE(0x00, 0xFF), PCE(0x00, 0x5F)}, { PCE(0x01, 0xFF), PCE(0x01, 0xBF)}, {} }, { INTEL_NOVALAKE, { PCE(0x00, 0xFF), PCE(0x00, 0x5F)}, { PCE(0x01, 0xFF), PCE(0x01, 0xBF)}, {} }, -- cgit v1.2.3 From 481006fbcb22ba1f134283c017aa3ae8a67e0d59 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Rewrite Linux/Android MSR path discovery First check that the Linux MSR driver path exists, modprobe if no. If still no, then check that the Android MSR driver path exists. Read or Write permissions are handled at run-time in the get_msr()/put_msr() error paths. Create set_msr_path() helper. Return -1 for all fatal errors. Suggested-by: Andy Shevchenko Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Signed-off-by: Len Brown --- .../x86_energy_perf_policy.c | 73 ++++++++++++++-------- 1 file changed, 47 insertions(+), 26 deletions(-) (limited to 'tools') 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 0dc959e30076..8a15093a485e 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 #include #include +#include #include #include #include @@ -98,6 +99,7 @@ unsigned char update_platform_profile; int soc_slider_balance; int soc_slider_offset; char platform_profile[64]; +char msr_path[64]; #define PATH_TO_CPU "/sys/devices/system/cpu/" #define SYSFS_PATH_MAX 255 @@ -799,21 +801,32 @@ void err_on_hypervisor(void) err(-1, "not supported on this virtual machine"); } +/* + * if (use_android_msr_path) + * msr_path = /dev/msr%d // Android + * else + * msr_path = /dev/cpu/%d/msr // Linux + */ +static void set_msr_path(int cpu) +{ + if (snprintf(msr_path, sizeof(msr_path), use_android_msr_path ? "/dev/msr%d" : "/dev/cpu/%d/msr", cpu) >= (int)sizeof(msr_path)) + err(-1, "MSR path buffer overflow for cpu%d", cpu); +} + int get_msr(int cpu, int offset, unsigned long long *msr) { int retval; - char pathname[32]; int fd; - sprintf(pathname, use_android_msr_path ? "/dev/msr%d" : "/dev/cpu/%d/msr", cpu); - fd = open(pathname, O_RDONLY); + set_msr_path(cpu); + fd = open(msr_path, O_RDONLY); if (fd < 0) - err(-1, "%s open failed, try chown or chmod +r %s, or run as root", pathname, use_android_msr_path ? "/dev/msr*" : "/dev/cpu/*/msr"); + err(-1, "%s open failed, try chown or chmod +r, or run as root", msr_path); retval = pread(fd, msr, sizeof(*msr), offset); if (retval != sizeof(*msr)) { err_on_hypervisor(); - err(-1, "%s offset 0x%llx read failed", pathname, (unsigned long long)offset); + err(-1, "%s offset 0x%llx read failed", msr_path, (unsigned long long)offset); } if (debug > 1) @@ -825,14 +838,13 @@ int get_msr(int cpu, int offset, unsigned long long *msr) int put_msr(int cpu, int offset, unsigned long long new_msr) { - char pathname[32]; int retval; int fd; - sprintf(pathname, use_android_msr_path ? "/dev/msr%d" : "/dev/cpu/%d/msr", cpu); - fd = open(pathname, O_RDWR); + set_msr_path(cpu); + fd = open(msr_path, O_RDWR); if (fd < 0) - err(-1, "%s open failed, try chown or chmod +r %s, or run as root", pathname, use_android_msr_path ? "/dev/msr*" : "/dev/cpu/*/msr"); + err(-1, "%s open failed, try chown or chmod +w, or run as root", msr_path); retval = pwrite(fd, &new_msr, sizeof(new_msr), offset); if (retval != sizeof(new_msr)) @@ -1601,32 +1613,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; - char test_path[32]; - sprintf(test_path, "/dev/msr%d", base_cpu); - if (stat(test_path, &sb) == 0) - 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; - char pathname[32]; + int retval; - probe_android_msr_path(); + use_android_msr_path = 0; + set_msr_path(base_cpu); + if (check_msr_path() == 0) + return; - sprintf(pathname, use_android_msr_path ? "/dev/msr%d" : "/dev/cpu/%d/msr", base_cpu); - if (stat(pathname, &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\" "); - } - } + 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 (check_msr_path() == 0) + return; + + if (WIFEXITED(retval)) + retval = WEXITSTATUS(retval); + errx(-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) -- cgit v1.2.3 From 74bd795c99e4ca8c4d9b35ae7294b535f49689a3 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Harden update_cpufreq_scaling_freq() Protect update_cpufreq_scaling_freq() from buffer overflow if somehow it was called with a huge CPU number. Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') 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 8a15093a485e..da89b267f357 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 @@ -1167,12 +1167,12 @@ int ratio_2_sysfs_khz(int ratio) */ void update_cpufreq_scaling_freq(int is_max, int cpu, unsigned int ratio) { - char pathname[64]; + char pathname[96]; FILE *fp; int retval; int khz; - sprintf(pathname, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_%s_freq", cpu, is_max ? "max" : "min"); + snprintf(pathname, sizeof(pathname), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_%s_freq", cpu, is_max ? "max" : "min"); fp = fopen(pathname, "w"); if (!fp) { -- cgit v1.2.3 From 0aaac38a0d770c9291c4c96298966a7cf73a0194 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Harden with strtol() Replace atoi() with strtol() and proper error checking when parsing the --hwp-use-pkg command-line argument value, and other spots. Add explicit check that value is in valid range [0, 1]. Update associated error message strings. parse_optarg_string() now returns long, as returned from strtol(). Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Signed-off-by: Len Brown --- .../x86_energy_perf_policy.c | 71 ++++++++++++---------- 1 file changed, 39 insertions(+), 32 deletions(-) (limited to 'tools') 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 da89b267f357..d53427a059f3 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 @@ -191,7 +191,7 @@ int parse_cmdline_epb(int i) return ENERGY_PERF_BIAS_PERFORMANCE; } if (i < 0 || i > ENERGY_PERF_BIAS_POWERSAVE) - errx(1, "--epb must be from 0 to 15"); + errx(1, "--epb must be 0 through 15"); return i; } @@ -305,8 +305,8 @@ int parse_cmdline_hwp_epp(int i) case OPTARG_PERFORMANCE: return HWP_EPP_PERFORMANCE; } - if (i < 0 || i > 0xff) { - fprintf(stderr, "--hwp-epp must be from 0 to 0xff\n"); + if (i < 0 || i > 255) { + fprintf(stderr, "--hwp-epp must be 0 through 255\n"); usage(); } return i; @@ -332,9 +332,9 @@ int parse_cmdline_turbo(int i) return i; } -int parse_optarg_string(char *s) +long parse_optarg_string(char *s) { - int i; + long i; char *endptr; if (!strncmp(s, "default", 7)) @@ -355,19 +355,13 @@ int parse_optarg_string(char *s) if (!strncmp(s, "performance", 11)) return OPTARG_PERFORMANCE; + errno = 0; i = strtol(s, &endptr, 0); - if (s == endptr) { - fprintf(stderr, "no digits in \"%s\"\n", s); + if (endptr == s || errno == ERANGE || i < 0 || i > 255) { + warnx("bad value \"%s\"", s); usage(); } - if (i == LONG_MIN || i == LONG_MAX) - errx(-1, "%s", s); - if (i > 0xFF) - errx(-1, "%d (0x%x) must be < 256", i, i); - - if (i < 0) - errx(-1, "%d (0x%x) must be >= 0", i, i); return i; } @@ -424,9 +418,10 @@ void parse_cmdline_cpu(char *s) int end_cpu; startp++; + errno = 0; end_cpu = strtol(startp, &endp, 10); - if (startp == endp) - continue; + if (startp == endp || errno == ERANGE) + errx(1, "Confused by end_cpu '%s'", startp); while (cpu <= end_cpu) { if (cpu > max_cpu_num) @@ -469,11 +464,11 @@ void parse_cmdline_cpu(char *s) break; } + errno = 0; cpu = strtol(startp, &endp, 10); - if (startp == endp) + if (startp == endp || errno == ERANGE || cpu < 0 || cpu > max_cpu_num) errx(1, "--cpu cpu-set: confused by '%s'", startp); - if (cpu > max_cpu_num) - errx(1, "Requested cpu%d exceeds max cpu%d", cpu, max_cpu_num); + CPU_SET_S(cpu, cpu_setsize, cpu_selected_set); startp = endp; } @@ -504,9 +499,10 @@ void parse_cmdline_pkg(char *s) int end_pkg; startp++; + errno = 0; end_pkg = strtol(startp, &endp, 10); - if (startp == endp) - continue; + if (startp == endp || errno == ERANGE) + errx(1, "Confused by end_pkg '%s'", startp); while (pkg <= end_pkg) { if (pkg > max_pkg_num) @@ -523,9 +519,11 @@ void parse_cmdline_pkg(char *s) return; } + errno = 0; pkg = strtol(startp, &endp, 10); - if (pkg > max_pkg_num) - errx(1, "Requested pkg%d Exceeds max pkg%d", pkg, max_pkg_num); + if (startp == endp || errno == ERANGE || pkg < 0 || pkg > max_pkg_num) + errx(1, "Confused by pkg '%s'", startp); + pkg_selected_set |= 1 << pkg; startp = endp; } @@ -546,6 +544,7 @@ static int parse_cmdline_int(const char *s, int *out) char *endp; long val; + errno = 0; val = strtol(s, &endp, 0); if (endp == s || errno == ERANGE) return -1; @@ -714,13 +713,19 @@ void cmdline(int argc, char **argv) case 't': turbo_update_value = parse_cmdline_turbo(parse_optarg_string(optarg)); break; - case 'u': - update_hwp_use_pkg++; - if (atoi(optarg) == 0) - req_update.hwp_use_pkg = 0; - else - req_update.hwp_use_pkg = 1; - break; + case 'u': { + char *endp; + long val; + + update_hwp_use_pkg++; + + errno = 0; + val = strtol(optarg, &endp, 10); + if (endp == optarg || errno == ERANGE || val < 0 || val > 1) + errx(1, "--hwp-use-pkg: must be 0 or 1"); + req_update.hwp_use_pkg = val; + break; + } case 'v': print_version(); exit(0); @@ -1016,8 +1021,9 @@ static int get_epb_sysfs(int cpu) if (!read_sysfs(path, linebuf, 3)) return -1; + errno = 0; val = strtol(linebuf, &endp, 0); - if (endp == linebuf || errno == ERANGE) + if (endp == linebuf || errno == ERANGE || val < 0 || val > 15) return -1; return (int)val; @@ -1040,8 +1046,9 @@ static int set_epb_sysfs(int cpu, int val) if (ret <= 0) return -1; + errno = 0; val = strtol(linebuf, &endp, 0); - if (endp == linebuf || errno == ERANGE) + if (endp == linebuf || errno == ERANGE || val < 0 || val > 15) return -1; return (int)val; -- cgit v1.2.3 From db2cffbc80853d2cc37159f01bc36c18958ad6c9 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Cleanup: Use snprintf() for platform-profile Better hygiene to use snprintf() instead of strcpy(). Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') 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 d53427a059f3..33de17efb4df 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 @@ -678,7 +678,7 @@ void cmdline(int argc, char **argv) errx(1, "--platform-profile: value too long"); if (!platform_profile_access(W_OK)) errx(1, "Can not update platform-profile in '%s'", PATH_PLATFORM_PROFILE); - strcpy(platform_profile, optarg); + snprintf(platform_profile, sizeof(platform_profile), "%s", optarg); update_platform_profile = 1; break; case 'm': -- cgit v1.2.3 From 0177067d195a4757149f6702af191987377c71c3 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Fix optarg keyword matching Replace strncmp() with strcmp() for exact string matching in parse_optarg_string(). Exact keyword matching is safer and clearer. This prevents accidental matches with longer strings like "performance-foo". Fixes: 4beec1d75196 ("tools/power x86_energy_perf_policy: support HWP.EPP") Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- .../x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tools') 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 33de17efb4df..a6b918fff5e4 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 @@ -337,22 +337,22 @@ long parse_optarg_string(char *s) long i; char *endptr; - if (!strncmp(s, "default", 7)) + if (strcmp(s, "default") == 0) return OPTARG_NORMAL; - if (!strncmp(s, "normal", 6)) + if (strcmp(s, "normal") == 0) return OPTARG_NORMAL; - if (!strncmp(s, "power", 9)) + if (strcmp(s, "power") == 0) return OPTARG_POWER; - if (!strncmp(s, "balance-power", 17)) + if (strcmp(s, "balance-power") == 0) return OPTARG_BALANCE_POWER; - if (!strncmp(s, "balance-performance", 19)) + if (strcmp(s, "balance-performance") == 0) return OPTARG_BALANCE_PERFORMANCE; - if (!strncmp(s, "performance", 11)) + if (strcmp(s, "performance") == 0) return OPTARG_PERFORMANCE; errno = 0; -- cgit v1.2.3 From 128c6fd2afa49d01a7aa9d51fb73bfd171e77316 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Harden against potential ratio overflow Prevent integer overflow in ratio_2_msr_perf() by using 64-bit arithmetic for the intermediate multiplication calculation. Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tools') 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 a6b918fff5e4..e79462f93f3a 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 @@ -141,11 +141,13 @@ void usage(void) int ratio_2_msr_perf(int ratio) { int msr_perf; + unsigned long long temp; if (!bdx_highest_ratio) return ratio; - msr_perf = ratio * 255 / bdx_highest_ratio; + temp = (unsigned long long)ratio * 255; + msr_perf = temp / bdx_highest_ratio; if (debug) fprintf(stderr, "%d = ratio_to_msr_perf(%d)\n", msr_perf, ratio); -- cgit v1.2.3 From d865b3810bb1c2a0f9b92f1162f48ce547db8bae Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Bound package iteration Add explicit bounds checking against MAX_PACKAGES in for_packages() to prevent potential out-of-bounds bit shift operations. Also, use consistent shift idiom: (1ULL << pkg_num) Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') 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 e79462f93f3a..2d77f465f1ee 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 @@ -509,7 +509,7 @@ void parse_cmdline_pkg(char *s) while (pkg <= end_pkg) { if (pkg > max_pkg_num) errx(1, "Requested pkg%d exceeds max pkg%d", pkg, max_pkg_num); - pkg_selected_set |= 1 << pkg; + pkg_selected_set |= 1ULL << pkg; pkg++; } startp = endp; @@ -526,7 +526,7 @@ void parse_cmdline_pkg(char *s) if (startp == endp || errno == ERANGE || pkg < 0 || pkg > max_pkg_num) errx(1, "Confused by pkg '%s'", startp); - pkg_selected_set |= 1 << pkg; + pkg_selected_set |= 1ULL << pkg; startp = endp; } } @@ -535,8 +535,8 @@ void for_packages(unsigned long long pkg_set, int (func) (int)) { int pkg_num; - for (pkg_num = 0; pkg_num <= max_pkg_num; ++pkg_num) { - if (pkg_set & (1UL << pkg_num)) + for (pkg_num = 0; pkg_num <= max_pkg_num && pkg_num < MAX_PACKAGES; ++pkg_num) { + if (pkg_set & (1ULL << pkg_num)) func(pkg_num); } } -- cgit v1.2.3 From 22d8ec33a79518598594efb5178899ed841e34df Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Cleanup: Define HWP_WINDOW_MAX_USEC Define HWP_WINDOW_MAX_USEC Doing so pointed out that it should be unsigned, so change associated code that touches it to use unsigned. Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- .../x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'tools') 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 2d77f465f1ee..5fb6b0883e55 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 @@ -34,6 +34,9 @@ #define OPTARG_BALANCE_PERFORMANCE (INT_MAX - 4) #define OPTARG_PERFORMANCE (INT_MAX - 5) +/* Maximum HWP activity window duration in microseconds */ +#define HWP_WINDOW_MAX_USEC 1270000000U + struct msr_hwp_cap { unsigned char highest; unsigned char guaranteed; @@ -259,7 +262,7 @@ int parse_cmdline_hwp_desired(int i) return i; } -int parse_cmdline_hwp_window(int i) +unsigned int parse_cmdline_hwp_window(unsigned int i) { unsigned int exponent; @@ -273,13 +276,13 @@ int parse_cmdline_hwp_window(int i) case OPTARG_PERFORMANCE: return 0; } - if (i < 0 || i > 1270000000) { - fprintf(stderr, "--hwp-window: 0 for auto; 1 - 1270000000 usec for window duration\n"); + if (i > HWP_WINDOW_MAX_USEC) { + fprintf(stderr, "--hwp-window: 0 for auto; 1 - %u usec for window duration\n", HWP_WINDOW_MAX_USEC); usage(); } for (exponent = 0;; ++exponent) { if (debug) - printf("%d 10^%d\n", i, exponent); + printf("%u 10^%d\n", i, exponent); if (i <= 127) break; @@ -287,7 +290,7 @@ int parse_cmdline_hwp_window(int i) i = i / 10; } if (debug) - fprintf(stderr, "%d*10^%d: 0x%x\n", i, exponent, (exponent << 7) | i); + fprintf(stderr, "%u*10^%d: 0x%x\n", i, exponent, (exponent << 7) | i); return (exponent << 7) | i; } -- cgit v1.2.3 From 029db3fc5e5592982add7df05800a15cc072f5fa Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Cleanup: Define BCLK_MHZ Replace the hardcoded value 100 with a named symbolic constant BCLK_MHZ in ratio_2_sysfs_khz() to document the assumed bus clock frequency. Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tools') 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 5fb6b0883e55..0a67b6f5381c 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 @@ -37,6 +37,10 @@ /* Maximum HWP activity window duration in microseconds */ #define HWP_WINDOW_MAX_USEC 1270000000U +/* Nominal bus clock frequency in MHz - assumed for all HWP systems */ +#define BCLK_MHZ 100 +#define KHZ_PER_MHZ 1000 + struct msr_hwp_cap { unsigned char highest; unsigned char guaranteed; @@ -1163,7 +1167,7 @@ int print_pkg_msrs(int pkg) */ int ratio_2_sysfs_khz(int ratio) { - int bclk_khz = 100 * 1000; /* 100,000 KHz = 100 MHz */ + int bclk_khz = BCLK_MHZ * KHZ_PER_MHZ; /* Convert MHz to KHz */ return ratio * bclk_khz; } -- cgit v1.2.3 From 2778dc35d40e7e84c134ca4cab1376fa58208f80 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Cleanup: Check fseek() in VM path Add return value validation for fseek() and ensure consistent resource cleanup on all error paths in err_on_hypervisor(). Fixes: 0936cdfbb527 ("tools/power x86_energy_perf_policy: Input/output error in a VM") Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tools') 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 0a67b6f5381c..b7515e815f76 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 @@ -799,7 +799,11 @@ void err_on_hypervisor(void) err(1, "Failed to find 'flags' in /proc/cpuinfo"); } rewind(cpuinfo); - fseek(cpuinfo, flags - buffer, SEEK_SET); + if (fseek(cpuinfo, flags - buffer, SEEK_SET) != 0) { + fclose(cpuinfo); + free(buffer); + err(1, "Failed to seek in /proc/cpuinfo"); + } if (!fgets(buffer, 4096, cpuinfo)) { fclose(cpuinfo); free(buffer); -- cgit v1.2.3 From 2d14634951b042a8fd8c2cffef3bbab94a844715 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Document MSRHEADER Add comment documenting MSRHEADER Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tools') 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 b7515e815f76..6f6697f8fc5e 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 @@ -9,7 +9,12 @@ */ #define _GNU_SOURCE -#include MSRHEADER +/* + * MSRHEADER macro should be defined by the build system to include the + * appropriate MSR definitions header file. Typical usage: + * gcc -DMSRHEADER=\"msr-index.h\" or similar platform-specific MSR header + */ +#include MSRHEADER /* e.g., msr-index.h with MSR_* constant definitions */ #include #include #include -- cgit v1.2.3 From 8afbe9b7fa68a81e6e49a59af52a74cc37b4a2d0 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Cleanup: Drop unused signal.h Remove unused #include Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 1 - 1 file changed, 1 deletion(-) (limited to 'tools') 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 6f6697f8fc5e..70b1d0fcd067 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 @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.3 From febae602a541e9ee59fe6b818c0fac700fe5ec50 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Wed, 6 May 2026 10:00:00 -0400 Subject: x86_energy_perf_policy: Cleanup: Constify read only parameters Add const qualifiers to the parameters of parse_optarg_string(), platform_profile_name_is(), print_hwp_request(), and print_hwp_request_pkg() which are read-only. Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') 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 70b1d0fcd067..b1754070f095 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 @@ -345,7 +345,7 @@ int parse_cmdline_turbo(int i) return i; } -long parse_optarg_string(char *s) +long parse_optarg_string(const char *s) { long i; char *endptr; @@ -586,7 +586,7 @@ static int platform_profile_access(int mode) return 1; } -static int platform_profile_name_is(char *name) +static int platform_profile_name_is(const char *name) { char buf[64]; @@ -968,7 +968,7 @@ void read_hwp_cap(int cpu, struct msr_hwp_cap *cap, unsigned int msr_offset) cap->lowest = msr_perf_2_ratio(HWP_LOWEST_PERF(msr)); } -void print_hwp_request(int cpu, struct msr_hwp_request *h, char *str) +void print_hwp_request(int cpu, struct msr_hwp_request *h, const char *str) { if (cpu != -1) printf("cpu%d: ", cpu); @@ -980,7 +980,7 @@ void print_hwp_request(int cpu, struct msr_hwp_request *h, char *str) h->hwp_min, h->hwp_max, h->hwp_desired, h->hwp_epp, h->hwp_window, h->hwp_window & 0x7F, (h->hwp_window >> 7) & 0x7, h->hwp_use_pkg); } -void print_hwp_request_pkg(int pkg, struct msr_hwp_request *h, char *str) +void print_hwp_request_pkg(int pkg, struct msr_hwp_request *h, const char *str) { printf("pkg%d: ", pkg); -- cgit v1.2.3 From d833146644272d90693066cc0a706b9933824b3e Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sat, 23 May 2026 18:37:20 -0400 Subject: x86_energy_perf_policy: Use calloc to initialize string buffer strstr was being run on a potentially unterminated buffer. Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6 Reviewed-by: Andy Shevchenko Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tools') 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 b1754070f095..904ab803f5c7 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 @@ -784,10 +784,10 @@ void err_on_hypervisor(void) /* On VMs /proc/cpuinfo contains a "flags" entry for hypervisor */ cpuinfo = fopen_or_die("/proc/cpuinfo", "r"); - buffer = malloc(4096); + buffer = calloc(4096, 1); if (!buffer) { fclose(cpuinfo); - err(-ENOMEM, "buffer malloc fail"); + err(-ENOMEM, "buffer calloc fail"); } if (!fread(buffer, 1024, 1, cpuinfo)) { @@ -816,11 +816,10 @@ void err_on_hypervisor(void) fclose(cpuinfo); hypervisor = strstr(buffer, "hypervisor"); - - free(buffer); - if (hypervisor) err(-1, "not supported on this virtual machine"); + + free(buffer); } /* -- cgit v1.2.3 From 5afe2d3ce2fb6a2772acacc96b1d7eb870a1cdb5 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Tue, 28 Jul 2026 13:24:22 +0530 Subject: x86_energy_perf_policy: Simplify write_sysfs() return type Simplify error check in write_sysfs(). Suggested-by: Amarjeet Signed-off-by: Len Brown --- .../x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'tools') 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 904ab803f5c7..2b4d48b520f2 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 @@ -900,14 +900,14 @@ static unsigned int read_sysfs(const char *path, char *buf, size_t buflen) return (unsigned int)numread; } -static unsigned int write_sysfs(const char *path, char *buf, size_t buflen) +static int write_sysfs(const char *path, char *buf, size_t buflen) { ssize_t numwritten; int fd; fd = open(path, O_WRONLY); if (fd == -1) - return 0; + return -1; numwritten = write(fd, buf, buflen - 1); if (numwritten < 1) { @@ -919,7 +919,7 @@ static unsigned int write_sysfs(const char *path, char *buf, size_t buflen) close(fd); - return (unsigned int)numwritten; + return 0; } static int sysfs_read_string(const char *path, char *buf, size_t buflen) @@ -944,7 +944,7 @@ static int sysfs_write_string(const char *path, const char *buf) len = snprintf(tmp, sizeof(tmp), "%s\n", buf); if (len < 0 || len >= (int)sizeof(tmp)) return -1; - return write_sysfs(path, tmp, (size_t)len + 1) ? 0 : -1; + return write_sysfs(path, tmp, (size_t)len + 1); } void print_hwp_cap(int cpu, struct msr_hwp_cap *cap, char *str) @@ -1050,7 +1050,6 @@ static int set_epb_sysfs(int cpu, int val) char path[SYSFS_PATH_MAX]; char linebuf[3]; char *endp; - int ret; if (!has_epb) return -1; @@ -1058,8 +1057,7 @@ static int set_epb_sysfs(int cpu, int val) snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/power/energy_perf_bias", cpu); snprintf(linebuf, sizeof(linebuf), "%d", val); - ret = write_sysfs(path, linebuf, 3); - if (ret <= 0) + if (write_sysfs(path, linebuf, 3)) return -1; errno = 0; -- cgit v1.2.3 From ab6e94fb4a25278ab84ccc390f37719d13ad86f8 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Fri, 16 Oct 2026 17:28:36 -0400 Subject: tools/power turbostat: Fix --Joules when used with --show power The "--Joules" option displays energy in Joules, replacing the same metrics displayed as power in Watts. But when used with --show power, it deletes the power metrics without replacing them with their energy counterparts: $ sudo ./turbostat -q --list --show power --Joules CoreTmp,PkgTmp,RAM_J,PKG_%,RAM_% Fix it thus: $ sudo ./turbostat -q --list --show power --Joules CoreTmp,PkgTmp,Pkg_J,Cor_J,GFX_J,RAM_J,PKG_%,RAM_%,Sys_J Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 113 ++++++++++++---------------------- 1 file changed, 40 insertions(+), 73 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 50efbc3ca012..9b848dd1d54c 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -399,6 +399,11 @@ static void bic_groups_init(void) SET_BIC(BIC_CorWatt, &bic_group_thermal_pwr); SET_BIC(BIC_GFXWatt, &bic_group_thermal_pwr); SET_BIC(BIC_RAMWatt, &bic_group_thermal_pwr); + SET_BIC(BIC_Pkg_J, &bic_group_thermal_pwr); + SET_BIC(BIC_Cor_J, &bic_group_thermal_pwr); + SET_BIC(BIC_GFX_J, &bic_group_thermal_pwr); + SET_BIC(BIC_RAM_J, &bic_group_thermal_pwr); + SET_BIC(BIC_Sys_J, &bic_group_thermal_pwr); SET_BIC(BIC_PKG__, &bic_group_thermal_pwr); SET_BIC(BIC_RAM__, &bic_group_thermal_pwr); SET_BIC(BIC_SysWatt, &bic_group_thermal_pwr); @@ -2496,8 +2501,7 @@ int has_allowed_lower_ht_sibling(int cpu) return 0; } -int for_all_cpus(int (func) (struct thread_data *, struct core_data *, struct pkg_data *), - struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base) +int for_all_cpus(int (func) (struct thread_data *, struct core_data *, struct pkg_data *), struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base) { int cpu, retval; @@ -2582,8 +2586,7 @@ int get_msr_fd(int cpu) sprintf(pathname, use_android_msr_path ? "/dev/msr%d" : "/dev/cpu/%d/msr", cpu); fd = open(pathname, O_RDONLY); if (fd < 0) - err(-1, "%s open failed, try chown or chmod +r %s, " - "or run with --no-msr, or run as root", pathname, use_android_msr_path ? "/dev/msr*" : "/dev/cpu/*/msr"); + err(-1, "%s open failed, try chown or chmod +r %s, " "or run with --no-msr, or run as root", pathname, use_android_msr_path ? "/dev/msr*" : "/dev/cpu/*/msr"); fd_percpu[cpu] = fd; return fd; @@ -2790,8 +2793,7 @@ void help(void) " -T, --TCC temperature\n" " sets the Thermal Control Circuit temperature in\n" " degrees Celsius\n" - " -h, --help\n" - " print this help message\n -v, --version\n\t\tprint version information\n\nFor more help, run \"man turbostat\"\n"); + " -h, --help\n" " print this help message\n -v, --version\n\t\tprint version information\n\nFor more help, run \"man turbostat\"\n"); } /* @@ -4006,8 +4008,7 @@ int delta_thread(struct thread_data *new, struct thread_data *old, struct core_d /* check for TSC < 1 Mcycles over interval */ if (old->tsc < (1000 * 1000)) - errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" - "You can disable all c-states by booting with \"idle=poll\"\nor just the deep ones with \"processor.max_cstate=1\""); + errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" "You can disable all c-states by booting with \"idle=poll\"\nor just the deep ones with \"processor.max_cstate=1\""); old->c1 = new->c1 - old->c1; @@ -4900,8 +4901,7 @@ int get_rapl_counters(int cpu, unsigned int domain, struct core_data *c, struct assert(rci->fd_perf != -1); if (debug >= 2) - fprintf(stderr, "Reading rapl counter via perf at %u (%llu %e %lf)\n", - i, perf_data[pi], rci->scale[i], perf_data[pi] * rci->scale[i]); + fprintf(stderr, "Reading rapl counter via perf at %u (%llu %e %lf)\n", i, perf_data[pi], rci->scale[i], perf_data[pi] * rci->scale[i]); rci->data[i] = perf_data[pi]; @@ -5725,8 +5725,7 @@ static void dump_cst_cfg(void) (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", - (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", - (msr & (1 << 15)) ? "" : "UN", (unsigned int)msr & 0xF, pkg_cstate_limit_strings[pkg_cstate_limit]); + (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", (msr & (1 << 15)) ? "" : "UN", (unsigned int)msr & 0xF, pkg_cstate_limit_strings[pkg_cstate_limit]); #define AUTOMATIC_CSTATE_CONVERSION (1UL << 16) if (platform->has_cst_auto_convension) { @@ -6223,8 +6222,7 @@ static int parse_cpu_str(char *cpu_str, cpu_set_t *cpu_set, int cpu_set_size) int for_all_cpus_2(int (func) (struct thread_data *, struct core_data *, struct pkg_data *, struct thread_data *, struct core_data *, struct pkg_data *), struct thread_data *thread_base, - struct core_data *core_base, struct pkg_data *pkg_base, - struct thread_data *thread_base2, struct core_data *core_base2, struct pkg_data *pkg_base2) + struct core_data *core_base, struct pkg_data *pkg_base, struct thread_data *thread_base2, struct core_data *core_base2, struct pkg_data *pkg_base2) { int cpu, retval; @@ -7014,8 +7012,7 @@ void check_msr_permission(void) } if (failed) { - warnx("Failed to access %s. Some of the counters may not be available\n" - "\tRun as root to enable them or use %s to disable the access explicitly", pathname, "--no-msr"); + warnx("Failed to access %s. Some of the counters may not be available\n" "\tRun as root to enable them or use %s to disable the access explicitly", pathname, "--no-msr"); no_msr = 1; } } @@ -7592,9 +7589,7 @@ int print_hwp(PER_THREAD_PARAMS) get_msr(cpu, MSR_HWP_CAPABILITIES, &msr); fprintf(outf, "cpu%d: MSR_HWP_CAPABILITIES: 0x%08llx " "(high %d guar %d eff %d low %d)\n", - cpu, msr, - (unsigned int)HWP_HIGHEST_PERF(msr), - (unsigned int)HWP_GUARANTEED_PERF(msr), (unsigned int)HWP_MOSTEFFICIENT_PERF(msr), (unsigned int)HWP_LOWEST_PERF(msr)); + cpu, msr, (unsigned int)HWP_HIGHEST_PERF(msr), (unsigned int)HWP_GUARANTEED_PERF(msr), (unsigned int)HWP_MOSTEFFICIENT_PERF(msr), (unsigned int)HWP_LOWEST_PERF(msr)); get_msr(cpu, MSR_HWP_REQUEST, &msr); fprintf(outf, "cpu%d: MSR_HWP_REQUEST: 0x%08llx " @@ -7602,8 +7597,7 @@ int print_hwp(PER_THREAD_PARAMS) cpu, msr, (unsigned int)(((msr) >> 0) & 0xff), (unsigned int)(((msr) >> 8) & 0xff), - (unsigned int)(((msr) >> 16) & 0xff), - (unsigned int)(((msr) >> 24) & 0xff), (unsigned int)(((msr) >> 32) & 0xff3), (unsigned int)(((msr) >> 42) & 0x1)); + (unsigned int)(((msr) >> 16) & 0xff), (unsigned int)(((msr) >> 24) & 0xff), (unsigned int)(((msr) >> 32) & 0xff3), (unsigned int)(((msr) >> 42) & 0x1)); if (has_hwp_pkg) { get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr); @@ -7611,17 +7605,14 @@ int print_hwp(PER_THREAD_PARAMS) "(min %d max %d des %d epp 0x%x window 0x%x)\n", cpu, msr, (unsigned int)(((msr) >> 0) & 0xff), - (unsigned int)(((msr) >> 8) & 0xff), - (unsigned int)(((msr) >> 16) & 0xff), (unsigned int)(((msr) >> 24) & 0xff), (unsigned int)(((msr) >> 32) & 0xff3)); + (unsigned int)(((msr) >> 8) & 0xff), (unsigned int)(((msr) >> 16) & 0xff), (unsigned int)(((msr) >> 24) & 0xff), (unsigned int)(((msr) >> 32) & 0xff3)); } if (has_hwp_notify) { get_msr(cpu, MSR_HWP_INTERRUPT, &msr); - fprintf(outf, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx " - "(%s_Guaranteed_Perf_Change, %s_Excursion_Min)\n", cpu, msr, ((msr) & 0x1) ? "EN" : "Dis", ((msr) & 0x2) ? "EN" : "Dis"); + fprintf(outf, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx " "(%s_Guaranteed_Perf_Change, %s_Excursion_Min)\n", cpu, msr, ((msr) & 0x1) ? "EN" : "Dis", ((msr) & 0x2) ? "EN" : "Dis"); } get_msr(cpu, MSR_HWP_STATUS, &msr); - fprintf(outf, "cpu%d: MSR_HWP_STATUS: 0x%08llx " - "(%sGuaranteed_Perf_Change, %sExcursion_Min)\n", cpu, msr, ((msr) & 0x1) ? "" : "No-", ((msr) & 0x4) ? "" : "No-"); + fprintf(outf, "cpu%d: MSR_HWP_STATUS: 0x%08llx " "(%sGuaranteed_Perf_Change, %sExcursion_Min)\n", cpu, msr, ((msr) & 0x1) ? "" : "No-", ((msr) & 0x4) ? "" : "No-"); return 0; } @@ -7665,8 +7656,7 @@ int print_perf_limit(PER_THREAD_PARAMS) (msr & 1 << 8) ? "Amps, " : "", (msr & 1 << 6) ? "VR-Therm, " : "", (msr & 1 << 5) ? "Auto-HWP, " : "", - (msr & 1 << 4) ? "Graphics, " : "", - (msr & 1 << 2) ? "bit2, " : "", (msr & 1 << 1) ? "ThermStatus, " : "", (msr & 1 << 0) ? "PROCHOT, " : ""); + (msr & 1 << 4) ? "Graphics, " : "", (msr & 1 << 2) ? "bit2, " : "", (msr & 1 << 1) ? "ThermStatus, " : "", (msr & 1 << 0) ? "PROCHOT, " : ""); fprintf(outf, " (Logged: %s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n", (msr & 1 << 31) ? "bit31, " : "", (msr & 1 << 30) ? "bit30, " : "", @@ -7678,8 +7668,7 @@ int print_perf_limit(PER_THREAD_PARAMS) (msr & 1 << 24) ? "Amps, " : "", (msr & 1 << 22) ? "VR-Therm, " : "", (msr & 1 << 21) ? "Auto-HWP, " : "", - (msr & 1 << 20) ? "Graphics, " : "", - (msr & 1 << 18) ? "bit18, " : "", (msr & 1 << 17) ? "ThermStatus, " : "", (msr & 1 << 16) ? "PROCHOT, " : ""); + (msr & 1 << 20) ? "Graphics, " : "", (msr & 1 << 18) ? "bit18, " : "", (msr & 1 << 17) ? "ThermStatus, " : "", (msr & 1 << 16) ? "PROCHOT, " : ""); } if (platform->plr_msrs & PLR_GFX) { @@ -7690,15 +7679,13 @@ int print_perf_limit(PER_THREAD_PARAMS) (msr & 1 << 1) ? "ThermStatus, " : "", (msr & 1 << 4) ? "Graphics, " : "", (msr & 1 << 6) ? "VR-Therm, " : "", - (msr & 1 << 8) ? "Amps, " : "", - (msr & 1 << 9) ? "GFXPwr, " : "", (msr & 1 << 10) ? "PkgPwrL1, " : "", (msr & 1 << 11) ? "PkgPwrL2, " : ""); + (msr & 1 << 8) ? "Amps, " : "", (msr & 1 << 9) ? "GFXPwr, " : "", (msr & 1 << 10) ? "PkgPwrL1, " : "", (msr & 1 << 11) ? "PkgPwrL2, " : ""); fprintf(outf, " (Logged: %s%s%s%s%s%s%s%s)\n", (msr & 1 << 16) ? "PROCHOT, " : "", (msr & 1 << 17) ? "ThermStatus, " : "", (msr & 1 << 20) ? "Graphics, " : "", (msr & 1 << 22) ? "VR-Therm, " : "", - (msr & 1 << 24) ? "Amps, " : "", - (msr & 1 << 25) ? "GFXPwr, " : "", (msr & 1 << 26) ? "PkgPwrL1, " : "", (msr & 1 << 27) ? "PkgPwrL2, " : ""); + (msr & 1 << 24) ? "Amps, " : "", (msr & 1 << 25) ? "GFXPwr, " : "", (msr & 1 << 26) ? "PkgPwrL1, " : "", (msr & 1 << 27) ? "PkgPwrL2, " : ""); } if (platform->plr_msrs & PLR_RING) { get_msr(cpu, MSR_RING_PERF_LIMIT_REASONS, &msr); @@ -7706,13 +7693,11 @@ int print_perf_limit(PER_THREAD_PARAMS) fprintf(outf, " (Active: %s%s%s%s%s%s)", (msr & 1 << 0) ? "PROCHOT, " : "", (msr & 1 << 1) ? "ThermStatus, " : "", - (msr & 1 << 6) ? "VR-Therm, " : "", - (msr & 1 << 8) ? "Amps, " : "", (msr & 1 << 10) ? "PkgPwrL1, " : "", (msr & 1 << 11) ? "PkgPwrL2, " : ""); + (msr & 1 << 6) ? "VR-Therm, " : "", (msr & 1 << 8) ? "Amps, " : "", (msr & 1 << 10) ? "PkgPwrL1, " : "", (msr & 1 << 11) ? "PkgPwrL2, " : ""); fprintf(outf, " (Logged: %s%s%s%s%s%s)\n", (msr & 1 << 16) ? "PROCHOT, " : "", (msr & 1 << 17) ? "ThermStatus, " : "", - (msr & 1 << 22) ? "VR-Therm, " : "", - (msr & 1 << 24) ? "Amps, " : "", (msr & 1 << 26) ? "PkgPwrL1, " : "", (msr & 1 << 27) ? "PkgPwrL2, " : ""); + (msr & 1 << 22) ? "VR-Therm, " : "", (msr & 1 << 24) ? "Amps, " : "", (msr & 1 << 26) ? "PkgPwrL1, " : "", (msr & 1 << 27) ? "PkgPwrL2, " : ""); } return 0; } @@ -7837,8 +7822,7 @@ void print_power_limit_msr(int cpu, unsigned long long msr, char *label) fprintf(outf, "cpu%d: %s: %sabled (%0.3f Watts, %f sec, clamp %sabled)\n", cpu, label, ((msr >> 15) & 1) ? "EN" : "DIS", - ((msr >> 0) & 0x7FFF) * rapl_power_units, - (1.0 + (((msr >> 22) & 0x3) / 4.0)) * (1 << ((msr >> 17) & 0x1F)) * rapl_time_units, (((msr >> 16) & 1) ? "EN" : "DIS")); + ((msr >> 0) & 0x7FFF) * rapl_power_units, (1.0 + (((msr >> 22) & 0x3) / 4.0)) * (1 << ((msr >> 17) & 0x1F)) * rapl_time_units, (((msr >> 16) & 1) ? "EN" : "DIS")); return; } @@ -8046,8 +8030,7 @@ int print_rapl(PER_THREAD_PARAMS) fprintf(outf, "cpu%d: PKG Limit #2: %sabled (%0.3f Watts, %f* sec, clamp %sabled)\n", cpu, ((msr >> 47) & 1) ? "EN" : "DIS", - ((msr >> 32) & 0x7FFF) * rapl_power_units, - (1.0 + (((msr >> 54) & 0x3) / 4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, ((msr >> 48) & 1) ? "EN" : "DIS"); + ((msr >> 32) & 0x7FFF) * rapl_power_units, (1.0 + (((msr >> 54) & 0x3) / 4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, ((msr >> 48) & 1) ? "EN" : "DIS"); get_msr(cpu, MSR_VR_CURRENT_CONFIG, &msr); fprintf(outf, "cpu%d: MSR_VR_CURRENT_CONFIG: 0x%08llx\n", cpu, msr); @@ -8203,8 +8186,7 @@ int set_temperature_target(PER_THREAD_PARAMS) if (bits && enabled) { tcc_offset = (msr >> 24) & GENMASK(bits - 1, 0); - fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C) (%d default - %d offset)\n", - cpu, msr, tcc_default - tcc_offset, tcc_default, tcc_offset); + fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C) (%d default - %d offset)\n", cpu, msr, tcc_default - tcc_offset, tcc_default, tcc_offset); } else { fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C)\n", cpu, msr, tcc_default); } @@ -8326,8 +8308,7 @@ void decode_feature_control_msr(void) return; get_msr(master_cpu, MSR_IA32_FEAT_CTL, &msr); - fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", - master_cpu, msr, msr & FEAT_CTL_LOCKED ? "" : "UN-", msr & (1 << 18) ? "SGX" : ""); + fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", master_cpu, msr, msr & FEAT_CTL_LOCKED ? "" : "UN-", msr & (1 << 18) ? "SGX" : ""); } void decode_misc_enable_msr(void) @@ -8345,8 +8326,7 @@ void decode_misc_enable_msr(void) master_cpu, msr, msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", - msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", - msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); + msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); } void decode_misc_feature_control(void) @@ -8448,8 +8428,7 @@ static int has_perf_instr_count_access(void) if (fd == -1) warnx("Failed to access %s. Some of the counters may not be available\n" - "\tRun as root to enable them or use %s to disable the access explicitly", "perf instructions retired counter", - "'--hide IPC' or '--no-perf'"); + "\tRun as root to enable them or use %s to disable the access explicitly", "perf instructions retired counter", "'--hide IPC' or '--no-perf'"); return (fd != -1); } @@ -8495,8 +8474,7 @@ end: return ret; } -int initialize_cpu_set_from_sysfs(cpu_set_t *cpu_set, const char *sysfs_path, - const char *sysfs_file) +int initialize_cpu_set_from_sysfs(cpu_set_t *cpu_set, const char *sysfs_path, const char *sysfs_file) { FILE *fp; char *cpuset_buf = NULL; @@ -9122,8 +9100,7 @@ void dump_rdt_a_leaf(int leaf) has_rp_thread = eax & (1 << 0); has_rp_package = eax & (1 << 1); - fprintf(outf, "cpu%d: CPUID(0x%x).%d: %sRP_THREAD, %sRP_PKG", - cpu, leaf, RDT_RP_INDEX, has_rp_thread ? "" : "No-", has_rp_package ? "" : "No-"); + fprintf(outf, "cpu%d: CPUID(0x%x).%d: %sRP_THREAD, %sRP_PKG", cpu, leaf, RDT_RP_INDEX, has_rp_thread ? "" : "No-", has_rp_package ? "" : "No-"); if (has_rp_thread && !no_msr) { unsigned long long msr; @@ -9217,8 +9194,7 @@ void process_cpuid() ecx_flags & (1 << 8) ? "" : "No-", cpuid_has_hv ? "" : "No-", edx_flags & (1 << 4) ? "" : "No-", - edx_flags & (1 << 5) ? "" : "No-", - edx_flags & (1 << 22) ? "" : "No-", edx_flags & (1 << 28) ? "" : "No-", edx_flags & (1 << 29) ? "" : "No-"); + edx_flags & (1 << 5) ? "" : "No-", edx_flags & (1 << 22) ? "" : "No-", edx_flags & (1 << 28) ? "" : "No-", edx_flags & (1 << 29) ? "" : "No-"); } if (!quiet && cpuid_has_hv) dump_cpuid_hypervisor(); @@ -9267,9 +9243,7 @@ void process_cpuid() has_turbo ? "" : "No-", do_dts ? "" : "No-", do_ptm ? "" : "No-", - has_hwp ? "" : "No-", - has_hwp_notify ? "" : "No-", - has_hwp_activity_window ? "" : "No-", has_hwp_epp ? "" : "No-", has_hwp_pkg ? "" : "No-", has_epb ? "" : "No-"); + has_hwp ? "" : "No-", has_hwp_notify ? "" : "No-", has_hwp_activity_window ? "" : "No-", has_hwp_epp ? "" : "No-", has_hwp_pkg ? "" : "No-", has_epb ? "" : "No-"); if (!quiet) decode_misc_enable_msr(); @@ -9294,8 +9268,7 @@ void process_cpuid() has_ardt_a = ecx & (1 << 1); fprintf(outf, "CPUID(7): %sSGX %sRDT_M %sRDT_A %sARDT_M %sARDT_A %sHybrid\n", - has_sgx ? "" : "No-", has_rdt_m ? "" : "No-", has_rdt_a ? "" : "No-", has_ardt_m ? "" : "No-", has_ardt_a ? "" : "No-", - is_hybrid ? "" : "No-"); + has_sgx ? "" : "No-", has_rdt_m ? "" : "No-", has_rdt_a ? "" : "No-", has_ardt_m ? "" : "No-", has_ardt_a ? "" : "No-", is_hybrid ? "" : "No-"); if (has_sgx) decode_feature_control_msr(); @@ -9837,8 +9810,7 @@ void topology_probe(bool startup) continue; fprintf(outf, "cpu %d pkg %d die %d l3 %d node %d lnode %d module 0x%x core %d ht_id %d", - i, cpus[i].package_id, cpus[i].die_id, cpus[i].l3_id, - cpus[i].physical_node_id, cpus[i].logical_node_id, cpus[i].module_id, cpus[i].core_id, cpus[i].ht_id); + i, cpus[i].package_id, cpus[i].die_id, cpus[i].l3_id, cpus[i].physical_node_id, cpus[i].logical_node_id, cpus[i].module_id, cpus[i].core_id, cpus[i].ht_id); fprintf(outf, " siblings"); for (ht_id = 0; ht_id <= MAX_HT_ID; ++ht_id) fprintf(outf, " %d", cpus[i].ht_sibling_cpu_id[ht_id]); @@ -10444,8 +10416,7 @@ void pmt_counter_add_domain(struct pmt_counter *pcounter, unsigned long *pmmio, } int pmt_add_counter(unsigned int guid, unsigned int seq, const char *name, enum pmt_datatype type, - unsigned int lsb, unsigned int msb, unsigned int offset, enum counter_scope scope, - enum counter_format format, unsigned int domain_id, enum pmt_open_mode mode) + unsigned int lsb, unsigned int msb, unsigned int offset, enum counter_scope scope, enum counter_format format, unsigned int domain_id, enum pmt_open_mode mode) { struct pmt_mmio *mmio; struct pmt_counter *pcounter; @@ -10744,8 +10715,7 @@ struct msr_counter *find_msrp_by_name(struct msr_counter *head, const char *name return NULL; } -int add_counter(unsigned int msr_num, const char *path, const char *name, - unsigned int width, enum counter_scope scope, enum counter_type type, enum counter_format format, int flags, int id) +int add_counter(unsigned int msr_num, const char *path, const char *name, unsigned int width, enum counter_scope scope, enum counter_type type, enum counter_format format, int flags, int id) { struct msr_counter *msrp; @@ -10753,8 +10723,7 @@ int add_counter(unsigned int msr_num, const char *path, const char *name, errx(1, "Requested MSR counter 0x%x, but in --no-msr mode", msr_num); if (debug) - fprintf(stderr, "%s(msr%d, %s, %s, width%d, scope%d, type%d, format%d, flags%x, id%d)\n", - __func__, msr_num, path, name, width, scope, type, format, flags, id); + fprintf(stderr, "%s(msr%d, %s, %s, width%d, scope%d, type%d, format%d, flags%x, id%d)\n", __func__, msr_num, path, name, width, scope, type, format, flags, id); switch (scope) { @@ -10853,9 +10822,7 @@ int add_counter(unsigned int msr_num, const char *path, const char *name, * easily call re_initialize(). */ struct perf_counter_info *make_perf_counter_info(const char *perf_device, - const char *perf_event, - const char *name, - unsigned int width, enum counter_scope scope, enum counter_type type, enum counter_format format) + const char *perf_event, const char *name, unsigned int width, enum counter_scope scope, enum counter_type type, enum counter_format format) { struct perf_counter_info *pinfo; -- cgit v1.2.3 From 3d6fc92be1feb6436932979e4652174467e7a42a Mon Sep 17 00:00:00 2001 From: Kaushlendra Kumar Date: Thu, 29 Oct 2026 14:14:29 +0530 Subject: tools/power turbostat: Fix undefined behavior in pmt_gen_value_mask() The function uses plain int literal '1' for bit shifting, which causes undefined behavior when msb >= 31. This is because shifting a 32-bit int by 32 or more bits is undefined behavior in C. Fix by using 1ULL (unsigned long long) instead of 1 to ensure 64-bit arithmetic on all platforms. Signed-off-by: Kaushlendra Kumar Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 9b848dd1d54c..0ba51e67962d 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -5194,9 +5194,9 @@ unsigned long pmt_gen_value_mask(unsigned int lsb, unsigned int msb) if (msb == 63) mask = 0xffffffffffffffff; else - mask = ((1 << (msb + 1)) - 1); + mask = ((1ULL << (msb + 1)) - 1); - mask -= (1 << lsb) - 1; + mask -= (1ULL << lsb) - 1; return mask; } -- cgit v1.2.3 From cfdb43387f3e6144bc374165ebf6deecb0324470 Mon Sep 17 00:00:00 2001 From: Kaushlendra Kumar Date: Thu, 29 Oct 2026 20:02:00 +0530 Subject: tools/power turbostat: Fix PMT mmap size and bounds check Remove assert(offset == 0), to allow non-zero PMT offsets. Fix the pmt_mmio_open() mapping to round-up (offset + size). Fix the offset bounds check to disallow running past the end of the region. [lenb: commit message re-write] Signed-off-by: Kaushlendra Kumar Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 0ba51e67962d..f5a7654cf513 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -10266,13 +10266,11 @@ struct pmt_mmio *pmt_mmio_open(unsigned int target_guid) break; } - assert(offset == 0); - fd_pmt = openat(fd_telem_dir, "telem", O_RDONLY); if (fd_pmt == -1) goto loop_cleanup_and_break; - mmap_size = ROUND_UP_TO_PAGE_SIZE(size); + mmap_size = ROUND_UP_TO_PAGE_SIZE(offset + size); mmio = mmap(0, mmap_size, PROT_READ, MAP_SHARED, fd_pmt, 0); if (mmio != MAP_FAILED) { if (debug) @@ -10444,7 +10442,7 @@ int pmt_add_counter(unsigned int guid, unsigned int seq, const char *name, enum return 1; } - if (offset >= mmio->size) { + if (offset > mmio->size || mmio->size - offset < 8) { if (mode != PMT_OPEN_TRY) { fprintf(stderr, "%s: offset %u outside of PMT MMIO size %u\n", __func__, offset, mmio->size); exit(1); -- cgit v1.2.3 From a8d65a89a31fd5a04709f002feaf847602904950 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sat, 31 Oct 2026 13:47:21 -0300 Subject: tools/power turbostat: Version 2026.10.31 Since version 2026.09.28: Fix --cpu option to work more than once. Fix --Joules option to work with --show power. Remove hard-coded 8192-CPU limit. Decode Uncore Frequency Agent Types. Dump RDT (Resource Director Technology) config. Dump RP (Resource Priority) config. Recognize Rugged Panther Lake. Fix PMT mmap size, bounds check, and mask computation. Misc cleanups and minor fixes. Signed-off-by: Len Brown --- tools/power/x86/turbostat/turbostat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index f5a7654cf513..123078926131 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -10674,7 +10674,7 @@ int get_and_dump_counters(void) void print_version() { - fprintf(outf, "turbostat version 2026.09.28 - Len Brown \n"); + fprintf(outf, "turbostat version 2026.10.31 - Len Brown \n"); } #define COMMAND_LINE_SIZE 2048 -- cgit v1.2.3 From ed9324befbded16f66840327f981e508091eab3e Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sat, 31 Oct 2026 14:00:43 -0300 Subject: tools/power x86_energy_perf_policy: Version 2026.10.31 Since 2026.04.25: Harden input parsing and bounds checks. Fix optarg keyword matching. Rewrite MSR device path discovery. Misc cleanups and minor fixes. Signed-off-by: Len Brown --- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') 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 2b4d48b520f2..be134aab3711 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 @@ -572,7 +572,7 @@ static int parse_cmdline_int(const char *s, int *out) void print_version(void) { - printf("x86_energy_perf_policy 2026.04.25 Len Brown \n"); + printf("x86_energy_perf_policy 2026.10.31 Len Brown \n"); } static int platform_profile_access(int mode) -- cgit v1.2.3