Commit | Line | Data |
---|---|---|
91233b5b MD |
1 | #ifndef _TEST_URCU_JA_RANGE_H |
2 | #define _TEST_URCU_JA_RANGE_H | |
3 | ||
4 | /* | |
5 | * test_urcu_ja.h | |
6 | * | |
7 | * Userspace RCU library - test program | |
8 | * | |
9 | * Copyright 2009-2012 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License along | |
22 | * with this program; if not, write to the Free Software Foundation, Inc., | |
23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
24 | */ | |
25 | ||
26 | #include "../config.h" | |
27 | #include <stdio.h> | |
28 | #include <pthread.h> | |
29 | #include <stdlib.h> | |
30 | #include <string.h> | |
31 | #include <sys/types.h> | |
32 | #include <sys/wait.h> | |
33 | #include <unistd.h> | |
34 | #include <stdio.h> | |
35 | #include <assert.h> | |
36 | #include <sched.h> | |
37 | #include <errno.h> | |
38 | #include <signal.h> | |
39 | ||
40 | #include <urcu/tls-compat.h> | |
41 | ||
42 | #ifdef __linux__ | |
43 | #include <syscall.h> | |
44 | #endif | |
45 | ||
46 | #define DEFAULT_RAND_POOL 1000000 | |
47 | ||
48 | /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ | |
49 | #define CACHE_LINE_SIZE 4096 | |
50 | ||
51 | /* hardcoded number of CPUs */ | |
52 | #define NR_CPUS 16384 | |
53 | ||
54 | #ifdef POISON_FREE | |
55 | #define poison_free(ptr) \ | |
56 | do { \ | |
57 | memset(ptr, 0x42, sizeof(*(ptr))); \ | |
58 | free(ptr); \ | |
59 | } while (0) | |
60 | #else | |
61 | #define poison_free(ptr) free(ptr) | |
62 | #endif | |
63 | ||
64 | ||
65 | ||
66 | #if defined(_syscall0) | |
67 | _syscall0(pid_t, gettid) | |
68 | #elif defined(__NR_gettid) | |
69 | static inline pid_t gettid(void) | |
70 | { | |
71 | return syscall(__NR_gettid); | |
72 | } | |
73 | #else | |
74 | #warning "use pid as tid" | |
75 | static inline pid_t gettid(void) | |
76 | { | |
77 | return getpid(); | |
78 | } | |
79 | #endif | |
80 | ||
81 | #ifndef DYNAMIC_LINK_TEST | |
82 | #define _LGPL_SOURCE | |
83 | #else | |
84 | #define debug_yield_read() | |
85 | #endif | |
86 | #include <urcu-qsbr.h> | |
87 | #include <urcu/rcuja-range.h> | |
88 | #include <urcu-call-rcu.h> | |
89 | ||
90 | struct wr_count { | |
91 | unsigned long update_ops; | |
92 | unsigned long add; | |
93 | unsigned long add_exist; | |
94 | unsigned long remove; | |
95 | }; | |
96 | ||
97 | extern DECLARE_URCU_TLS(unsigned int, rand_lookup); | |
98 | extern DECLARE_URCU_TLS(unsigned long, nr_add); | |
99 | extern DECLARE_URCU_TLS(unsigned long, nr_addexist); | |
100 | extern DECLARE_URCU_TLS(unsigned long, nr_del); | |
101 | extern DECLARE_URCU_TLS(unsigned long, nr_delnoent); | |
102 | extern DECLARE_URCU_TLS(unsigned long, lookup_fail); | |
103 | extern DECLARE_URCU_TLS(unsigned long, lookup_ok); | |
104 | ||
105 | extern struct cds_ja *test_ja; | |
106 | ||
107 | extern volatile int test_go, test_stop; | |
108 | ||
109 | extern unsigned long wdelay; | |
110 | ||
111 | extern unsigned long duration; | |
112 | ||
113 | /* read-side C.S. duration, in loops */ | |
114 | extern unsigned long rduration; | |
115 | ||
116 | extern unsigned long init_populate; | |
117 | extern int add_only; | |
118 | ||
119 | extern unsigned long init_pool_offset, lookup_pool_offset, write_pool_offset; | |
120 | extern unsigned long init_pool_size, | |
121 | lookup_pool_size, | |
122 | write_pool_size; | |
123 | extern int validate_lookup; | |
124 | ||
125 | extern int count_pipe[2]; | |
126 | ||
127 | static inline void loop_sleep(unsigned long l) | |
128 | { | |
129 | while(l-- != 0) | |
130 | caa_cpu_relax(); | |
131 | } | |
132 | ||
133 | extern int verbose_mode; | |
134 | ||
135 | #define printf_verbose(fmt, args...) \ | |
136 | do { \ | |
137 | if (verbose_mode) \ | |
138 | printf(fmt, ## args); \ | |
139 | } while (0) | |
140 | ||
141 | extern unsigned int cpu_affinities[NR_CPUS]; | |
142 | extern unsigned int next_aff; | |
143 | extern int use_affinity; | |
144 | ||
145 | extern pthread_mutex_t affinity_mutex; | |
146 | ||
147 | #ifndef HAVE_CPU_SET_T | |
148 | typedef unsigned long cpu_set_t; | |
149 | # define CPU_ZERO(cpuset) do { *(cpuset) = 0; } while(0) | |
150 | # define CPU_SET(cpu, cpuset) do { *(cpuset) |= (1UL << (cpu)); } while(0) | |
151 | #endif | |
152 | ||
153 | void set_affinity(void); | |
154 | ||
155 | /* | |
156 | * returns 0 if test should end. | |
157 | */ | |
158 | static inline int test_duration_write(void) | |
159 | { | |
160 | return !test_stop; | |
161 | } | |
162 | ||
163 | static inline int test_duration_read(void) | |
164 | { | |
165 | return !test_stop; | |
166 | } | |
167 | ||
168 | extern DECLARE_URCU_TLS(unsigned long long, nr_writes); | |
169 | extern DECLARE_URCU_TLS(unsigned long long, nr_reads); | |
170 | ||
171 | extern unsigned int nr_readers; | |
172 | extern unsigned int nr_writers; | |
173 | ||
174 | void rcu_copy_mutex_lock(void); | |
175 | void rcu_copy_mutex_unlock(void); | |
176 | ||
177 | #endif /* _TEST_URCU_JA_RANGE_H */ |