amd64 modules still use atomics as callable functions

John Baldwin jhb at freebsd.org
Tue Oct 28 18:26:52 UTC 2014


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


More information about the freebsd-arch mailing list