Skip to content

Commit 9b3b4dd

Browse files
authored
Merge pull request #605 from bgoglin/backend-info
Cleanup Backend info attribute: All backends add a Backend=foo info attr in the root object if they added some objects to the topology. Once and only once per backend for backends that have multiple phases. No Backend info attr in OS devices anymore.
2 parents a2e28b5 + d92b1a4 commit 9b3b4dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+318
-123
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Version 3.0.0
3232
in PCI object attributes.
3333
+ "Block" OS devices are now "Storage" (for actual Block devices)
3434
or "Memory" (for Linux DAX and CXL devices, etc).
35+
+ The "Backend" info attribute of OS devices is now in the topology
36+
root object together with other backends.
3537
* Tools
3638
+ lstopo has a new --osf option to tune the displaying of object
3739
attributes and units.

doc/hwloc.doxy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,11 +2046,11 @@ placed.
20462046
Unless specified, these info attributes are attached to the root object (Machine).
20472047

20482048
<dl>
2049-
<dt>Backend (topology root, or specific object added by that backend)</dt>
2050-
<dd>The name of the hwloc backend/component that filled the topology.
2049+
<dt>Backend (topology root object)</dt>
2050+
<dd>The name of a hwloc backend/component that added objects in the topology.
20512051
If several components were combined, multiple Backend keys may exist,
2052-
with different values, for instance <tt>x86</tt> and <tt>Linux</tt> in the root
2053-
object and <tt>CUDA</tt> in CUDA OS device objects.
2052+
with different values, for instance <tt>x86</tt>, <tt>Linux</tt> and
2053+
<tt>CUDA</tt>.
20542054
</dd>
20552055
<dt>SyntheticDescription</dt>
20562056
<dd>The description string that was given to hwloc to build this

hwloc/topology-cuda.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ hwloc_cuda_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dst
7373
struct hwloc_topology *topology = backend->topology;
7474
enum hwloc_type_filter_e filter;
7575
cudaError_t cures;
76+
unsigned added = 0;
7677
int nb, i;
7778

7879
assert(dstatus->phase == HWLOC_DISC_PHASE_IO);
@@ -105,7 +106,6 @@ hwloc_cuda_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dst
105106
cuda_device->attr->osdev.type = HWLOC_OBJ_OSDEV_COPROC;
106107

107108
cuda_device->subtype = strdup("CUDA");
108-
hwloc_obj_add_info(cuda_device, "Backend", "CUDA");
109109
hwloc_obj_add_info(cuda_device, "GPUVendor", "NVIDIA Corporation");
110110

111111
cures = cudaGetDeviceProperties(&prop, i);
@@ -138,8 +138,11 @@ hwloc_cuda_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dst
138138
parent = hwloc_get_root_obj(topology);
139139

140140
hwloc_insert_object_by_parent(topology, parent, cuda_device);
141+
added++;
141142
}
142143

144+
if (added > 0)
145+
hwloc_obj_add_info(hwloc_get_root_obj(topology), "Backend", "CUDA");
143146
return 0;
144147
}
145148

hwloc/topology-freebsd.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#include "private/private.h"
3737
#include "private/debug.h"
3838

39+
struct hwloc_freebsd_backend_data_s {
40+
int need_global_infos;
41+
};
42+
3943
#if defined(HAVE_SYS_CPUSET_H) && defined(HAVE_CPUSET_SETAFFINITY)
4044
static void
4145
hwloc_freebsd_bsd2hwloc(hwloc_bitmap_t hwloc_cpuset, const cpuset_t *cset)
@@ -525,6 +529,7 @@ hwloc_look_freebsd(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
525529
* we may still force use this backend when debugging with !thissystem.
526530
*/
527531
struct hwloc_topology *topology = backend->topology;
532+
struct hwloc_freebsd_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
528533

529534
if (dstatus->phase == HWLOC_DISC_PHASE_CPU) {
530535
if (!topology->levels[0][0]->cpuset) {
@@ -545,8 +550,12 @@ hwloc_look_freebsd(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
545550
memsize = hwloc_fallback_memsize();
546551
if (memsize > 0)
547552
topology->machine_memory.local_memory = memsize;
548-
hwloc_obj_add_info(topology->levels[0][0], "Backend", "FreeBSD");
549-
hwloc_add_uname_info(topology, NULL);
553+
}
554+
555+
if (data->need_global_infos) {
556+
hwloc_obj_add_info(topology->levels[0][0], "Backend", "FreeBSD");
557+
hwloc_add_uname_info(topology, NULL);
558+
data->need_global_infos = 0;
550559
}
551560
return 0;
552561
}
@@ -595,9 +604,15 @@ hwloc_freebsd_component_instantiate(struct hwloc_topology *topology,
595604
const void *_data3 __hwloc_attribute_unused)
596605
{
597606
struct hwloc_backend *backend;
598-
backend = hwloc_backend_alloc(topology, component, 0);
607+
struct hwloc_freebsd_backend_data_s *data;
608+
609+
backend = hwloc_backend_alloc(topology, component, sizeof(struct hwloc_freebsd_backend_data_s));
599610
if (!backend)
600611
return NULL;
612+
613+
data = HWLOC_BACKEND_PRIVATE_DATA(backend);
614+
data->need_global_infos = 1;
615+
601616
backend->discover = hwloc_look_freebsd;
602617
return backend;
603618
}

hwloc/topology-gl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ hwloc_gl_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dstat
3232

3333
struct hwloc_topology *topology = backend->topology;
3434
enum hwloc_type_filter_e filter;
35-
unsigned i;
35+
unsigned i, added = 0;
3636
int err;
3737

3838
assert(dstatus->phase == HWLOC_DISC_PHASE_IO);
@@ -123,7 +123,6 @@ hwloc_gl_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dstat
123123
osdev->name = strdup(name);
124124
osdev->subtype = strdup("Display");
125125
osdev->attr->osdev.type = HWLOC_OBJ_OSDEV_GPU;
126-
hwloc_obj_add_info(osdev, "Backend", "GL");
127126
hwloc_obj_add_info(osdev, "GPUVendor", "NVIDIA Corporation");
128127
if (productname)
129128
hwloc_obj_add_info(osdev, "GPUModel", productname);
@@ -133,6 +132,7 @@ hwloc_gl_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dstat
133132
parent = hwloc_get_root_obj(topology);
134133

135134
hwloc_insert_object_by_parent(topology, parent, osdev);
135+
added++;
136136

137137
hwloc_debug("GL device %s (product %s) on PCI %04x:%02x:%02x.%01x\n",
138138
name, productname,
@@ -141,6 +141,8 @@ hwloc_gl_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dstat
141141
XCloseDisplay(display);
142142
}
143143

144+
if (added)
145+
hwloc_obj_add_info(hwloc_get_root_obj(topology), "Backend", "GL");
144146
return 0;
145147
}
146148

hwloc/topology-hardwired.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2015-2020 Inria. All rights reserved.
2+
* Copyright © 2015-2023 Inria. All rights reserved.
33
* See COPYING in top-level directory.
44
*/
55

@@ -73,6 +73,7 @@ int hwloc_look_hardwired_fujitsu_k(struct hwloc_topology *topology)
7373
topology->support.discovery->pu = 1;
7474
hwloc_setup_pu_level(topology, 8);
7575

76+
hwloc_obj_add_info(topology->levels[0][0], "Backend", "hardwired:K-computer");
7677
return 0;
7778
}
7879

@@ -142,6 +143,7 @@ int hwloc_look_hardwired_fujitsu_fx10(struct hwloc_topology *topology)
142143
topology->support.discovery->pu = 1;
143144
hwloc_setup_pu_level(topology, 16);
144145

146+
hwloc_obj_add_info(topology->levels[0][0], "Backend", "hardwired:FX10");
145147
return 0;
146148
}
147149

@@ -221,5 +223,6 @@ int hwloc_look_hardwired_fujitsu_fx100(struct hwloc_topology *topology)
221223
topology->support.discovery->pu = 1;
222224
hwloc_setup_pu_level(topology, 34);
223225

226+
hwloc_obj_add_info(topology->levels[0][0], "Backend", "hardwired:FX100");
224227
return 0;
225228
}

hwloc/topology-levelzero.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ hwloc_levelzero_discover(struct hwloc_backend *backend, struct hwloc_disc_status
601601
enum hwloc_type_filter_e filter;
602602
ze_result_t res;
603603
ze_driver_handle_t *drh;
604-
uint32_t nbdrivers, i, k, zeidx;
604+
uint32_t nbdrivers, i, k, zeidx, added = 0;
605605
struct hwloc_osdev_array oarray;
606606
struct hwloc_levelzero_ports hports;
607607
int sysman_maybe_missing = 0; /* 1 if ZES_ENABLE_SYSMAN=1 was NOT set early, 2 if ZES_ENABLE_SYSMAN=0 */
@@ -709,7 +709,6 @@ hwloc_levelzero_discover(struct hwloc_backend *backend, struct hwloc_disc_status
709709
osdev->depth = HWLOC_TYPE_DEPTH_UNKNOWN;
710710
osdev->attr->osdev.type = HWLOC_OBJ_OSDEV_COPROC;
711711
osdev->subtype = strdup("LevelZero");
712-
hwloc_obj_add_info(osdev, "Backend", "LevelZero");
713712

714713
snprintf(buffer, sizeof(buffer), "%u", i);
715714
hwloc_obj_add_info(osdev, "LevelZeroDriverIndex", buffer);
@@ -738,7 +737,6 @@ hwloc_levelzero_discover(struct hwloc_backend *backend, struct hwloc_disc_status
738737
subosdevs[k]->depth = HWLOC_TYPE_DEPTH_UNKNOWN;
739738
subosdevs[k]->attr->osdev.type = HWLOC_OBJ_OSDEV_COPROC;
740739
subosdevs[k]->subtype = strdup("LevelZero");
741-
hwloc_obj_add_info(subosdevs[k], "Backend", "LevelZero");
742740
snprintf(tmp, sizeof(tmp), "%u", k);
743741
hwloc_obj_add_info(subosdevs[k], "LevelZeroSubdeviceID", tmp);
744742

@@ -805,11 +803,13 @@ hwloc_levelzero_discover(struct hwloc_backend *backend, struct hwloc_disc_status
805803
*/
806804
hwloc_insert_object_by_parent(topology, parent, osdev);
807805
hwloc__levelzero_osdev_array_add(&oarray, osdev);
806+
added++;
808807
if (nr_subdevices) {
809808
for(k=0; k<nr_subdevices; k++)
810809
if (subosdevs[k]) {
811810
hwloc_insert_object_by_parent(topology, osdev, subosdevs[k]);
812811
hwloc__levelzero_osdev_array_add(&oarray, subosdevs[k]);
812+
added++;
813813
}
814814
free(subosdevs);
815815
free(subh);
@@ -826,6 +826,9 @@ hwloc_levelzero_discover(struct hwloc_backend *backend, struct hwloc_disc_status
826826
hwloc__levelzero_osdev_array_free(&oarray);
827827

828828
free(drh);
829+
830+
if (added)
831+
hwloc_obj_add_info(hwloc_get_root_obj(topology), "Backend", "LevelZero");
829832
return 0;
830833
}
831834

hwloc/topology-linux.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct hwloc_linux_backend_data_s {
6363
struct utsname utsname; /* fields contain \0 when unknown */
6464
int fallback_nbprocessors; /* only used in hwloc_linux_fallback_pu_level(), maybe be <= 0 (error) earlier */
6565
unsigned pagesize;
66+
int need_global_infos;
6667
};
6768

6869

@@ -5768,16 +5769,6 @@ hwloc_linuxfs_look_cpu(struct hwloc_backend *backend, struct hwloc_disc_status *
57685769

57695770
hwloc_alloc_root_sets(topology->levels[0][0]);
57705771

5771-
/*********************************
5772-
* Platform information for later
5773-
*/
5774-
hwloc_gather_system_info(topology, data);
5775-
5776-
/**********************************
5777-
* Detect things in /proc/cmdline
5778-
*/
5779-
hwloc_linuxfs_check_kernel_cmdline(data);
5780-
57815772
/**********************
57825773
* /proc/cpuinfo
57835774
*/
@@ -5862,22 +5853,11 @@ hwloc_linuxfs_look_cpu(struct hwloc_backend *backend, struct hwloc_disc_status *
58625853
} else
58635854
nbnodes = 0;
58645855

5865-
/**********************
5866-
* Misc
5867-
*/
5868-
5869-
/* Gather DMI info */
5870-
hwloc__get_dmi_id_info(data, topology->levels[0][0]);
5871-
5872-
hwloc_obj_add_info(topology->levels[0][0], "Backend", "Linux");
58735856
if (cpuset_name) {
58745857
hwloc_obj_add_info(topology->levels[0][0], "LinuxCgroup", cpuset_name);
58755858
free(cpuset_name);
58765859
}
58775860

5878-
/* data->utsname was filled with real uname or \0, we can safely pass it */
5879-
hwloc_add_uname_info(topology, &data->utsname);
5880-
58815861
hwloc_linux_free_cpuinfo(Lprocs, numprocs, global_infos, global_infos_count);
58825862
return 0;
58835863
}
@@ -7292,14 +7272,20 @@ hwloc_look_linuxfs(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
72927272
* or not (modified fsroot path).
72937273
*/
72947274

7275+
struct hwloc_linux_backend_data_s *data = HWLOC_BACKEND_PRIVATE_DATA(backend);
72957276
struct hwloc_topology *topology = backend->topology;
72967277
#ifdef HWLOC_HAVE_LINUXIO
72977278
enum hwloc_type_filter_e pfilter, bfilter, ofilter, mfilter;
72987279
#endif /* HWLOC_HAVE_LINUXIO */
72997280

7281+
if (data->need_global_infos) {
7282+
hwloc_gather_system_info(topology, data);
7283+
hwloc_linuxfs_check_kernel_cmdline(data);
7284+
}
7285+
73007286
if (dstatus->phase == HWLOC_DISC_PHASE_CPU) {
73017287
hwloc_linuxfs_look_cpu(backend, dstatus);
7302-
return 0;
7288+
goto out;
73037289
}
73047290

73057291
#ifdef HWLOC_HAVE_LINUXIO
@@ -7353,6 +7339,14 @@ hwloc_look_linuxfs(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
73537339
}
73547340
#endif /* HWLOC_HAVE_LINUXIO */
73557341

7342+
out:
7343+
if (data->need_global_infos) {
7344+
hwloc__get_dmi_id_info(data, topology->levels[0][0]);
7345+
hwloc_obj_add_info(topology->levels[0][0], "Backend", "Linux");
7346+
/* data->utsname was filled with real uname or \0, we can safely pass it */
7347+
hwloc_add_uname_info(topology, &data->utsname);
7348+
data->need_global_infos = 0;
7349+
}
73567350
return 0;
73577351
}
73587352

@@ -7405,6 +7399,7 @@ hwloc_linux_component_instantiate(struct hwloc_topology *topology,
74057399
data->is_knl = 0;
74067400
data->is_amd_with_CU = 0;
74077401
data->is_fake_numa_uniform = 0;
7402+
data->need_global_infos = 1;
74087403
data->is_real_fsroot = 1;
74097404
data->root_path = NULL;
74107405
fsroot_path = getenv("HWLOC_FSROOT");

hwloc/topology-noos.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ hwloc_look_noos(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus
3535
nbprocs = 1;
3636
hwloc_alloc_root_sets(topology->levels[0][0]);
3737
hwloc_setup_pu_level(topology, nbprocs);
38+
hwloc_obj_add_info(topology->levels[0][0], "Backend", "noOS");
3839
}
3940

4041
memsize = hwloc_fallback_memsize();

hwloc/topology-nvml.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ hwloc_nvml_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dst
159159
struct hwloc_topology *topology = backend->topology;
160160
enum hwloc_type_filter_e filter;
161161
nvmlReturn_t ret;
162-
unsigned nb, i;
162+
unsigned nb, i, added = 0;
163163
#ifdef NVML_NVLINK_MAX_LINKS
164164
unsigned nbobjs, j;
165165
hwloc_obj_t *objs;
@@ -224,7 +224,6 @@ hwloc_nvml_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dst
224224
osdev->depth = HWLOC_TYPE_DEPTH_UNKNOWN;
225225
osdev->attr->osdev.type = HWLOC_OBJ_OSDEV_GPU;
226226

227-
hwloc_obj_add_info(osdev, "Backend", "NVML");
228227
hwloc_obj_add_info(osdev, "GPUVendor", "NVIDIA Corporation");
229228

230229
buffer[0] = '\0';
@@ -272,6 +271,7 @@ hwloc_nvml_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dst
272271
#ifdef NVML_NVLINK_MAX_LINKS
273272
objs[i] = osdev;
274273
#endif
274+
added++;
275275
}
276276

277277
#ifdef NVML_NVLINK_MAX_LINKS
@@ -397,6 +397,9 @@ hwloc_nvml_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dst
397397
#endif /* NVML_NVLINK_MAX_LINKS */
398398

399399
nvmlShutdown();
400+
401+
if (added)
402+
hwloc_obj_add_info(hwloc_get_root_obj(topology), "Backend", "NVML");
400403
return 0;
401404
}
402405

0 commit comments

Comments
 (0)