Skip to content

Commit a03b7f3

Browse files
committed
core: use the new internal hwloc__replace_infos() and remove add_info_nodup()
And clarify that callers may always call replace, even if the info doesn't exist yet. Signed-off-by: Brice Goglin <[email protected]>
1 parent 5cb289d commit a03b7f3

File tree

5 files changed

+20
-47
lines changed

5 files changed

+20
-47
lines changed

hwloc/topology-linux.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,8 +2163,8 @@ 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,
2167-
"LinuxCgroup", cpuset_name, 1 /* replace */);
2166+
hwloc__replace_infos(&topology->levels[0][0]->infos,
2167+
"LinuxCgroup", cpuset_name);
21682168
free(cpuset_name);
21692169
}
21702170
if (root_fd != -1)
@@ -5238,7 +5238,7 @@ hwloc_linux_parse_cpuinfo_ppc(const char *prefix, const char *value,
52385238
hwloc__add_info(infos, "PlatformName", value);
52395239
} else if (!strcmp("model", prefix)) {
52405240
if (value[0])
5241-
hwloc__add_info(infos, "PlatformModel", value);
5241+
hwloc__replace_infos(infos, "PlatformModel", value);
52425242
}
52435243
/* platform-specific fields */
52445244
else if (!strcasecmp("vendor", prefix)) {
@@ -5251,7 +5251,7 @@ hwloc_linux_parse_cpuinfo_ppc(const char *prefix, const char *value,
52515251
|| !strcasecmp("Machine", prefix)) {
52525252
/* machine and board are similar (and often more precise) than model above */
52535253
if (value[0])
5254-
hwloc__add_info_nodup(infos, "PlatformModel", value, 1);
5254+
hwloc__replace_infos(infos, "PlatformModel", value);
52555255
} else if (!strcasecmp("Revision", prefix)
52565256
|| !strcmp("Hardware rev", prefix)) {
52575257
if (value[0])
@@ -5303,7 +5303,7 @@ hwloc_linux_parse_cpuinfo_generic(const char *prefix, const char *value,
53035303
* we should have the Architecture keypair for basic information anyway.
53045304
*/
53055305
if (value[0])
5306-
hwloc__add_info_nodup(infos, "CPUModel", value, 1);
5306+
hwloc__replace_infos(infos, "CPUModel", value);
53075307
}
53085308
return 0;
53095309
}

hwloc/topology-x86.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -911,23 +911,24 @@ static void look_proc(struct hwloc_backend *backend, struct procinfo *infos, uns
911911
}
912912

913913
static void
914-
hwloc_x86_add_cpuinfos(hwloc_obj_t obj, struct procinfo *info, int replace)
914+
hwloc_x86_add_cpuinfos(hwloc_obj_t obj, struct procinfo *info)
915915
{
916+
/* these attributes may have been set by somebody else earlier, so always try to replace */
916917
char number[12];
917918
if (info->cpuvendor[0])
918-
hwloc__add_info_nodup(&obj->infos, "CPUVendor", info->cpuvendor, replace);
919+
hwloc__replace_infos(&obj->infos, "CPUVendor", info->cpuvendor);
919920
snprintf(number, sizeof(number), "%u", info->cpufamilynumber);
920-
hwloc__add_info_nodup(&obj->infos, "CPUFamilyNumber", number, replace);
921+
hwloc__replace_infos(&obj->infos, "CPUFamilyNumber", number);
921922
snprintf(number, sizeof(number), "%u", info->cpumodelnumber);
922-
hwloc__add_info_nodup(&obj->infos, "CPUModelNumber", number, replace);
923+
hwloc__replace_infos(&obj->infos, "CPUModelNumber", number);
923924
if (info->cpumodel[0]) {
924925
const char *c = info->cpumodel;
925926
while (*c == ' ')
926927
c++;
927-
hwloc__add_info_nodup(&obj->infos, "CPUModel", c, replace);
928+
hwloc__replace_infos(&obj->infos, "CPUModel", c);
928929
}
929930
snprintf(number, sizeof(number), "%u", info->cpustepping);
930-
hwloc__add_info_nodup(&obj->infos, "CPUStepping", number, replace);
931+
hwloc__replace_infos(&obj->infos, "CPUStepping", number);
931932
}
932933

933934
static void
@@ -1037,7 +1038,7 @@ static void summarize(struct hwloc_backend *backend, struct procinfo *infos, uns
10371038
package = hwloc_alloc_setup_object(topology, HWLOC_OBJ_PACKAGE, packageid);
10381039
package->cpuset = package_cpuset;
10391040

1040-
hwloc_x86_add_cpuinfos(package, &infos[i], 0);
1041+
hwloc_x86_add_cpuinfos(package, &infos[i]);
10411042

10421043
hwloc_debug_1arg_bitmap("os package %u has cpuset %s\n",
10431044
packageid, package_cpuset);
@@ -1050,12 +1051,12 @@ static void summarize(struct hwloc_backend *backend, struct procinfo *infos, uns
10501051
package = hwloc_get_next_obj_covering_cpuset_by_type(topology, set, HWLOC_OBJ_PACKAGE, NULL);
10511052
hwloc_bitmap_free(set);
10521053
if (package) {
1053-
/* Found package above that PU, annotate if no such attribute yet */
1054-
hwloc_x86_add_cpuinfos(package, &infos[i], 1);
1054+
/* Found package above that PU, annotate */
1055+
hwloc_x86_add_cpuinfos(package, &infos[i]);
10551056
hwloc_bitmap_andnot(remaining_cpuset, remaining_cpuset, package->cpuset);
10561057
} else {
10571058
/* No package, annotate the root object */
1058-
hwloc_x86_add_cpuinfos(hwloc_get_root_obj(topology), &infos[i], 1);
1059+
hwloc_x86_add_cpuinfos(hwloc_get_root_obj(topology), &infos[i]);
10591060
break;
10601061
}
10611062
}

hwloc/topology.c

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -540,36 +540,8 @@ static int hwloc__add_info_unique(struct hwloc_infos_s *infos, const char *name,
540540
return hwloc__add_info(infos, name, value);
541541
}
542542

543-
int hwloc__add_info_nodup(struct hwloc_infos_s *infos,
544-
const char *name, const char *value,
545-
int replace)
546-
{
547-
struct hwloc_info_s *array = infos->array;
548-
unsigned count = infos->count;
549-
unsigned i;
550-
551-
if (!name || !value) {
552-
errno = EINVAL;
553-
return -1;
554-
}
555-
556-
for(i=0; i<count; i++) {
557-
if (!strcmp(array[i].name, name)) {
558-
if (replace) {
559-
char *new = strdup(value);
560-
if (!new)
561-
return -1;
562-
free(array[i].value);
563-
array[i].value = new;
564-
}
565-
return 0;
566-
}
567-
}
568-
return hwloc__add_info(infos, name, value);
569-
}
570-
571-
static int hwloc__replace_infos(struct hwloc_infos_s *infos,
572-
const char *name, const char *value)
543+
int hwloc__replace_infos(struct hwloc_infos_s *infos,
544+
const char *name, const char *value)
573545
{
574546
struct hwloc_info_s *array = infos->array;
575547
unsigned count = infos->count;

include/hwloc/rename.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ extern "C" {
833833
#define hwloc_find_insert_io_parent_by_complete_cpuset HWLOC_NAME(hwloc_find_insert_io_parent_by_complete_cpuset)
834834

835835
#define hwloc__add_info HWLOC_NAME(_add_info)
836-
#define hwloc__add_info_nodup HWLOC_NAME(_add_info_nodup)
836+
#define hwloc__replace_infos HWLOC_NAME(_replace_infos)
837837
#define hwloc__move_infos HWLOC_NAME(_move_infos)
838838
#define hwloc__free_infos HWLOC_NAME(_free_infos)
839839
#define hwloc__tma_dup_infos HWLOC_NAME(_tma_dup_infos)

include/private/private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ extern void hwloc_pci_discovery_exit(struct hwloc_topology *topology);
326326
extern hwloc_obj_t hwloc_find_insert_io_parent_by_complete_cpuset(struct hwloc_topology *topology, hwloc_cpuset_t cpuset);
327327

328328
extern int hwloc__add_info(struct hwloc_infos_s *infos, const char *name, const char *value);
329-
extern int hwloc__add_info_nodup(struct hwloc_infos_s *infos, const char *name, const char *value, int replace);
329+
extern int hwloc__replace_infos(struct hwloc_infos_s *infos, const char *name, const char *value);
330330
extern int hwloc__move_infos(struct hwloc_infos_s *dst_infos, struct hwloc_infos_s *src_infos);
331331
extern int hwloc__tma_dup_infos(struct hwloc_tma *tma, struct hwloc_infos_s *dst_infos, struct hwloc_infos_s *src_infos);
332332
extern void hwloc__free_infos(struct hwloc_infos_s *infos);

0 commit comments

Comments
 (0)