Skip to content

Commit 42fd37d

Browse files
committed
tools/power turbostat: version 2025.06.08
Add initial DMR support, which required smarter RAPL probe Fix AMD MSR RAPL energy reporting Add RAPL power limit configuration output Minor fixes Signed-off-by: Len Brown <[email protected]>
1 parent d8c0f5d commit 42fd37d

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ struct msr_counter bic[] = {
280280
#define BIC_GROUP_FREQUENCY (BIC_Avg_MHz | BIC_Busy | BIC_Bzy_MHz | BIC_TSC_MHz | BIC_GFXMHz | BIC_GFXACTMHz | BIC_SAMMHz | BIC_SAMACTMHz | BIC_UNCORE_MHZ)
281281
#define BIC_GROUP_HW_IDLE (BIC_Busy | BIC_CPU_c1 | BIC_CPU_c3 | BIC_CPU_c6 | BIC_CPU_c7 | BIC_GFX_rc6 | BIC_Pkgpc2 | BIC_Pkgpc3 | BIC_Pkgpc6 | BIC_Pkgpc7 | BIC_Pkgpc8 | BIC_Pkgpc9 | BIC_Pkgpc10 | BIC_CPU_LPI | BIC_SYS_LPI | BIC_Mod_c6 | BIC_Totl_c0 | BIC_Any_c0 | BIC_GFX_c0 | BIC_CPUGFX | BIC_SAM_mc6 | BIC_Diec6)
282282
#define BIC_GROUP_SW_IDLE (BIC_Busy | BIC_cpuidle | BIC_pct_idle )
283-
#define BIC_GROUP_IDLE (BIC_GROUP_HW_IDLE | BIC_pct_idle)
283+
#define BIC_GROUP_IDLE (BIC_GROUP_HW_IDLE | BIC_pct_idle)
284284
#define BIC_OTHER (BIC_IRQ | BIC_NMI | BIC_SMI | BIC_ThreadC | BIC_CoreTmp | BIC_IPC)
285285

286286
#define BIC_DISABLED_BY_DEFAULT (BIC_USEC | BIC_TOD | BIC_APIC | BIC_X2APIC | BIC_cpuidle)
@@ -1091,7 +1091,6 @@ void probe_platform_features(unsigned int family, unsigned int model)
10911091
{
10921092
int i;
10931093

1094-
10951094
if (authentic_amd || hygon_genuine) {
10961095
/* fallback to default features on unsupported models */
10971096
force_load++;
@@ -1125,8 +1124,7 @@ void probe_platform_features(unsigned int family, unsigned int model)
11251124
if (platform)
11261125
return;
11271126

1128-
fprintf(stderr, "Unsupported platform detected.\n"
1129-
"\tSee RUN THE LATEST VERSION on turbostat(8)\n");
1127+
fprintf(stderr, "Unsupported platform detected.\n\tSee RUN THE LATEST VERSION on turbostat(8)\n");
11301128
exit(1);
11311129
}
11321130

@@ -1146,7 +1144,8 @@ char *progname;
11461144

11471145
#define CPU_SUBSET_MAXCPUS 8192 /* need to use before probe... */
11481146
cpu_set_t *cpu_present_set, *cpu_possible_set, *cpu_effective_set, *cpu_allowed_set, *cpu_affinity_set, *cpu_subset;
1149-
size_t cpu_present_setsize, cpu_possible_setsize, cpu_effective_setsize, cpu_allowed_setsize, cpu_affinity_setsize, cpu_subset_size;
1147+
size_t cpu_present_setsize, cpu_possible_setsize, cpu_effective_setsize, cpu_allowed_setsize, cpu_affinity_setsize,
1148+
cpu_subset_size;
11501149
#define MAX_ADDED_THREAD_COUNTERS 24
11511150
#define MAX_ADDED_CORE_COUNTERS 8
11521151
#define MAX_ADDED_PACKAGE_COUNTERS 16
@@ -2373,8 +2372,7 @@ void help(void)
23732372
" degrees Celsius\n"
23742373
" -h, --help\n"
23752374
" print this help message\n"
2376-
" -v, --version\n"
2377-
" print version information\n\nFor more help, run \"man turbostat\"\n");
2375+
" -v, --version\n\t\tprint version information\n\nFor more help, run \"man turbostat\"\n");
23782376
}
23792377

23802378
/*
@@ -3989,7 +3987,6 @@ void compute_average(struct thread_data *t, struct core_data *c, struct pkg_data
39893987
if (average.threads.nmi_count > 9999999)
39903988
sums_need_wide_columns = 1;
39913989

3992-
39933990
average.cores.c3 /= topo.allowed_cores;
39943991
average.cores.c6 /= topo.allowed_cores;
39953992
average.cores.c7 /= topo.allowed_cores;
@@ -4812,7 +4809,6 @@ unsigned long pmt_read_counter(struct pmt_counter *ppmt, unsigned int domain_id)
48124809
return (value & value_mask) >> value_shift;
48134810
}
48144811

4815-
48164812
/* Rapl domain enumeration helpers */
48174813
static inline int get_rapl_num_domains(void)
48184814
{
@@ -6822,8 +6818,10 @@ static void probe_intel_uncore_frequency_cluster(void)
68226818
* This allows "--show/--hide UncMHz" to be effective for
68236819
* the clustered MHz counters, as a group.
68246820
*/
6825-
if BIC_IS_ENABLED(BIC_UNCORE_MHZ)
6826-
add_counter(0, path, name_buf, 0, SCOPE_PACKAGE, COUNTER_K2M, FORMAT_AVERAGE, 0, package_id);
6821+
if BIC_IS_ENABLED
6822+
(BIC_UNCORE_MHZ)
6823+
add_counter(0, path, name_buf, 0, SCOPE_PACKAGE, COUNTER_K2M, FORMAT_AVERAGE, 0,
6824+
package_id);
68276825

68286826
if (quiet)
68296827
continue;
@@ -6895,17 +6893,21 @@ static void probe_graphics(void)
68956893
else
68966894
goto next;
68976895

6898-
set_graphics_fp("/sys/class/drm/card0/device/tile0/gt0/gtidle/idle_residency_ms", gt0_is_gt ? GFX_rc6 : SAM_mc6);
6896+
set_graphics_fp("/sys/class/drm/card0/device/tile0/gt0/gtidle/idle_residency_ms",
6897+
gt0_is_gt ? GFX_rc6 : SAM_mc6);
68996898

69006899
set_graphics_fp("/sys/class/drm/card0/device/tile0/gt0/freq0/cur_freq", gt0_is_gt ? GFX_MHz : SAM_MHz);
69016900

6902-
set_graphics_fp("/sys/class/drm/card0/device/tile0/gt0/freq0/act_freq", gt0_is_gt ? GFX_ACTMHz : SAM_ACTMHz);
6901+
set_graphics_fp("/sys/class/drm/card0/device/tile0/gt0/freq0/act_freq",
6902+
gt0_is_gt ? GFX_ACTMHz : SAM_ACTMHz);
69036903

6904-
set_graphics_fp("/sys/class/drm/card0/device/tile0/gt1/gtidle/idle_residency_ms", gt0_is_gt ? SAM_mc6 : GFX_rc6);
6904+
set_graphics_fp("/sys/class/drm/card0/device/tile0/gt1/gtidle/idle_residency_ms",
6905+
gt0_is_gt ? SAM_mc6 : GFX_rc6);
69056906

69066907
set_graphics_fp("/sys/class/drm/card0/device/tile0/gt1/freq0/cur_freq", gt0_is_gt ? SAM_MHz : GFX_MHz);
69076908

6908-
set_graphics_fp("/sys/class/drm/card0/device/tile0/gt1/freq0/act_freq", gt0_is_gt ? SAM_ACTMHz : GFX_ACTMHz);
6909+
set_graphics_fp("/sys/class/drm/card0/device/tile0/gt1/freq0/act_freq",
6910+
gt0_is_gt ? SAM_ACTMHz : GFX_ACTMHz);
69096911

69106912
goto end;
69116913
}
@@ -7428,7 +7430,7 @@ static int fread_int(char *path, int *val)
74287430
FILE *filep;
74297431
int ret;
74307432

7431-
filep = fopen (path, "r");
7433+
filep = fopen(path, "r");
74327434
if (!filep)
74337435
return -1;
74347436

@@ -7442,7 +7444,7 @@ static int fread_ull(char *path, unsigned long long *val)
74427444
FILE *filep;
74437445
int ret;
74447446

7445-
filep = fopen (path, "r");
7447+
filep = fopen(path, "r");
74467448
if (!filep)
74477449
return -1;
74487450

@@ -7457,7 +7459,7 @@ static int fread_str(char *path, char *buf, int size)
74577459
int ret;
74587460
char *cp;
74597461

7460-
filep = fopen (path, "r");
7462+
filep = fopen(path, "r");
74617463
if (!filep)
74627464
return -1;
74637465

@@ -7500,17 +7502,16 @@ static int dump_one_domain(char *domain_path)
75007502
return 0;
75017503
}
75027504

7503-
for (constraint = 0;; constraint++)
7504-
{
7505+
for (constraint = 0;; constraint++) {
75057506
snprintf(path, PATH_MAX, "%s/constraint_%d_time_window_us", domain_path, constraint);
75067507
ret = fread_ull(path, &val);
75077508
if (ret <= 0)
75087509
break;
75097510

75107511
if (val > 1000000)
7511-
fprintf(outf, " %0.1fs", (double)val/1000000);
7512+
fprintf(outf, " %0.1fs", (double)val / 1000000);
75127513
else if (val > 1000)
7513-
fprintf(outf, " %0.1fms", (double)val/1000);
7514+
fprintf(outf, " %0.1fms", (double)val / 1000);
75147515
else
75157516
fprintf(outf, " %0.1fus", (double)val);
75167517

@@ -7541,30 +7542,29 @@ static int print_rapl_sysfs(void)
75417542
return 1;
75427543
}
75437544

7544-
while ((entry = readdir (dir)) != NULL) {
7545+
while ((entry = readdir(dir)) != NULL) {
75457546
if (strlen(entry->d_name) > 100)
7546-
continue;
7547+
continue;
75477548

75487549
if (strncmp(entry->d_name, "intel-rapl", strlen("intel-rapl")))
7549-
continue;
7550+
continue;
75507551

75517552
snprintf(path, PATH_MAX, "%s/%s/name", PATH_RAPL_SYSFS, entry->d_name);
75527553

75537554
/* Parse top level domains first, including package and psys */
75547555
fread_str(path, str, PATH_MAX);
7555-
if (strncmp(str, "package", strlen("package")) &&
7556-
strncmp(str, "psys", strlen("psys")))
7556+
if (strncmp(str, "package", strlen("package")) && strncmp(str, "psys", strlen("psys")))
75577557
continue;
75587558

75597559
snprintf(path, PATH_MAX, "%s/%s", PATH_RAPL_SYSFS, entry->d_name);
75607560
if ((cdir = opendir(path)) == NULL) {
7561-
perror ("opendir() error");
7561+
perror("opendir() error");
75627562
return 1;
75637563
}
75647564

75657565
dump_one_domain(path);
75667566

7567-
while ((centry = readdir (cdir)) != NULL) {
7567+
while ((centry = readdir(cdir)) != NULL) {
75687568
if (strncmp(centry->d_name, "intel-rapl", strlen("intel-rapl")))
75697569
continue;
75707570
snprintf(path, PATH_MAX, "%s/%s/%s", PATH_RAPL_SYSFS, entry->d_name, centry->d_name);
@@ -8049,7 +8049,7 @@ static int has_instr_count_access(void)
80498049
}
80508050

80518051
int add_rapl_perf_counter(int cpu, struct rapl_counter_info_t *rci, const struct rapl_counter_arch_info *cai,
8052-
double *scale_, enum rapl_unit *unit_)
8052+
double *scale_, enum rapl_unit *unit_)
80538053
{
80548054
int ret = -1;
80558055

@@ -8188,7 +8188,7 @@ void rapl_perf_init(void)
81888188
rci->unit[cai->rci_index] = unit;
81898189
rci->flags[cai->rci_index] = cai->flags;
81908190

8191-
/* Use MSR for this counter */
8191+
/* Use MSR for this counter */
81928192
} else if (add_rapl_msr_counter(cpu, cai) >= 0) {
81938193
rci->source[cai->rci_index] = COUNTER_SOURCE_MSR;
81948194
rci->msr[cai->rci_index] = cai->msr;
@@ -9299,15 +9299,14 @@ int added_perf_counters_init_(struct perf_counter_info *pinfo)
92999299
perf_device = "cpu_atom";
93009300
break;
93019301

9302-
default: /* Don't change, we will probably fail and report a problem soon. */
9302+
default: /* Don't change, we will probably fail and report a problem soon. */
93039303
break;
93049304
}
93059305
}
93069306

93079307
perf_type = read_perf_type(perf_device);
93089308
if (perf_type == (unsigned int)-1) {
9309-
warnx("%s: perf/%s/%s: failed to read %s",
9310-
__func__, perf_device, pinfo->event, "type");
9309+
warnx("%s: perf/%s/%s: failed to read %s", __func__, perf_device, pinfo->event, "type");
93119310
continue;
93129311
}
93139312

@@ -9409,7 +9408,7 @@ struct pmt_mmio *pmt_mmio_open(unsigned int target_guid)
94099408
return NULL;
94109409
}
94119410

9412-
for ( ; entry != NULL; entry = pmt_diriter_next(&pmt_iter)) {
9411+
for (; entry != NULL; entry = pmt_diriter_next(&pmt_iter)) {
94139412
if (fstatat(dirfd(pmt_iter.dir), entry->d_name, &st, 0) == -1)
94149413
break;
94159414

@@ -9849,7 +9848,7 @@ int get_and_dump_counters(void)
98499848

98509849
void print_version()
98519850
{
9852-
fprintf(outf, "turbostat version 2025.04.06 - Len Brown <[email protected]>\n");
9851+
fprintf(outf, "turbostat version 2025.06.08 - Len Brown <[email protected]>\n");
98539852
}
98549853

98559854
#define COMMAND_LINE_SIZE 2048
@@ -10305,7 +10304,7 @@ void parse_add_command_pmt(char *add_command)
1030510304
unsigned int lsb;
1030610305
unsigned int msb;
1030710306
unsigned int guid;
10308-
unsigned int seq = 0; /* By default, pick first file in a sequence with a given GUID. */
10307+
unsigned int seq = 0; /* By default, pick first file in a sequence with a given GUID. */
1030910308
unsigned int domain_id;
1031010309
enum counter_scope scope = 0;
1031110310
enum pmt_datatype type = PMT_TYPE_RAW;

0 commit comments

Comments
 (0)