Skip to content

Commit d7a40a4

Browse files
committed
API: add hwloc_infos_s structure in objects
It contains the existing hwloc_info_s array and its length. Signed-off-by: Brice Goglin <[email protected]>
1 parent 37b590b commit d7a40a4

File tree

20 files changed

+100
-87
lines changed

20 files changed

+100
-87
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Version 3.0.0
3434
or "Memory" (for Linux DAX and CXL devices, etc).
3535
+ The "Backend" info attribute of OS devices is now in the topology
3636
root object together with other backends.
37+
+ The array and count of info attributes are now embedded in the new
38+
struct hwloc_infos_s.
3739
* Tools
3840
+ lstopo has a new --osf option to tune the displaying of object
3941
attributes and units.

hwloc/diff.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ hwloc_diff_trees(hwloc_topology_t topo1, hwloc_obj_t obj1,
212212
}
213213

214214
/* infos */
215-
if (obj1->infos_count != obj2->infos_count)
215+
if (obj1->infos.count != obj2->infos.count)
216216
goto out_too_complex;
217-
for(i=0; i<obj1->infos_count; i++) {
218-
struct hwloc_info_s *info1 = &obj1->infos[i], *info2 = &obj2->infos[i];
217+
for(i=0; i<obj1->infos.count; i++) {
218+
struct hwloc_info_s *info1 = &obj1->infos.array[i], *info2 = &obj2->infos.array[i];
219219
if (strcmp(info1->name, info2->name))
220220
goto out_too_complex;
221221
if (strcmp(info1->value, info2->value)) {
@@ -494,8 +494,8 @@ hwloc_apply_diff_one(hwloc_topology_t topology,
494494
const char *newvalue = reverse ? obj_attr->diff.string.oldvalue : obj_attr->diff.string.newvalue;
495495
unsigned i;
496496
int found = 0;
497-
for(i=0; i<obj->infos_count; i++) {
498-
struct hwloc_info_s *info = &obj->infos[i];
497+
for(i=0; i<obj->infos.count; i++) {
498+
struct hwloc_info_s *info = &obj->infos.array[i];
499499
if (!strcmp(info->name, name)
500500
&& !strcmp(info->value, oldvalue)) {
501501
free(info->value);

hwloc/topology-linux.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,7 @@ static int hwloc_linux_get_allowed_resources_hook(hwloc_topology_t topology)
21632163

21642164
hwloc_linux__get_allowed_resources(topology, fsroot_path, root_fd, &cpuset_name);
21652165
if (cpuset_name) {
2166-
hwloc__add_info_nodup(&topology->levels[0][0]->infos, &topology->levels[0][0]->infos_count,
2166+
hwloc__add_info_nodup(&topology->levels[0][0]->infos.array, &topology->levels[0][0]->infos.count,
21672167
"LinuxCgroup", cpuset_name, 1 /* replace */);
21682168
free(cpuset_name);
21692169
}
@@ -4884,7 +4884,7 @@ look_sysfscpu(struct hwloc_topology *topology,
48844884
if (cpuinfo_Lprocs) {
48854885
for(j=0; j<(int) cpuinfo_numprocs; j++)
48864886
if ((int) cpuinfo_Lprocs[j].Pproc == i) {
4887-
hwloc__move_infos(&package->infos, &package->infos_count,
4887+
hwloc__move_infos(&package->infos.array, &package->infos.count,
48884888
&cpuinfo_Lprocs[j].infos, &cpuinfo_Lprocs[j].infos_count);
48894889
}
48904890
}
@@ -5825,7 +5825,7 @@ hwloc_linuxfs_look_cpu(struct hwloc_backend *backend, struct hwloc_disc_status *
58255825
goto cpudone;
58265826

58275827
/* setup root info */
5828-
hwloc__move_infos(&hwloc_get_root_obj(topology)->infos, &hwloc_get_root_obj(topology)->infos_count,
5828+
hwloc__move_infos(&hwloc_get_root_obj(topology)->infos.array, &hwloc_get_root_obj(topology)->infos.count,
58295829
&global_infos, &global_infos_count);
58305830

58315831
/* sysfs */
@@ -6986,7 +6986,7 @@ hwloc__get_firmware_dmi_memory_info_one(struct hwloc_topology *topology,
69866986

69876987
misc->subtype = strdup("MemoryModule");
69886988

6989-
hwloc__move_infos(&misc->infos, &misc->infos_count, &infos, &infos_count);
6989+
hwloc__move_infos(&misc->infos.array, &misc->infos.count, &infos, &infos_count);
69906990
/* FIXME: find a way to identify the corresponding NUMA node and attach these objects there.
69916991
* but it means we need to parse DeviceLocation=DIMM_B4 but these vary significantly
69926992
* with the vendor, and it's hard to be 100% sure 'B' is second socket.

hwloc/topology-x86.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -915,19 +915,19 @@ hwloc_x86_add_cpuinfos(hwloc_obj_t obj, struct procinfo *info, int replace)
915915
{
916916
char number[12];
917917
if (info->cpuvendor[0])
918-
hwloc__add_info_nodup(&obj->infos, &obj->infos_count, "CPUVendor", info->cpuvendor, replace);
918+
hwloc__add_info_nodup(&obj->infos.array, &obj->infos.count, "CPUVendor", info->cpuvendor, replace);
919919
snprintf(number, sizeof(number), "%u", info->cpufamilynumber);
920-
hwloc__add_info_nodup(&obj->infos, &obj->infos_count, "CPUFamilyNumber", number, replace);
920+
hwloc__add_info_nodup(&obj->infos.array, &obj->infos.count, "CPUFamilyNumber", number, replace);
921921
snprintf(number, sizeof(number), "%u", info->cpumodelnumber);
922-
hwloc__add_info_nodup(&obj->infos, &obj->infos_count, "CPUModelNumber", number, replace);
922+
hwloc__add_info_nodup(&obj->infos.array, &obj->infos.count, "CPUModelNumber", number, replace);
923923
if (info->cpumodel[0]) {
924924
const char *c = info->cpumodel;
925925
while (*c == ' ')
926926
c++;
927-
hwloc__add_info_nodup(&obj->infos, &obj->infos_count, "CPUModel", c, replace);
927+
hwloc__add_info_nodup(&obj->infos.array, &obj->infos.count, "CPUModel", c, replace);
928928
}
929929
snprintf(number, sizeof(number), "%u", info->cpustepping);
930-
hwloc__add_info_nodup(&obj->infos, &obj->infos_count, "CPUStepping", number, replace);
930+
hwloc__add_info_nodup(&obj->infos.array, &obj->infos.count, "CPUStepping", number, replace);
931931
}
932932

933933
static void

hwloc/topology-xml.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,19 +1832,19 @@ hwloc_look_xml(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus)
18321832
if (data->version_major <= 2) {
18331833
unsigned i;
18341834
/* check if root already has some backend info */
1835-
for(i=0; i<root->infos_count; i++)
1836-
if (!strcmp(root->infos[i].name, "Backend")) {
1837-
if (!strcmp(root->infos[i].value, "CUDA"))
1835+
for(i=0; i<root->infos.count; i++)
1836+
if (!strcmp(root->infos.array[i].name, "Backend")) {
1837+
if (!strcmp(root->infos.array[i].value, "CUDA"))
18381838
data->need_cuda_backend_info = 0;
1839-
if (!strcmp(root->infos[i].value, "NVML"))
1839+
if (!strcmp(root->infos.array[i].value, "NVML"))
18401840
data->need_nvml_backend_info = 0;
1841-
if (!strcmp(root->infos[i].value, "RSMI"))
1841+
if (!strcmp(root->infos.array[i].value, "RSMI"))
18421842
data->need_rsmi_backend_info = 0;
1843-
if (!strcmp(root->infos[i].value, "LevelZero"))
1843+
if (!strcmp(root->infos.array[i].value, "LevelZero"))
18441844
data->need_levelzero_backend_info = 0;
1845-
if (!strcmp(root->infos[i].value, "OpenCL"))
1845+
if (!strcmp(root->infos.array[i].value, "OpenCL"))
18461846
data->need_opencl_backend_info = 0;
1847-
if (!strcmp(root->infos[i].value, "GL"))
1847+
if (!strcmp(root->infos.array[i].value, "GL"))
18481848
data->need_gl_backend_info = 0;
18491849
}
18501850
/* add missing backend info */
@@ -2197,8 +2197,8 @@ hwloc__xml_export_object_contents (hwloc__xml_export_state_t state, hwloc_topolo
21972197
break;
21982198
}
21992199

2200-
for(i=0; i<obj->infos_count; i++)
2201-
hwloc__xml_export_info_attr(state, obj->infos[i].name, obj->infos[i].value);
2200+
for(i=0; i<obj->infos.count; i++)
2201+
hwloc__xml_export_info_attr(state, obj->infos.array[i].name, obj->infos.array[i].value);
22022202

22032203
if (v2export && obj->type == HWLOC_OBJ_OS_DEVICE && obj->subtype && !hwloc_obj_get_info_by_name(obj, "Backend")) {
22042204
/* v2 gpus had Backend inside the object itself */

hwloc/topology.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ int hwloc__move_infos(struct hwloc_info_s **dst_infosp, unsigned *dst_countp,
566566

567567
int hwloc_obj_add_info(hwloc_obj_t obj, const char *name, const char *value)
568568
{
569-
return hwloc__add_info(&obj->infos, &obj->infos_count, name, value);
569+
return hwloc__add_info(&obj->infos.array, &obj->infos.count, name, value);
570570
}
571571

572572
/* This function may be called with topology->tma set, it cannot free() or realloc() */
@@ -610,7 +610,7 @@ hwloc__free_object_contents(hwloc_obj_t obj)
610610
default:
611611
break;
612612
}
613-
hwloc__free_infos(obj->infos, obj->infos_count);
613+
hwloc__free_infos(obj->infos.array, obj->infos.count);
614614
free(obj->attr);
615615
free(obj->children);
616616
free(obj->subtype);
@@ -915,7 +915,7 @@ hwloc__duplicate_object(struct hwloc_topology *newtopology,
915915
newobj->nodeset = hwloc_bitmap_tma_dup(tma, src->nodeset);
916916
newobj->complete_nodeset = hwloc_bitmap_tma_dup(tma, src->complete_nodeset);
917917

918-
hwloc__tma_dup_infos(tma, &newobj->infos, &newobj->infos_count, src->infos, src->infos_count);
918+
hwloc__tma_dup_infos(tma, &newobj->infos.array, &newobj->infos.count, src->infos.array, src->infos.count);
919919

920920
/* find our level */
921921
if (src->depth < 0) {
@@ -1357,10 +1357,10 @@ merge_insert_equal(hwloc_obj_t new, hwloc_obj_t old)
13571357
if (old->os_index == HWLOC_UNKNOWN_INDEX)
13581358
old->os_index = new->os_index;
13591359

1360-
if (new->infos_count) {
1360+
if (new->infos.count) {
13611361
/* FIXME: dedup */
1362-
hwloc__move_infos(&old->infos, &old->infos_count,
1363-
&new->infos, &new->infos_count);
1362+
hwloc__move_infos(&old->infos.array, &old->infos.count,
1363+
&new->infos.array, &new->infos.count);
13641364
}
13651365

13661366
if (new->name && !old->name) {

hwloc/traversal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,8 @@ hwloc_obj_attr_snprintf(char * __hwloc_restrict string, size_t size, hwloc_obj_t
705705
/* printf infos */
706706
if (verbose) {
707707
unsigned i;
708-
for(i=0; i<obj->infos_count; i++) {
709-
struct hwloc_info_s *info = &obj->infos[i];
708+
for(i=0; i<obj->infos.count; i++) {
709+
struct hwloc_info_s *info = &obj->infos.array[i];
710710
const char *quote;
711711
if (strchr(info->value, ' '))
712712
quote = "\"";

include/hwloc.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,25 @@ HWLOC_DECLSPEC int hwloc_compare_types (hwloc_obj_type_t type1, hwloc_obj_type_t
416416

417417
union hwloc_obj_attr_u;
418418

419+
/** \brief Info attribute (name and value strings)
420+
* \sa hwlocality_info_attr
421+
*/
422+
struct hwloc_info_s {
423+
char *name; /**< \brief Info name */
424+
char *value; /**< \brief Info value */
425+
};
426+
427+
/** \brief Array of string info attributes (pairs of name and value).
428+
*
429+
* These structures may only be modified with hwloc_obj_add_info().
430+
*
431+
* \sa hwlocality_info_attr
432+
*/
433+
struct hwloc_infos_s {
434+
struct hwloc_info_s *array; /**< \brief Array of string pairs */
435+
unsigned count; /**< \brief Number of elements in the array. */
436+
};
437+
419438
/** \brief Structure of a topology object
420439
*
421440
* Applications must not modify any field except \p hwloc_obj.userdata.
@@ -602,8 +621,7 @@ struct hwloc_obj {
602621
* \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
603622
*/
604623

605-
struct hwloc_info_s *infos; /**< \brief Array of info attributes (name and value strings). */
606-
unsigned infos_count; /**< \brief Size of infos array. */
624+
struct hwloc_infos_s infos; /**< \brief Array of info attributes (name and value strings). */
607625

608626
/* misc */
609627
void *userdata; /**< \brief Application-given private data pointer,
@@ -687,15 +705,6 @@ union hwloc_obj_attr_u {
687705
} osdev;
688706
};
689707

690-
/** \brief Object info attribute (name and value strings)
691-
*
692-
* \sa hwlocality_info_attr
693-
*/
694-
struct hwloc_info_s {
695-
char *name; /**< \brief Info name */
696-
char *value; /**< \brief Info value */
697-
};
698-
699708
/** @} */
700709

701710

include/hwloc/inlines.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2018 Inria. All rights reserved.
3+
* Copyright © 2009-2022 Inria. All rights reserved.
44
* Copyright © 2009-2012 Université Bordeaux
55
* Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -111,8 +111,9 @@ static __hwloc_inline const char *
111111
hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name)
112112
{
113113
unsigned i;
114-
for(i=0; i<obj->infos_count; i++) {
115-
struct hwloc_info_s *info = &obj->infos[i];
114+
struct hwloc_infos_s *infos = &obj->infos;
115+
for(i=0; i<obj->infos.count; i++) {
116+
struct hwloc_info_s *info = &infos->array[i];
116117
if (!strcmp(info->name, name))
117118
return info->value;
118119
}

include/hwloc/rename.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ extern "C" {
9898
#define hwloc_obj_t HWLOC_NAME(obj_t)
9999

100100
#define hwloc_info_s HWLOC_NAME(info_s)
101+
#define hwloc_infos_s HWLOC_NAME(infos_s)
101102

102103
#define hwloc_obj_attr_u HWLOC_NAME(obj_attr_u)
103104
#define hwloc_numanode_attr_s HWLOC_NAME(numanode_attr_s)

0 commit comments

Comments
 (0)