5 * arch_x86.h: trivial definitions for the x86 architecture.
7 * Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
8 * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 /* Assume P4 or newer */
28 #define CONFIG_HAVE_FENCE 1
29 #define CONFIG_HAVE_MEM_COHERENCY
32 #define BITS_PER_LONG (__SIZEOF_LONG__ * 8)
35 #ifdef CONFIG_HAVE_FENCE
36 #define mb() asm volatile("mfence":::"memory")
37 #define rmb() asm volatile("lfence":::"memory")
38 #define wmb() asm volatile("sfence"::: "memory")
41 * Some non-Intel clones support out of order store. wmb() ceases to be a
44 #define mb() asm volatile("lock; addl $0,0(%%esp)":::"memory")
45 #define rmb() asm volatile("lock; addl $0,0(%%esp)":::"memory")
46 #define wmb() asm volatile("lock; addl $0,0(%%esp)"::: "memory")
50 * Architectures without cache coherency need something like the following:
55 * #define mc() arch_cache_flush()
56 * #define rmc() arch_cache_flush_read()
57 * #define wmc() arch_cache_flush_write()
60 #define mc() barrier()
61 #define rmc() barrier()
62 #define wmc() barrier()
64 /* Assume SMP machine, given we don't have this information */
69 #define smp_rmb() rmb()
70 #define smp_wmb() wmb()
72 #define smp_rmc() rmc()
73 #define smp_wmc() wmc()
75 #define smp_mb() barrier()
76 #define smp_rmb() barrier()
77 #define smp_wmb() barrier()
78 #define smp_mc() barrier()
79 #define smp_rmc() barrier()
80 #define smp_wmc() barrier()
83 /* Nop everywhere except on alpha. */
84 #define smp_read_barrier_depends()
86 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
87 static inline void rep_nop(void)
89 asm volatile("rep; nop" ::: "memory");
92 static inline void cpu_relax(void)
97 #define xchg(ptr, v) \
98 ((__typeof__(*(ptr)))__xchg((ptr), (unsigned long)(v), sizeof(*(ptr))))
100 struct __xchg_ptr_as_array
{
101 unsigned long a
[100];
104 #define __xchg_ptr_as_array(x) ((struct __xchg_ptr_as_array *)(x))
107 * xchg always implies a "lock" prefix, even on UP. See Intel documentation.
108 * volatile attribute is neccessary due to xchg side effect.
109 * *ptr is an output argument.
110 * x is considered local, ptr is considered remote.
112 static inline unsigned long __xchg(volatile void *ptr
, unsigned long x
,
117 asm volatile("xchgb %b0,%1"
119 : "m" (*__xchg_ptr_as_array(ptr
)), "0" (x
)
123 asm volatile("xchgw %w0,%1"
125 : "m" (*__xchg_ptr_as_array(ptr
)), "0" (x
)
129 asm volatile("xchgl %k0,%1"
131 : "m" (*__xchg_ptr_as_array(ptr
)), "0" (x
)
134 #if (BITS_PER_LONG == 64)
136 asm volatile("xchgq %0,%1"
138 : "m" (*__xchg_ptr_as_array(ptr
)), "0" (x
)
147 #define rdtscll(val) \
149 unsigned int __a, __d; \
150 asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \
151 (val) = ((unsigned long long)__a) \
152 | (((unsigned long long)__d) << 32); \
155 typedef unsigned long long cycles_t
;
157 static inline cycles_t
get_cycles(void)
165 #endif /* _ARCH_X86_H */
This page took 0.031994 seconds and 4 git commands to generate.