13
13
#include "evlist.h"
14
14
#include "evsel.h"
15
15
#include "thread_map.h"
16
+ #include "hashmap.h"
16
17
#include <linux/zalloc.h>
17
18
18
19
void update_stats (struct stats * stats , u64 val )
@@ -277,18 +278,29 @@ void evlist__save_aggr_prev_raw_counts(struct evlist *evlist)
277
278
}
278
279
}
279
280
280
- static void zero_per_pkg ( struct evsel * counter )
281
+ static size_t pkg_id_hash ( const void * __key , void * ctx __maybe_unused )
281
282
{
282
- if (counter -> per_pkg_mask )
283
- memset (counter -> per_pkg_mask , 0 , cpu__max_cpu ());
283
+ uint64_t * key = (uint64_t * ) __key ;
284
+
285
+ return * key & 0xffffffff ;
286
+ }
287
+
288
+ static bool pkg_id_equal (const void * __key1 , const void * __key2 ,
289
+ void * ctx __maybe_unused )
290
+ {
291
+ uint64_t * key1 = (uint64_t * ) __key1 ;
292
+ uint64_t * key2 = (uint64_t * ) __key2 ;
293
+
294
+ return * key1 == * key2 ;
284
295
}
285
296
286
297
static int check_per_pkg (struct evsel * counter ,
287
298
struct perf_counts_values * vals , int cpu , bool * skip )
288
299
{
289
- unsigned long * mask = counter -> per_pkg_mask ;
300
+ struct hashmap * mask = counter -> per_pkg_mask ;
290
301
struct perf_cpu_map * cpus = evsel__cpus (counter );
291
- int s ;
302
+ int s , d , ret = 0 ;
303
+ uint64_t * key ;
292
304
293
305
* skip = false;
294
306
@@ -299,7 +311,7 @@ static int check_per_pkg(struct evsel *counter,
299
311
return 0 ;
300
312
301
313
if (!mask ) {
302
- mask = zalloc ( cpu__max_cpu () );
314
+ mask = hashmap__new ( pkg_id_hash , pkg_id_equal , NULL );
303
315
if (!mask )
304
316
return - ENOMEM ;
305
317
@@ -321,8 +333,25 @@ static int check_per_pkg(struct evsel *counter,
321
333
if (s < 0 )
322
334
return -1 ;
323
335
324
- * skip = test_and_set_bit (s , mask ) == 1 ;
325
- return 0 ;
336
+ /*
337
+ * On multi-die system, die_id > 0. On no-die system, die_id = 0.
338
+ * We use hashmap(socket, die) to check the used socket+die pair.
339
+ */
340
+ d = cpu_map__get_die (cpus , cpu , NULL ).die ;
341
+ if (d < 0 )
342
+ return -1 ;
343
+
344
+ key = malloc (sizeof (* key ));
345
+ if (!key )
346
+ return - ENOMEM ;
347
+
348
+ * key = (uint64_t )d << 32 | s ;
349
+ if (hashmap__find (mask , (void * )key , NULL ))
350
+ * skip = true;
351
+ else
352
+ ret = hashmap__add (mask , (void * )key , (void * )1 );
353
+
354
+ return ret ;
326
355
}
327
356
328
357
static int
@@ -422,7 +451,7 @@ int perf_stat_process_counter(struct perf_stat_config *config,
422
451
}
423
452
424
453
if (counter -> per_pkg )
425
- zero_per_pkg (counter );
454
+ evsel__zero_per_pkg (counter );
426
455
427
456
ret = process_counter_maps (config , counter );
428
457
if (ret )
0 commit comments