Skip to content

Commit e5f687b

Browse files
Patryk Wlazlynlenb
Patryk Wlazlyn
authored andcommitted
tools/power turbostat: Add RAPL psys as a built-in counter
Introduce the counter as a part of global, platform counters structure. We open the counter for only one cpu, but otherwise treat it as an ordinary RAPL counter, allowing for grouped perf read. The counter is disabled by default, because it's interpretation may require additional, platform specific information, making it unsuitable for general use. Signed-off-by: Patryk Wlazlyn <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent 1da0daf commit e5f687b

File tree

2 files changed

+85
-10
lines changed

2 files changed

+85
-10
lines changed

tools/power/x86/turbostat/turbostat.8

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ The system configuration dump (if --quiet is not used) is followed by statistics
190190
.PP
191191
\fBRAMWatt\fP Watts consumed by the DRAM DIMMS -- available only on server processors.
192192
.PP
193+
\fBSysWatt\fP Watts consumed by the whole platform (RAPL PSYS). Disabled by default. May require platform specific information to interpret the data, making it not suitable for general use.
194+
.PP
193195
\fBPKG_%\fP percent of the interval that RAPL throttling was active on the Package. Note that the system summary is the sum of the package throttling time, and thus may be higher than 100% on a multi-package system. Note that the meaning of this field is model specific. For example, some hardware increments this counter when RAPL responds to thermal limits, but does not increment this counter when RAPL responds to power limits. Comparing PkgWatt and PkgTmp to system limits is necessary.
194196
.PP
195197
\fBRAM_%\fP percent of the interval that RAPL throttling was active on DRAM.

tools/power/x86/turbostat/turbostat.c

+83-10
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ struct msr_counter bic[] = {
200200
{ 0x0, "SAMMHz", NULL, 0, 0, 0, NULL, 0 },
201201
{ 0x0, "SAMAMHz", NULL, 0, 0, 0, NULL, 0 },
202202
{ 0x0, "Die%c6", NULL, 0, 0, 0, NULL, 0 },
203+
{ 0x0, "SysWatt", NULL, 0, 0, 0, NULL, 0 },
204+
{ 0x0, "Sys_J", NULL, 0, 0, 0, NULL, 0 },
203205
};
204206

205207
#define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter))
@@ -262,14 +264,16 @@ struct msr_counter bic[] = {
262264
#define BIC_SAMMHz (1ULL << 56)
263265
#define BIC_SAMACTMHz (1ULL << 57)
264266
#define BIC_Diec6 (1ULL << 58)
267+
#define BIC_SysWatt (1ULL << 59)
268+
#define BIC_Sys_J (1ULL << 60)
265269

266270
#define BIC_TOPOLOGY (BIC_Package | BIC_Node | BIC_CoreCnt | BIC_PkgCnt | BIC_Core | BIC_CPU | BIC_Die )
267271
#define BIC_THERMAL_PWR ( BIC_CoreTmp | BIC_PkgTmp | BIC_PkgWatt | BIC_CorWatt | BIC_GFXWatt | BIC_RAMWatt | BIC_PKG__ | BIC_RAM__)
268272
#define BIC_FREQUENCY (BIC_Avg_MHz | BIC_Busy | BIC_Bzy_MHz | BIC_TSC_MHz | BIC_GFXMHz | BIC_GFXACTMHz | BIC_SAMMHz | BIC_SAMACTMHz | BIC_UNCORE_MHZ)
269273
#define BIC_IDLE (BIC_sysfs | 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)
270274
#define BIC_OTHER ( BIC_IRQ | BIC_SMI | BIC_ThreadC | BIC_CoreTmp | BIC_IPC)
271275

272-
#define BIC_DISABLED_BY_DEFAULT (BIC_USEC | BIC_TOD | BIC_APIC | BIC_X2APIC)
276+
#define BIC_DISABLED_BY_DEFAULT (BIC_USEC | BIC_TOD | BIC_APIC | BIC_X2APIC | BIC_SysWatt | BIC_Sys_J)
273277

274278
unsigned long long bic_enabled = (0xFFFFFFFFFFFFFFFFULL & ~BIC_DISABLED_BY_DEFAULT);
275279
unsigned long long bic_present = BIC_USEC | BIC_TOD | BIC_sysfs | BIC_APIC | BIC_X2APIC;
@@ -507,12 +511,15 @@ enum rapl_msrs {
507511
RAPL_AMD_PWR_UNIT = BIT(14), /* 0xc0010299 MSR_AMD_RAPL_POWER_UNIT */
508512
RAPL_AMD_CORE_ENERGY_STAT = BIT(15), /* 0xc001029a MSR_AMD_CORE_ENERGY_STATUS */
509513
RAPL_AMD_PKG_ENERGY_STAT = BIT(16), /* 0xc001029b MSR_AMD_PKG_ENERGY_STATUS */
514+
RAPL_PLATFORM_ENERGY_LIMIT = BIT(17), /* 0x64c MSR_PLATFORM_ENERGY_LIMIT */
515+
RAPL_PLATFORM_ENERGY_STATUS = BIT(18), /* 0x64d MSR_PLATFORM_ENERGY_STATUS */
510516
};
511517

512518
#define RAPL_PKG (RAPL_PKG_ENERGY_STATUS | RAPL_PKG_POWER_LIMIT)
513519
#define RAPL_DRAM (RAPL_DRAM_ENERGY_STATUS | RAPL_DRAM_POWER_LIMIT)
514520
#define RAPL_CORE (RAPL_CORE_ENERGY_STATUS | RAPL_CORE_POWER_LIMIT)
515521
#define RAPL_GFX (RAPL_GFX_POWER_LIMIT | RAPL_GFX_ENERGY_STATUS)
522+
#define RAPL_PSYS (RAPL_PLATFORM_ENERGY_STATUS | RAPL_PLATFORM_ENERGY_LIMIT)
516523

517524
#define RAPL_PKG_ALL (RAPL_PKG | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO)
518525
#define RAPL_DRAM_ALL (RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_DRAM_POWER_INFO)
@@ -713,7 +720,7 @@ static const struct platform_features skl_features = {
713720
.has_ext_cst_msrs = 1,
714721
.trl_msrs = TRL_BASE,
715722
.tcc_offset_bits = 6,
716-
.rapl_msrs = RAPL_PKG_ALL | RAPL_CORE_ALL | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_GFX,
723+
.rapl_msrs = RAPL_PKG_ALL | RAPL_CORE_ALL | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_GFX | RAPL_PSYS,
717724
.enable_tsc_tweak = 1,
718725
};
719726

@@ -730,7 +737,7 @@ static const struct platform_features cnl_features = {
730737
.has_ext_cst_msrs = 1,
731738
.trl_msrs = TRL_BASE,
732739
.tcc_offset_bits = 6,
733-
.rapl_msrs = RAPL_PKG_ALL | RAPL_CORE_ALL | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_GFX,
740+
.rapl_msrs = RAPL_PKG_ALL | RAPL_CORE_ALL | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_GFX | RAPL_PSYS,
734741
.enable_tsc_tweak = 1,
735742
};
736743

@@ -797,7 +804,7 @@ static const struct platform_features icx_features = {
797804
.has_irtl_msrs = 1,
798805
.has_cst_prewake_bit = 1,
799806
.trl_msrs = TRL_BASE | TRL_CORECOUNT,
800-
.rapl_msrs = RAPL_PKG_ALL | RAPL_DRAM_ALL,
807+
.rapl_msrs = RAPL_PKG_ALL | RAPL_DRAM_ALL | RAPL_PSYS,
801808
.has_fixed_rapl_unit = 1,
802809
};
803810

@@ -813,7 +820,7 @@ static const struct platform_features spr_features = {
813820
.has_irtl_msrs = 1,
814821
.has_cst_prewake_bit = 1,
815822
.trl_msrs = TRL_BASE | TRL_CORECOUNT,
816-
.rapl_msrs = RAPL_PKG_ALL | RAPL_DRAM_ALL,
823+
.rapl_msrs = RAPL_PKG_ALL | RAPL_DRAM_ALL | RAPL_PSYS,
817824
};
818825

819826
static const struct platform_features srf_features = {
@@ -829,7 +836,7 @@ static const struct platform_features srf_features = {
829836
.has_irtl_msrs = 1,
830837
.has_cst_prewake_bit = 1,
831838
.trl_msrs = TRL_BASE | TRL_CORECOUNT,
832-
.rapl_msrs = RAPL_PKG_ALL | RAPL_DRAM_ALL,
839+
.rapl_msrs = RAPL_PKG_ALL | RAPL_DRAM_ALL | RAPL_PSYS,
833840
};
834841

835842
static const struct platform_features grr_features = {
@@ -845,7 +852,7 @@ static const struct platform_features grr_features = {
845852
.has_irtl_msrs = 1,
846853
.has_cst_prewake_bit = 1,
847854
.trl_msrs = TRL_BASE | TRL_CORECOUNT,
848-
.rapl_msrs = RAPL_PKG_ALL | RAPL_DRAM_ALL,
855+
.rapl_msrs = RAPL_PKG_ALL | RAPL_DRAM_ALL | RAPL_PSYS,
849856
};
850857

851858
static const struct platform_features slv_features = {
@@ -1108,6 +1115,7 @@ enum rapl_rci_index {
11081115
RAPL_RCI_INDEX_PKG_PERF_STATUS = 4,
11091116
RAPL_RCI_INDEX_DRAM_PERF_STATUS = 5,
11101117
RAPL_RCI_INDEX_CORE_ENERGY = 6,
1118+
RAPL_RCI_INDEX_ENERGY_PLATFORM = 7,
11111119
NUM_RAPL_COUNTERS,
11121120
};
11131121

@@ -1134,6 +1142,7 @@ struct rapl_counter_info_t {
11341142
struct rapl_counter_info_t *rapl_counter_info_perdomain;
11351143
unsigned int rapl_counter_info_perdomain_size;
11361144

1145+
#define RAPL_COUNTER_FLAG_PLATFORM_COUNTER (1u << 0)
11371146
#define RAPL_COUNTER_FLAG_USE_MSR_SUM (1u << 1)
11381147

11391148
struct rapl_counter_arch_info {
@@ -1255,6 +1264,19 @@ static const struct rapl_counter_arch_info rapl_counter_arch_infos[] = {
12551264
.compat_scale = 1.0,
12561265
.flags = 0,
12571266
},
1267+
{
1268+
.feature_mask = RAPL_PSYS,
1269+
.perf_subsys = "power",
1270+
.perf_name = "energy-psys",
1271+
.msr = MSR_PLATFORM_ENERGY_STATUS,
1272+
.msr_mask = 0x00000000FFFFFFFF,
1273+
.msr_shift = 0,
1274+
.platform_rapl_msr_scale = &rapl_energy_units,
1275+
.rci_index = RAPL_RCI_INDEX_ENERGY_PLATFORM,
1276+
.bic = BIC_SysWatt | BIC_Sys_J,
1277+
.compat_scale = 1.0,
1278+
.flags = RAPL_COUNTER_FLAG_PLATFORM_COUNTER | RAPL_COUNTER_FLAG_USE_MSR_SUM,
1279+
},
12581280
};
12591281

12601282
struct rapl_counter {
@@ -1682,6 +1704,7 @@ enum {
16821704
IDX_PP1_ENERGY,
16831705
IDX_PKG_PERF,
16841706
IDX_DRAM_PERF,
1707+
IDX_PSYS_ENERGY,
16851708
IDX_COUNT,
16861709
};
16871710

@@ -1726,6 +1749,9 @@ off_t idx_to_offset(int idx)
17261749
case IDX_DRAM_PERF:
17271750
offset = MSR_DRAM_PERF_STATUS;
17281751
break;
1752+
case IDX_PSYS_ENERGY:
1753+
offset = MSR_PLATFORM_ENERGY_STATUS;
1754+
break;
17291755
default:
17301756
offset = -1;
17311757
}
@@ -1756,6 +1782,9 @@ int offset_to_idx(off_t offset)
17561782
case MSR_DRAM_PERF_STATUS:
17571783
idx = IDX_DRAM_PERF;
17581784
break;
1785+
case MSR_PLATFORM_ENERGY_STATUS:
1786+
idx = IDX_PSYS_ENERGY;
1787+
break;
17591788
default:
17601789
idx = -1;
17611790
}
@@ -1777,6 +1806,8 @@ int idx_valid(int idx)
17771806
return platform->rapl_msrs & RAPL_PKG_PERF_STATUS;
17781807
case IDX_DRAM_PERF:
17791808
return platform->rapl_msrs & RAPL_DRAM_PERF_STATUS;
1809+
case IDX_PSYS_ENERGY:
1810+
return platform->rapl_msrs & RAPL_PSYS;
17801811
default:
17811812
return 0;
17821813
}
@@ -1848,6 +1879,10 @@ struct system_summary {
18481879
struct pkg_data packages;
18491880
} average;
18501881

1882+
struct platform_counters {
1883+
struct rapl_counter energy_psys; /* MSR_PLATFORM_ENERGY_STATUS */
1884+
} platform_counters_odd, platform_counters_even;
1885+
18511886
struct cpu_topology {
18521887
int physical_package_id;
18531888
int die_id;
@@ -2512,13 +2547,19 @@ void print_header(char *delim)
25122547
ppmt = ppmt->next;
25132548
}
25142549

2550+
if (DO_BIC(BIC_SysWatt))
2551+
outp += sprintf(outp, "%sSysWatt", (printed++ ? delim : ""));
2552+
if (DO_BIC(BIC_Sys_J))
2553+
outp += sprintf(outp, "%sSys_J", (printed++ ? delim : ""));
2554+
25152555
outp += sprintf(outp, "\n");
25162556
}
25172557

25182558
int dump_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
25192559
{
25202560
int i;
25212561
struct msr_counter *mp;
2562+
struct platform_counters *pplat_cnt = p == package_odd ? &platform_counters_odd : &platform_counters_even;
25222563

25232564
outp += sprintf(outp, "t %p, c %p, p %p\n", t, c, p);
25242565

@@ -2590,6 +2631,7 @@ int dump_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p
25902631
outp += sprintf(outp, "Joules COR: %0llX\n", p->energy_cores.raw_value);
25912632
outp += sprintf(outp, "Joules GFX: %0llX\n", p->energy_gfx.raw_value);
25922633
outp += sprintf(outp, "Joules RAM: %0llX\n", p->energy_dram.raw_value);
2634+
outp += sprintf(outp, "Joules PSYS: %0llX\n", pplat_cnt->energy_psys.raw_value);
25932635
outp += sprintf(outp, "Throttle PKG: %0llX\n", p->rapl_pkg_perf_status.raw_value);
25942636
outp += sprintf(outp, "Throttle RAM: %0llX\n", p->rapl_dram_perf_status.raw_value);
25952637
outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c);
@@ -2628,6 +2670,9 @@ double rapl_counter_get_value(const struct rapl_counter *c, enum rapl_unit desir
26282670
*/
26292671
int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
26302672
{
2673+
static int count;
2674+
2675+
struct platform_counters *pplat_cnt = NULL;
26312676
double interval_float, tsc;
26322677
char *fmt8;
26332678
int i;
@@ -2637,6 +2682,11 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
26372682
char *delim = "\t";
26382683
int printed = 0;
26392684

2685+
if (t == &average.threads) {
2686+
pplat_cnt = count & 1 ? &platform_counters_odd : &platform_counters_even;
2687+
++count;
2688+
}
2689+
26402690
/* if showing only 1st thread in core and this isn't one, bail out */
26412691
if (show_core_only && !is_cpu_first_thread_in_core(t, c, p))
26422692
return 0;
@@ -3093,6 +3143,13 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
30933143
}
30943144
}
30953145

3146+
if (DO_BIC(BIC_SysWatt) && (t == &average.threads))
3147+
outp += sprintf(outp, fmt8, (printed++ ? delim : ""),
3148+
rapl_counter_get_value(&pplat_cnt->energy_psys, RAPL_UNIT_WATTS, interval_float));
3149+
if (DO_BIC(BIC_Sys_J) && (t == &average.threads))
3150+
outp += sprintf(outp, fmt8, (printed++ ? delim : ""),
3151+
rapl_counter_get_value(&pplat_cnt->energy_psys, RAPL_UNIT_JOULES, interval_float));
3152+
30963153
done:
30973154
if (*(outp - 1) != '\n')
30983155
outp += sprintf(outp, "\n");
@@ -3400,6 +3457,11 @@ int delta_cpu(struct thread_data *t, struct core_data *c,
34003457
return retval;
34013458
}
34023459

3460+
void delta_platform(struct platform_counters *new, struct platform_counters *old)
3461+
{
3462+
old->energy_psys.raw_value = new->energy_psys.raw_value - old->energy_psys.raw_value;
3463+
}
3464+
34033465
void rapl_counter_clear(struct rapl_counter *c)
34043466
{
34053467
c->raw_value = 0;
@@ -4129,13 +4191,17 @@ static size_t cstate_counter_info_count_perf(const struct cstate_counter_info_t
41294191

41304192
void write_rapl_counter(struct rapl_counter *rc, struct rapl_counter_info_t *rci, unsigned int idx)
41314193
{
4194+
if (rci->source[idx] == COUNTER_SOURCE_NONE)
4195+
return;
4196+
41324197
rc->raw_value = rci->data[idx];
41334198
rc->unit = rci->unit[idx];
41344199
rc->scale = rci->scale[idx];
41354200
}
41364201

41374202
int get_rapl_counters(int cpu, unsigned int domain, struct core_data *c, struct pkg_data *p)
41384203
{
4204+
struct platform_counters *pplat_cnt = p == package_odd ? &platform_counters_odd : &platform_counters_even;
41394205
unsigned long long perf_data[NUM_RAPL_COUNTERS + 1];
41404206
struct rapl_counter_info_t *rci;
41414207

@@ -4163,6 +4229,7 @@ int get_rapl_counters(int cpu, unsigned int domain, struct core_data *c, struct
41634229
for (unsigned int i = 0, pi = 1; i < NUM_RAPL_COUNTERS; ++i) {
41644230
switch (rci->source[i]) {
41654231
case COUNTER_SOURCE_NONE:
4232+
rci->data[i] = 0;
41664233
break;
41674234

41684235
case COUNTER_SOURCE_PERF:
@@ -4201,14 +4268,15 @@ int get_rapl_counters(int cpu, unsigned int domain, struct core_data *c, struct
42014268
}
42024269
}
42034270

4204-
BUILD_BUG_ON(NUM_RAPL_COUNTERS != 7);
4271+
BUILD_BUG_ON(NUM_RAPL_COUNTERS != 8);
42054272
write_rapl_counter(&p->energy_pkg, rci, RAPL_RCI_INDEX_ENERGY_PKG);
42064273
write_rapl_counter(&p->energy_cores, rci, RAPL_RCI_INDEX_ENERGY_CORES);
42074274
write_rapl_counter(&p->energy_dram, rci, RAPL_RCI_INDEX_DRAM);
42084275
write_rapl_counter(&p->energy_gfx, rci, RAPL_RCI_INDEX_GFX);
42094276
write_rapl_counter(&p->rapl_pkg_perf_status, rci, RAPL_RCI_INDEX_PKG_PERF_STATUS);
42104277
write_rapl_counter(&p->rapl_dram_perf_status, rci, RAPL_RCI_INDEX_DRAM_PERF_STATUS);
42114278
write_rapl_counter(&c->core_energy, rci, RAPL_RCI_INDEX_CORE_ENERGY);
4279+
write_rapl_counter(&pplat_cnt->energy_psys, rci, RAPL_RCI_INDEX_ENERGY_PLATFORM);
42124280

42134281
return 0;
42144282
}
@@ -6144,6 +6212,7 @@ void turbostat_loop()
61446212
re_initialize();
61456213
goto restart;
61466214
}
6215+
delta_platform(&platform_counters_odd, &platform_counters_even);
61476216
compute_average(EVEN_COUNTERS);
61486217
format_all_counters(EVEN_COUNTERS);
61496218
flush_output_stdout();
@@ -6167,6 +6236,7 @@ void turbostat_loop()
61676236
re_initialize();
61686237
goto restart;
61696238
}
6239+
delta_platform(&platform_counters_even, &platform_counters_odd);
61706240
compute_average(ODD_COUNTERS);
61716241
format_all_counters(ODD_COUNTERS);
61726242
flush_output_stdout();
@@ -6945,8 +7015,8 @@ void rapl_probe_intel(void)
69457015
unsigned long long msr;
69467016
unsigned int time_unit;
69477017
double tdp;
6948-
const unsigned long long bic_watt_bits = BIC_PkgWatt | BIC_CorWatt | BIC_RAMWatt | BIC_GFXWatt;
6949-
const unsigned long long bic_joules_bits = BIC_Pkg_J | BIC_Cor_J | BIC_RAM_J | BIC_GFX_J;
7018+
const unsigned long long bic_watt_bits = BIC_SysWatt | BIC_PkgWatt | BIC_CorWatt | BIC_RAMWatt | BIC_GFXWatt;
7019+
const unsigned long long bic_joules_bits = BIC_Sys_J | BIC_Pkg_J | BIC_Cor_J | BIC_RAM_J | BIC_GFX_J;
69507020

69517021
if (rapl_joules)
69527022
bic_enabled &= ~bic_watt_bits;
@@ -7606,6 +7676,9 @@ void rapl_perf_init(void)
76067676

76077677
domain_visited[next_domain] = 1;
76087678

7679+
if ((cai->flags & RAPL_COUNTER_FLAG_PLATFORM_COUNTER) && (cpu != base_cpu))
7680+
continue;
7681+
76097682
struct rapl_counter_info_t *rci = &rapl_counter_info_perdomain[next_domain];
76107683

76117684
/* Check if the counter is enabled and accessible */

0 commit comments

Comments
 (0)