Skip to content

Commit

Permalink
Merge pull request #665 from bgoglin/memorytiersnr
Browse files Browse the repository at this point in the history
`hwloc-info --get-attr "info MemoryTiersNr" topology`
Closes #661
  • Loading branch information
bgoglin committed Apr 30, 2024
2 parents 6242b42 + 0839821 commit f88d3e6
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 12 deletions.
10 changes: 10 additions & 0 deletions doc/hwloc.doxy
Expand Up @@ -2034,6 +2034,10 @@ placed.
These info attributes are attached to the topology itself.

<dl>
<dt>MemoryTiersNr</dt>
<dd>The number of different memory tiers in the topology, if any.
See \ref heteromem.
</dd>
<dt>Backend</dt>
<dd>The name of a hwloc backend/component that added objects in the topology.
If several components were combined, multiple Backend pairs may exist,
Expand Down Expand Up @@ -2574,6 +2578,12 @@ $ hwloc-calc -I 'numa[tier=0]' -p all
2,3
\endverbatim

The number of tiers may be retrieved at looking in topology attributes:
\verbatim
$ hwloc-info --get-attr "info MemoryTiersNr" topology
2
\endverbatim

hwloc-calc and hwloc-bind also have options such as
<tt>\--local-memory</tt> and <tt>\--best-memattr</tt>
to select the best NUMA node among the local ones.
Expand Down
16 changes: 14 additions & 2 deletions hwloc/memattrs.c
@@ -1,5 +1,5 @@
/*
* Copyright © 2020-2023 Inria. All rights reserved.
* Copyright © 2020-2024 Inria. All rights reserved.
* See COPYING in top-level directory.
*/

Expand Down Expand Up @@ -1801,22 +1801,34 @@ hwloc__apply_memory_tiers_subtypes(hwloc_topology_t topology,
if (nr_tiers > 1) {
char tmp[20];
snprintf(tmp, sizeof(tmp), "%u", j);
hwloc__replace_infos(&node->infos, "MemoryTier", tmp);
hwloc__add_info(&node->infos, "MemoryTier", tmp);
}
break; /* each node is in a single tier */
}
}
}
if (nr_tiers > 1) {
char tmp[20];
snprintf(tmp, sizeof(tmp), "%u", nr_tiers);
hwloc__replace_infos(&topology->infos, "MemoryTiersNr", tmp);
}
}

int
hwloc_internal_memattrs_guess_memory_tiers(hwloc_topology_t topology, int force_subtype)
{
struct hwloc_memory_tier_s *tiers;
hwloc_obj_t node = NULL;
unsigned nr_tiers;
unsigned i;
const char *env;

/* removing existing info attrs */
while ((node = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_NUMANODE, node)) != NULL) {
hwloc__remove_infos(&node->infos, "MemoryTier", NULL);
}
hwloc__remove_infos(&topology->infos, "MemoryTiersNr", NULL);

env = getenv("HWLOC_MEMTIERS");
if (env) {
if (!strcmp(env, "none"))
Expand Down
3 changes: 2 additions & 1 deletion hwloc/topology-xml.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2023 Inria. All rights reserved.
* Copyright © 2009-2024 Inria. All rights reserved.
* Copyright © 2009-2011, 2020 Université Bordeaux
* Copyright © 2009-2018 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
Expand Down Expand Up @@ -458,6 +458,7 @@ hwloc__xml_import_obj_info(hwloc_topology_t topology,
if (!strcmp(infoname, "Backend")
|| !strcmp(infoname, "SyntheticDescription")
|| !strcmp(infoname, "LinuxCgroup")
|| !strcmp(infoname, "MemoryTiersNr")
|| !strcmp(infoname, "WindowsBuildEnvironment")
|| !strcmp(infoname, "OSName")
|| !strcmp(infoname, "OSRelease")
Expand Down
6 changes: 3 additions & 3 deletions hwloc/topology.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2023 Inria. All rights reserved.
* Copyright © 2009-2024 Inria. All rights reserved.
* Copyright © 2009-2012, 2020 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* Copyright © 2022 IBM Corporation. All rights reserved.
Expand Down Expand Up @@ -607,8 +607,8 @@ int hwloc__replace_infos(struct hwloc_infos_s *infos,
}
}

static int hwloc__remove_infos(struct hwloc_infos_s *infos,
const char *name, const char *value)
int hwloc__remove_infos(struct hwloc_infos_s *infos,
const char *name, const char *value)
{
struct hwloc_info_s *array = infos->array;
unsigned count = infos->count;
Expand Down
1 change: 1 addition & 0 deletions include/hwloc/rename.h
Expand Up @@ -832,6 +832,7 @@ extern "C" {

#define hwloc__add_info HWLOC_NAME(_add_info)
#define hwloc__replace_infos HWLOC_NAME(_replace_infos)
#define hwloc__remove_infos HWLOC_NAME(_remove_infos)
#define hwloc__move_infos HWLOC_NAME(_move_infos)
#define hwloc__free_infos HWLOC_NAME(_free_infos)
#define hwloc__tma_dup_infos HWLOC_NAME(_tma_dup_infos)
Expand Down
3 changes: 2 additions & 1 deletion include/private/private.h
@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2023 Inria. All rights reserved.
* Copyright © 2009-2024 Inria. All rights reserved.
* Copyright © 2009-2012, 2020 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
*
Expand Down Expand Up @@ -329,6 +329,7 @@ extern hwloc_obj_t hwloc_find_insert_io_parent_by_complete_cpuset(struct hwloc_t

extern int hwloc__add_info(struct hwloc_infos_s *infos, const char *name, const char *value);
extern int hwloc__replace_infos(struct hwloc_infos_s *infos, const char *name, const char *value);
extern int hwloc__remove_infos(struct hwloc_infos_s *infos, const char *name, const char *value);
extern int hwloc__move_infos(struct hwloc_infos_s *dst_infos, struct hwloc_infos_s *src_infos);
extern int hwloc__tma_dup_infos(struct hwloc_tma *tma, struct hwloc_infos_s *dst_infos, struct hwloc_infos_s *src_infos);
extern void hwloc__free_infos(struct hwloc_infos_s *infos);
Expand Down
Expand Up @@ -155,5 +155,5 @@ Memory attribute #2 name `Bandwidth' flags 5
NUMANode L#5 = 90000 from cpuset 0x0f000f00,0x0f000f00 (Group0 L#2)
NUMANode L#6 = 22500 from cpuset 0xf000f000,0xf000f000 (Group0 L#3)
NUMANode L#7 = 90000 from cpuset 0xf000f000,0xf000f000 (Group0 L#3)
Topology infos: Backend=Linux OSName=Linux OSRelease=3.10.0-327.el7.x86_64 OSVersion="#1 SMP Thu Oct 29 17:29:29 EDT 2015" HostName=localhost.localdomain Architecture=x86_64
Topology infos: Backend=Linux OSName=Linux OSRelease=3.10.0-327.el7.x86_64 OSVersion="#1 SMP Thu Oct 29 17:29:29 EDT 2015" HostName=localhost.localdomain Architecture=x86_64 MemoryTiersNr=2
Topology not from this system
2 changes: 1 addition & 1 deletion tests/hwloc/linux/64intel64-fakeKNL-SNC4-hybrid.console
Expand Up @@ -150,5 +150,5 @@ Memory attribute #2 name `Bandwidth' flags 5
NUMANode L#5 = 90000 from cpuset 0x0f000f00,0x0f000f00 (L3 L#2)
NUMANode L#6 = 22500 from cpuset 0xf000f000,0xf000f000 (L3 L#3)
NUMANode L#7 = 90000 from cpuset 0xf000f000,0xf000f000 (L3 L#3)
Topology infos: Backend=Linux OSName=Linux OSRelease=3.10.0-327.el7.x86_64 OSVersion="#1 SMP Thu Oct 29 17:29:29 EDT 2015" HostName=localhost.localdomain Architecture=x86_64
Topology infos: Backend=Linux OSName=Linux OSRelease=3.10.0-327.el7.x86_64 OSVersion="#1 SMP Thu Oct 29 17:29:29 EDT 2015" HostName=localhost.localdomain Architecture=x86_64 MemoryTiersNr=2
Topology not from this system
2 changes: 1 addition & 1 deletion tests/hwloc/linux/fakeheteromemtiers.console
Expand Up @@ -88,5 +88,5 @@ Memory attribute #5 name `WriteBandwidth' flags 5
NUMANode L#4 = 100 from cpuset 0x0000000c (Group0 L#1)
NUMANode L#1 = 100 from cpuset 0x00000003 (Group0 L#0)
NUMANode L#6 = 100 from cpuset 0x00000030 (Group0 L#2)
Topology infos: LinuxCgroup=/ Backend=Linux OSName=Linux OSRelease=5.18.0-rc4 OSVersion="#1 SMP PREEMPT_DYNAMIC Tue Apr 26 11:49:51 CEST 2022" HostName=efi Architecture=x86_64
Topology infos: LinuxCgroup=/ Backend=Linux OSName=Linux OSRelease=5.18.0-rc4 OSVersion="#1 SMP PREEMPT_DYNAMIC Tue Apr 26 11:49:51 CEST 2022" HostName=efi Architecture=x86_64 MemoryTiersNr=3
Topology not from this system
2 changes: 1 addition & 1 deletion tests/hwloc/linux/fakememinitiators-1np2c+1npp+gi.console
Expand Up @@ -83,5 +83,5 @@ Memory attribute #7 name `WriteLatency' flags 6
NUMANode L#3 = 26 from cpuset 0x0000000c (Group0 L#2)
NUMANode L#4 = 26 from cpuset 0x000000c0 (Group0 L#3)
NUMANode L#5 = 77 from cpuset 0x000000cc (Package L#1)
Topology infos: LinuxCgroup=/ Backend=Linux
Topology infos: LinuxCgroup=/ Backend=Linux MemoryTiersNr=2
Topology not from this system
2 changes: 1 addition & 1 deletion tests/hwloc/linux/nvidiagpunumanodes-kept.console
Expand Up @@ -106,5 +106,5 @@ Relative latency matrix (name NUMALatency kind 5) between 8 NUMANodes (depth -3)
1 80 80 80 80 80 10 80 80
2 80 80 80 80 80 80 10 80
3 80 80 80 80 80 80 80 10
Topology infos: LinuxCgroup=/jjh Backend=Linux OSName=Linux OSRelease=4.14.0-49.el7a.bz1553205.page_fault_hang.ppc64le OSVersion="#1 SMP Fri Mar 30 12:06:11 CDT 2018" HostName=c685f8n02 Architecture=ppc64le
Topology infos: LinuxCgroup=/jjh Backend=Linux OSName=Linux OSRelease=4.14.0-49.el7a.bz1553205.page_fault_hang.ppc64le OSVersion="#1 SMP Fri Mar 30 12:06:11 CDT 2018" HostName=c685f8n02 Architecture=ppc64le MemoryTiersNr=2
Topology not from this system

0 comments on commit f88d3e6

Please sign in to comment.