Skip to content

Commit 237ddc1

Browse files
committed
lstopo: add --misc-from
Allows to give a list of Misc objects in a separate file (or stdin), will be used to bring hwloc-ps flexibility without adding many options to lstopo. Refs #606 Signed-off-by: Brice Goglin <[email protected]>
1 parent 64fdad2 commit 237ddc1

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

contrib/completion/bash/hwloc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ _lstopo() {
8080
--export-xml-flags
8181
--export-synthetic-flags
8282
--ps --top
83+
--misc-from
8384
--version
8485
-h --help
8586
)

utils/lstopo/lstopo-no-graphics.1in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,18 @@ cluttering the output, only processes that are restricted to some part of the
330330
machine are shown. On Linux, kernel threads are not shown.
331331
If many processes appear, the output may become hard to read anyway,
332332
making the hwloc-ps program more practical.
333+
334+
.TP
335+
\fB\-\-misc\-from\fR <file>
336+
Add Misc objects as described in <file> containing entries such as:
337+
338+
name=myMisc1
339+
cpuset=0x5
340+
341+
name=myMisc2
342+
cpuset=0x7
343+
subtype=myOptionalSubtype
344+
333345
.TP
334346
\fB\-\-children\-order\fR <order>
335347
Change the order of the different kinds of children with respect to

utils/lstopo/lstopo.c

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,77 @@ static void add_process_objects(hwloc_topology_t topology)
154154
HWLOC_PS_FLAG_THREADS | HWLOC_PS_FLAG_SHORTNAME, NULL, HWLOC_PS_ALL_UIDS);
155155
}
156156

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+
157228
static __hwloc_inline void lstopo_update_factorize_bounds(unsigned min, unsigned *first, unsigned *last)
158229
{
159230
switch (min) {
@@ -577,6 +648,7 @@ void usage(const char *name, FILE *where)
577648
" Set flags during the synthetic topology export\n");
578649
/* --shmem-output-addr is undocumented on purpose */
579650
fprintf (where, " --ps --top Display processes within the hierarchy\n");
651+
fprintf (where, " --misc-from <file> Create Misc objects as defined in <file>");
580652
fprintf (where, " --version Report version and exit\n");
581653
fprintf (where, " -h --help Show this usage\n");
582654
}
@@ -838,6 +910,7 @@ main (int argc, char *argv[])
838910
#endif
839911
char *env;
840912
int top = 0;
913+
FILE * miscfrom = NULL;
841914
int opt;
842915
unsigned i;
843916

@@ -1472,7 +1545,19 @@ main (int argc, char *argv[])
14721545
loutput.pid_number = atoi(argv[1]); opt = 1;
14731546
} else if (!strcmp (argv[0], "--ps") || !strcmp (argv[0], "--top"))
14741547
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")) {
14761561
printf("%s %s\n", callname, HWLOC_VERSION);
14771562
exit(EXIT_SUCCESS);
14781563
} else if (!strcmp (argv[0], "--output-format") || !strcmp (argv[0], "--of")) {
@@ -1815,6 +1900,8 @@ main (int argc, char *argv[])
18151900

18161901
if (top)
18171902
add_process_objects(topology);
1903+
if (miscfrom)
1904+
add_misc_objects_from(topology, miscfrom);
18181905

18191906
if (restrictstring) {
18201907
hwloc_bitmap_t restrictset = hwloc_bitmap_alloc();
@@ -1900,5 +1987,7 @@ main (int argc, char *argv[])
19001987
hwloc_bitmap_free(allow_nodeset);
19011988
hwloc_bitmap_free(loutput.cpubind_set);
19021989
hwloc_bitmap_free(loutput.membind_set);
1990+
if (miscfrom && miscfrom != stdin)
1991+
fclose(miscfrom);
19031992
return EXIT_FAILURE;
19041993
}

0 commit comments

Comments
 (0)