@@ -154,6 +154,77 @@ static void add_process_objects(hwloc_topology_t topology)
154
154
HWLOC_PS_FLAG_THREADS | HWLOC_PS_FLAG_SHORTNAME , NULL , HWLOC_PS_ALL_UIDS );
155
155
}
156
156
157
+ static void add_one_misc_object_from (hwloc_topology_t topology ,
158
+ char * subtype , char * name , hwloc_bitmap_t cpuset )
159
+ {
160
+ if (!hwloc_bitmap_iszero (cpuset ) && subtype && name ) {
161
+ insert_misc (topology , cpuset , subtype , name );
162
+ } else {
163
+ char * s ;
164
+ hwloc_bitmap_asprintf (& s , cpuset );
165
+ fprintf (stderr , "Ignoring misc object subtype %s name %s cpuset %s\n" , subtype , name , s );
166
+ free (s );
167
+ }
168
+ }
169
+
170
+ /* reads Misc description from the FILE*
171
+ * entries must look like:
172
+ * name=... (must be first)
173
+ * cpuset=... (cannot be 0)
174
+ * subtype=... (optional)
175
+ */
176
+ static void add_misc_objects_from (hwloc_topology_t topology , FILE * from )
177
+ {
178
+ char line [256 ];
179
+ hwloc_bitmap_t cpuset ;
180
+ char * subtype = NULL ;
181
+ char * name = NULL ;
182
+ cpuset = hwloc_bitmap_alloc ();
183
+ if (!cpuset )
184
+ return ;
185
+
186
+ while (fgets (line , sizeof line , from )) {
187
+ char * end ;
188
+
189
+ /* remove ending \n */
190
+ end = strchr (line , '\n' );
191
+ if (end )
192
+ * end = '\0' ;
193
+ /* ignoring empty lines */
194
+ if (line [0 ] == '\0' )
195
+ continue ;
196
+
197
+ if (!strncmp (line , "name=" , 5 )) {
198
+ /* commit (or ignore) the previous entry */
199
+ if (name )
200
+ add_one_misc_object_from (topology , subtype , name , cpuset );
201
+ /* start a new entry */
202
+ free (subtype );
203
+ subtype = NULL ;
204
+ free (name );
205
+ name = strdup (line + 5 );
206
+ hwloc_bitmap_zero (cpuset );
207
+
208
+ } else if (!strncmp (line , "cpuset=" , 7 )) {
209
+ hwloc_bitmap_sscanf (cpuset , line + 7 );
210
+
211
+ } else if (!strncmp (line , "subtype=" , 8 )) {
212
+ free (subtype );
213
+ subtype = strdup (line + 8 );
214
+
215
+ } else {
216
+ fprintf (stderr , "Unrecognized --misc-from line `%s', ignored\n" , line );
217
+ }
218
+ }
219
+
220
+ /* commit (or ignore) the last entry */
221
+ if (name )
222
+ add_one_misc_object_from (topology , subtype , name , cpuset );
223
+ free (name );
224
+ free (subtype );
225
+ hwloc_bitmap_free (cpuset );
226
+ }
227
+
157
228
static __hwloc_inline void lstopo_update_factorize_bounds (unsigned min , unsigned * first , unsigned * last )
158
229
{
159
230
switch (min ) {
@@ -577,6 +648,7 @@ void usage(const char *name, FILE *where)
577
648
" Set flags during the synthetic topology export\n" );
578
649
/* --shmem-output-addr is undocumented on purpose */
579
650
fprintf (where , " --ps --top Display processes within the hierarchy\n" );
651
+ fprintf (where , " --misc-from <file> Create Misc objects as defined in <file>" );
580
652
fprintf (where , " --version Report version and exit\n" );
581
653
fprintf (where , " -h --help Show this usage\n" );
582
654
}
@@ -838,6 +910,7 @@ main (int argc, char *argv[])
838
910
#endif
839
911
char * env ;
840
912
int top = 0 ;
913
+ FILE * miscfrom = NULL ;
841
914
int opt ;
842
915
unsigned i ;
843
916
@@ -1472,7 +1545,19 @@ main (int argc, char *argv[])
1472
1545
loutput .pid_number = atoi (argv [1 ]); opt = 1 ;
1473
1546
} else if (!strcmp (argv [0 ], "--ps" ) || !strcmp (argv [0 ], "--top" ))
1474
1547
top = 1 ;
1475
- else if (!strcmp (argv [0 ], "--version" )) {
1548
+ else if (!strcmp (argv [0 ], "--misc-from" )) {
1549
+ if (argc < 2 )
1550
+ goto out_usagefailure ;
1551
+ if (!strcmp (argv [1 ], "-" ))
1552
+ miscfrom = stdin ;
1553
+ else
1554
+ miscfrom = fopen (argv [1 ], "r" );
1555
+ if (!miscfrom ) {
1556
+ fprintf (stderr , "Failed open --misc-from %s file for reading (%s)\n" , argv [1 ], strerror (errno ));
1557
+ exit (EXIT_FAILURE );
1558
+ }
1559
+ opt = 1 ;
1560
+ } else if (!strcmp (argv [0 ], "--version" )) {
1476
1561
printf ("%s %s\n" , callname , HWLOC_VERSION );
1477
1562
exit (EXIT_SUCCESS );
1478
1563
} else if (!strcmp (argv [0 ], "--output-format" ) || !strcmp (argv [0 ], "--of" )) {
@@ -1815,6 +1900,8 @@ main (int argc, char *argv[])
1815
1900
1816
1901
if (top )
1817
1902
add_process_objects (topology );
1903
+ if (miscfrom )
1904
+ add_misc_objects_from (topology , miscfrom );
1818
1905
1819
1906
if (restrictstring ) {
1820
1907
hwloc_bitmap_t restrictset = hwloc_bitmap_alloc ();
@@ -1900,5 +1987,7 @@ main (int argc, char *argv[])
1900
1987
hwloc_bitmap_free (allow_nodeset );
1901
1988
hwloc_bitmap_free (loutput .cpubind_set );
1902
1989
hwloc_bitmap_free (loutput .membind_set );
1990
+ if (miscfrom && miscfrom != stdin )
1991
+ fclose (miscfrom );
1903
1992
return EXIT_FAILURE ;
1904
1993
}
0 commit comments