@@ -192,60 +192,6 @@ hwloc_calc_parse_level(struct hwloc_calc_location_context_s *lcontext,
192
192
return 0 ;
193
193
}
194
194
195
- static __hwloc_inline int
196
- hwloc_calc_parse_depth_prefix (struct hwloc_calc_location_context_s * lcontext ,
197
- const char * string , size_t typelen ,
198
- hwloc_obj_type_t * typep )
199
- {
200
- hwloc_topology_t topology = lcontext -> topology ;
201
- int topodepth = lcontext -> topodepth ;
202
- int verbose = lcontext -> verbose ;
203
- char typestring [20 + 1 ]; /* large enough to store all type names, even with a depth attribute */
204
- hwloc_obj_type_t type ;
205
- union hwloc_obj_attr_u attr ;
206
- int depth ;
207
- char * end ;
208
- int err ;
209
-
210
- if (typelen >= sizeof (typestring )) {
211
- if (verbose >= 0 )
212
- fprintf (stderr , "invalid type name %s\n" , string );
213
- return -1 ;
214
- }
215
- strncpy (typestring , string , typelen );
216
- typestring [typelen ] = '\0' ;
217
-
218
- /* try to match a type name */
219
- err = hwloc_type_sscanf (typestring , & type , & attr , sizeof (attr ));
220
- if (!err ) {
221
- * typep = type ;
222
- return hwloc_get_type_depth_with_attr (topology , type , & attr , sizeof (attr ));
223
- }
224
-
225
- if (!strcasecmp (typestring , "HBM" ) || !strcasecmp (typestring , "MCDRAM" )) {
226
- if (lcontext -> only_hbm == -1 )
227
- lcontext -> only_hbm = 1 ;
228
- * typep = HWLOC_OBJ_NUMANODE ;
229
- depth = HWLOC_TYPE_DEPTH_NUMANODE ;
230
- return depth ;
231
- }
232
-
233
- /* try to match a numeric depth */
234
- depth = strtol (string , & end , 0 );
235
- if (end != & string [typelen ]) {
236
- if (verbose >= 0 )
237
- fprintf (stderr , "invalid type name %s\n" , string );
238
- return -1 ;
239
- }
240
- if (depth >= topodepth ) {
241
- if (verbose >= 0 )
242
- fprintf (stderr , "ignoring invalid depth %d\n" , depth );
243
- return -1 ;
244
- }
245
- * typep = HWLOC_OBJ_TYPE_NONE ;
246
- return depth ;
247
- }
248
-
249
195
static __hwloc_inline int
250
196
hwloc_calc_parse_range (const char * _string ,
251
197
int * firstp , int * amountp , int * stepp , int * wrapp ,
@@ -351,6 +297,7 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
351
297
void (* cbfunc )(struct hwloc_calc_location_context_s * , void * , hwloc_obj_t ), void * cbdata )
352
298
{
353
299
int verbose = lcontext -> verbose ;
300
+ hwloc_topology_t topology = lcontext -> topology ;
354
301
hwloc_obj_t obj ;
355
302
unsigned width ;
356
303
const char * dot , * nextsep = NULL ;
@@ -374,7 +321,7 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
374
321
if (dot ) {
375
322
/* parse the next string before calling ourself recursively */
376
323
size_t typelen ;
377
- hwloc_obj_type_t type ;
324
+ struct hwloc_calc_level level ;
378
325
const char * nextstring = dot + 1 ;
379
326
typelen = strspn (nextstring , "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" );
380
327
if (!typelen || nextstring [typelen ] != ':' ) {
@@ -384,19 +331,21 @@ hwloc_calc_append_object_range(struct hwloc_calc_location_context_s *lcontext,
384
331
}
385
332
nextsep = & nextstring [typelen ];
386
333
387
- nextdepth = hwloc_calc_parse_depth_prefix (lcontext ,
388
- nextstring , typelen ,
389
- & type );
390
- if (nextdepth == HWLOC_TYPE_DEPTH_UNKNOWN ) {
391
- if ( verbose >= 0 )
392
- fprintf ( stderr , "could not find level specified by location %s\n" , nextstring ) ;
393
- return -1 ;
394
- }
395
- if (nextdepth == HWLOC_TYPE_DEPTH_MULTIPLE ) {
396
- if ( verbose >= 0 )
397
- fprintf ( stderr , "found multiple levels for location %s\n" , nextstring ) ;
398
- return -1 ;
334
+ err = hwloc_calc_parse_level (lcontext , topology , nextstring , typelen , & level );
335
+ if ( err < 0 ) {
336
+ if ( level . depth == HWLOC_TYPE_DEPTH_UNKNOWN ) {
337
+ if (verbose >= 0 )
338
+ fprintf ( stderr , "could not find level specified by location %s\n" , nextstring );
339
+ return -1 ;
340
+ }
341
+ if ( level . depth == HWLOC_TYPE_DEPTH_MULTIPLE ) {
342
+ if (verbose >= 0 )
343
+ fprintf ( stderr , "found multiple levels for location %s\n" , nextstring );
344
+ return -1 ;
345
+ }
399
346
}
347
+ nextdepth = level .depth ;
348
+
400
349
/* we need an object with a cpuset, that's depth>=0 or memory */
401
350
if (nextdepth < 0 && nextdepth != HWLOC_TYPE_DEPTH_NUMANODE ) {
402
351
if (verbose >= 0 )
@@ -615,33 +564,33 @@ hwloc_calc_process_location(struct hwloc_calc_location_context_s *lcontext,
615
564
hwloc_topology_t topology = lcontext -> topology ;
616
565
int verbose = lcontext -> verbose ;
617
566
const char * sep = & arg [typelen ];
618
- hwloc_obj_type_t type = HWLOC_OBJ_TYPE_NONE ;
619
- int depth ;
567
+ struct hwloc_calc_level level ;
568
+ int err ;
620
569
621
- depth = hwloc_calc_parse_depth_prefix (lcontext ,
622
- arg , typelen ,
623
- & type );
624
- if (depth == HWLOC_TYPE_DEPTH_UNKNOWN ) {
625
- if ( verbose >= 0 )
626
- fprintf ( stderr , "could not find level specified by location %s\n" , arg ) ;
627
- return -1 ;
628
- }
629
- if (depth == HWLOC_TYPE_DEPTH_MULTIPLE ) {
630
- if ( verbose >= 0 )
631
- fprintf ( stderr , "found multiple levels for location %s\n" , arg ) ;
632
- return -1 ;
570
+ err = hwloc_calc_parse_level (lcontext , topology , arg , typelen , & level );
571
+ if ( err < 0 ) {
572
+ if ( level . depth == HWLOC_TYPE_DEPTH_UNKNOWN ) {
573
+ if (verbose >= 0 )
574
+ fprintf ( stderr , "could not find level specified by location %s\n" , arg );
575
+ return -1 ;
576
+ }
577
+ if ( level . depth == HWLOC_TYPE_DEPTH_MULTIPLE ) {
578
+ if (verbose >= 0 )
579
+ fprintf ( stderr , "found multiple levels for location %s\n" , arg );
580
+ return -1 ;
581
+ }
633
582
}
634
583
635
- if (depth < 0 && depth != HWLOC_TYPE_DEPTH_NUMANODE ) {
584
+ if (level . depth < 0 && level . depth != HWLOC_TYPE_DEPTH_NUMANODE ) {
636
585
/* special object without cpusets */
637
586
638
587
/* if we didn't find a depth but found a type, handle special cases */
639
588
hwloc_obj_t obj = NULL ;
640
589
641
590
if (* sep == ':' || * sep == '[' ) {
642
- return hwloc_calc_append_iodev_by_index (lcontext , type , depth , sep , cbfunc , cbdata );
591
+ return hwloc_calc_append_iodev_by_index (lcontext , level . type , level . depth , sep , cbfunc , cbdata );
643
592
644
- } else if (* sep == '=' && type == HWLOC_OBJ_PCI_DEVICE ) {
593
+ } else if (* sep == '=' && level . type == HWLOC_OBJ_PCI_DEVICE ) {
645
594
/* try to match a busid */
646
595
obj = hwloc_get_pcidev_by_busidstring (topology , sep + 1 );
647
596
if (obj )
@@ -650,7 +599,7 @@ hwloc_calc_process_location(struct hwloc_calc_location_context_s *lcontext,
650
599
fprintf (stderr , "invalid PCI device %s\n" , sep + 1 );
651
600
return -1 ;
652
601
653
- } else if (* sep == '=' && type == HWLOC_OBJ_OS_DEVICE ) {
602
+ } else if (* sep == '=' && level . type == HWLOC_OBJ_OS_DEVICE ) {
654
603
/* try to match a OS device name */
655
604
while ((obj = hwloc_get_next_osdev (topology , obj )) != NULL ) {
656
605
if (!strcmp (obj -> name , sep + 1 ))
@@ -660,7 +609,7 @@ hwloc_calc_process_location(struct hwloc_calc_location_context_s *lcontext,
660
609
fprintf (stderr , "invalid OS device %s\n" , sep + 1 );
661
610
return -1 ;
662
611
663
- } else if (* sep == '=' && type == HWLOC_OBJ_MISC ) {
612
+ } else if (* sep == '=' && level . type == HWLOC_OBJ_MISC ) {
664
613
/* try to match a Misc device name */
665
614
obj = hwloc_get_obj_by_type (topology , HWLOC_OBJ_MISC , 0 );
666
615
while (obj ) {
@@ -680,7 +629,7 @@ hwloc_calc_process_location(struct hwloc_calc_location_context_s *lcontext,
680
629
return hwloc_calc_append_object_range (lcontext ,
681
630
hwloc_topology_get_complete_cpuset (topology ),
682
631
hwloc_topology_get_complete_nodeset (topology ),
683
- depth , sep + 1 , cbfunc , cbdata );
632
+ level . depth , sep + 1 , cbfunc , cbdata );
684
633
}
685
634
686
635
struct hwloc_calc_set_context_s {
0 commit comments