Skip to content

Commit 3ab7296

Browse files
committed
tools/power turbostat: v2024.04.10
Much of turbostat can now run with perf, rather than using the MSR driver Some of turbostat can now run as a regular non-root user. Add some new output columns for some new GFX hardware. [This patch updates the version, but otherwise changes no function; it touches up some checkpatch issues from previous patches] Signed-off-by: Len Brown <[email protected]>
1 parent 91a91d3 commit 3ab7296

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22116,6 +22116,7 @@ Q: https://patchwork.kernel.org/project/linux-pm/list/
2211622116
B: https://bugzilla.kernel.org
2211722117
T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git turbostat
2211822118
F: tools/power/x86/turbostat/
22119+
F: tools/testing/selftests/turbostat/
2211922120

2212022121
TW5864 VIDEO4LINUX DRIVER
2212122122
M: Bluecherry Maintainers <[email protected]>

tools/power/x86/turbostat/turbostat.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* turbostat -- show CPU frequency and C-state residency
44
* on modern Intel and AMD processors.
55
*
6-
* Copyright (c) 2023 Intel Corporation.
6+
* Copyright (c) 2024 Intel Corporation.
77
* Len Brown <[email protected]>
88
*/
99

@@ -1360,6 +1360,7 @@ struct sys_counters {
13601360
void free_sys_counters(void)
13611361
{
13621362
struct msr_counter *p = sys.tp, *pnext = NULL;
1363+
13631364
while (p) {
13641365
pnext = p->next;
13651366
free(p);
@@ -1979,6 +1980,7 @@ int dump_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p
19791980

19801981
const unsigned long long energy_value = c->core_energy.raw_value * c->core_energy.scale;
19811982
const double energy_scale = c->core_energy.scale;
1983+
19821984
if (c->core_energy.unit == RAPL_UNIT_JOULES)
19831985
outp += sprintf(outp, "Joules: %0llX (scale: %lf)\n", energy_value, energy_scale);
19841986

@@ -3153,31 +3155,31 @@ static unsigned int read_perf_counter_info_n(const char *const path, const char
31533155
return v;
31543156
}
31553157

3156-
static unsigned read_msr_type(void)
3158+
static unsigned int read_msr_type(void)
31573159
{
31583160
const char *const path = "/sys/bus/event_source/devices/msr/type";
31593161
const char *const format = "%u";
31603162

31613163
return read_perf_counter_info_n(path, format);
31623164
}
31633165

3164-
static unsigned read_aperf_config(void)
3166+
static unsigned int read_aperf_config(void)
31653167
{
31663168
const char *const path = "/sys/bus/event_source/devices/msr/events/aperf";
31673169
const char *const format = "event=%x";
31683170

31693171
return read_perf_counter_info_n(path, format);
31703172
}
31713173

3172-
static unsigned read_mperf_config(void)
3174+
static unsigned int read_mperf_config(void)
31733175
{
31743176
const char *const path = "/sys/bus/event_source/devices/msr/events/mperf";
31753177
const char *const format = "event=%x";
31763178

31773179
return read_perf_counter_info_n(path, format);
31783180
}
31793181

3180-
static unsigned read_perf_type(const char *subsys)
3182+
static unsigned int read_perf_type(const char *subsys)
31813183
{
31823184
const char *const path_format = "/sys/bus/event_source/devices/%s/type";
31833185
const char *const format = "%u";
@@ -3188,7 +3190,7 @@ static unsigned read_perf_type(const char *subsys)
31883190
return read_perf_counter_info_n(path, format);
31893191
}
31903192

3191-
static unsigned read_rapl_config(const char *subsys, const char *event_name)
3193+
static unsigned int read_rapl_config(const char *subsys, const char *event_name)
31923194
{
31933195
const char *const path_format = "/sys/bus/event_source/devices/%s/events/%s";
31943196
const char *const format = "event=%x";
@@ -3199,7 +3201,7 @@ static unsigned read_rapl_config(const char *subsys, const char *event_name)
31993201
return read_perf_counter_info_n(path, format);
32003202
}
32013203

3202-
static unsigned read_perf_rapl_unit(const char *subsys, const char *event_name)
3204+
static unsigned int read_perf_rapl_unit(const char *subsys, const char *event_name)
32033205
{
32043206
const char *const path_format = "/sys/bus/event_source/devices/%s/events/%s.unit";
32053207
const char *const format = "%s";
@@ -3235,7 +3237,7 @@ static struct amperf_group_fd open_amperf_fd(int cpu)
32353237
const unsigned int msr_type = read_msr_type();
32363238
const unsigned int aperf_config = read_aperf_config();
32373239
const unsigned int mperf_config = read_mperf_config();
3238-
struct amperf_group_fd fds = {.aperf = -1,.mperf = -1 };
3240+
struct amperf_group_fd fds = {.aperf = -1, .mperf = -1 };
32393241

32403242
fds.aperf = open_perf_counter(cpu, msr_type, aperf_config, -1, PERF_FORMAT_GROUP);
32413243
fds.mperf = open_perf_counter(cpu, msr_type, mperf_config, fds.aperf, PERF_FORMAT_GROUP);
@@ -3277,6 +3279,7 @@ static int read_aperf_mperf_tsc_perf(struct thread_data *t, int cpu)
32773279
t->tsc = rdtsc();
32783280

32793281
const int n = read(fd_amperf, &cnt.as_array[0], sizeof(cnt.as_array));
3282+
32803283
if (n != sizeof(cnt.as_array))
32813284
return -2;
32823285

@@ -3371,7 +3374,7 @@ int get_rapl_counters(int cpu, int domain, struct core_data *c, struct pkg_data
33713374
struct rapl_counter_info_t *rci = &rapl_counter_info_perdomain[domain];
33723375

33733376
if (debug)
3374-
fprintf(stderr, "get_rapl_counters: cpu%d domain%d\n", cpu, domain);
3377+
fprintf(stderr, "%s: cpu%d domain%d\n", __func__, cpu, domain);
33753378

33763379
assert(rapl_counter_info_perdomain);
33773380

@@ -3382,8 +3385,9 @@ int get_rapl_counters(int cpu, int domain, struct core_data *c, struct pkg_data
33823385
size_t num_perf_counters = rapl_counter_info_count_perf(rci);
33833386
const ssize_t expected_read_size = (num_perf_counters + 1) * sizeof(unsigned long long);
33843387
const ssize_t actual_read_size = read(rci->fd_perf, &perf_data[0], sizeof(perf_data));
3388+
33853389
if (actual_read_size != expected_read_size)
3386-
err(-1, "get_rapl_counters: failed to read perf_data (%zu %zu)", expected_read_size,
3390+
err(-1, "%s: failed to read perf_data (%zu %zu)", __func__, expected_read_size,
33873391
actual_read_size);
33883392
}
33893393

@@ -3454,7 +3458,7 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
34543458
int status;
34553459

34563460
if (cpu_migrate(cpu)) {
3457-
fprintf(outf, "get_counters: Could not migrate to CPU %d\n", cpu);
3461+
fprintf(outf, "%s: Could not migrate to CPU %d\n", __func__, cpu);
34583462
return -1;
34593463
}
34603464

@@ -6411,15 +6415,17 @@ int add_rapl_perf_counter_(int cpu, struct rapl_counter_info_t *rci, const struc
64116415
return -1;
64126416

64136417
const double scale = read_perf_rapl_scale(cai->perf_subsys, cai->perf_name);
6418+
64146419
if (scale == 0.0)
64156420
return -1;
64166421

64176422
const enum rapl_unit unit = read_perf_rapl_unit(cai->perf_subsys, cai->perf_name);
6423+
64186424
if (unit == RAPL_UNIT_INVALID)
64196425
return -1;
64206426

6421-
const unsigned rapl_type = read_perf_type(cai->perf_subsys);
6422-
const unsigned rapl_energy_pkg_config = read_rapl_config(cai->perf_subsys, cai->perf_name);
6427+
const unsigned int rapl_type = read_perf_type(cai->perf_subsys);
6428+
const unsigned int rapl_energy_pkg_config = read_rapl_config(cai->perf_subsys, cai->perf_name);
64236429

64246430
const int fd_counter =
64256431
open_perf_counter(cpu, rapl_type, rapl_energy_pkg_config, rci->fd_perf, PERF_FORMAT_GROUP);
@@ -6441,7 +6447,7 @@ int add_rapl_perf_counter(int cpu, struct rapl_counter_info_t *rci, const struct
64416447
int ret = add_rapl_perf_counter_(cpu, rci, cai, scale, unit);
64426448

64436449
if (debug)
6444-
fprintf(stderr, "add_rapl_perf_counter: %d (cpu: %d)\n", ret, cpu);
6450+
fprintf(stderr, "%s: %d (cpu: %d)\n", __func__, ret, cpu);
64456451

64466452
return ret;
64476453
}
@@ -6462,6 +6468,7 @@ void linux_perf_init(void)
64626468
}
64636469

64646470
const bool aperf_required = is_aperf_access_required();
6471+
64656472
if (aperf_required && has_aperf && amperf_source == AMPERF_SOURCE_PERF) {
64666473
fd_amperf_percpu = calloc(topo.max_cpu_num + 1, sizeof(*fd_amperf_percpu));
64676474
if (fd_amperf_percpu == NULL)
@@ -6483,6 +6490,7 @@ void rapl_perf_init(void)
64836490
*/
64846491
for (int domain_id = 0; domain_id < num_domains; ++domain_id) {
64856492
struct rapl_counter_info_t *rci = &rapl_counter_info_perdomain[domain_id];
6493+
64866494
rci->fd_perf = -1;
64876495
for (size_t i = 0; i < NUM_RAPL_COUNTERS; ++i) {
64886496
rci->data[i] = 0;
@@ -7296,6 +7304,7 @@ static void set_amperf_source(void)
72967304
amperf_source = AMPERF_SOURCE_PERF;
72977305

72987306
const bool aperf_required = is_aperf_access_required();
7307+
72997308
if (no_perf || !aperf_required || !has_amperf_access_via_perf())
73007309
amperf_source = AMPERF_SOURCE_MSR;
73017310

@@ -7373,10 +7382,12 @@ void check_msr_access(void)
73737382
void check_perf_access(void)
73747383
{
73757384
const bool intrcount_required = BIC_IS_ENABLED(BIC_IPC);
7385+
73767386
if (no_perf || !intrcount_required || !has_instr_count_access())
73777387
bic_enabled &= ~BIC_IPC;
73787388

73797389
const bool aperf_required = is_aperf_access_required();
7390+
73807391
if (!aperf_required || !has_amperf_access()) {
73817392
bic_enabled &= ~BIC_Avg_MHz;
73827393
bic_enabled &= ~BIC_Busy;
@@ -7486,7 +7497,7 @@ int get_and_dump_counters(void)
74867497

74877498
void print_version()
74887499
{
7489-
fprintf(outf, "turbostat version 2023.11.07 - Len Brown <[email protected]>\n");
7500+
fprintf(outf, "turbostat version 2024.04.08 - Len Brown <[email protected]>\n");
74907501
}
74917502

74927503
#define COMMAND_LINE_SIZE 2048

tools/testing/selftests/turbostat/defcolumns.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/env python3
2+
# SPDX-License-Identifier: GPL-2.0
23

34
import subprocess
45
from shutil import which

0 commit comments

Comments
 (0)