Date: Tue, 9 Oct 2012 14:32:31 +0000 (UTC) From: Attilio Rao <attilio@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r241374 - in head/sys: amd64/include gnu/fs/xfs/FreeBSD i386/include kern mips/include pc98/include sparc64/include sys x86/include Message-ID: <201210091432.q99EWVQm021726@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: attilio Date: Tue Oct 9 14:32:30 2012 New Revision: 241374 URL: http://svn.freebsd.org/changeset/base/241374 Log: Add an unified macro to deny ability from the compiler to reorder instruction loads/stores at its will. The macro __compiler_membar() is currently supported for both gcc and clang, but kernel compilation will fail otherwise. Reviewed by: bde, kib Discussed with: dim, theraven MFC after: 2 weeks Modified: head/sys/amd64/include/atomic.h head/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h head/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h head/sys/i386/include/atomic.h head/sys/kern/kern_rmlock.c head/sys/mips/include/cpufunc.h head/sys/pc98/include/bus.h head/sys/sparc64/include/atomic.h head/sys/sys/cdefs.h head/sys/x86/include/bus.h Modified: head/sys/amd64/include/atomic.h ============================================================================== --- head/sys/amd64/include/atomic.h Tue Oct 9 14:25:14 2012 (r241373) +++ head/sys/amd64/include/atomic.h Tue Oct 9 14:32:30 2012 (r241374) @@ -226,7 +226,7 @@ atomic_fetchadd_long(volatile u_long *p, static __inline void \ atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ { \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ *p = v; \ } \ struct __hack @@ -240,7 +240,7 @@ atomic_load_acq_##TYPE(volatile u_##TYPE u_##TYPE tmp; \ \ tmp = *p; \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ return (tmp); \ } \ struct __hack Modified: head/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h ============================================================================== --- head/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h Tue Oct 9 14:25:14 2012 (r241373) +++ head/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h Tue Oct 9 14:32:30 2012 (r241374) @@ -129,10 +129,6 @@ typedef dev_t os_dev_t; #define copy_from_user(dst, src, len) copyin((src), (dst), (len)) #endif -#ifndef barrier -#define barrier() __asm__ __volatile__("": : :"memory") -#endif - /* * Map simple global vairables to FreeBSD kernel equivalents */ Modified: head/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h ============================================================================== --- head/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h Tue Oct 9 14:25:14 2012 (r241373) +++ head/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h Tue Oct 9 14:32:30 2012 (r241374) @@ -162,7 +162,7 @@ */ #define EFSCORRUPTED 990 /* Filesystem is corrupted */ -#define SYNCHRONIZE() barrier() +#define SYNCHRONIZE() __compiler_membar() #define __return_address __builtin_return_address(0) /* Modified: head/sys/i386/include/atomic.h ============================================================================== --- head/sys/i386/include/atomic.h Tue Oct 9 14:25:14 2012 (r241373) +++ head/sys/i386/include/atomic.h Tue Oct 9 14:32:30 2012 (r241374) @@ -296,7 +296,7 @@ atomic_fetchadd_int(volatile u_int *p, u static __inline void \ atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ { \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ *p = v; \ } \ struct __hack @@ -310,7 +310,7 @@ atomic_load_acq_##TYPE(volatile u_##TYPE u_##TYPE tmp; \ \ tmp = *p; \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ return (tmp); \ } \ struct __hack Modified: head/sys/kern/kern_rmlock.c ============================================================================== --- head/sys/kern/kern_rmlock.c Tue Oct 9 14:25:14 2012 (r241373) +++ head/sys/kern/kern_rmlock.c Tue Oct 9 14:32:30 2012 (r241374) @@ -65,10 +65,6 @@ __FBSDID("$FreeBSD$"); * does not seem very useful */ -static __inline void compiler_memory_barrier(void) { - __asm __volatile("":::"memory"); -} - static void assert_rm(const struct lock_object *lock, int what); static void lock_rm(struct lock_object *lock, int how); #ifdef KDTRACE_HOOKS @@ -353,7 +349,7 @@ _rm_rlock(struct rmlock *rm, struct rm_p td->td_critnest++; /* critical_enter(); */ - compiler_memory_barrier(); + __compiler_membar(); pc = cpuid_to_pcpu[td->td_oncpu]; /* pcpu_find(td->td_oncpu); */ @@ -361,7 +357,7 @@ _rm_rlock(struct rmlock *rm, struct rm_p sched_pin(); - compiler_memory_barrier(); + __compiler_membar(); td->td_critnest--; Modified: head/sys/mips/include/cpufunc.h ============================================================================== --- head/sys/mips/include/cpufunc.h Tue Oct 9 14:25:14 2012 (r241373) +++ head/sys/mips/include/cpufunc.h Tue Oct 9 14:32:30 2012 (r241374) @@ -70,7 +70,7 @@ static __inline void mips_barrier(void) { #if defined(CPU_CNMIPS) || defined(CPU_RMI) || defined(CPU_NLM) - __asm __volatile("" : : : "memory"); + __compiler_membar(); #else __asm __volatile (".set noreorder\n\t" "nop\n\t" Modified: head/sys/pc98/include/bus.h ============================================================================== --- head/sys/pc98/include/bus.h Tue Oct 9 14:25:14 2012 (r241373) +++ head/sys/pc98/include/bus.h Tue Oct 9 14:32:30 2012 (r241374) @@ -593,7 +593,7 @@ bus_space_barrier(bus_space_tag_t tag, b if (flags & BUS_SPACE_BARRIER_READ) __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory"); else - __asm __volatile("" : : : "memory"); + __compiler_membar(); } #ifdef BUS_SPACE_NO_LEGACY Modified: head/sys/sparc64/include/atomic.h ============================================================================== --- head/sys/sparc64/include/atomic.h Tue Oct 9 14:25:14 2012 (r241373) +++ head/sys/sparc64/include/atomic.h Tue Oct 9 14:32:30 2012 (r241374) @@ -97,7 +97,7 @@ #define atomic_cas_acq(p, e, s, sz) ({ \ itype(sz) v; \ v = atomic_cas((p), (e), (s), sz); \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ v; \ }) @@ -122,7 +122,7 @@ #define atomic_op_acq(p, op, v, sz) ({ \ itype(sz) t; \ t = atomic_op((p), op, (v), sz); \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ t; \ }) @@ -139,7 +139,7 @@ #define atomic_load_acq(p, sz) ({ \ itype(sz) v; \ v = atomic_load((p), sz); \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ v; \ }) Modified: head/sys/sys/cdefs.h ============================================================================== --- head/sys/sys/cdefs.h Tue Oct 9 14:25:14 2012 (r241373) +++ head/sys/sys/cdefs.h Tue Oct 9 14:32:30 2012 (r241374) @@ -82,6 +82,13 @@ # define __GNUC_VA_LIST_COMPATIBILITY 1 #endif +/* + * Compiler memory barriers, specific to gcc and clang. + */ +#if defined(__GNUC__) +#define __compiler_membar() __asm __volatile(" " : : : "memory") +#endif + #ifndef __INTEL_COMPILER # define __GNUCLIKE_BUILTIN_NEXT_ARG 1 # define __GNUCLIKE_MATH_BUILTIN_RELOPS Modified: head/sys/x86/include/bus.h ============================================================================== --- head/sys/x86/include/bus.h Tue Oct 9 14:25:14 2012 (r241373) +++ head/sys/x86/include/bus.h Tue Oct 9 14:32:30 2012 (r241374) @@ -1014,7 +1014,7 @@ bus_space_barrier(bus_space_tag_t tag __ __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory"); #endif else - __asm __volatile("" : : : "memory"); + __compiler_membar(); #endif }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210091432.q99EWVQm021726>