Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Oct 2014 23:49:01 +0100
From:      Mateusz Guzik <mjguzik@gmail.com>
To:        freebsd-arch@freebsd.org
Cc:        Konstantin Belousov <kib@FreeBSD.org>, Alan Cox <alc@rice.edu>
Subject:   amd64 modules still use atomics as callable functions
Message-ID:  <20141027224901.GC28049@dft-labs.eu>

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

diff --git a/sys/amd64/amd64/atomic.c b/sys/amd64/amd64/atomic.c
deleted file mode 100644
index 1b4ff7e..0000000
--- a/sys/amd64/amd64/atomic.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-
- * Copyright (c) 1999 Peter Jeremy
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* This file creates publically callable functions to perform various
- * simple arithmetic on memory which is atomic in the presence of
- * interrupts and multiple processors.
- */
-#include <sys/types.h>
-
-/* Firstly make atomic.h generate prototypes as it will for kernel modules */
-#define KLD_MODULE
-#include <machine/atomic.h>
-#undef _MACHINE_ATOMIC_H_	/* forget we included it */
-#undef KLD_MODULE
-#undef ATOMIC_ASM
-
-/* Make atomic.h generate public functions */
-#define WANT_FUNCTIONS
-#define static
-#undef __inline
-#define __inline
-
-#include <machine/atomic.h>
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
@@ -293,8 +272,6 @@ struct __hack
 
 #endif /* _KERNEL && !SMP */
 
-#endif /* KLD_MODULE || !__GNUCLIKE_ASM */
-
 ATOMIC_ASM(set,	     char,  "orb %b1,%0",  "iq",  v);
 ATOMIC_ASM(clear,    char,  "andb %b1,%0", "iq", ~v);
 ATOMIC_ASM(add,	     char,  "addb %b1,%0", "iq",  v);
diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index 9e5a2ed..0749b05 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -91,7 +91,6 @@ acpi_wakedata.h			optional	acpi			\
 #
 amd64/amd64/amd64_mem.c		optional	mem
 #amd64/amd64/apic_vector.S	standard
-amd64/amd64/atomic.c		standard
 amd64/amd64/autoconf.c		standard
 amd64/amd64/bios.c		standard
 amd64/amd64/bpf_jit_machdep.c	optional	bpf_jitter

-- 
Mateusz Guzik <mjguzik gmail.com>



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