Skip to content

Commit 17d0842

Browse files
committed
utils/hwloc: Enforce the options order (topology options first)
Reorder the options. Signed-off-by: Clément Foyer <[email protected]>
1 parent 75234cb commit 17d0842

11 files changed

+496
-463
lines changed

utils/hwloc/hwloc-annotate.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ int main(int argc, char *argv[])
494494
putenv((char *) "HWLOC_XML_VERBOSE=1");
495495

496496
while (argc && *argv[0] == '-') {
497+
/* Options */
497498
if (!strcmp(argv[0], "--ci"))
498499
clearinfos = 1;
499500
else if (!strcmp(argv[0], "--ri"))
@@ -502,14 +503,17 @@ int main(int argc, char *argv[])
502503
clearuserdata = 1;
503504
else if (!strcmp(argv[0], "--cd"))
504505
cleardistances = 1;
505-
else if (!strcmp (argv[0], "--version")) {
506-
printf("%s %s\n", callname, HWLOC_VERSION);
507-
exit(EXIT_SUCCESS);
508-
}
506+
/* Misc */
507+
else if (!strcmp (argv[0], "--version")) {
508+
printf("%s %s\n", callname, HWLOC_VERSION);
509+
exit(EXIT_SUCCESS);
510+
}
509511
else if (!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help")) {
510512
usage(callname, stdout);
511513
exit(EXIT_SUCCESS);
512-
} else {
514+
}
515+
/* Errors */
516+
else {
513517
fprintf(stderr, "Unrecognized options: %s\n", argv[0]);
514518
usage(callname, stderr);
515519
exit(EXIT_FAILURE);

utils/hwloc/hwloc-bind.c

+92-87
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,25 @@ void usage(const char *name, FILE *where)
3535
fprintf(where, " --no-smt Only keep a single PU per core\n");
3636
fprintf(where, " --restrict [nodeset=]<bitmap>\n");
3737
fprintf(where, " Restrict the topology to some processors or NUMA nodes.\n");
38-
fprintf(where, " --restrict-flags <n> Set the flags to be used during restrict\n");
38+
fprintf(where, " --restrict-flags <n>\n");
39+
fprintf(where, " Set the flags to be used during restrict\n");
3940
fprintf(where, " --disallowed Include objects disallowed by administrative limitations\n");
4041
fprintf(where, " --hbm Only consider high bandwidth memory nodes\n");
4142
fprintf(where, " --no-hbm Ignore high-bandwidth memory nodes\n");
4243
fprintf(where, "Options:\n");
4344
fprintf(where, " --cpubind Use following arguments for cpu binding (default)\n");
4445
fprintf(where, " --membind Use following arguments for memory binding\n");
45-
fprintf(where, " --mempolicy <default|firsttouch|bind|interleave|nexttouch>\n"
46-
" Change policy that --membind applies (default is bind)\n");
46+
fprintf(where, " --mempolicy <default|firsttouch|bind|interleave|nexttouch>\n");
47+
fprintf(where, " Change policy that --membind applies (default is bind)\n");
4748
fprintf(where, " --best-memattr <attr>\n");
4849
fprintf(where, " Select the best target node in the given memory binding\n");
4950
fprintf(where, " -l --logical Take logical object indexes (default)\n");
5051
fprintf(where, " -p --physical Take physical object indexes\n");
5152
fprintf(where, " --single Bind on a single CPU to prevent migration\n");
5253
fprintf(where, " --strict Require strict binding\n");
5354
fprintf(where, " --get Retrieve current process binding\n");
54-
fprintf(where, " -e --get-last-cpu-location\n"
55-
" Retrieve the last processors where the current process ran\n");
55+
fprintf(where, " -e --get-last-cpu-location\n");
56+
fprintf(where, " Retrieve the last processors where the current process ran\n");
5657
fprintf(where, " --nodeset Display (and parse) cpusets as nodesets\n");
5758
fprintf(where, " --pid <pid> Operate on process <pid>\n");
5859
#ifdef HWLOC_LINUX_SYS
@@ -120,8 +121,13 @@ int main(int argc, char *argv[])
120121
while (argc >= 1) {
121122
opt = 0;
122123

123-
if (!strcmp (argv[0], "--disallowed") || !strcmp (argv[0], "--whole-system")) {
124-
flags |= HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED;
124+
/* Topology */
125+
if (!strcmp(argv[0], "--no-smt")) {
126+
no_smt = 0;
127+
goto next_config;
128+
}
129+
if (!strncmp(argv[0], "--no-smt=", 9)) {
130+
no_smt = atoi(argv[0] + 9);
125131
goto next_config;
126132
}
127133
if (!strcmp (argv[0], "--restrict")) {
@@ -147,12 +153,8 @@ int main(int argc, char *argv[])
147153
opt = 1;
148154
goto next_config;
149155
}
150-
if (!strcmp(argv[0], "--no-smt")) {
151-
no_smt = 0;
152-
goto next_config;
153-
}
154-
if (!strncmp(argv[0], "--no-smt=", 9)) {
155-
no_smt = atoi(argv[0] + 9);
156+
if (!strcmp (argv[0], "--disallowed") || !strcmp (argv[0], "--whole-system")) {
157+
flags |= HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED;
156158
goto next_config;
157159
}
158160
if (!strcmp(argv[0], "--hbm")) {
@@ -163,15 +165,6 @@ int main(int argc, char *argv[])
163165
only_hbm = 0;
164166
goto next_config;
165167
}
166-
if (!strcmp (argv[0], "--best-memattr")) {
167-
if (argc < 2) {
168-
usage (callname, stderr);
169-
exit(EXIT_FAILURE);
170-
}
171-
best_memattr_str = argv[1];
172-
opt = 1;
173-
goto next_config;
174-
}
175168

176169
break;
177170

@@ -213,30 +206,72 @@ int main(int argc, char *argv[])
213206
opt = 0;
214207

215208
if (*argv[0] == '-') {
216-
if (!strcmp(argv[0], "-v") || !strcmp(argv[0], "--verbose")) {
217-
verbose++;
218-
goto next;
209+
/* Options */
210+
if (!strcmp (argv[0], "--cpubind")) {
211+
working_on_cpubind = 1;
212+
goto next;
219213
}
220-
if (!strcmp(argv[0], "-q") || !strcmp(argv[0], "--quiet")) {
221-
verbose--;
222-
goto next;
214+
if (!strcmp (argv[0], "--membind")) {
215+
working_on_cpubind = 0;
216+
goto next;
223217
}
224-
if (!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help")) {
225-
usage(callname, stdout);
226-
return EXIT_SUCCESS;
218+
if (!strcmp (argv[0], "--mempolicy")) {
219+
if (!strncmp(argv[1], "default", 2))
220+
membind_policy = HWLOC_MEMBIND_DEFAULT;
221+
else if (!strncmp(argv[1], "firsttouch", 2))
222+
membind_policy = HWLOC_MEMBIND_FIRSTTOUCH;
223+
else if (!strncmp(argv[1], "bind", 2))
224+
membind_policy = HWLOC_MEMBIND_BIND;
225+
else if (!strncmp(argv[1], "interleave", 2))
226+
membind_policy = HWLOC_MEMBIND_INTERLEAVE;
227+
else if (!strncmp(argv[1], "nexttouch", 2))
228+
membind_policy = HWLOC_MEMBIND_NEXTTOUCH;
229+
else {
230+
fprintf(stderr, "Unrecognized memory binding policy %s\n", argv[1]);
231+
usage (callname, stderr);
232+
exit(EXIT_FAILURE);
233+
}
234+
got_mempolicy = 1;
235+
opt = 1;
236+
goto next;
227237
}
228-
if (!strcmp(argv[0], "--single")) {
229-
single = 1;
230-
goto next;
238+
if (!strcmp (argv[0], "--best-memattr")) {
239+
if (argc < 2) {
240+
usage (callname, stderr);
241+
exit(EXIT_FAILURE);
242+
}
243+
best_memattr_str = argv[1];
244+
opt = 1;
245+
goto next;
231246
}
232-
if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--force")) {
233-
force = 1;
234-
goto next;
247+
if (!strcmp(argv[0], "-l") || !strcmp(argv[0], "--logical")) {
248+
logical = 1;
249+
goto next;
250+
}
251+
if (!strcmp(argv[0], "-p") || !strcmp(argv[0], "--physical")) {
252+
logical = 0;
253+
goto next;
254+
}
255+
if (!strcmp(argv[0], "--single")) {
256+
single = 1;
257+
goto next;
235258
}
236259
if (!strcmp(argv[0], "--strict")) {
237-
cpubind_flags |= HWLOC_CPUBIND_STRICT;
238-
membind_flags |= HWLOC_MEMBIND_STRICT;
239-
goto next;
260+
cpubind_flags |= HWLOC_CPUBIND_STRICT;
261+
membind_flags |= HWLOC_MEMBIND_STRICT;
262+
goto next;
263+
}
264+
if (!strcmp (argv[0], "--get")) {
265+
get_binding = 1;
266+
goto next;
267+
}
268+
if (!strcmp (argv[0], "-e") || !strncmp (argv[0], "--get-last-cpu-location", 10)) {
269+
get_last_cpu_location = 1;
270+
goto next;
271+
}
272+
if (!strcmp (argv[0], "--nodeset")) {
273+
use_nodeset = 1;
274+
goto next;
240275
}
241276
if (!strcmp(argv[0], "--pid")) {
242277
if (argc < 2) {
@@ -258,63 +293,33 @@ int main(int argc, char *argv[])
258293
goto next;
259294
}
260295
#endif
261-
if (!strcmp (argv[0], "--version")) {
262-
printf("%s %s\n", callname, HWLOC_VERSION);
263-
exit(EXIT_SUCCESS);
264-
}
265-
if (!strcmp(argv[0], "-l") || !strcmp(argv[0], "--logical")) {
266-
logical = 1;
267-
goto next;
268-
}
269-
if (!strcmp(argv[0], "-p") || !strcmp(argv[0], "--physical")) {
270-
logical = 0;
271-
goto next;
272-
}
273296
if (!strcmp(argv[0], "--taskset")) {
274297
taskset = 1;
275298
goto next;
276299
}
277-
if (!strcmp (argv[0], "-e") || !strncmp (argv[0], "--get-last-cpu-location", 10)) {
278-
get_last_cpu_location = 1;
279-
goto next;
280-
}
281-
if (!strcmp (argv[0], "--get")) {
282-
get_binding = 1;
283-
goto next;
300+
/* Misc */
301+
if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--force")) {
302+
force = 1;
303+
goto next;
284304
}
285-
if (!strcmp (argv[0], "--nodeset")) {
286-
use_nodeset = 1;
287-
goto next;
305+
if (!strcmp(argv[0], "-q") || !strcmp(argv[0], "--quiet")) {
306+
verbose--;
307+
goto next;
288308
}
289-
if (!strcmp (argv[0], "--cpubind")) {
290-
working_on_cpubind = 1;
291-
goto next;
309+
if (!strcmp(argv[0], "-v") || !strcmp(argv[0], "--verbose")) {
310+
verbose++;
311+
goto next;
292312
}
293-
if (!strcmp (argv[0], "--membind")) {
294-
working_on_cpubind = 0;
295-
goto next;
313+
if (!strcmp (argv[0], "--version")) {
314+
printf("%s %s\n", callname, HWLOC_VERSION);
315+
exit(EXIT_SUCCESS);
296316
}
297-
if (!strcmp (argv[0], "--mempolicy")) {
298-
if (!strncmp(argv[1], "default", 2))
299-
membind_policy = HWLOC_MEMBIND_DEFAULT;
300-
else if (!strncmp(argv[1], "firsttouch", 2))
301-
membind_policy = HWLOC_MEMBIND_FIRSTTOUCH;
302-
else if (!strncmp(argv[1], "bind", 2))
303-
membind_policy = HWLOC_MEMBIND_BIND;
304-
else if (!strncmp(argv[1], "interleave", 2))
305-
membind_policy = HWLOC_MEMBIND_INTERLEAVE;
306-
else if (!strncmp(argv[1], "nexttouch", 2))
307-
membind_policy = HWLOC_MEMBIND_NEXTTOUCH;
308-
else {
309-
fprintf(stderr, "Unrecognized memory binding policy %s\n", argv[1]);
310-
usage (callname, stderr);
311-
exit(EXIT_FAILURE);
312-
}
313-
got_mempolicy = 1;
314-
opt = 1;
315-
goto next;
317+
if (!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help")) {
318+
usage(callname, stdout);
319+
return EXIT_SUCCESS;
316320
}
317321

322+
/* Errors */
318323
fprintf (stderr, "Unrecognized option: %s\n", argv[0]);
319324
usage(callname, stderr);
320325
return EXIT_FAILURE;

0 commit comments

Comments
 (0)