Skip to content

Commit 18a7005

Browse files
committed
linux/cpukinds: factorize the registration of a single cpukind
Signed-off-by: Brice Goglin <[email protected]>
1 parent 60f2031 commit 18a7005

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

hwloc/topology-linux.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4498,6 +4498,24 @@ hwloc_linux_cpukinds_compar(const void *_a, const void *_b)
44984498
return a->value - b->value;
44994499
}
45004500

4501+
static void
4502+
hwloc_linux_cpukinds_register_one(struct hwloc_topology *topology,
4503+
hwloc_bitmap_t cpuset,
4504+
int efficiency,
4505+
char *infoname,
4506+
char *infovalue)
4507+
{
4508+
struct hwloc_info_s infoattr;
4509+
struct hwloc_infos_s infos;
4510+
infoattr.name = infoname;
4511+
infoattr.value = infovalue;
4512+
infos.array = &infoattr;
4513+
infos.count = 1;
4514+
infos.allocated = 0;
4515+
hwloc_internal_cpukinds_register(topology, cpuset, efficiency, &infos, 0);
4516+
/* the cpuset is given to the callee */
4517+
}
4518+
45014519
static void
45024520
hwloc_linux_cpukinds_register(struct hwloc_linux_cpukinds *cpukinds,
45034521
struct hwloc_topology *topology,
@@ -4510,19 +4528,12 @@ hwloc_linux_cpukinds_register(struct hwloc_linux_cpukinds *cpukinds,
45104528
qsort(cpukinds->sets, cpukinds->nr_sets, sizeof(*cpukinds->sets), hwloc_linux_cpukinds_compar);
45114529

45124530
for(i=0; i<cpukinds->nr_sets; i++) {
4513-
struct hwloc_info_s infoattr;
4514-
struct hwloc_infos_s infos;
45154531
char value[32];
4516-
infoattr.name = (char *) name;
4517-
infoattr.value = value;
4518-
infos.array = &infoattr;
4519-
infos.count = 1;
4520-
infos.allocated = 0;
45214532
snprintf(value, sizeof(value), "%lu", cpukinds->sets[i].value);
45224533
/* value (at least cpu_capacity) may be > INT_MAX, too large for a forced_efficiency, hence use i instead */
4523-
hwloc_internal_cpukinds_register(topology, cpukinds->sets[i].cpuset,
4524-
forced_efficiency ? (int) i : HWLOC_CPUKIND_EFFICIENCY_UNKNOWN,
4525-
&infos, 0);
4534+
hwloc_linux_cpukinds_register_one(topology, cpukinds->sets[i].cpuset,
4535+
forced_efficiency ? (int) i : HWLOC_CPUKIND_EFFICIENCY_UNKNOWN,
4536+
(char *) name, value);
45264537
/* the cpuset is given to the callee */
45274538
cpukinds->sets[i].cpuset = NULL;
45284539
}
@@ -4694,27 +4705,17 @@ look_sysfscpukinds(struct hwloc_topology *topology,
46944705
atom_pmu_set = hwloc__alloc_read_path_as_cpulist("/sys/devices/cpu_atom/cpus", data->root_fd);
46954706
core_pmu_set = hwloc__alloc_read_path_as_cpulist("/sys/devices/cpu_core/cpus", data->root_fd);
46964707
if (atom_pmu_set) {
4697-
struct hwloc_infos_s infos;
4698-
struct hwloc_info_s infoattr;
4699-
infoattr.name = (char *) "CoreType";
4700-
infoattr.value = (char *) "IntelAtom";
4701-
infos.array = &infoattr;
4702-
infos.count = 1;
4703-
infos.allocated = 0;
4704-
hwloc_internal_cpukinds_register(topology, atom_pmu_set, HWLOC_CPUKIND_EFFICIENCY_UNKNOWN, &infos, 0);
4708+
hwloc_linux_cpukinds_register_one(topology, atom_pmu_set,
4709+
HWLOC_CPUKIND_EFFICIENCY_UNKNOWN,
4710+
(char *) "CoreType", (char *) "IntelAtom");
47054711
/* the cpuset is given to the callee */
47064712
} else {
47074713
hwloc_bitmap_free(atom_pmu_set);
47084714
}
47094715
if (core_pmu_set) {
4710-
struct hwloc_infos_s infos;
4711-
struct hwloc_info_s infoattr;
4712-
infoattr.name = (char *) "CoreType";
4713-
infoattr.value = (char *) "IntelCore";
4714-
infos.array = &infoattr;
4715-
infos.count = 1;
4716-
infos.allocated = 0;
4717-
hwloc_internal_cpukinds_register(topology, core_pmu_set, HWLOC_CPUKIND_EFFICIENCY_UNKNOWN, &infos, 0);
4716+
hwloc_linux_cpukinds_register_one(topology, core_pmu_set,
4717+
HWLOC_CPUKIND_EFFICIENCY_UNKNOWN,
4718+
(char *) "CoreType", (char *) "IntelCore");
47184719
/* the cpuset is given to the callee */
47194720
} else {
47204721
hwloc_bitmap_free(core_pmu_set);

0 commit comments

Comments
 (0)