Skip to content

Commit dbede24

Browse files
committed
utils: fix --flags/--thissystem when using a fake fsroot or cpuid directory
fsroot and cpuid are implemented in tools using environment variables (those debug cases are not in the API since v2). Those backends forced by environment variable override the normal topology thissystem flag that may be set with set_flags() in the API and with --flags or --thissystem in cli tools. One must use the HWLOC_THISSYSTEM envvar to force the this system flag. Implement this automatically in the tools (common helpers). Signed-off-by: Brice Goglin <[email protected]>
1 parent 0685cb8 commit dbede24

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

utils/hwloc/hwloc-calc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ int main(int argc, char *argv[])
255255
hwloc_topology_set_all_types_filter(topology, HWLOC_TYPE_FILTER_KEEP_ALL); \
256256
hwloc_topology_set_flags(topology, flags); \
257257
if (input) { \
258-
err = hwloc_utils_enable_input_format(topology, input, &input_format, verbose, callname); \
258+
err = hwloc_utils_enable_input_format(topology, flags, input, &input_format, verbose, callname); \
259259
if (err) return EXIT_FAILURE; \
260260
} \
261261
err = hwloc_topology_load(topology); \

utils/hwloc/hwloc-distrib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ int main(int argc, char *argv[])
200200
cpuset = malloc(n * sizeof(hwloc_bitmap_t));
201201

202202
if (input) {
203-
err = hwloc_utils_enable_input_format(topology, input, &input_format, verbose, callname);
203+
err = hwloc_utils_enable_input_format(topology, flags, input, &input_format, verbose, callname);
204204
if (err) {
205205
free(cpuset);
206206
return EXIT_FAILURE;

utils/hwloc/hwloc-info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ main (int argc, char *argv[])
524524
hwloc_topology_set_flags(topology, flags);
525525

526526
if (input) {
527-
err = hwloc_utils_enable_input_format(topology, input, &input_format, verbose_mode, callname);
527+
err = hwloc_utils_enable_input_format(topology, flags, input, &input_format, verbose_mode, callname);
528528
if (err)
529529
return err;
530530
}

utils/hwloc/misc.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ hwloc_utils_autodetect_input_format(const char *input, int verbose)
217217
}
218218

219219
static __hwloc_inline int
220-
hwloc_utils_enable_input_format(struct hwloc_topology *topology,
220+
hwloc_utils_enable_input_format(struct hwloc_topology *topology, unsigned long flags,
221221
const char *input,
222222
enum hwloc_utils_input_format *input_format,
223223
int verbose, const char *callname)
@@ -258,6 +258,9 @@ hwloc_utils_enable_input_format(struct hwloc_topology *topology,
258258
fprintf(stderr, "Cannot force linux component first because HWLOC_COMPONENTS environment variable is already set to %s.\n", env);
259259
else
260260
putenv((char *) "HWLOC_COMPONENTS=linux,pci,stop");
261+
/* normally-set flags are overriden by envvar-forced backends */
262+
if (flags & HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM)
263+
putenv((char *) "HWLOC_THISSYSTEM=1");
261264
#else /* HWLOC_LINUX_SYS */
262265
fprintf(stderr, "This installation of hwloc does not support changing the file-system root, sorry.\n");
263266
exit(EXIT_FAILURE);
@@ -280,6 +283,9 @@ hwloc_utils_enable_input_format(struct hwloc_topology *topology,
280283
fprintf(stderr, "Cannot force x86 component first because HWLOC_COMPONENTS environment variable is already set to %s.\n", env);
281284
else
282285
putenv((char *) "HWLOC_COMPONENTS=x86,stop");
286+
/* normally-set flags are overriden by envvar-forced backends */
287+
if (flags & HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM)
288+
putenv((char *) "HWLOC_THISSYSTEM=1");
283289
#else
284290
fprintf(stderr, "This installation of hwloc does not support loading from a cpuid dump, sorry.\n");
285291
exit(EXIT_FAILURE);

utils/lstopo/lstopo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ main (int argc, char *argv[])
11261126
}
11271127

11281128
if (input) {
1129-
err = hwloc_utils_enable_input_format(topology, input, &input_format, loutput.verbose_mode > 1, callname);
1129+
err = hwloc_utils_enable_input_format(topology, flags, input, &input_format, loutput.verbose_mode > 1, callname);
11301130
if (err)
11311131
goto out_with_topology;
11321132
}

0 commit comments

Comments
 (0)