Skip to content

Commit c160398

Browse files
committed
synthetic: factorize/fix default attributes
NUMA nodes declared as attached (between []) didn't have the default size (1GB), they remained empty. Signed-off-by: Brice Goglin <[email protected]>
1 parent 577b327 commit c160398

File tree

3 files changed

+41
-29
lines changed

3 files changed

+41
-29
lines changed

hwloc/topology-synthetic.c

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,32 @@ hwloc_synthetic_parse_attrs(const char *attrs, const char **next_posp,
416416
return 0;
417417
}
418418

419+
static void
420+
hwloc_synthetic_set_default_attrs(struct hwloc_synthetic_attr_s *sattr,
421+
int *type_count)
422+
{
423+
hwloc_obj_type_t type = sattr->type;
424+
425+
if (type == HWLOC_OBJ_GROUP) {
426+
if (sattr->depth == (unsigned)-1)
427+
sattr->depth = type_count[HWLOC_OBJ_GROUP]--;
428+
429+
} else if (hwloc__obj_type_is_cache(type)) {
430+
if (!sattr->memorysize) {
431+
if (1 == sattr->depth)
432+
/* 32KiB in L1 */
433+
sattr->memorysize = 32*1024;
434+
else
435+
/* *4 at each level, starting from 1MiB for L2, unified */
436+
sattr->memorysize = 256ULL*1024 << (2*sattr->depth);
437+
}
438+
439+
} else if (type == HWLOC_OBJ_NUMANODE && !sattr->memorysize) {
440+
/* 1GiB in memory nodes. */
441+
sattr->memorysize = 1024*1024*1024;
442+
}
443+
}
444+
419445
/* frees level until arity = 0 */
420446
static void
421447
hwloc_synthetic_free_levels(struct hwloc_synthetic_backend_data_s *data)
@@ -803,30 +829,14 @@ hwloc_backend_synthetic_init(struct hwloc_synthetic_backend_data_s *data,
803829
count++;
804830
}
805831

832+
/* set default attributes that depend on the depth/hierarchy of levels */
806833
for (i=0; i<count; i++) {
834+
struct hwloc_synthetic_attached_s *attached;
807835
struct hwloc_synthetic_level_data_s *curlevel = &data->level[i];
808-
hwloc_obj_type_t type = curlevel->attr.type;
809-
810-
if (type == HWLOC_OBJ_GROUP) {
811-
if (curlevel->attr.depth == (unsigned)-1)
812-
curlevel->attr.depth = type_count[HWLOC_OBJ_GROUP]--;
813-
814-
} else if (hwloc__obj_type_is_cache(type)) {
815-
if (!curlevel->attr.memorysize) {
816-
if (1 == curlevel->attr.depth)
817-
/* 32KiB in L1 */
818-
curlevel->attr.memorysize = 32*1024;
819-
else
820-
/* *4 at each level, starting from 1MiB for L2, unified */
821-
curlevel->attr.memorysize = 256ULL*1024 << (2*curlevel->attr.depth);
822-
}
823-
824-
} else if (type == HWLOC_OBJ_NUMANODE && !curlevel->attr.memorysize) {
825-
/* 1GiB in memory nodes. */
826-
curlevel->attr.memorysize = 1024*1024*1024;
827-
}
828-
829-
hwloc_synthetic_process_indexes(data, &data->level[i].indexes, data->level[i].totalwidth, verbose);
836+
hwloc_synthetic_set_default_attrs(&curlevel->attr, type_count);
837+
for(attached = curlevel->attached; attached != NULL; attached = attached->next)
838+
hwloc_synthetic_set_default_attrs(&attached->attr, type_count);
839+
hwloc_synthetic_process_indexes(data, &curlevel->indexes, curlevel->totalwidth, verbose);
830840
}
831841

832842
hwloc_synthetic_process_indexes(data, &data->numa_attached_indexes, data->numa_attached_nr, verbose);

tests/hwloc/hwloc_synthetic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2022 Inria. All rights reserved.
3+
* Copyright © 2009-2023 Inria. All rights reserved.
44
* Copyright © 2009 Université Bordeaux
55
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -162,8 +162,8 @@ int main(void)
162162
assert(hwloc_get_memory_parents_depth(topology) == HWLOC_TYPE_DEPTH_MULTIPLE);
163163

164164
err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), 0);
165-
assert(err == 114);
166-
err = strcmp("Package:2 [NUMANode(memory=1073741824)] [NUMANode(memory=1048576)] Core:2 [NUMANode(indexes=8,7,5,6,4,3,1,2)] PU:4", buffer);
165+
assert(err == 132);
166+
err = strcmp("Package:2 [NUMANode(memory=1073741824)] [NUMANode(memory=1048576)] Core:2 [NUMANode(memory=1073741824 indexes=8,7,5,6,4,3,1,2)] PU:4", buffer);
167167
assert(!err);
168168

169169
err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_V1);

utils/hwloc/test-hwloc-info.output

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,16 @@ NUMANode L#1 = local memory #0 of PU L#8
388388
memory children = 0
389389
i/o children = 0
390390
misc children = 0
391-
local memory = 0
391+
local memory = 1073741824
392+
total memory = 1073741824
392393
cpuset = 0x0000ff00
393394
complete cpuset = 0x0000ff00
394395
allowed cpuset = 0x0000ff00
395396
nodeset = 0x00000002
396397
complete nodeset = 0x00000002
397398
allowed nodeset = 0x00000002
398399
symmetric subtree = 0
399-
memory attribute Capacity = 0
400+
memory attribute Capacity = 1073741824
400401
memory attribute Locality = 8
401402
NUMANode L#2 = local memory #1 of PU L#8
402403
type = NUMANode
@@ -410,15 +411,16 @@ NUMANode L#2 = local memory #1 of PU L#8
410411
memory children = 0
411412
i/o children = 0
412413
misc children = 0
413-
local memory = 0
414+
local memory = 1073741824
415+
total memory = 1073741824
414416
cpuset = 0x0000ffff
415417
complete cpuset = 0x0000ffff
416418
allowed cpuset = 0x0000ffff
417419
nodeset = 0x00000004
418420
complete nodeset = 0x00000004
419421
allowed nodeset = 0x00000004
420422
symmetric subtree = 0
421-
memory attribute Capacity = 0
423+
memory attribute Capacity = 1073741824
422424
memory attribute Locality = 16
423425

424426
# 2 local-or-larger memories for one PU, silent

0 commit comments

Comments
 (0)