@@ -327,6 +327,37 @@ hwloc__type_match(const char *string,
327
327
return NULL ;
328
328
}
329
329
330
+ static int
331
+ hwloc__osdev_type_sscanf (const char * string , hwloc_obj_osdev_type_t * ostype )
332
+ {
333
+ if (hwloc__type_match (string , "storage" , 4 )
334
+ || hwloc__type_match (string , "block" , 4 )) { /* backward compat with v2.x */
335
+ * ostype = HWLOC_OBJ_OSDEV_STORAGE ;
336
+ return 1 ;
337
+ } else if (hwloc__type_match (string , "memory" , 3 )) {
338
+ * ostype = HWLOC_OBJ_OSDEV_MEMORY ;
339
+ return 1 ;
340
+ } else if (hwloc__type_match (string , "network" , 3 )) {
341
+ * ostype = HWLOC_OBJ_OSDEV_NETWORK ;
342
+ return 1 ;
343
+ } else if (hwloc__type_match (string , "ofed" , 4 )
344
+ || hwloc__type_match (string , "openfabrics" , 7 )) {
345
+ * ostype = HWLOC_OBJ_OSDEV_OPENFABRICS ;
346
+ return 1 ;
347
+ } else if (hwloc__type_match (string , "dma" , 3 )) {
348
+ * ostype = HWLOC_OBJ_OSDEV_DMA ;
349
+ return 1 ;
350
+ } else if (hwloc__type_match (string , "gpu" , 3 )) {
351
+ * ostype = HWLOC_OBJ_OSDEV_GPU ;
352
+ return 1 ;
353
+ } else if (hwloc__type_match (string , "coproc" , 5 )
354
+ || hwloc__type_match (string , "co-processor" , 6 )) {
355
+ * ostype = HWLOC_OBJ_OSDEV_COPROC ;
356
+ return 1 ;
357
+ }
358
+ return 0 ;
359
+ }
360
+
330
361
int
331
362
hwloc_type_sscanf (const char * string , hwloc_obj_type_t * typep ,
332
363
union hwloc_obj_attr_u * attrp , size_t attrsize )
@@ -344,32 +375,20 @@ hwloc_type_sscanf(const char *string, hwloc_obj_type_t *typep,
344
375
345
376
/* types without a custom depth */
346
377
347
- /* osdev subtype first to avoid conflicts coproc/core etc */
348
- if ( hwloc__type_match ( string , "osdev" , 2 )) {
378
+ if (! hwloc_strncasecmp ( string , " osdev[" , 6 )) {
379
+ /* proper "OSDev[type]" */
349
380
type = HWLOC_OBJ_OS_DEVICE ;
350
- } else if (hwloc__type_match (string , "storage" , 4 )
351
- || hwloc__type_match (string , "block" , 4 )) { /* backward compat with v2.x */
381
+ hwloc__osdev_type_sscanf (string + 6 , & ostype );
382
+ } else if (!hwloc_strncasecmp (string , "os[" , 3 )) {
383
+ /* shorter "OS[type]" */
352
384
type = HWLOC_OBJ_OS_DEVICE ;
353
- ostype = HWLOC_OBJ_OSDEV_STORAGE ;
354
- } else if (hwloc__type_match (string , "memory" , 3 )) {
355
- type = HWLOC_OBJ_OS_DEVICE ;
356
- ostype = HWLOC_OBJ_OSDEV_MEMORY ;
357
- } else if (hwloc__type_match (string , "network" , 3 )) {
385
+ hwloc__osdev_type_sscanf (string + 3 , & ostype );
386
+ } else if (hwloc__type_match (string , "osdev" , 2 )) {
387
+ /* basic "OSDev" without type */
358
388
type = HWLOC_OBJ_OS_DEVICE ;
359
- ostype = HWLOC_OBJ_OSDEV_NETWORK ;
360
- } else if (hwloc__type_match (string , "openfabrics" , 7 )) {
361
- type = HWLOC_OBJ_OS_DEVICE ;
362
- ostype = HWLOC_OBJ_OSDEV_OPENFABRICS ;
363
- } else if (hwloc__type_match (string , "dma" , 3 )) {
364
- type = HWLOC_OBJ_OS_DEVICE ;
365
- ostype = HWLOC_OBJ_OSDEV_DMA ;
366
- } else if (hwloc__type_match (string , "gpu" , 3 )) {
389
+ } else if (hwloc__osdev_type_sscanf (string , & ostype )) {
390
+ /* ugly osdev type without "osdev" prefix, parsed here to avoid conflicts coproc/core/etc below */
367
391
type = HWLOC_OBJ_OS_DEVICE ;
368
- ostype = HWLOC_OBJ_OSDEV_GPU ;
369
- } else if (hwloc__type_match (string , "coproc" , 5 )
370
- || hwloc__type_match (string , "co-processor" , 6 )) {
371
- type = HWLOC_OBJ_OS_DEVICE ;
372
- ostype = HWLOC_OBJ_OSDEV_COPROC ;
373
392
374
393
} else if (hwloc__type_match (string , "machine" , 2 )) {
375
394
type = HWLOC_OBJ_MACHINE ;
524
543
hwloc_obj_type_snprintf (char * __hwloc_restrict string , size_t size , hwloc_obj_t obj , unsigned long flags )
525
544
{
526
545
int longnames = (flags & (HWLOC_OBJ_SNPRINTF_FLAG_OLD_VERBOSE |HWLOC_OBJ_SNPRINTF_FLAG_LONG_NAMES ));
546
+ int shortnames = (flags & HWLOC_OBJ_SNPRINTF_FLAG_SHORT_NAMES );
527
547
hwloc_obj_type_t type = obj -> type ;
528
548
switch (type ) {
529
549
case HWLOC_OBJ_MISC :
@@ -558,21 +578,29 @@ hwloc_obj_type_snprintf(char * __hwloc_restrict string, size_t size, hwloc_obj_t
558
578
return hwloc_snprintf (string , size , obj -> attr -> bridge .upstream_type == HWLOC_OBJ_BRIDGE_PCI ? "PCIBridge" : "HostBridge" );
559
579
case HWLOC_OBJ_PCI_DEVICE :
560
580
return hwloc_snprintf (string , size , "PCI" );
561
- case HWLOC_OBJ_OS_DEVICE :
581
+ case HWLOC_OBJ_OS_DEVICE : {
582
+ const char * prefix = shortnames ? "" : longnames ? "OSDev" : "OS" ;
583
+ const char * middle ;
562
584
switch (obj -> attr -> osdev .type ) {
563
- case HWLOC_OBJ_OSDEV_STORAGE : return hwloc_snprintf ( string , size , "Storage" ) ;
564
- case HWLOC_OBJ_OSDEV_MEMORY : return hwloc_snprintf ( string , size , longnames ? "Memory" : "Mem" ) ;
565
- case HWLOC_OBJ_OSDEV_NETWORK : return hwloc_snprintf ( string , size , longnames ? "Network" : "Net" ) ;
566
- case HWLOC_OBJ_OSDEV_OPENFABRICS : return hwloc_snprintf ( string , size , "OpenFabrics" ) ;
567
- case HWLOC_OBJ_OSDEV_DMA : return hwloc_snprintf ( string , size , "DMA" ) ;
568
- case HWLOC_OBJ_OSDEV_GPU : return hwloc_snprintf ( string , size , "GPU" ) ;
569
- case HWLOC_OBJ_OSDEV_COPROC : return hwloc_snprintf ( string , size , longnames ? "Co-Processor" : "CoProc" ) ;
585
+ case HWLOC_OBJ_OSDEV_STORAGE : middle = "Storage" ; break ;
586
+ case HWLOC_OBJ_OSDEV_MEMORY : middle = longnames ? "Memory" : "Mem" ; break ;
587
+ case HWLOC_OBJ_OSDEV_NETWORK : middle = longnames ? "Network" : "Net" ; break ;
588
+ case HWLOC_OBJ_OSDEV_OPENFABRICS : middle = longnames ? "OpenFabrics" : "OFED" ; break ;
589
+ case HWLOC_OBJ_OSDEV_DMA : middle = "DMA" ; break ;
590
+ case HWLOC_OBJ_OSDEV_GPU : middle = "GPU" ; break ;
591
+ case HWLOC_OBJ_OSDEV_COPROC : middle = longnames ? "Co-Processor" : "CoProc" ; break ;
570
592
default :
571
- if (size > 0 )
572
- * string = '\0' ;
573
- return 0 ;
593
+ middle = NULL ;
574
594
}
575
- break ;
595
+ if (middle ) {
596
+ if (shortnames )
597
+ return hwloc_snprintf (string , size , "%s" , middle );
598
+ else
599
+ return hwloc_snprintf (string , size , "%s[%s]" , prefix , middle );
600
+ } else
601
+ return hwloc_snprintf (string , size , "%s" , prefix );
602
+ }
603
+ /* fallthrough */
576
604
default :
577
605
if (size > 0 )
578
606
* string = '\0' ;
0 commit comments