@@ -1052,6 +1052,7 @@ struct rapl_counter_info_t {
1052
1052
1053
1053
/* struct rapl_counter_info_t for each RAPL domain */
1054
1054
struct rapl_counter_info_t * rapl_counter_info_perdomain ;
1055
+ unsigned int rapl_counter_info_perdomain_size ;
1055
1056
1056
1057
#define RAPL_COUNTER_FLAG_USE_MSR_SUM (1u << 1)
1057
1058
@@ -1451,6 +1452,8 @@ struct topo_params {
1451
1452
int allowed_cpus ;
1452
1453
int allowed_cores ;
1453
1454
int max_cpu_num ;
1455
+ int max_core_id ;
1456
+ int max_package_id ;
1454
1457
int max_die_id ;
1455
1458
int max_node_num ;
1456
1459
int nodes_per_pkg ;
@@ -3425,15 +3428,18 @@ void write_rapl_counter(struct rapl_counter *rc, struct rapl_counter_info_t *rci
3425
3428
rc -> scale = rci -> scale [idx ];
3426
3429
}
3427
3430
3428
- int get_rapl_counters (int cpu , int domain , struct core_data * c , struct pkg_data * p )
3431
+ int get_rapl_counters (int cpu , unsigned int domain , struct core_data * c , struct pkg_data * p )
3429
3432
{
3430
3433
unsigned long long perf_data [NUM_RAPL_COUNTERS + 1 ];
3431
- struct rapl_counter_info_t * rci = & rapl_counter_info_perdomain [ domain ] ;
3434
+ struct rapl_counter_info_t * rci ;
3432
3435
3433
3436
if (debug )
3434
3437
fprintf (stderr , "%s: cpu%d domain%d\n" , __func__ , cpu , domain );
3435
3438
3436
3439
assert (rapl_counter_info_perdomain );
3440
+ assert (domain < rapl_counter_info_perdomain_size );
3441
+
3442
+ rci = & rapl_counter_info_perdomain [domain ];
3437
3443
3438
3444
/*
3439
3445
* If we have any perf counters to read, read them all now, in bulk
@@ -4257,14 +4263,16 @@ void free_fd_rapl_percpu(void)
4257
4263
if (!rapl_counter_info_perdomain )
4258
4264
return ;
4259
4265
4260
- const int num_domains = platform -> has_per_core_rapl ? topo . num_cores : topo . num_packages ;
4266
+ const int num_domains = rapl_counter_info_perdomain_size ;
4261
4267
4262
4268
for (int domain_id = 0 ; domain_id < num_domains ; ++ domain_id ) {
4263
4269
if (rapl_counter_info_perdomain [domain_id ].fd_perf != -1 )
4264
4270
close (rapl_counter_info_perdomain [domain_id ].fd_perf );
4265
4271
}
4266
4272
4267
4273
free (rapl_counter_info_perdomain );
4274
+ rapl_counter_info_perdomain = NULL ;
4275
+ rapl_counter_info_perdomain_size = 0 ;
4268
4276
}
4269
4277
4270
4278
void free_all_buffers (void )
@@ -6582,17 +6590,18 @@ void linux_perf_init(void)
6582
6590
6583
6591
void rapl_perf_init (void )
6584
6592
{
6585
- const int num_domains = platform -> has_per_core_rapl ? topo .num_cores : topo .num_packages ;
6593
+ const unsigned int num_domains = ( platform -> has_per_core_rapl ? topo .max_core_id : topo .max_package_id ) + 1 ;
6586
6594
bool * domain_visited = calloc (num_domains , sizeof (bool ));
6587
6595
6588
6596
rapl_counter_info_perdomain = calloc (num_domains , sizeof (* rapl_counter_info_perdomain ));
6589
6597
if (rapl_counter_info_perdomain == NULL )
6590
6598
err (-1 , "calloc rapl_counter_info_percpu" );
6599
+ rapl_counter_info_perdomain_size = num_domains ;
6591
6600
6592
6601
/*
6593
6602
* Initialize rapl_counter_info_percpu
6594
6603
*/
6595
- for (int domain_id = 0 ; domain_id < num_domains ; ++ domain_id ) {
6604
+ for (unsigned int domain_id = 0 ; domain_id < num_domains ; ++ domain_id ) {
6596
6605
struct rapl_counter_info_t * rci = & rapl_counter_info_perdomain [domain_id ];
6597
6606
6598
6607
rci -> fd_perf = -1 ;
@@ -6612,7 +6621,7 @@ void rapl_perf_init(void)
6612
6621
bool has_counter = 0 ;
6613
6622
double scale ;
6614
6623
enum rapl_unit unit ;
6615
- int next_domain ;
6624
+ unsigned int next_domain ;
6616
6625
6617
6626
memset (domain_visited , 0 , num_domains * sizeof (* domain_visited ));
6618
6627
@@ -6625,6 +6634,8 @@ void rapl_perf_init(void)
6625
6634
next_domain =
6626
6635
platform -> has_per_core_rapl ? cpus [cpu ].physical_core_id : cpus [cpu ].physical_package_id ;
6627
6636
6637
+ assert (next_domain < num_domains );
6638
+
6628
6639
if (domain_visited [next_domain ])
6629
6640
continue ;
6630
6641
@@ -7207,6 +7218,8 @@ void topology_probe(bool startup)
7207
7218
if (cpus [i ].thread_id == 0 )
7208
7219
topo .num_cores ++ ;
7209
7220
}
7221
+ topo .max_core_id = max_core_id ;
7222
+ topo .max_package_id = max_package_id ;
7210
7223
7211
7224
topo .cores_per_node = max_core_id + 1 ;
7212
7225
if (debug > 1 )
0 commit comments