3
3
* turbostat -- show CPU frequency and C-state residency
4
4
* on modern Intel and AMD processors.
5
5
*
6
- * Copyright (c) 2023 Intel Corporation.
6
+ * Copyright (c) 2024 Intel Corporation.
7
7
8
8
*/
9
9
@@ -1360,6 +1360,7 @@ struct sys_counters {
1360
1360
void free_sys_counters (void )
1361
1361
{
1362
1362
struct msr_counter * p = sys .tp , * pnext = NULL ;
1363
+
1363
1364
while (p ) {
1364
1365
pnext = p -> next ;
1365
1366
free (p );
@@ -1979,6 +1980,7 @@ int dump_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p
1979
1980
1980
1981
const unsigned long long energy_value = c -> core_energy .raw_value * c -> core_energy .scale ;
1981
1982
const double energy_scale = c -> core_energy .scale ;
1983
+
1982
1984
if (c -> core_energy .unit == RAPL_UNIT_JOULES )
1983
1985
outp += sprintf (outp , "Joules: %0llX (scale: %lf)\n" , energy_value , energy_scale );
1984
1986
@@ -3153,31 +3155,31 @@ static unsigned int read_perf_counter_info_n(const char *const path, const char
3153
3155
return v ;
3154
3156
}
3155
3157
3156
- static unsigned read_msr_type (void )
3158
+ static unsigned int read_msr_type (void )
3157
3159
{
3158
3160
const char * const path = "/sys/bus/event_source/devices/msr/type" ;
3159
3161
const char * const format = "%u" ;
3160
3162
3161
3163
return read_perf_counter_info_n (path , format );
3162
3164
}
3163
3165
3164
- static unsigned read_aperf_config (void )
3166
+ static unsigned int read_aperf_config (void )
3165
3167
{
3166
3168
const char * const path = "/sys/bus/event_source/devices/msr/events/aperf" ;
3167
3169
const char * const format = "event=%x" ;
3168
3170
3169
3171
return read_perf_counter_info_n (path , format );
3170
3172
}
3171
3173
3172
- static unsigned read_mperf_config (void )
3174
+ static unsigned int read_mperf_config (void )
3173
3175
{
3174
3176
const char * const path = "/sys/bus/event_source/devices/msr/events/mperf" ;
3175
3177
const char * const format = "event=%x" ;
3176
3178
3177
3179
return read_perf_counter_info_n (path , format );
3178
3180
}
3179
3181
3180
- static unsigned read_perf_type (const char * subsys )
3182
+ static unsigned int read_perf_type (const char * subsys )
3181
3183
{
3182
3184
const char * const path_format = "/sys/bus/event_source/devices/%s/type" ;
3183
3185
const char * const format = "%u" ;
@@ -3188,7 +3190,7 @@ static unsigned read_perf_type(const char *subsys)
3188
3190
return read_perf_counter_info_n (path , format );
3189
3191
}
3190
3192
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 )
3192
3194
{
3193
3195
const char * const path_format = "/sys/bus/event_source/devices/%s/events/%s" ;
3194
3196
const char * const format = "event=%x" ;
@@ -3199,7 +3201,7 @@ static unsigned read_rapl_config(const char *subsys, const char *event_name)
3199
3201
return read_perf_counter_info_n (path , format );
3200
3202
}
3201
3203
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 )
3203
3205
{
3204
3206
const char * const path_format = "/sys/bus/event_source/devices/%s/events/%s.unit" ;
3205
3207
const char * const format = "%s" ;
@@ -3235,7 +3237,7 @@ static struct amperf_group_fd open_amperf_fd(int cpu)
3235
3237
const unsigned int msr_type = read_msr_type ();
3236
3238
const unsigned int aperf_config = read_aperf_config ();
3237
3239
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 };
3239
3241
3240
3242
fds .aperf = open_perf_counter (cpu , msr_type , aperf_config , -1 , PERF_FORMAT_GROUP );
3241
3243
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)
3277
3279
t -> tsc = rdtsc ();
3278
3280
3279
3281
const int n = read (fd_amperf , & cnt .as_array [0 ], sizeof (cnt .as_array ));
3282
+
3280
3283
if (n != sizeof (cnt .as_array ))
3281
3284
return -2 ;
3282
3285
@@ -3371,7 +3374,7 @@ int get_rapl_counters(int cpu, int domain, struct core_data *c, struct pkg_data
3371
3374
struct rapl_counter_info_t * rci = & rapl_counter_info_perdomain [domain ];
3372
3375
3373
3376
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 );
3375
3378
3376
3379
assert (rapl_counter_info_perdomain );
3377
3380
@@ -3382,8 +3385,9 @@ int get_rapl_counters(int cpu, int domain, struct core_data *c, struct pkg_data
3382
3385
size_t num_perf_counters = rapl_counter_info_count_perf (rci );
3383
3386
const ssize_t expected_read_size = (num_perf_counters + 1 ) * sizeof (unsigned long long );
3384
3387
const ssize_t actual_read_size = read (rci -> fd_perf , & perf_data [0 ], sizeof (perf_data ));
3388
+
3385
3389
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 ,
3387
3391
actual_read_size );
3388
3392
}
3389
3393
@@ -3454,7 +3458,7 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
3454
3458
int status ;
3455
3459
3456
3460
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 );
3458
3462
return -1 ;
3459
3463
}
3460
3464
@@ -6411,15 +6415,17 @@ int add_rapl_perf_counter_(int cpu, struct rapl_counter_info_t *rci, const struc
6411
6415
return -1 ;
6412
6416
6413
6417
const double scale = read_perf_rapl_scale (cai -> perf_subsys , cai -> perf_name );
6418
+
6414
6419
if (scale == 0.0 )
6415
6420
return -1 ;
6416
6421
6417
6422
const enum rapl_unit unit = read_perf_rapl_unit (cai -> perf_subsys , cai -> perf_name );
6423
+
6418
6424
if (unit == RAPL_UNIT_INVALID )
6419
6425
return -1 ;
6420
6426
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 );
6423
6429
6424
6430
const int fd_counter =
6425
6431
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
6441
6447
int ret = add_rapl_perf_counter_ (cpu , rci , cai , scale , unit );
6442
6448
6443
6449
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 );
6445
6451
6446
6452
return ret ;
6447
6453
}
@@ -6462,6 +6468,7 @@ void linux_perf_init(void)
6462
6468
}
6463
6469
6464
6470
const bool aperf_required = is_aperf_access_required ();
6471
+
6465
6472
if (aperf_required && has_aperf && amperf_source == AMPERF_SOURCE_PERF ) {
6466
6473
fd_amperf_percpu = calloc (topo .max_cpu_num + 1 , sizeof (* fd_amperf_percpu ));
6467
6474
if (fd_amperf_percpu == NULL )
@@ -6483,6 +6490,7 @@ void rapl_perf_init(void)
6483
6490
*/
6484
6491
for (int domain_id = 0 ; domain_id < num_domains ; ++ domain_id ) {
6485
6492
struct rapl_counter_info_t * rci = & rapl_counter_info_perdomain [domain_id ];
6493
+
6486
6494
rci -> fd_perf = -1 ;
6487
6495
for (size_t i = 0 ; i < NUM_RAPL_COUNTERS ; ++ i ) {
6488
6496
rci -> data [i ] = 0 ;
@@ -7296,6 +7304,7 @@ static void set_amperf_source(void)
7296
7304
amperf_source = AMPERF_SOURCE_PERF ;
7297
7305
7298
7306
const bool aperf_required = is_aperf_access_required ();
7307
+
7299
7308
if (no_perf || !aperf_required || !has_amperf_access_via_perf ())
7300
7309
amperf_source = AMPERF_SOURCE_MSR ;
7301
7310
@@ -7373,10 +7382,12 @@ void check_msr_access(void)
7373
7382
void check_perf_access (void )
7374
7383
{
7375
7384
const bool intrcount_required = BIC_IS_ENABLED (BIC_IPC );
7385
+
7376
7386
if (no_perf || !intrcount_required || !has_instr_count_access ())
7377
7387
bic_enabled &= ~BIC_IPC ;
7378
7388
7379
7389
const bool aperf_required = is_aperf_access_required ();
7390
+
7380
7391
if (!aperf_required || !has_amperf_access ()) {
7381
7392
bic_enabled &= ~BIC_Avg_MHz ;
7382
7393
bic_enabled &= ~BIC_Busy ;
@@ -7486,7 +7497,7 @@ int get_and_dump_counters(void)
7486
7497
7487
7498
void print_version ()
7488
7499
{
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" );
7490
7501
}
7491
7502
7492
7503
#define COMMAND_LINE_SIZE 2048
0 commit comments