From owner-freebsd-arch@FreeBSD.ORG Tue Oct 28 18:26:51 2014 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id ED6162DB; Tue, 28 Oct 2014 18:26:51 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B8BA0240; Tue, 28 Oct 2014 18:26:51 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 8ADE7B9B4; Tue, 28 Oct 2014 14:26:50 -0400 (EDT) From: John Baldwin To: freebsd-arch@freebsd.org Subject: Re: amd64 modules still use atomics as callable functions Date: Tue, 28 Oct 2014 14:18:04 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20140415; KDE/4.5.5; amd64; ; ) References: <20141027224901.GC28049@dft-labs.eu> In-Reply-To: <20141027224901.GC28049@dft-labs.eu> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201410281418.04704.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 28 Oct 2014 14:26:50 -0400 (EDT) Cc: Mateusz Guzik , Konstantin Belousov , Alan Cox X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Oct 2014 18:26:52 -0000 On Monday, October 27, 2014 6:49:01 pm Mateusz Guzik wrote: > Turns out several years ago the kernel was modified to provide actual > functions for atomic operations and modules are always using them. > > I propose plugging it on amd64 in head. > > For stable/10 we can always provide them, but inline in modules by default > (testing a KLD_WANT_ATOMIC_FUNC knob?). I think some of the comments might need tweaking still: > diff --git a/sys/amd64/include/atomic.h b/sys/amd64/include/atomic.h > index 9110dc5..e7e1735 100644 > --- a/sys/amd64/include/atomic.h > +++ b/sys/amd64/include/atomic.h > @@ -69,28 +69,7 @@ > * The above functions are expanded inline in the statically-linked > * kernel. Lock prefixes are generated if an SMP kernel is being > * built. > - * > - * Kernel modules call real functions which are built into the kernel. > - * This allows kernel modules to be portable between UP and SMP systems. > */ > -#if defined(KLD_MODULE) || !defined(__GNUCLIKE_ASM) > -#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \ > -void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v); \ > -void atomic_##NAME##_barr_##TYPE(volatile u_##TYPE *p, u_##TYPE v) > - > -int atomic_cmpset_int(volatile u_int *dst, u_int expect, u_int src); > -int atomic_cmpset_long(volatile u_long *dst, u_long expect, u_long src); > -u_int atomic_fetchadd_int(volatile u_int *p, u_int v); > -u_long atomic_fetchadd_long(volatile u_long *p, u_long v); > -int atomic_testandset_int(volatile u_int *p, u_int v); > -int atomic_testandset_long(volatile u_long *p, u_int v); > - > -#define ATOMIC_LOAD(TYPE, LOP) \ > -u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p) > -#define ATOMIC_STORE(TYPE) \ > -void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v) > - > -#else /* !KLD_MODULE && __GNUCLIKE_ASM */ > > /* > * For userland, always use lock prefixes so that the binaries will run Like here: maybe "For userland and kernel modules, always use lock prefixes..." Also, this does break the !__GNUCLIKE_ASM case, but I'm not sure if that case actually works anyway. -- John Baldwin