19 #include <ndb_global.h>
21 static int NDB_TRACE_NUMA = 0;
23 #if defined HAVE_DLFCN_H && defined HAVE_DLOPEN
34 typedef int (* fun0)(void);
35 typedef void (* fun1)(
struct bitmask*);
36 typedef void (* fun2)(int);
37 typedef int (* fun3)(
int node,
unsigned long * bug,
int buflen);
38 typedef bitmask * (* fun4)();
39 typedef void (* fun5)(
struct bitmask*);
40 typedef bitmask * (* fun6)(
struct bitmask*);
46 NdbNuma() { handle = 0;}
47 ~NdbNuma() {
if (handle) dlclose(handle); }
50 int build_cputonodemap();
56 fun0 numa_max_possible_node;
57 fun1 numa_set_interleave_mask;
59 fun3 numa_node_to_cpus;
60 fun4 numa_allocate_nodemask;
61 fun5 numa_bitmask_free;
62 fun6 numa_bitmask_setall;
64 struct bitmask * numa_all_nodes;
65 struct bitmask * numa_all_nodes_ptr;
70 my_dlopen(
const char *
name)
72 void * p = dlopen(name, RTLD_LAZY);
76 printf(
"info: failed to load %s\n", name);
78 printf(
"info: loaded %s\n", name);
85 my_dlsym(
void * handle,
const char * name)
87 void * p = dlsym(handle, name);
92 printf(
"info: %s OK\n", name);
96 printf(
"info: %s NOT FOUND\n", name);
105 handle = my_dlopen(
"libnuma.so");
108 handle = my_dlopen(
"libnuma.so.1");
115 numa_available = (fun0)my_dlsym(handle,
"numa_available");
116 if (numa_available == 0)
121 if ((* numa_available)() == -1)
125 printf(
"info: numa_available() returns -1 => no numa support\n");
130 numa_max_node = (fun0)my_dlsym(handle,
"numa_max_node");
131 numa_set_interleave_mask = (fun1)my_dlsym(handle,
"numa_set_interleave_mask");
132 numa_set_strict = (fun2)my_dlsym(handle,
"numa_set_strict");
133 numa_node_to_cpus = (fun3)my_dlsym(handle,
"numa_node_to_cpus");
134 numa_all_nodes = (
struct bitmask*)my_dlsym(handle,
"numa_all_nodes");
135 numa_all_nodes_ptr = (
struct bitmask*)my_dlsym(handle,
"numa_all_nodes_ptr");
136 numa_allocate_nodemask = (fun4)my_dlsym(handle,
"numa_allocate_nodemask");
137 numa_bitmask_free = (fun5)my_dlsym(handle,
"numa_bitmask_free");
138 numa_bitmask_setall = (fun6)my_dlsym(handle,
"numa_bitmask_setall");
150 bit_is_set(
unsigned long * mask,
int bit)
152 int n = bit / (8 *
sizeof(
unsigned long));
153 int b = bit % (8 *
sizeof(
unsigned long));
154 return (mask[n] & (1UL << b)) != 0;
158 NdbNuma::build_cputonodemap()
161 unsigned long *
buf = (
unsigned long*)malloc(len);
165 int m = (* numa_max_node)();
166 for (
int i = 0;
i <= m;
i++)
169 int r = (* numa_node_to_cpus)(
i,
buf, len);
179 void * p = realloc(buf, len);
183 buf = (
unsigned long*)p;
186 printf(
"node %d cpu(s): ", i);
187 for (
int j = 0; j<8*len;j++)
188 if (bit_is_set(buf, j))
201 NdbNuma_setInterleaved()
204 if (numa.open() == -1)
207 if (numa.numa_set_interleave_mask == 0)
210 if (numa.numa_all_nodes_ptr != 0)
215 if (numa.numa_allocate_nodemask != 0 &&
216 numa.numa_bitmask_setall != 0 &&
217 numa.numa_bitmask_free != 0)
219 struct bitmask * bm = (* numa.numa_allocate_nodemask)();
222 (* numa.numa_bitmask_setall)(bm);
223 (* numa.numa_set_interleave_mask)(bm);
224 (* numa.numa_bitmask_free)(bm);
236 else if (numa.numa_all_nodes != 0)
241 (* numa.numa_set_interleave_mask)(numa.numa_all_nodes);
254 NdbNuma_setInterleaved()
261 NdbNuma_setInterleavedOnCpus(
unsigned cpu[],
unsigned len)
268 #include <NdbTap.hpp>
270 TAPTEST(SetInterleaved)
273 NdbNuma_setInterleaved();