diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:48:23 +0200 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:48:23 +0200 |
commit | 1b6242fc583a6b871304fb995af6dc211b58f69b (patch) | |
tree | b5d434d90dedae24792906aa304897c23a134386 /recipes-core/numad/numad-0.6/test.patch | |
download | meta-ip-daisy-enea.tar.gz |
initial commit for Enea Linux 4.0daisy-enea
Migrated from the internal git server on the daisy-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'recipes-core/numad/numad-0.6/test.patch')
-rw-r--r-- | recipes-core/numad/numad-0.6/test.patch | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/recipes-core/numad/numad-0.6/test.patch b/recipes-core/numad/numad-0.6/test.patch new file mode 100644 index 0000000..762790c --- /dev/null +++ b/recipes-core/numad/numad-0.6/test.patch | |||
@@ -0,0 +1,175 @@ | |||
1 | Test output format: ptest style (PASS, FAIL, SKIP) | ||
2 | Description: Allocate memory from a node other than | ||
3 | the current CPU is running on. Wait for numad to modify | ||
4 | memory and CPU policy binding the process to run and allocate on | ||
5 | the same node. | ||
6 | Dependencies: libnuma | ||
7 | |||
8 | Signed-off-by: Radu Patriu <radu.patriu@enea.com> | ||
9 | Upstream-Status: Pending | ||
10 | |||
11 | Index: numa-test/test.c | ||
12 | =================================================================== | ||
13 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
14 | +++ numa-test/test.c 2014-02-18 17:22:49.952290472 +0200 | ||
15 | @@ -0,0 +1,160 @@ | ||
16 | +#define _GNU_SOURCE | ||
17 | +#include <sched.h> | ||
18 | +#include <stdio.h> | ||
19 | +#include <unistd.h> | ||
20 | +#include <ctype.h> | ||
21 | +#include <sys/time.h> | ||
22 | +#include <sched.h> | ||
23 | +#include <numa.h> | ||
24 | + | ||
25 | +#define TIMEOUT (1000 * 60) /*60 seconds*/ | ||
26 | +#define LOOP_TIME (1000 * 5) /*5 seconds*/ | ||
27 | +#define MEM_POLICY_CHANGED 1 | ||
28 | +#define NODE_POLICY_CHANGED 2 | ||
29 | +#define TEST_DONE (MEM_POLICY_CHANGED | NODE_POLICY_CHANGED) | ||
30 | + | ||
31 | +#define TEST_PASS 0 | ||
32 | +#define TEST_FAIL 1 | ||
33 | +#define TEST_SKIP 2 | ||
34 | + | ||
35 | +#define MEM_SIZE 0.3 /* 30 % node memory */ | ||
36 | + | ||
37 | +unsigned int numa_bitmask_weight(const struct bitmask *bmp); | ||
38 | + | ||
39 | +void print_bitmask(struct bitmask *mask) | ||
40 | +{ | ||
41 | + /*assume 32 max nodes*/ | ||
42 | + printf("0x%08lx", *(mask->maskp)); | ||
43 | +} | ||
44 | + | ||
45 | +int test() | ||
46 | +{ | ||
47 | + int i, j, total_nodes, total_mem_nodes, total_cpus, prefered_node; | ||
48 | + struct bitmask *allowed_mem_nodes, *allowed_nodes, *cpu_mask, *mem_bind, *bit_mask; | ||
49 | + long long mem_size, page_size; | ||
50 | + unsigned char *mem; | ||
51 | + struct timeval start, end, res; | ||
52 | + int local_node, local_cpu, other_node, test_complete; | ||
53 | + | ||
54 | + allowed_mem_nodes = numa_allocate_nodemask(); | ||
55 | + allowed_nodes = numa_allocate_nodemask(); | ||
56 | + mem_bind = numa_allocate_nodemask(); | ||
57 | + cpu_mask = numa_allocate_cpumask(); | ||
58 | + if (!(allowed_mem_nodes && allowed_nodes && mem_bind && cpu_mask)) { | ||
59 | + printf("Error: numa_allocate failed\n"); | ||
60 | + return TEST_FAIL; | ||
61 | + } | ||
62 | + | ||
63 | + total_nodes = numa_max_node() + 1; | ||
64 | + printf("total_nodes %d\n", total_nodes); | ||
65 | + | ||
66 | + total_mem_nodes = numa_num_configured_nodes(); | ||
67 | + printf("total_mem_nodes %d\n", total_mem_nodes); | ||
68 | + | ||
69 | + total_cpus = numa_num_configured_cpus(); | ||
70 | + printf("total_cpus %d\n", total_cpus); | ||
71 | + | ||
72 | + page_size = numa_pagesize(); | ||
73 | + printf("page_size %llu\n", page_size); | ||
74 | + | ||
75 | + i = 0; | ||
76 | + test_complete = 0; | ||
77 | + gettimeofday(&start, NULL); | ||
78 | + do { | ||
79 | + printf("\n\n\nLoop %d\n", i); | ||
80 | + | ||
81 | + bit_mask = numa_get_mems_allowed(); | ||
82 | + if (i && !numa_bitmask_equal(bit_mask, allowed_mem_nodes)) { | ||
83 | + printf("\nInfo: memory policy modified\n\n"); | ||
84 | + test_complete |= MEM_POLICY_CHANGED; | ||
85 | + } | ||
86 | + copy_bitmask_to_bitmask(bit_mask, allowed_mem_nodes); | ||
87 | + printf("allowed_mem_nodes "); print_bitmask(allowed_mem_nodes); printf("\n"); | ||
88 | + if ((0 == i) && (1 == numa_bitmask_weight(allowed_mem_nodes))) { | ||
89 | + printf("Error: need at least two memory nodes\n"); | ||
90 | + return TEST_SKIP; | ||
91 | + } | ||
92 | + | ||
93 | + bit_mask = numa_get_run_node_mask(); | ||
94 | + if (i && !numa_bitmask_equal(bit_mask, allowed_nodes)) { | ||
95 | + printf("\nInfo: node/cpu policy modified\n\n"); | ||
96 | + test_complete |= NODE_POLICY_CHANGED; | ||
97 | + } | ||
98 | + copy_bitmask_to_bitmask(bit_mask, allowed_nodes); | ||
99 | + printf("allowed_nodes "); print_bitmask(allowed_nodes); printf("\n"); | ||
100 | + | ||
101 | + prefered_node = numa_preferred(); | ||
102 | + printf("prefered_node %d\n", prefered_node); | ||
103 | + | ||
104 | + bit_mask = numa_get_membind(); | ||
105 | + copy_bitmask_to_bitmask(bit_mask, mem_bind); | ||
106 | + printf("mem_bind "); print_bitmask(mem_bind); printf("\n"); | ||
107 | + | ||
108 | + if (numa_sched_getaffinity(0, cpu_mask) < 0) { | ||
109 | + printf("Error: numa_sched_getaffinity failed\n"); | ||
110 | + return TEST_FAIL; | ||
111 | + } | ||
112 | + printf("sched_affinity "); print_bitmask(cpu_mask); printf("\n"); | ||
113 | + | ||
114 | + other_node = -1; | ||
115 | + local_cpu = sched_getcpu(); | ||
116 | + local_node = numa_node_of_cpu(local_cpu); | ||
117 | + for (j = 0; j < total_mem_nodes; ++j) | ||
118 | + if (numa_bitmask_isbitset(allowed_mem_nodes, j) && (j != local_node)) | ||
119 | + other_node = j; | ||
120 | + | ||
121 | + printf("running on node %d, cpu %d\n", local_node, local_cpu); | ||
122 | + printf("alloc memory from node %d\n", other_node); | ||
123 | + | ||
124 | + mem_size = numa_node_size64(other_node, NULL) * MEM_SIZE; | ||
125 | + printf("test_mem_size %llu\n", mem_size); | ||
126 | + | ||
127 | + /* avoid mbind: Invalid argument */ | ||
128 | + if (TEST_DONE == test_complete) | ||
129 | + return TEST_PASS; | ||
130 | + | ||
131 | + mem = numa_alloc_onnode(mem_size, other_node); | ||
132 | + if (!mem) { | ||
133 | + printf("Error: numa_alloc_onnode failed for node %d\n", other_node); | ||
134 | + return TEST_FAIL; | ||
135 | + } | ||
136 | + | ||
137 | + gettimeofday(&end, NULL); | ||
138 | + /* do some work */ | ||
139 | + do { | ||
140 | + struct timeval now; | ||
141 | + memcpy(mem, mem + mem_size/2, mem_size/2); | ||
142 | + gettimeofday(&now, NULL); | ||
143 | + timersub(&now, &end, &res); | ||
144 | + } while((res.tv_sec * 1000 + res.tv_usec / 1000) < LOOP_TIME); | ||
145 | + | ||
146 | + numa_free(mem, mem_size); | ||
147 | + ++i; | ||
148 | + gettimeofday(&end, NULL); | ||
149 | + timersub(&end, &start, &res); | ||
150 | + } while((res.tv_sec * 1000 + res.tv_usec / 1000) < TIMEOUT); | ||
151 | + | ||
152 | + return TEST_FAIL; | ||
153 | +} | ||
154 | + | ||
155 | +int main() | ||
156 | +{ | ||
157 | + if (numa_available() < 0) { | ||
158 | + printf("Error: numa not available\n"); | ||
159 | + printf("SKIP: numad\n"); | ||
160 | + return 0; | ||
161 | + } | ||
162 | + | ||
163 | + switch(test()) { | ||
164 | + case TEST_PASS: | ||
165 | + printf("PASS: numad\n"); | ||
166 | + break; | ||
167 | + case TEST_SKIP: | ||
168 | + printf("FAIL: numad\n"); | ||
169 | + break; | ||
170 | + default: | ||
171 | + printf("FAIL: numad\n"); | ||
172 | + } | ||
173 | + | ||
174 | + return 0; | ||
175 | +} | ||