@@ -216,12 +216,21 @@ struct pkg_data {
216
216
#define ODD_COUNTERS thread_odd, core_odd, package_odd
217
217
#define EVEN_COUNTERS thread_even, core_even, package_even
218
218
219
- #define GET_THREAD (thread_base , thread_no , core_no , pkg_no ) \
220
- (thread_base + (pkg_no) * topo.cores_per_node * \
221
- topo.threads_per_core + \
222
- (core_no) * topo.threads_per_core + (thread_no))
223
- #define GET_CORE (core_base , core_no , pkg_no ) \
224
- (core_base + (pkg_no) * topo.cores_per_node + (core_no))
219
+ #define GET_THREAD (thread_base , thread_no , core_no , node_no , pkg_no ) \
220
+ ((thread_base) + \
221
+ ((pkg_no) * \
222
+ topo.nodes_per_pkg * topo.cores_per_node * topo.threads_per_core) + \
223
+ ((node_no) * topo.cores_per_node * topo.threads_per_core) + \
224
+ ((core_no) * topo.threads_per_core) + \
225
+ (thread_no))
226
+
227
+ #define GET_CORE (core_base , core_no , node_no , pkg_no ) \
228
+ ((core_base) + \
229
+ ((pkg_no) * topo.nodes_per_pkg * topo.cores_per_node) + \
230
+ ((node_no) * topo.cores_per_node) + \
231
+ (core_no))
232
+
233
+
225
234
#define GET_PKG (pkg_base , pkg_no ) (pkg_base + pkg_no)
226
235
227
236
enum counter_scope {SCOPE_CPU , SCOPE_CORE , SCOPE_PACKAGE };
@@ -297,27 +306,33 @@ int cpu_is_not_present(int cpu)
297
306
int for_all_cpus (int (func )(struct thread_data * , struct core_data * , struct pkg_data * ),
298
307
struct thread_data * thread_base , struct core_data * core_base , struct pkg_data * pkg_base )
299
308
{
300
- int retval , pkg_no , core_no , thread_no ;
309
+ int retval , pkg_no , core_no , thread_no , node_no ;
301
310
302
311
for (pkg_no = 0 ; pkg_no < topo .num_packages ; ++ pkg_no ) {
303
312
for (core_no = 0 ; core_no < topo .cores_per_node ; ++ core_no ) {
304
- for (thread_no = 0 ; thread_no <
305
- topo .threads_per_core ; ++ thread_no ) {
306
- struct thread_data * t ;
307
- struct core_data * c ;
308
- struct pkg_data * p ;
309
-
310
- t = GET_THREAD (thread_base , thread_no , core_no , pkg_no );
311
-
312
- if (cpu_is_not_present (t -> cpu_id ))
313
- continue ;
314
-
315
- c = GET_CORE (core_base , core_no , pkg_no );
316
- p = GET_PKG (pkg_base , pkg_no );
317
-
318
- retval = func (t , c , p );
319
- if (retval )
320
- return retval ;
313
+ for (node_no = 0 ; node_no < topo .nodes_per_pkg ;
314
+ node_no ++ ) {
315
+ for (thread_no = 0 ; thread_no <
316
+ topo .threads_per_core ; ++ thread_no ) {
317
+ struct thread_data * t ;
318
+ struct core_data * c ;
319
+ struct pkg_data * p ;
320
+
321
+ t = GET_THREAD (thread_base , thread_no ,
322
+ core_no , node_no ,
323
+ pkg_no );
324
+
325
+ if (cpu_is_not_present (t -> cpu_id ))
326
+ continue ;
327
+
328
+ c = GET_CORE (core_base , core_no ,
329
+ node_no , pkg_no );
330
+ p = GET_PKG (pkg_base , pkg_no );
331
+
332
+ retval = func (t , c , p );
333
+ if (retval )
334
+ return retval ;
335
+ }
321
336
}
322
337
}
323
338
}
@@ -2488,32 +2503,42 @@ int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *,
2488
2503
struct thread_data * thread_base2 , struct core_data * core_base2 ,
2489
2504
struct pkg_data * pkg_base2 )
2490
2505
{
2491
- int retval , pkg_no , core_no , thread_no ;
2506
+ int retval , pkg_no , node_no , core_no , thread_no ;
2492
2507
2493
2508
for (pkg_no = 0 ; pkg_no < topo .num_packages ; ++ pkg_no ) {
2494
- for (core_no = 0 ; core_no < topo .cores_per_node ; ++ core_no ) {
2495
- for (thread_no = 0 ; thread_no <
2496
- topo .threads_per_core ; ++ thread_no ) {
2497
- struct thread_data * t , * t2 ;
2498
- struct core_data * c , * c2 ;
2499
- struct pkg_data * p , * p2 ;
2500
-
2501
- t = GET_THREAD (thread_base , thread_no , core_no , pkg_no );
2502
-
2503
- if (cpu_is_not_present (t -> cpu_id ))
2504
- continue ;
2505
-
2506
- t2 = GET_THREAD (thread_base2 , thread_no , core_no , pkg_no );
2507
-
2508
- c = GET_CORE (core_base , core_no , pkg_no );
2509
- c2 = GET_CORE (core_base2 , core_no , pkg_no );
2510
-
2511
- p = GET_PKG (pkg_base , pkg_no );
2512
- p2 = GET_PKG (pkg_base2 , pkg_no );
2513
-
2514
- retval = func (t , c , p , t2 , c2 , p2 );
2515
- if (retval )
2516
- return retval ;
2509
+ for (node_no = 0 ; node_no < topo .nodes_per_pkg ; ++ node_no ) {
2510
+ for (core_no = 0 ; core_no < topo .cores_per_node ;
2511
+ ++ core_no ) {
2512
+ for (thread_no = 0 ; thread_no <
2513
+ topo .threads_per_core ; ++ thread_no ) {
2514
+ struct thread_data * t , * t2 ;
2515
+ struct core_data * c , * c2 ;
2516
+ struct pkg_data * p , * p2 ;
2517
+
2518
+ t = GET_THREAD (thread_base , thread_no ,
2519
+ core_no , node_no ,
2520
+ pkg_no );
2521
+
2522
+ if (cpu_is_not_present (t -> cpu_id ))
2523
+ continue ;
2524
+
2525
+ t2 = GET_THREAD (thread_base2 , thread_no ,
2526
+ core_no , node_no ,
2527
+ pkg_no );
2528
+
2529
+ c = GET_CORE (core_base , core_no ,
2530
+ node_no , pkg_no );
2531
+ c2 = GET_CORE (core_base2 , core_no ,
2532
+ node_no ,
2533
+ pkg_no );
2534
+
2535
+ p = GET_PKG (pkg_base , pkg_no );
2536
+ p2 = GET_PKG (pkg_base2 , pkg_no );
2537
+
2538
+ retval = func (t , c , p , t2 , c2 , p2 );
2539
+ if (retval )
2540
+ return retval ;
2541
+ }
2517
2542
}
2518
2543
}
2519
2544
}
@@ -4752,25 +4777,26 @@ void topology_probe()
4752
4777
}
4753
4778
4754
4779
void
4755
- allocate_counters (struct thread_data * * t , struct core_data * * c , struct pkg_data * * p )
4780
+ allocate_counters (struct thread_data * * t , struct core_data * * c ,
4781
+ struct pkg_data * * p )
4756
4782
{
4757
4783
int i ;
4784
+ int num_cores = topo .cores_per_node * topo .nodes_per_pkg *
4785
+ topo .num_packages ;
4786
+ int num_threads = topo .threads_per_core * num_cores ;
4758
4787
4759
- * t = calloc (topo .threads_per_core * topo .cores_per_node *
4760
- topo .num_packages , sizeof (struct thread_data ));
4788
+ * t = calloc (num_threads , sizeof (struct thread_data ));
4761
4789
if (* t == NULL )
4762
4790
goto error ;
4763
4791
4764
- for (i = 0 ; i < topo .threads_per_core *
4765
- topo .cores_per_node * topo .num_packages ; i ++ )
4792
+ for (i = 0 ; i < num_threads ; i ++ )
4766
4793
(* t )[i ].cpu_id = -1 ;
4767
4794
4768
- * c = calloc (topo .cores_per_node * topo .num_packages ,
4769
- sizeof (struct core_data ));
4795
+ * c = calloc (num_cores , sizeof (struct core_data ));
4770
4796
if (* c == NULL )
4771
4797
goto error ;
4772
4798
4773
- for (i = 0 ; i < topo . cores_per_node * topo . num_packages ; i ++ )
4799
+ for (i = 0 ; i < num_cores ; i ++ )
4774
4800
(* c )[i ].core_id = -1 ;
4775
4801
4776
4802
* p = calloc (topo .num_packages , sizeof (struct pkg_data ));
@@ -4793,14 +4819,15 @@ void init_counter(struct thread_data *thread_base, struct core_data *core_base,
4793
4819
struct pkg_data * pkg_base , int cpu_id )
4794
4820
{
4795
4821
int pkg_id = cpus [cpu_id ].physical_package_id ;
4822
+ int node_id = cpus [cpu_id ].logical_node_id ;
4796
4823
int core_id = cpus [cpu_id ].physical_core_id ;
4797
4824
int thread_id = cpus [cpu_id ].thread_id ;
4798
4825
struct thread_data * t ;
4799
4826
struct core_data * c ;
4800
4827
struct pkg_data * p ;
4801
4828
4802
- t = GET_THREAD (thread_base , thread_id , core_id , pkg_id );
4803
- c = GET_CORE (core_base , core_id , pkg_id );
4829
+ t = GET_THREAD (thread_base , thread_id , core_id , node_id , pkg_id );
4830
+ c = GET_CORE (core_base , core_id , node_id , pkg_id );
4804
4831
p = GET_PKG (pkg_base , pkg_id );
4805
4832
4806
4833
t -> cpu_id = cpu_id ;
0 commit comments