Debian Codegraph @

src/cyclictest/rt_numa.h

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * A numa library for cyclictest.
4 *
5 * (C) 2010 John Kacur <[email protected]>
6 * (C) 2010 Clark Williams <[email protected]>
7 *
8 */
9
10 #ifndef _RT_NUMA_H
11 #define _RT_NUMA_H
12
13 #include "rt-utils.h"
14 #include "rt-error.h"
15
16 static int numa = 0;
17
18 #include <numa.h>
19
20 static void *
21 threadalloc(size_t size, int node)
22 {
23 if (node == -1)
24 return malloc(size);
25 return numa_alloc_onnode(size, node);
26 }
27
28 static void
29 threadfree(void *ptr, size_t size, int node)
30 {
31 if (node == -1)
32 free(ptr);
33 else
34 numa_free(ptr, size);
35 }
36
37 static void rt_numa_set_numa_run_on_node(int node, int cpu)
38 {
39 int res;
40 res = numa_run_on_node(node);
41 if (res)
42 warn("Could not set NUMA node %d for thread %d: %s\n",
43 node, cpu, strerror(errno));
44 return;
45 }
46
47 static void *rt_numa_numa_alloc_onnode(size_t size, int node, int cpu)
48 {
49 void *stack;
50 stack = numa_alloc_onnode(size, node);
51 if (stack == NULL)
52 fatal("failed to allocate %d bytes on node %d for cpu %d\n",
53 size, node, cpu);
54 return stack;
55 }
56
57 /*
58 * Use new bit mask CPU affinity behavior
59 */
60 static int rt_numa_numa_node_of_cpu(int cpu)
61 {
62 int node;
63 node = numa_node_of_cpu(cpu);
64 if (node == -1)
65 fatal("invalid cpu passed to numa_node_of_cpu(%d)\n", cpu);
66 return node;
67 }
68
69 static inline unsigned int rt_numa_bitmask_isbitset( const struct bitmask *mask,
70 unsigned long i)
71 {
72 return numa_bitmask_isbitset(mask,i);
73 }
74
75 static inline struct bitmask* rt_numa_parse_cpustring(const char* s)
76 {
77 return numa_parse_cpustring_all(s);
78 }
79
80 static inline void rt_bitmask_free(struct bitmask *mask)
81 {
82 numa_bitmask_free(mask);
83 }
84
85 #endif /* _RT_NUMA_H */