-
Notifications
You must be signed in to change notification settings - Fork 0
/
libNUMA.h
191 lines (159 loc) · 7.48 KB
/
libNUMA.h
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
/* Copyright (C) 2007, 2012 Ulrich Drepper.
This file is part of libNUMA.
libNUMA is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; version 2 of the License.
libNUMA is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details. */
#ifndef _LIBNUMA_H
#define _LIBNUMA_H 1
#include <sched.h>
#include <stdlib.h>
/* Size definition for memory node sets. */
#define __MEMNODE_SETSIZE 128
#define __NMEMNODEBITS (8 * sizeof (__memnode_mask))
/* Type for array elements in 'memnode_set_t'. */
typedef unsigned long int __memnode_mask;
/* Basic access functions. */
#define __MEMNODEELT(node) ((node) / __NMEMNODEBITS)
#define __MEMNODEMASK(node) ((__memnode_mask) 1 << ((node) % __NMEMNODEBITS))
/* Data structure to describe memory node mask. */
typedef struct
{
__memnode_mask __bits[__MEMNODE_SETSIZE / __NMEMNODEBITS];
} memnode_set_t;
/* Access functions for memory node masks. */
#if __GNUC_PREREQ (2, 91)
# define MEMNODE_ZERO_S(setsize, memnodesetp) \
do __builtin_memset (memnodesetp, '\0', setsize); while (0)
#else
# define MEMNODE_ZERO_S(setsize, memnodesetp) \
do { \
size_t __i; \
size_t __imax = (setsize) / sizeof (__memnode_mask); \
memnode_set_t *__arr = (cpusetp); \
for (__i = 0; __i < __imax; ++__i) \
__arr->__bits[__i] = 0; \
} while (0)
#endif
#define MEMNODE_SET_S(node, setsize, memnodesetp) \
({ size_t __node = (node); \
__node < 8 * (setsize) \
? ((memnodesetp)->__bits[__MEMNODEELT (__node)] \
|= __MEMNODEMASK (__node)) : 0; })
#define MEMNODE_CLR_S(node, setsize, memnodesetp) \
({ size_t __node = (node); \
__node < 8 * (setsize) \
? ((memnodesetp)->__bits[__MEMNODEELT (__node)] \
&= ~__MEMNODEMASK (__node)) : 0; })
#define MEMNODE_ISSET_S(node, setsize, memnodesetp) \
({ size_t __node = (node); \
__node < 8 * (setsize) \
? (((memnodesetp)->__bits[__MEMNODEELT (__node)] \
& __MEMNODEMASK (__node))) != 0 : 0; })
#define MEMNODE_COUNT_S(setsize, memnodesetp) \
NUMA_memnode_count (setsize, memnodesetp)
#if __GNUC_PREREQ (2, 91)
# define MEMNODE_EQUAL_S(setsize, memnodesetp1, memnodesetp2) \
(__builtin_memcmp (memnodesetp1, memnodesetp2, setsize) == 0)
#else
# define MEMNODE_EQUAL_S(setsize, memnodesetp1, memnodesetp2) \
({ memnode_set_t *__arr1 = (memnodesetp1); \
memnode_set_t *__arr2 = (memnodesetp2); \
size_t __imax = (setsize) / sizeof (__memnode_mask); \
size_t __i; \
for (__i = 0; __i < __imax; ++__i) \
if (__arr1->__bits[__i] != __arr2->__bits[__i]) \
break; \
__i == __imax; })
#endif
#define __MEMNODE_OP_S(setsize, destset, srcset1, srcset2, op) \
({ memnode_set_t *__dest = (destset); \
memnode_set_t *__arr1 = (srcset1); \
memnode_set_t *__arr2 = (srcset2); \
size_t __imax = (setsize) / sizeof (__cpu_mask); \
size_t __i; \
for (__i = 0; __i < __imax; ++__i) \
__dest->__bits[__i] = __arr1->__bits[__i] op __arr2->__bits[__i]; \
__dest; })
#define MEMNODE_AND_S(setsize, destset, srcset1, srcset2) \
__MEMNODE_OP_S (setsize, destset, srcset1, srcset2, &)
#define MEMNODE_OR_S(setsize, destset, srcset1, srcset2) \
__MEMNODE_OP_S (setsize, destset, srcset1, srcset2, |)
#define MEMNODE_XOR_S(setsize, destset, srcset1, srcset2) \
__MEMNODE_OP_S (setsize, destset, srcset1, srcset2, ^)
#define MEMNODE_ALLOC_SIZE(count) \
((((count) + __NMEMNODEBITS - 1) / __NMEMNODEBITS) * 8)
#define MEMNODE_ALLOC(count) \
((memnode_set_t *) malloc (MEMNODE_ALLOC_SIZE (count)))
#define MEMNODE_FREE(memnodeset) \
free (memnodeset)
__BEGIN_DECLS
/* Return current number of online CPUs in the system. */
extern int NUMA_cpu_system_count (void) __THROW;
/* Set bits for all online CPUs in the system and return the number of
bits set. */
extern int NUMA_cpu_system_mask (size_t __destsize, cpu_set_t *__dest) __THROW;
/* Return current number of CPUs the calling thread is allowed to run on. */
extern int NUMA_cpu_self_count (void) __THROW;
/* Set bits for all CPUs the calling thread is allowed to run on and
return the number of bits set. */
extern int NUMA_cpu_self_mask (size_t __destsize, cpu_set_t *__dest) __THROW;
/* Return index of CPUS currently used by the calling thread. */
extern int NUMA_cpu_self_current_idx (void) __THROW;
/* Set bit for the CPU currently used by the calling thread. */
extern int NUMA_cpu_self_current_mask (size_t __destsize, cpu_set_t *__dest)
__THROW;
/* Return CPUs up to LEVEL from CPU in SRC. */
extern ssize_t NUMA_cpu_level_mask (size_t __destsize, cpu_set_t *__dest,
size_t __srcsize, const cpu_set_t *__src,
unsigned int __level) __THROW;
/* Determine set of CPUs local to device for network interface IFNAME. */
extern int NUMA_ifname_to_cpu_mask (const char *__ifname, size_t __destsize,
cpu_set_t *__dest) __THROW;
/* Return current number of online memory nodes in the system. */
extern int NUMA_memnode_system_count (void) __THROW;
/* Set bits for all online memory nodes in the system and return the
number of bits set. */
extern int NUMA_memnode_system_mask (size_t __destsize, memnode_set_t *__dest)
__THROW;
/* Set bits for all memory nodes locale to any CPU the calling thread
is currently allowed to is return the number of bits set. */
extern int NUMA_memnode_self_mask (size_t __destsize, memnode_set_t *__dest)
__THROW;
/* Return index of memory node of currently used CPU. */
extern int NUMA_memnode_self_current_idx (void) __THROW;
/* Set bit for memory node of currently used CPU. */
extern int NUMA_memnode_self_current_mask (size_t __destsize,
memnode_set_t *__dest) __THROW;
/* Set bits for all memory nodes which are local to any of the CPUs
indicated by bits set in CPUSET. Return -1 on failure, otherwise
the number of bits set in MEMNODESET. */
extern int NUMA_cpu_to_memnode (size_t __cpusetsize, const cpu_set_t *__cpuset,
size_t __memnodesize,
memnode_set_t *__memnodeset) __THROW;
/* Set bits for all CPUs which are local to any of the memory nodes
indicated by bits set in MEMNODESET. Return -1 on failure, otherwise
the number of bits set in CPUSET. */
extern int NUMA_memnode_to_cpu (size_t __memnodesize,
const memnode_set_t *__memnodeset,
size_t __cpusetsize, cpu_set_t *__cpuset)
__THROW;
/* Count the number of bits set for memory nodes in SET. */
extern int NUMA_memnode_count (size_t __setsize, const memnode_set_t *__set)
__THROW;
/* Return the index of the memory node which contains (or would
contain) the memory page pointed to by ADDR. Returns the index of
the memory node or -1 in case of a failure. */
extern int NUMA_mem_get_node_idx (void *__addr) __THROW;
/* In DEST set bits for all the memory nodes which contain (or would
contain) any of the memory pages allocated for the address range
[ADDR,ADDR+SIZE). Returns the number of bits set in DEST or -1 in
case of a failure. */
extern int NUMA_mem_get_node_mask (void *__addr, size_t __size,
size_t __destsize, memnode_set_t *__dest)
__THROW;
__END_DECLS
#endif /* libNUMA.h */