From owner-svn-src-projects@FreeBSD.ORG Tue Sep 18 19:00:52 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0EE68106564A; Tue, 18 Sep 2012 19:00:52 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from mail-lpp01m010-f54.google.com (mail-lpp01m010-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 5CAD68FC12; Tue, 18 Sep 2012 19:00:49 +0000 (UTC) Received: by lahe6 with SMTP id e6so7139lah.13 for ; Tue, 18 Sep 2012 12:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=CuR34U0p/4G2mmwNAeNjJnB+b8PUx8v5rVPXGGl+Ubo=; b=B1ngsx2rLNG6lAA6a8IEwdrlpQHEU8IOW3a+BIeaG07Y0CpbjsMQraUvnJ4g75BFUZ kx7neDFOq+9BqqMc0QM4Lvo4VvY3r0q6aPfff8n3DAYfzegf0QIdh7cMJMfGSG3pc5kG vzpajRyqCUZND/o/Yn1x4bqnAuRBOgrPD0WC+jX8eCVmUDizv/L5ppuLa+HSVOhlS5vT vkPKXFojVOaHTG23ZFreeOEMWlk6clw7fiSv5VTP9wHztJsuK/ZCVRQc68/6UXMBzpZu RTwuR3D5qs4R6nZy3pn0deJBs96akg79dz8T+RMgOoNndA9muouDHDN4O3O01/7fF/vO zzmw== MIME-Version: 1.0 Received: by 10.152.131.68 with SMTP id ok4mr589903lab.47.1347994848689; Tue, 18 Sep 2012 12:00:48 -0700 (PDT) Sender: asmrookie@gmail.com Received: by 10.112.102.39 with HTTP; Tue, 18 Sep 2012 12:00:48 -0700 (PDT) In-Reply-To: References: <201207301350.q6UDobCI099069@svn.freebsd.org> <201207301732.33474.jhb@freebsd.org> <20120918083324.GX37286@deviant.kiev.zoral.com.ua> Date: Tue, 18 Sep 2012 20:00:48 +0100 X-Google-Sender-Auth: 82XaShVBfQZMvfG9kLpp8RBDVF8 Message-ID: From: Attilio Rao To: Konstantin Belousov Content-Type: text/plain; charset=UTF-8 Cc: Davide Italiano , src-committers@freebsd.org, John Baldwin , Jeff Roberson , Dimitry Andric , svn-src-projects@freebsd.org Subject: Re: svn commit: r238907 - projects/calloutng/sys/kern X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: attilio@FreeBSD.org List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Sep 2012 19:00:52 -0000 On Tue, Sep 18, 2012 at 4:30 PM, Attilio Rao wrote: > On 9/18/12, Konstantin Belousov wrote: >> On Tue, Sep 18, 2012 at 01:13:08AM +0100, Attilio Rao wrote: >>> diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h >>> index 8224672..fc6a75f 100644 >>> --- a/sys/sys/cdefs.h >>> +++ b/sys/sys/cdefs.h >>> @@ -114,6 +114,13 @@ >>> #endif >>> >>> /* >>> + * Compiler memory barriers, specific to gcc and clang. >>> + */ >>> +#if defined(__GNUC__) >>> +#define __compiler_membar() __asm __volatile(" " : : : >>> "memory") >>> +#endif >>> + >>> +/* >> >> Traditionally, we do provide the fallback for non-GNUC compilers, by >> defining extern function with the compatible signature. In this case, >> the empty function just works for the purpose, although with higher >> overhead than the GNUC case. > > I agree, we need a fallback here. Unfortunately I'm buried with job > stuff but I will provide an errata patch ASAP. Here is the patch. I didn't use a real extern function body for it, but just went with an empty macro. Attilio Index: sys/sparc64/include/atomic.h =================================================================== --- sys/sparc64/include/atomic.h (revisione 240672) +++ sys/sparc64/include/atomic.h (copia locale) @@ -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; \ }) Index: sys/pc98/include/bus.h =================================================================== --- sys/pc98/include/bus.h (revisione 240672) +++ sys/pc98/include/bus.h (copia locale) @@ -593,7 +593,7 @@ bus_space_barrier(bus_space_tag_t tag, bus_space_h 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 Index: sys/i386/include/atomic.h =================================================================== --- sys/i386/include/atomic.h (revisione 240672) +++ sys/i386/include/atomic.h (copia locale) @@ -296,7 +296,7 @@ atomic_fetchadd_int(volatile u_int *p, u_int v) 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 *p) \ u_##TYPE tmp; \ \ tmp = *p; \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ return (tmp); \ } \ struct __hack Index: sys/amd64/include/atomic.h =================================================================== --- sys/amd64/include/atomic.h (revisione 240672) +++ sys/amd64/include/atomic.h (copia locale) @@ -226,7 +226,7 @@ atomic_fetchadd_long(volatile u_long *p, u_long v) 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 *p) \ u_##TYPE tmp; \ \ tmp = *p; \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ return (tmp); \ } \ struct __hack Index: sys/sys/cdefs.h =================================================================== --- sys/sys/cdefs.h (revisione 240672) +++ sys/sys/cdefs.h (copia locale) @@ -487,6 +487,15 @@ #define __GLOBL1(sym) __asm__(".globl " #sym) #define __GLOBL(sym) __GLOBL1(sym) +/* + * Compiler memory barriers, specific to gcc and clang. + */ +#if defined(__GNUC__) +#define __compiler_membar() __asm __volatile(" " : : : "memory") +#else +#define __compiler_membar() struct __hack +#endif + #if defined(__GNUC__) || defined(__INTEL_COMPILER) #define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") #else Index: sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h =================================================================== --- sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h (revisione 240672) +++ sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h (copia locale) @@ -162,7 +162,7 @@ */ #define EFSCORRUPTED 990 /* Filesystem is corrupted */ -#define SYNCHRONIZE() barrier() +#define SYNCHRONIZE() __compiler_membar() #define __return_address __builtin_return_address(0) /* Index: sys/gnu/fs/xfs/FreeBSD/xfs_compat.h =================================================================== --- sys/gnu/fs/xfs/FreeBSD/xfs_compat.h (revisione 240672) +++ sys/gnu/fs/xfs/FreeBSD/xfs_compat.h (copia locale) @@ -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 */ Index: sys/kern/kern_rmlock.c =================================================================== --- sys/kern/kern_rmlock.c (revisione 240672) +++ sys/kern/kern_rmlock.c (copia locale) @@ -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_priotracker 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_priotracker sched_pin(); - compiler_memory_barrier(); + __compiler_membar(); td->td_critnest--; Index: sys/mips/include/cpufunc.h =================================================================== --- sys/mips/include/cpufunc.h (revisione 240672) +++ sys/mips/include/cpufunc.h (copia locale) @@ -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" Index: sys/x86/include/bus.h =================================================================== --- sys/x86/include/bus.h (revisione 240672) +++ sys/x86/include/bus.h (copia locale) @@ -1014,7 +1014,7 @@ bus_space_barrier(bus_space_tag_t tag __unused, bu __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory"); #endif else - __asm __volatile("" : : : "memory"); + __compiler_membar(); #endif }