Cleanup: move generic caa_get_cycles to arch/generic.h
[urcu.git] / urcu / arch / generic.h
1 #ifndef _URCU_ARCH_GENERIC_H
2 #define _URCU_ARCH_GENERIC_H
3
4 /*
5 * arch_generic.h: common definitions for multiple architectures.
6 *
7 * Copyright (c) 2010 Paolo Bonzini <pbonzini@redhat.com>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include <urcu/compiler.h>
25 #include <urcu/config.h>
26 #include <urcu/syscall-compat.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #ifndef CAA_CACHE_LINE_SIZE
33 #define CAA_CACHE_LINE_SIZE 64
34 #endif
35
36 #if !defined(cmm_mc) && !defined(cmm_rmc) && !defined(cmm_wmc)
37 #define CONFIG_HAVE_MEM_COHERENCY
38 /*
39 * Architectures with cache coherency must _not_ define cmm_mc/cmm_rmc/cmm_wmc.
40 *
41 * For them, cmm_mc/cmm_rmc/cmm_wmc are implemented with a simple
42 * compiler barrier; in addition, we provide defaults for cmm_mb (using
43 * GCC builtins) as well as cmm_rmb and cmm_wmb (defaulting to cmm_mb).
44 */
45
46 #ifndef cmm_mb
47 #define cmm_mb() __sync_synchronize()
48 #endif
49
50 #ifndef cmm_rmb
51 #define cmm_rmb() cmm_mb()
52 #endif
53
54 #ifndef cmm_wmb
55 #define cmm_wmb() cmm_mb()
56 #endif
57
58 #define cmm_mc() cmm_barrier()
59 #define cmm_rmc() cmm_barrier()
60 #define cmm_wmc() cmm_barrier()
61 #else
62 /*
63 * Architectures without cache coherency need something like the following:
64 *
65 * #define cmm_mc() arch_cache_flush()
66 * #define cmm_rmc() arch_cache_flush_read()
67 * #define cmm_wmc() arch_cache_flush_write()
68 *
69 * Of these, only cmm_mc is mandatory. cmm_rmc and cmm_wmc default to
70 * cmm_mc. cmm_mb/cmm_rmb/cmm_wmb use these definitions by default:
71 *
72 * #define cmm_mb() cmm_mc()
73 * #define cmm_rmb() cmm_rmc()
74 * #define cmm_wmb() cmm_wmc()
75 */
76
77 #ifndef cmm_mb
78 #define cmm_mb() cmm_mc()
79 #endif
80
81 #ifndef cmm_rmb
82 #define cmm_rmb() cmm_rmc()
83 #endif
84
85 #ifndef cmm_wmb
86 #define cmm_wmb() cmm_wmc()
87 #endif
88
89 #ifndef cmm_rmc
90 #define cmm_rmc() cmm_mc()
91 #endif
92
93 #ifndef cmm_wmc
94 #define cmm_wmc() cmm_mc()
95 #endif
96 #endif
97
98 /* Nop everywhere except on alpha. */
99 #ifndef cmm_read_barrier_depends
100 #define cmm_read_barrier_depends()
101 #endif
102
103 #ifdef CONFIG_RCU_SMP
104 #ifndef cmm_smp_mb
105 #define cmm_smp_mb() cmm_mb()
106 #endif
107 #ifndef cmm_smp_rmb
108 #define cmm_smp_rmb() cmm_rmb()
109 #endif
110 #ifndef cmm_smp_wmb
111 #define cmm_smp_wmb() cmm_wmb()
112 #endif
113 #ifndef cmm_smp_mc
114 #define cmm_smp_mc() cmm_mc()
115 #endif
116 #ifndef cmm_smp_rmc
117 #define cmm_smp_rmc() cmm_rmc()
118 #endif
119 #ifndef cmm_smp_wmc
120 #define cmm_smp_wmc() cmm_wmc()
121 #endif
122 #ifndef cmm_smp_read_barrier_depends
123 #define cmm_smp_read_barrier_depends() cmm_read_barrier_depends()
124 #endif
125 #else
126 #ifndef cmm_smp_mb
127 #define cmm_smp_mb() cmm_barrier()
128 #endif
129 #ifndef cmm_smp_rmb
130 #define cmm_smp_rmb() cmm_barrier()
131 #endif
132 #ifndef cmm_smp_wmb
133 #define cmm_smp_wmb() cmm_barrier()
134 #endif
135 #ifndef cmm_smp_mc
136 #define cmm_smp_mc() cmm_barrier()
137 #endif
138 #ifndef cmm_smp_rmc
139 #define cmm_smp_rmc() cmm_barrier()
140 #endif
141 #ifndef cmm_smp_wmc
142 #define cmm_smp_wmc() cmm_barrier()
143 #endif
144 #ifndef cmm_smp_read_barrier_depends
145 #define cmm_smp_read_barrier_depends()
146 #endif
147 #endif
148
149 #ifndef caa_cpu_relax
150 #define caa_cpu_relax() cmm_barrier()
151 #endif
152
153 #ifndef HAS_CAA_GET_CYCLES
154 #define HAS_CAA_GET_CYCLES
155 typedef unsigned long long cycles_t;
156
157 static inline cycles_t caa_get_cycles (void)
158 {
159 cycles_t thetime;
160 struct timeval tv;
161
162 if (gettimeofday(&tv, NULL) != 0)
163 return 0;
164 thetime = ((cycles_t)tv.tv_sec) * 1000000ULL + ((cycles_t)tv.tv_usec);
165 return (cycles_t)thetime;
166 }
167 #endif /* HAS_CAA_GET_CYCLES */
168
169 #ifdef __cplusplus
170 }
171 #endif
172
173 #endif /* _URCU_ARCH_GENERIC_H */
This page took 0.047994 seconds and 4 git commands to generate.