Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Oct 2014 14:18:04 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-arch@freebsd.org
Cc:        Mateusz Guzik <mjguzik@gmail.com>, Konstantin Belousov <kib@freebsd.org>, Alan Cox <alc@rice.edu>
Subject:   Re: amd64 modules still use atomics as callable functions
Message-ID:  <201410281418.04704.jhb@freebsd.org>
In-Reply-To: <20141027224901.GC28049@dft-labs.eu>
References:  <20141027224901.GC28049@dft-labs.eu>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410281418.04704.jhb>