Skip to content

Commit 88a6c1d

Browse files
committed
API: add topology-specific info attributes
Accessible through hwloc_topology_get_infos() Nothing in this array yet. Signed-off-by: Brice Goglin <[email protected]>
1 parent 6d5614e commit 88a6c1d

File tree

12 files changed

+98
-23
lines changed

12 files changed

+98
-23
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Version 3.0.0
3737
+ The array and count of info attributes are now embedded in the new
3838
struct hwloc_infos_s.
3939
- hwloc_infos_s structures may be modified with hwloc_modify_infos().
40+
- hwloc_topology_get_infos() returns the new topology-global array
41+
of info attributes.
4042
- hwloc_cpukinds_get_info() and hwloc_cpukinds_register() now manipulate
4143
infos as such a structure.
4244
* Tools

doc/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ man3_object_info_attrs_DATA = \
356356
$(DOX_MAN_DIR)/man3/HWLOC_MODIFY_INFOS_OP_ADD.3 \
357357
$(DOX_MAN_DIR)/man3/HWLOC_MODIFY_INFOS_OP_ADD_UNIQUE.3 \
358358
$(DOX_MAN_DIR)/man3/HWLOC_MODIFY_INFOS_OP_REPLACE.3 \
359-
$(DOX_MAN_DIR)/man3/HWLOC_MODIFY_INFOS_OP_REMOVE.3
359+
$(DOX_MAN_DIR)/man3/HWLOC_MODIFY_INFOS_OP_REMOVE.3 \
360+
$(DOX_MAN_DIR)/man3/hwloc_topology_get_infos.3
360361

361362
man3_cpubindingdir = $(man3dir)
362363
man3_cpubinding_DATA = \

doc/hwloc.doxy

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,9 @@ or using the hwloc_obj_get_info_by_name().
19721972
The user may additionally add new name-value pairs to any object using
19731973
hwloc_obj_add_info(), hwloc_modify_infos() or the \ref cli_hwloc_annotate program.
19741974

1975+
Some topology-global info attributes (not specific to some objects)
1976+
are also accessible using hwloc_topology_get_infos().
1977+
19751978
Here is a non-exhaustive list of attributes that may be automatically
19761979
added by hwloc.
19771980
Note that these attributes heavily depend on the ability of the
@@ -2316,9 +2319,9 @@ that have a special meaning:
23162319
<div class="section">
23172320
\endhtmlonly
23182321

2319-
Besides the hierarchy of objects and individual object attributes
2320-
(see \ref attributes), hwloc may also expose finer information about
2321-
the hardware organization.
2322+
Besides the hierarchy of objects, individual object attributes
2323+
and topology info attributes (see \ref attributes),
2324+
hwloc may also expose finer information about the hardware organization.
23222325

23232326

23242327
\htmlonly

hwloc/diff.c

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ static int hwloc_append_diff_too_complex(hwloc_obj_t obj1,
6666
return 0;
6767
}
6868

69-
static int hwloc_append_diff_obj_attr_string(hwloc_obj_t obj,
69+
static int hwloc_append_diff_obj_attr_string(hwloc_topology_t topology,
70+
hwloc_obj_t obj,
7071
hwloc_topology_diff_obj_attr_type_t type,
7172
const char *name,
7273
const char *oldvalue,
@@ -80,8 +81,8 @@ static int hwloc_append_diff_obj_attr_string(hwloc_obj_t obj,
8081
return -1;
8182

8283
newdiff->obj_attr.type = HWLOC_TOPOLOGY_DIFF_OBJ_ATTR;
83-
newdiff->obj_attr.obj_depth = obj->depth;
84-
newdiff->obj_attr.obj_index = obj->logical_index;
84+
newdiff->obj_attr.obj_depth = obj ? obj->depth : (int) topology->nb_levels;
85+
newdiff->obj_attr.obj_index = obj ? obj->logical_index : 0;
8586
newdiff->obj_attr.diff.string.type = type;
8687
newdiff->obj_attr.diff.string.name = name ? strdup(name) : NULL;
8788
newdiff->obj_attr.diff.string.oldvalue = oldvalue ? strdup(oldvalue) : NULL;
@@ -155,7 +156,7 @@ hwloc_diff_trees(hwloc_topology_t topo1, hwloc_obj_t obj1,
155156

156157
if ((!obj1->name) != (!obj2->name)
157158
|| (obj1->name && strcmp(obj1->name, obj2->name))) {
158-
err = hwloc_append_diff_obj_attr_string(obj1,
159+
err = hwloc_append_diff_obj_attr_string(topo1, obj1,
159160
HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_NAME,
160161
NULL,
161162
obj1->name,
@@ -219,7 +220,7 @@ hwloc_diff_trees(hwloc_topology_t topo1, hwloc_obj_t obj1,
219220
if (strcmp(info1->name, info2->name))
220221
goto out_too_complex;
221222
if (strcmp(info1->value, info2->value)) {
222-
err = hwloc_append_diff_obj_attr_string(obj1,
223+
err = hwloc_append_diff_obj_attr_string(topo1, obj1,
223224
HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_INFO,
224225
info1->name,
225226
info1->value,
@@ -338,6 +339,27 @@ int hwloc_topology_diff_build(hwloc_topology_t topo1,
338339
goto roottoocomplex;
339340
}
340341

342+
/* topology infos */
343+
if (!err) {
344+
if (topo1->infos.count != topo2->infos.count)
345+
goto roottoocomplex;
346+
for(i=0; i<topo1->infos.count; i++) {
347+
struct hwloc_info_s *info1 = &topo1->infos.array[i], *info2 = &topo2->infos.array[i];
348+
if (strcmp(info1->name, info2->name))
349+
goto roottoocomplex;
350+
if (strcmp(info1->value, info2->value)) {
351+
err = hwloc_append_diff_obj_attr_string(topo1, NULL,
352+
HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_INFO,
353+
info1->name,
354+
info1->value,
355+
info2->value,
356+
diffp, &lastdiff);
357+
if (err < 0)
358+
return err;
359+
}
360+
}
361+
}
362+
341363
if (!err) {
342364
/* distances */
343365
hwloc_internal_distances_refresh(topo1);
@@ -458,15 +480,22 @@ hwloc_apply_diff_one(hwloc_topology_t topology,
458480
case HWLOC_TOPOLOGY_DIFF_OBJ_ATTR: {
459481
struct hwloc_topology_diff_obj_attr_s *obj_attr = &diff->obj_attr;
460482
hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, obj_attr->obj_depth, obj_attr->obj_index);
461-
if (!obj)
462-
return -1;
483+
struct hwloc_infos_s *infos;
484+
if (obj)
485+
infos = &obj->infos;
486+
else if (obj_attr->obj_depth == (int) topology->nb_levels)
487+
infos = &topology->infos;
488+
else
489+
return -1;
463490

464491
switch (obj_attr->diff.generic.type) {
465492
case HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_SIZE: {
466493
hwloc_obj_t tmpobj;
467494
hwloc_uint64_t oldvalue = reverse ? obj_attr->diff.uint64.newvalue : obj_attr->diff.uint64.oldvalue;
468495
hwloc_uint64_t newvalue = reverse ? obj_attr->diff.uint64.oldvalue : obj_attr->diff.uint64.newvalue;
469496
hwloc_uint64_t valuediff = newvalue - oldvalue;
497+
if (!obj)
498+
return -1;
470499
if (obj->type != HWLOC_OBJ_NUMANODE)
471500
return -1;
472501
if (obj->attr->numanode.local_memory != oldvalue)
@@ -482,7 +511,9 @@ hwloc_apply_diff_one(hwloc_topology_t topology,
482511
case HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_NAME: {
483512
const char *oldvalue = reverse ? obj_attr->diff.string.newvalue : obj_attr->diff.string.oldvalue;
484513
const char *newvalue = reverse ? obj_attr->diff.string.oldvalue : obj_attr->diff.string.newvalue;
485-
if (!obj->name || strcmp(obj->name, oldvalue))
514+
if (!obj)
515+
return -1;
516+
if (!obj->name || strcmp(obj->name, oldvalue))
486517
return -1;
487518
free(obj->name);
488519
obj->name = strdup(newvalue);
@@ -494,8 +525,8 @@ hwloc_apply_diff_one(hwloc_topology_t topology,
494525
const char *newvalue = reverse ? obj_attr->diff.string.oldvalue : obj_attr->diff.string.newvalue;
495526
unsigned i;
496527
int found = 0;
497-
for(i=0; i<obj->infos.count; i++) {
498-
struct hwloc_info_s *info = &obj->infos.array[i];
528+
for(i=0; i<infos->count; i++) {
529+
struct hwloc_info_s *info = &infos->array[i];
499530
if (!strcmp(info->name, name)
500531
&& !strcmp(info->value, oldvalue)) {
501532
free(info->value);

hwloc/hwloc2.dtd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!--
22
Copyright © 2009 CNRS
3-
Copyright © 2009-2022 Inria. All rights reserved.
3+
Copyright © 2009-2023 Inria. All rights reserved.
44
Copyright © 2009-2011 Université Bordeaux.
55
See COPYING in top-level directory.
66

77
This is the DTD for hwloc v2.x XMLs.
88
-->
99

10-
<!ELEMENT topology (object+,distances2*,distances2hetero*,support*,memattr*,cpukind*)>
10+
<!ELEMENT topology (object+,distances2*,distances2hetero*,support*,memattr*,cpukind*,info*)>
1111
<!ATTLIST topology version CDATA "">
1212

1313
<!ELEMENT object (page_type*,info*,userdata*,object*)>

hwloc/topology-xml.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,8 @@ hwloc_look_xml(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
17821782
ret = hwloc___xml_import_info(&infoname, &infovalue, &childstate);
17831783
if (ret < 0)
17841784
goto failed;
1785-
/* ignored */
1785+
if (infoname && infovalue)
1786+
hwloc__add_info(&topology->infos, infoname, infovalue);
17861787
} else {
17871788
if (hwloc__xml_verbose())
17881789
fprintf(stderr, "%s: ignoring unknown tag `%s' after root object.\n",
@@ -2518,6 +2519,14 @@ hwloc__xml_export_cpukinds(hwloc__xml_export_state_t state, hwloc_topology_t top
25182519
}
25192520
}
25202521

2522+
static void
2523+
hwloc__xml_export_infos(hwloc__xml_export_state_t state, hwloc_topology_t topology)
2524+
{
2525+
unsigned j;
2526+
for(j=0; j<topology->infos.count; j++)
2527+
hwloc__xml_export_info_attr(state, topology->infos.array[j].name, topology->infos.array[j].value);
2528+
}
2529+
25212530
void
25222531
hwloc__xml_export_topology(hwloc__xml_export_state_t state, hwloc_topology_t topology, unsigned long flags)
25232532
{
@@ -2531,6 +2540,7 @@ hwloc__xml_export_topology(hwloc__xml_export_state_t state, hwloc_topology_t top
25312540
hwloc__xml_v2export_support(state, topology);
25322541
hwloc__xml_export_memattrs(state, topology);
25332542
hwloc__xml_export_cpukinds(state, topology);
2543+
hwloc__xml_export_infos(state, topology);
25342544
}
25352545

25362546
void

hwloc/topology.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ hwloc_debug_print_objects(int indent __hwloc_attribute_unused, hwloc_obj_t obj)
461461
#define hwloc_debug_print_objects(indent, obj) do { /* nothing */ } while (0)
462462
#endif /* !HWLOC_DEBUG */
463463

464+
struct hwloc_infos_s * hwloc_topology_get_infos(hwloc_topology_t topology)
465+
{
466+
return &topology->infos;
467+
}
468+
464469
void hwloc__free_infos(struct hwloc_infos_s *infos)
465470
{
466471
unsigned i;
@@ -1206,6 +1211,8 @@ hwloc__topology_dup(hwloc_topology_t *newp,
12061211
if (err < 0)
12071212
goto out_with_topology;
12081213

1214+
hwloc__tma_dup_infos(tma, &new->infos, &old->infos);
1215+
12091216
err = hwloc_internal_distances_dup(new, old);
12101217
if (err < 0)
12111218
goto out_with_topology;
@@ -3830,6 +3837,10 @@ hwloc__topology_init (struct hwloc_topology **topologyp,
38303837
topology->support.membind = hwloc_tma_malloc(tma, sizeof(*topology->support.membind));
38313838
topology->support.misc = hwloc_tma_malloc(tma, sizeof(*topology->support.misc));
38323839

3840+
topology->infos.count = 0;
3841+
topology->infos.allocated = 0;
3842+
topology->infos.array = NULL;
3843+
38333844
topology->nb_levels_allocated = nblevels; /* enough for default 10 levels = Mach+Pack+Die+NUMA+L3+L2+L1d+L1i+Co+PU */
38343845
topology->levels = hwloc_tma_calloc(tma, topology->nb_levels_allocated * sizeof(*topology->levels));
38353846
topology->level_nbobjects = hwloc_tma_calloc(tma, topology->nb_levels_allocated * sizeof(*topology->level_nbobjects));
@@ -4127,6 +4138,8 @@ hwloc_topology_destroy (struct hwloc_topology *topology)
41274138

41284139
hwloc_topology_clear(topology);
41294140

4141+
hwloc__free_infos(&topology->infos);
4142+
41304143
free(topology->levels);
41314144
free(topology->level_nbobjects);
41324145

include/hwloc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,13 @@ enum hwloc_modify_infos_op_e {
12281228
static __hwloc_inline int
12291229
hwloc_obj_add_info(hwloc_obj_t obj, const char *name, const char *value);
12301230

1231+
/** \brief Get the structure of info attributes attached to the topology.
1232+
*
1233+
* \note The function cannot return \c NULL.
1234+
* \note The returned pointer belongs to the hwloc library, it should not be freed or modified.
1235+
*/
1236+
HWLOC_DECLSPEC struct hwloc_infos_s * hwloc_topology_get_infos(hwloc_topology_t topology);
1237+
12311238
/** @} */
12321239

12331240

include/hwloc/diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ typedef union hwloc_topology_diff_u {
138138
hwloc_topology_diff_type_t type; /* must be ::HWLOC_TOPOLOGY_DIFF_OBJ_ATTR */
139139
union hwloc_topology_diff_u * next;
140140
/* List of attribute differences for a single object */
141-
int obj_depth;
141+
int obj_depth; /* topology depth if topology attribute instead of object attribute */
142142
unsigned obj_index;
143143
union hwloc_topology_diff_obj_attr_u diff;
144144
} obj_attr;

include/hwloc/rename.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ extern "C" {
224224
#define HWLOC_MODIFY_INFOS_OP_ADD_UNIQUE HWLOC_NAME_CAPS(MODIFY_INFOS_OP_ADD_UNIQUE)
225225
#define HWLOC_MODIFY_INFOS_OP_REPLACE HWLOC_NAME_CAPS(MODIFY_INFOS_OP_REPLACE)
226226
#define HWLOC_MODIFY_INFOS_OP_REMOVE HWLOC_NAME_CAPS(MODIFY_INFOS_OP_REMOVE)
227+
#define hwloc_topology_get_infos HWLOC_NAME(topology_get_infos)
227228

228229
#define HWLOC_CPUBIND_PROCESS HWLOC_NAME_CAPS(CPUBIND_PROCESS)
229230
#define HWLOC_CPUBIND_THREAD HWLOC_NAME_CAPS(CPUBIND_THREAD)

0 commit comments

Comments
 (0)