Skip to content

Commit

Permalink
hwloc-annotate: add a command to change cache/memory sizes
Browse files Browse the repository at this point in the history
Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Oct 12, 2021
1 parent c69e0ad commit a7f283b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion NEWS
Expand Up @@ -36,7 +36,8 @@ Version 2.6.0
* Tools
+ lstopo has a better placement algorithm with respect to I/O
objects, see --children-order in the manpage for details.
+ hwloc-annotate may now change object subtypes.
+ hwloc-annotate may now change object subtypes and cache or memory
sizes.
* Build
+ Allow to specify the ROCm installation for building the RSMI backend:
- Use a custom installation path if specified with --with-rocm=<dir>.
Expand Down
4 changes: 4 additions & 0 deletions utils/hwloc/hwloc-annotate.1in
Expand Up @@ -85,6 +85,10 @@ value is \fIvalue\fR.
Specifies that the subtype attribute of the object should now be \fIsubtype\fR.
If an empty string is given, the subtype is removed.
.TP
.B size <size>
Specifies the size of a cache or NUMA node.
The value may be suffixed with \fBkB\fR, \fBMB\fR, \fBGB\fR or \fBTB\fR.
.TP
.B misc <name>
Specifies a new Misc object name.
.TP
Expand Down
26 changes: 26 additions & 0 deletions utils/hwloc/hwloc-annotate.c
Expand Up @@ -21,6 +21,7 @@ void usage(const char *callname __hwloc_attribute_unused, FILE *where)
fprintf(where, " <annotation> may be:\n");
fprintf(where, " info <name> <value>\n");
fprintf(where, " subtype <subtype>\n");
fprintf(where, " size <memory or cache size>\n");
fprintf(where, " misc <name>\n");
fprintf(where, " distances <filename> [<flags>]\n");
fprintf(where, " memattr <name> <flags>\n");
Expand All @@ -43,6 +44,7 @@ void usage(const char *callname __hwloc_attribute_unused, FILE *where)

static char *infoname = NULL, *infovalue = NULL;
static char *subtype = NULL;
static unsigned long long sizevalue = ~0ULL;
static char *miscname = NULL;
static char *distancesfilename = NULL;

Expand Down Expand Up @@ -130,6 +132,12 @@ static void apply(hwloc_topology_t topology, hwloc_obj_t obj)
else
obj->subtype = strdup(subtype);
}
if (sizevalue != ~0ULL) {
if (obj->type == HWLOC_OBJ_NUMANODE)
obj->attr->numanode.local_memory = sizevalue;
else if (hwloc_obj_type_is_cache(obj->type) || obj->type == HWLOC_OBJ_MEMCACHE)
obj->attr->cache.size = sizevalue;
}
if (miscname)
hwloc_topology_insert_misc_object(topology, obj, miscname);
if (mavname) {
Expand Down Expand Up @@ -584,6 +592,24 @@ int main(int argc, char *argv[])
}
subtype = argv[1];

} else if (!strcmp(argv[0], "size")) {
char *end;
if (argc < 2) {
usage(callname, stderr);
exit(EXIT_FAILURE);
}
sizevalue = strtoull(argv[1], &end, 0);
if (end) {
if (!strcasecmp(end, "kB"))
sizevalue <<= 10;
else if (!strcasecmp(end, "MB"))
sizevalue <<= 20;
if (!strcasecmp(end, "GB"))
sizevalue <<= 30;
if (!strcasecmp(end, "TB"))
sizevalue <<= 40;
}

} else if (!strcmp(argv[0], "misc")) {
if (argc < 2) {
usage(callname, stderr);
Expand Down

0 comments on commit a7f283b

Please sign in to comment.