-
Notifications
You must be signed in to change notification settings - Fork 168
/
memtiers.c
223 lines (195 loc) · 7.08 KB
/
memtiers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* Copyright © 2020-2023 Inria. All rights reserved.
* See COPYING in top-level directory.
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "hwloc.h"
static void
add_local_bw(hwloc_topology_t topo, hwloc_obj_t node, hwloc_uint64_t bw)
{
struct hwloc_location initiator;
initiator.type = HWLOC_LOCATION_TYPE_CPUSET;
initiator.location.cpuset = node->cpuset;
hwloc_memattr_set_value(topo, HWLOC_MEMATTR_ID_BANDWIDTH, node, &initiator, 0, bw);
}
static void
add_daxtype(hwloc_topology_t topo __hwloc_attribute_unused, hwloc_obj_t node, const char *daxtype)
{
hwloc_obj_add_info(node, "DAXType", daxtype);
}
static void
check_subtypes(hwloc_topology_t topo,
const char *rootnsubtype,
const char *pack1n1subtype,
const char *pack1n2subtype,
const char *pack2n1subtype,
const char *pack2n2subtype)
{
hwloc_obj_t root, rootn, pack1n1, pack1n2, pack2n1, pack2n2;
root = hwloc_get_root_obj(topo);
rootn = root->memory_first_child;
pack1n1 = root->first_child->memory_first_child;
pack1n2 = root->first_child->memory_first_child->next_sibling;
pack2n1 = root->last_child->memory_first_child;
pack2n2 = root->last_child->memory_first_child->next_sibling;
printf(" Expected %s %s %s %s %s\n", rootnsubtype, pack1n1subtype, pack1n2subtype, pack2n1subtype, pack2n2subtype);
printf(" Found %s %s %s %s %s\n", rootn->subtype, pack1n1->subtype, pack1n2->subtype, pack2n1->subtype, pack2n2->subtype);
if (rootnsubtype) {
assert(rootn->subtype);
assert(!strcmp(rootnsubtype, rootn->subtype));
} else {
assert(!rootn->subtype);
}
if (pack1n1subtype) {
assert(pack1n1->subtype);
assert(!strcmp(pack1n1subtype, pack1n1->subtype));
} else {
assert(!pack1n1->subtype);
}
if (pack1n2subtype) {
assert(pack1n2->subtype);
assert(!strcmp(pack1n2subtype, pack1n2->subtype));
} else {
assert(!pack1n2->subtype);
}
if (pack2n1subtype) {
assert(pack2n1->subtype);
assert(!strcmp(pack2n1subtype, pack2n1->subtype));
} else {
assert(!pack2n1->subtype);
}
if (pack2n2subtype) {
assert(pack2n2->subtype);
assert(!strcmp(pack2n2subtype, pack2n2->subtype));
} else {
assert(!pack2n2->subtype);
}
}
int
main(void)
{
hwloc_topology_t topology, new;
hwloc_obj_t root, rootn, pack1n1, pack1n2, pack2n1, pack2n2;
char *xmlbuffer;
int buflen;
int err;
printf("creating topology...\n");
err = hwloc_topology_init(&topology);
assert(!err);
err = hwloc_topology_set_synthetic(topology, "[numa] pack:2 [numa] [numa] pu:2");
assert(!err);
err = hwloc_topology_load(topology);
assert(!err);
printf("marking some nodes as NVM or SPM\n");
root = hwloc_get_root_obj(topology);
rootn = root->memory_first_child;
pack1n1 = root->first_child->memory_first_child;
pack1n2 = root->first_child->memory_first_child->next_sibling;
pack2n1 = root->last_child->memory_first_child;
pack2n2 = root->last_child->memory_first_child->next_sibling;
add_daxtype(topology, rootn, "NVM");
add_daxtype(topology, pack1n2, "SPM");
add_daxtype(topology, pack2n2, "SPM");
printf("checking subtypes aren't set\n");
check_subtypes(topology, NULL, NULL, NULL, NULL, NULL);
hwloc_topology_export_xmlbuffer(topology, &xmlbuffer, &buflen, 0);
printf("checking NVM and SPM subtypes are set on XML reload\n");
err = hwloc_topology_init(&new);
assert(!err);
err = hwloc_topology_set_xmlbuffer(new, xmlbuffer, buflen);
assert(!err);
err = hwloc_topology_load(new);
assert(!err);
check_subtypes(new, "NVM", NULL, "SPM", NULL, "SPM");
hwloc_topology_destroy(new);
printf("checking HBM subtypes are set on XML reload if HWLOC_MEMTIERS_GUESS=spm_is_hbm\n");
putenv((char*)"HWLOC_MEMTIERS_GUESS=spm_is_hbm");
err = hwloc_topology_init(&new);
assert(!err);
err = hwloc_topology_set_xmlbuffer(new, xmlbuffer, buflen);
assert(!err);
err = hwloc_topology_load(new);
assert(!err);
check_subtypes(new, "NVM", NULL, "HBM", NULL, "HBM");
hwloc_topology_destroy(new);
free(xmlbuffer);
printf("adding correct BW values\n");
add_local_bw(topology, rootn, 100);
add_local_bw(topology, pack1n1, 1000);
add_local_bw(topology, pack1n2, 10000);
add_local_bw(topology, pack2n1, 1000);
add_local_bw(topology, pack2n2, 10000);
hwloc_topology_export_xmlbuffer(topology, &xmlbuffer, &buflen, 0);
printf("checking DRAM and HBM subtypes are set on XML reload\n");
putenv((char*)"HWLOC_MEMTIERS_GUESS=default");
err = hwloc_topology_init(&new);
assert(!err);
err = hwloc_topology_set_xmlbuffer(new, xmlbuffer, buflen);
assert(!err);
err = hwloc_topology_load(new);
assert(!err);
check_subtypes(new, "NVM", "DRAM", "HBM", "DRAM", "HBM");
hwloc_topology_destroy(new);
printf("checking DRAM and HBM subtypes aren't set anymore on XML reload if HWLOC_MEMTIERS_GUESS=none\n");
putenv((char*)"HWLOC_MEMTIERS_GUESS=none");
err = hwloc_topology_init(&new);
assert(!err);
err = hwloc_topology_set_xmlbuffer(new, xmlbuffer, buflen);
assert(!err);
err = hwloc_topology_load(new);
assert(!err);
check_subtypes(new, "NVM", NULL, "SPM", NULL, "SPM");
hwloc_topology_destroy(new);
printf("checking that no subtypes are back on XML reload if disabling memory attributes (which disables tiers too)\n");
putenv((char*)"HWLOC_MEMTIERS_GUESS=spm_is_hbm");
err = hwloc_topology_init(&new);
assert(!err);
err = hwloc_topology_set_flags(new, HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS);
assert(!err);
err = hwloc_topology_set_xmlbuffer(new, xmlbuffer, buflen);
assert(!err);
err = hwloc_topology_load(new);
assert(!err);
check_subtypes(new, NULL, NULL, NULL, NULL, NULL);
hwloc_topology_destroy(new);
printf("breaking BW values\n");
add_local_bw(topology, rootn, 100);
add_local_bw(topology, pack2n1, 10000);
add_local_bw(topology, pack2n2, 1000);
hwloc_topology_export_xmlbuffer(topology, &xmlbuffer, &buflen, 0);
printf("checking DRAM and HBM subtypes aren't set anymore on XML reload\n");
putenv((char*)"HWLOC_MEMTIERS_GUESS=default");
err = hwloc_topology_init(&new);
assert(!err);
err = hwloc_topology_set_xmlbuffer(new, xmlbuffer, buflen);
assert(!err);
err = hwloc_topology_load(new);
assert(!err);
check_subtypes(new, "NVM", NULL, "SPM", NULL, "SPM");
hwloc_topology_destroy(new);
printf("checking broken BW can be ignored if HWLOC_MEMTIERS_GUESS=spm_is_hbm\n");
putenv((char*)"HWLOC_MEMTIERS_GUESS=spm_is_hbm");
err = hwloc_topology_init(&new);
assert(!err);
err = hwloc_topology_set_xmlbuffer(new, xmlbuffer, buflen);
assert(!err);
err = hwloc_topology_load(new);
assert(!err);
check_subtypes(new, "NVM", NULL, "HBM", NULL, "HBM");
hwloc_topology_destroy(new);
printf("checking everything can be disabled if HWLOC_MEMTIERS_GUESS=none\n");
putenv((char*)"HWLOC_MEMTIERS_GUESS=none");
err = hwloc_topology_init(&new);
assert(!err);
err = hwloc_topology_set_xmlbuffer(new, xmlbuffer, buflen);
assert(!err);
err = hwloc_topology_load(new);
assert(!err);
check_subtypes(new, "NVM", NULL, "SPM", NULL, "SPM");
hwloc_topology_destroy(new);
free(xmlbuffer);
hwloc_topology_destroy(topology);
return 0;
}