@@ -72,12 +72,10 @@ static int logicalo = 1;
72
72
static int nodeseti = 0 ;
73
73
static int nodeseto = 0 ;
74
74
static int objecto = 0 ;
75
- static int numberofdepth = -1 ;
76
- static union hwloc_obj_attr_u numberofattr ;
77
- static int intersectdepth = -1 ;
78
- static union hwloc_obj_attr_u intersectattr ;
79
- static int hiernblevels = 0 ;
80
- static int * hierdepth = NULL ;
75
+ static struct hwloc_calc_level numberof ;
76
+ static struct hwloc_calc_level intersect ;
77
+ static int hiernblevels ;
78
+ static struct hwloc_calc_level * hierlevels ;
81
79
static int local_numanodes = 0 ;
82
80
static unsigned long local_numanode_flags = HWLOC_LOCAL_NUMANODE_FLAG_SMALLER_LOCALITY | HWLOC_LOCAL_NUMANODE_FLAG_LARGER_LOCALITY ;
83
81
static hwloc_memattr_id_t best_memattr_id = (hwloc_memattr_id_t ) - 1 ;
@@ -119,12 +117,14 @@ hwloc_calc_hierarch_output(hwloc_topology_t topology, const char *prefix, const
119
117
hwloc_obj_t obj , prev = NULL ;
120
118
unsigned logi = 0 ;
121
119
int first = 1 ;
122
- while ((obj = hwloc_get_next_obj_covering_cpuset_by_depth (topology , root -> cpuset , hierdepth [level ], prev )) != NULL ) {
120
+ while ((obj = hwloc_get_next_obj_covering_cpuset_by_depth (topology , root -> cpuset , hierlevels [level ]. depth , prev )) != NULL ) {
123
121
char string [256 ];
124
122
char type [32 ];
125
123
unsigned idx = logicalo ? logi : obj -> os_index ;
126
124
if (!hwloc_bitmap_intersects (set , obj -> cpuset ))
127
125
goto next ;
126
+ if (hwloc_calc_check_object_filtered (obj , & hierlevels [level ]))
127
+ goto next ;
128
128
hwloc_obj_type_snprintf (type , sizeof (type ), obj , HWLOC_OBJ_SNPRINTF_FLAG_LONG_NAMES );
129
129
if (idx == (unsigned )-1 )
130
130
snprintf (string , sizeof (string ), "%s%s%s:-1" , prefix , level ? "." : "" , type );
@@ -190,25 +190,23 @@ hwloc_calc_output(hwloc_topology_t topology, const char *sep, hwloc_bitmap_t set
190
190
}
191
191
printf ("\n" );
192
192
hwloc_bitmap_free (remaining );
193
- } else if (numberofdepth != -1 ) {
193
+ } else if (numberof . depth != -1 ) {
194
194
unsigned nb = 0 ;
195
195
hwloc_obj_t obj = NULL ;
196
- while ((obj = hwloc_calc_get_next_obj_covering_set_by_depth (topology , set , nodeseto , numberofdepth , obj )) != NULL ) {
197
- if (numberofdepth == HWLOC_TYPE_DEPTH_OS_DEVICE
198
- && (obj -> attr -> osdev .type & numberofattr .osdev .type ) != numberofattr .osdev .type )
196
+ while ((obj = hwloc_calc_get_next_obj_covering_set_by_depth (topology , set , nodeseto , numberof .depth , obj )) != NULL ) {
197
+ if (hwloc_calc_check_object_filtered (obj , & numberof ))
199
198
continue ;
200
199
nb ++ ;
201
200
}
202
201
printf ("%u\n" , nb );
203
- } else if (intersectdepth != -1 ) {
202
+ } else if (intersect . depth != -1 ) {
204
203
hwloc_obj_t obj = NULL ;
205
204
int first = 1 ;
206
205
if (!sep )
207
206
sep = "," ;
208
- while ((obj = hwloc_calc_get_next_obj_covering_set_by_depth (topology , set , nodeseto , intersectdepth , obj )) != NULL ) {
207
+ while ((obj = hwloc_calc_get_next_obj_covering_set_by_depth (topology , set , nodeseto , intersect . depth , obj )) != NULL ) {
209
208
unsigned idx ;
210
- if (intersectdepth == HWLOC_TYPE_DEPTH_OS_DEVICE
211
- && (obj -> attr -> osdev .type & intersectattr .osdev .type ) != intersectattr .osdev .type )
209
+ if (hwloc_calc_check_object_filtered (obj , & intersect ))
212
210
continue ;
213
211
if (!first )
214
212
printf ("%s" , sep );
@@ -288,41 +286,6 @@ hwloc_calc_output(hwloc_topology_t topology, const char *sep, hwloc_bitmap_t set
288
286
return EXIT_SUCCESS ;
289
287
}
290
288
291
- static int hwloc_calc_type_depth (hwloc_topology_t topology , const char * string , int * depthp , union hwloc_obj_attr_u * attrp , const char * caller )
292
- {
293
- union hwloc_obj_attr_u attr ;
294
- hwloc_obj_type_t type ;
295
- int depth ;
296
- int err ;
297
-
298
- err = hwloc_type_sscanf (string , & type , & attr , sizeof (attr ));
299
- if (err < 0 ) {
300
- char * endptr ;
301
- depth = strtoul (string , & endptr , 0 );
302
- if (* endptr ) {
303
- fprintf (stderr , "unrecognized %s type or depth %s\n" , caller , string );
304
- return -1 ;
305
- }
306
-
307
- * depthp = depth ;
308
- return 0 ;
309
- }
310
-
311
- depth = hwloc_get_type_depth_with_attr (topology , type , & attr , sizeof (attr ));
312
- if (depth == HWLOC_TYPE_DEPTH_UNKNOWN ) {
313
- fprintf (stderr , "unavailable %s type %s\n" , caller , hwloc_obj_type_string (type ));
314
- return -1 ;
315
- } else if (depth == HWLOC_TYPE_DEPTH_MULTIPLE ) {
316
- fprintf (stderr , "cannot use %s type %s with multiple depth, please use the relevant depth\n" , caller , hwloc_obj_type_string (type ));
317
- return -1 ;
318
- }
319
-
320
- if (attrp )
321
- memcpy (attrp , & attr , sizeof (attr ));
322
- * depthp = depth ;
323
- return 0 ;
324
- }
325
-
326
289
int main (int argc , char * argv [])
327
290
{
328
291
hwloc_topology_t topology ;
@@ -333,10 +296,10 @@ int main(int argc, char *argv[])
333
296
int depth = 0 ;
334
297
hwloc_bitmap_t set ;
335
298
int cmdline_args = 0 ;
336
- const char * numberoftype = NULL ;
337
- const char * intersecttype = NULL ;
299
+ const char * numberof_string = NULL ;
300
+ const char * intersect_string = NULL ;
338
301
char * restrictstring = NULL ;
339
- char * hiertype = NULL ;
302
+ char * hier_string = NULL ;
340
303
char * best_memattr_str = NULL ;
341
304
char * callname ;
342
305
char * outsep = NULL ;
@@ -520,7 +483,7 @@ int main(int argc, char *argv[])
520
483
usage (callname , stderr );
521
484
return EXIT_FAILURE ;
522
485
}
523
- numberoftype = argv [1 ];
486
+ numberof_string = argv [1 ];
524
487
opt = 1 ;
525
488
goto next ;
526
489
}
@@ -529,7 +492,7 @@ int main(int argc, char *argv[])
529
492
usage (callname , stderr );
530
493
return EXIT_FAILURE ;
531
494
}
532
- intersecttype = argv [1 ];
495
+ intersect_string = argv [1 ];
533
496
opt = 1 ;
534
497
goto next ;
535
498
}
@@ -538,7 +501,7 @@ int main(int argc, char *argv[])
538
501
usage (callname , stderr );
539
502
return EXIT_FAILURE ;
540
503
}
541
- hiertype = argv [1 ];
504
+ hier_string = argv [1 ];
542
505
opt = 1 ;
543
506
goto next ;
544
507
}
@@ -663,32 +626,57 @@ int main(int argc, char *argv[])
663
626
argv += opt + 1 ;
664
627
}
665
628
666
- if (numberoftype && hwloc_calc_type_depth (topology , numberoftype , & numberofdepth , & numberofattr , "--number-of" ) < 0 )
629
+ numberof .depth = HWLOC_TYPE_DEPTH_UNKNOWN ; /* disable this feature by default */
630
+ if (numberof_string && hwloc_calc_parse_level (NULL , topology , numberof_string , strlen (numberof_string ), & numberof ) < 0 ) {
631
+ if (numberof .depth == HWLOC_TYPE_DEPTH_MULTIPLE )
632
+ fprintf (stderr , "cannot use --number-of type %s with multiple depth, please use the relevant depth\n" ,
633
+ numberof_string );
634
+ else if (numberof .depth == HWLOC_TYPE_DEPTH_UNKNOWN )
635
+ fprintf (stderr , "cannot use --number-of type %s, unavailable\n" ,
636
+ numberof_string );
667
637
goto out ;
638
+ }
668
639
669
- if (intersecttype && hwloc_calc_type_depth (topology , intersecttype , & intersectdepth , & intersectattr , "--intersect" ) < 0 )
640
+ intersect .depth = HWLOC_TYPE_DEPTH_UNKNOWN ; /* disable this feature by default */
641
+ if (intersect_string && hwloc_calc_parse_level (NULL , topology , intersect_string , strlen (intersect_string ), & intersect ) < 0 ) {
642
+ if (intersect .depth == HWLOC_TYPE_DEPTH_MULTIPLE )
643
+ fprintf (stderr , "cannot use --intersect type %s with multiple depth, please use the relevant depth\n" ,
644
+ intersect_string );
645
+ else if (intersect .depth == HWLOC_TYPE_DEPTH_UNKNOWN )
646
+ fprintf (stderr , "cannot use --intersect type %s, unavailable\n" ,
647
+ intersect_string );
670
648
goto out ;
649
+ }
671
650
672
- if (hiertype ) {
651
+ hiernblevels = 0 ; /* disable this feature by default */
652
+ hierlevels = NULL ;
653
+ if (hier_string ) {
673
654
char * tmp , * next ;
674
655
hiernblevels = 1 ;
675
- tmp = hiertype ;
656
+ tmp = hier_string ;
676
657
while (1 ) {
677
658
tmp = strchr (tmp , '.' );
678
659
if (!tmp )
679
660
break ;
680
661
tmp ++ ;
681
662
hiernblevels ++ ;
682
663
}
683
- hierdepth = malloc (hiernblevels * sizeof (int ));
684
- tmp = hiertype ;
664
+ hierlevels = malloc (hiernblevels * sizeof (struct hwloc_calc_level ));
665
+ tmp = hier_string ;
685
666
for (i = 0 ; i < hiernblevels ; i ++ ) {
686
667
next = strchr (tmp , '.' );
687
668
if (next )
688
669
* next = '\0' ;
689
- if (hwloc_calc_type_depth (topology , tmp , & hierdepth [i ], NULL , "--hierarchical" ) < 0 )
670
+ if (hwloc_calc_parse_level (NULL , topology , tmp , strlen (tmp ), & hierlevels [i ]) < 0 ) {
671
+ if (hierlevels [i ].depth == HWLOC_TYPE_DEPTH_MULTIPLE )
672
+ fprintf (stderr , "cannot use --hierarchical %s with multiple depth, please use the relevant depth\n" ,
673
+ tmp );
674
+ else if (hierlevels [i ].depth == HWLOC_TYPE_DEPTH_UNKNOWN )
675
+ fprintf (stderr , "cannot use --hierarchical type %s, unavailable\n" ,
676
+ tmp );
690
677
goto out ;
691
- if (hierdepth [i ] < 0 && hierdepth [i ] != HWLOC_TYPE_DEPTH_NUMANODE ) {
678
+ }
679
+ if (hierlevels [i ].depth < 0 && hierlevels [i ].depth != HWLOC_TYPE_DEPTH_NUMANODE ) {
692
680
fprintf (stderr , "unsupported (non-normal) --hierarchical type %s\n" , tmp );
693
681
goto out ;
694
682
}
@@ -768,7 +756,7 @@ int main(int argc, char *argv[])
768
756
hwloc_bitmap_free (set );
769
757
hwloc_bitmap_free (cpukind_cpuset );
770
758
771
- free (hierdepth );
759
+ free (hierlevels );
772
760
773
761
return ret ;
774
762
}
0 commit comments