From 030e3428e0c23c47cef4dfab51f988a8fa665d19 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Sun, 27 Jan 2019 22:06:08 +0800 Subject: [PATCH] atomic: Alway use inline functions. Originally only builtin functions use the inline version of the atomic ops, while modules only use real function call, which is designed for binary compatibility. However, this kind of compatibility is not necessary for DragonFly. --- sys/cpu/x86_64/include/atomic.h | 111 ------------------------------ sys/cpu/x86_64/misc/atomic.c | 47 ------------- sys/platform/pc64/conf/files | 2 - sys/platform/vkernel64/conf/files | 2 - 4 files changed, 162 deletions(-) delete mode 100644 sys/cpu/x86_64/misc/atomic.c diff --git a/sys/cpu/x86_64/include/atomic.h b/sys/cpu/x86_64/include/atomic.h index 4361e6bd3d..b55717ee79 100644 --- a/sys/cpu/x86_64/include/atomic.h +++ b/sys/cpu/x86_64/include/atomic.h @@ -59,30 +59,6 @@ * atomic_readandclear_int(P) (return (*(u_int*)(P)); *(u_int*)(P) = 0;) */ -/* - * The above functions are expanded inline in the statically-linked - * kernel and lock prefixes are generated. - * - * Kernel modules call real functions which are built into the kernel. - */ -#if defined(KLD_MODULE) -#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \ - extern void atomic_##NAME##_##TYPE \ - (volatile u_##TYPE *p, u_##TYPE v); \ - extern void atomic_##NAME##_##TYPE##_nonlocked \ - (volatile u_##TYPE *p, u_##TYPE v); \ - extern void atomic_##NAME##_##TYPE##_xacquire \ - (volatile u_##TYPE *p, u_##TYPE v); \ - extern void atomic_##NAME##_##TYPE##_xrelease \ - (volatile u_##TYPE *p, u_##TYPE v); - -int atomic_testandset_int(volatile u_int *p, u_int v); -int atomic_testandset_long(volatile u_long *p, u_long v); -int atomic_testandclear_int(volatile u_int *p, u_int v); -int atomic_testandclear_long(volatile u_long *p, u_long v); - -#else /* !KLD_MODULE */ - /* * locked bus cycle * lock elision (backwards compatible) @@ -139,8 +115,6 @@ atomic_##NAME##_##TYPE##_nonlocked(volatile u_##TYPE *p, u_##TYPE v)\ : CONS (V)); \ } -#endif /* KLD_MODULE */ - /* egcs 1.1.2+ version */ ATOMIC_ASM(set, char, "orb %b1,%0", "iq", v) ATOMIC_ASM(clear, char, "andb %b1,%0", "iq", ~v) @@ -162,13 +136,6 @@ ATOMIC_ASM(clear, long, "andq %1,%0", "r", ~v) ATOMIC_ASM(add, long, "addq %1,%0", "r", v) ATOMIC_ASM(subtract, long, "subq %1,%0", "r", v) -#if defined(KLD_MODULE) - -u_long atomic_readandclear_long(volatile u_long *addr); -u_int atomic_readandclear_int(volatile u_int *addr); - -#else /* !KLD_MODULE */ - static __inline u_long atomic_readandclear_long(volatile u_long *addr) { @@ -201,8 +168,6 @@ atomic_readandclear_int(volatile u_int *addr) return (res); } -#endif /* KLD_MODULE */ - /* * atomic_poll_acquire_int(P) Returns non-zero on success, 0 if the lock * has already been acquired. @@ -213,16 +178,6 @@ atomic_readandclear_int(volatile u_int *addr) * cache-synchronizing instructions. */ -#if defined(KLD_MODULE) - -extern int atomic_swap_int(volatile int *addr, int value); -extern long atomic_swap_long(volatile long *addr, long value); -extern void *atomic_swap_ptr(volatile void **addr, void *value); -extern int atomic_poll_acquire_int(volatile u_int *p); -extern void atomic_poll_release_int(volatile u_int *p); - -#else - static __inline int atomic_swap_int(volatile int *addr, int value) { @@ -262,8 +217,6 @@ atomic_poll_release_int(volatile u_int *p) __asm __volatile(MPLOCKED "btrl $0,%0" : "+m" (*p)); } -#endif - /* * These functions operate on a 32 bit interrupt interlock which is defined * as follows: @@ -317,21 +270,6 @@ atomic_poll_release_int(volatile u_int *p) * atomic_intr_cond_dec(P) Decrement wait counter by 1. */ -#if defined(KLD_MODULE) - -void atomic_intr_init(__atomic_intr_t *p); -int atomic_intr_handler_disable(__atomic_intr_t *p); -void atomic_intr_handler_enable(__atomic_intr_t *p); -int atomic_intr_handler_is_enabled(__atomic_intr_t *p); -int atomic_intr_cond_test(__atomic_intr_t *p); -int atomic_intr_cond_try(__atomic_intr_t *p); -void atomic_intr_cond_enter(__atomic_intr_t *p, void (*func)(void *), void *arg); -void atomic_intr_cond_exit(__atomic_intr_t *p, void (*func)(void *), void *arg); -void atomic_intr_cond_inc(__atomic_intr_t *p); -void atomic_intr_cond_dec(__atomic_intr_t *p); - -#else - static __inline void atomic_intr_init(__atomic_intr_t *p) { @@ -433,8 +371,6 @@ atomic_intr_cond_exit(__atomic_intr_t *p, void (*func)(void *), void *arg) /* YYY the function call may clobber even more registers? */ } -#endif - /* * Atomic compare and set * @@ -444,41 +380,6 @@ atomic_intr_cond_exit(__atomic_intr_t *p, void (*func)(void *), void *arg) * allow the compiler to optimize the common case where the caller calls * these functions from inside a conditional. */ -#if defined(KLD_MODULE) - -extern int atomic_cmpxchg_int(volatile u_int *_dst, u_int _old, u_int _new); -extern int atomic_cmpxchg_long_test(volatile u_long *_dst, - u_long _old, u_long _new); -extern int atomic_cmpset_short(volatile u_short *_dst, - u_short _old, u_short _new); -extern int atomic_cmpset_int(volatile u_int *_dst, u_int _old, u_int _new); -extern int atomic_cmpset_int_xacquire(volatile u_int *_dst, - u_int _old, u_int _new); -extern int atomic_cmpset_int_xrelease(volatile u_int *_dst, - u_int _old, u_int _new); -extern int atomic_cmpset_long(volatile u_long *_dst, u_long _exp, u_long _src); -extern int atomic_cmpset_long_xacquire(volatile u_long *_dst, - u_long _exp, u_long _src); -extern int atomic_cmpset_long_xrelease(volatile u_long *_dst, - u_long _exp, u_long _src); - -extern int atomic_fcmpset_char(volatile u_char *_dst, - u_char *_old, u_char _new); -extern int atomic_fcmpset_short(volatile u_short *_dst, - u_short *_old, u_short _new); -extern int atomic_fcmpset_int(volatile u_int *_dst, - u_int *_old, u_int _new); -extern int atomic_fcmpset_long(volatile u_long *_dst, - u_long *_exp, u_long _src); - -extern u_int atomic_fetchadd_int(volatile u_int *_p, u_int _v); -extern u_int atomic_fetchadd_int_xacquire(volatile u_int *_p, u_int _v); -extern u_int atomic_fetchadd_int_xrelease(volatile u_int *_p, u_int _v); -extern u_long atomic_fetchadd_long(volatile u_long *_p, u_long _v); -extern u_long atomic_fetchadd_long_xacquire(volatile u_long *_p, u_long _v); -extern u_long atomic_fetchadd_long_xrelease(volatile u_long *_p, u_long _v); - -#else static __inline int atomic_cmpxchg_int(volatile u_int *_dst, u_int _old, u_int _new) @@ -774,16 +675,6 @@ atomic_testandclear_long(volatile u_long *p, u_long v) return (res); } -#endif /* KLD_MODULE */ - -#if defined(KLD_MODULE) - -#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \ -extern u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p); \ -extern void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v); - -#else /* !KLD_MODULE */ - #define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \ static __inline u_##TYPE \ atomic_load_acq_##TYPE(volatile u_##TYPE *p) \ @@ -812,8 +703,6 @@ atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ } \ struct __hack -#endif /* !KLD_MODULE */ - ATOMIC_STORE_LOAD(char, "cmpxchgb %b0,%1", "xchgb %b1,%0"); ATOMIC_STORE_LOAD(short,"cmpxchgw %w0,%1", "xchgw %w1,%0"); ATOMIC_STORE_LOAD(int, "cmpxchgl %0,%1", "xchgl %1,%0"); diff --git a/sys/cpu/x86_64/misc/atomic.c b/sys/cpu/x86_64/misc/atomic.c deleted file mode 100644 index 9af3cbb55f..0000000000 --- a/sys/cpu/x86_64/misc/atomic.c +++ /dev/null @@ -1,47 +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. - * - * $FreeBSD: src/sys/i386/i386/atomic.c,v 1.3 1999/08/28 00:43:40 peter Exp $ - */ - -/* 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 - -/* Firstly make atomic.h generate prototypes as it will for kernel modules */ -#define KLD_MODULE -#include -#undef _MACHINE_ATOMIC_H_ /* forget we included it */ -#undef _CPU_ATOMIC_H_ /* forget we included it */ -#undef KLD_MODULE - -/* Make atomic.h generate public functions */ -#define static -#undef __inline -#define __inline - -#include diff --git a/sys/platform/pc64/conf/files b/sys/platform/pc64/conf/files index 3c1400a6e9..30b26d6927 100644 --- a/sys/platform/pc64/conf/files +++ b/sys/platform/pc64/conf/files @@ -117,8 +117,6 @@ vfs/smbfs/smbfs_subr.c optional smbfs vfs/smbfs/smbfs_vfsops.c optional smbfs vfs/smbfs/smbfs_vnops.c optional smbfs -cpu/x86_64/misc/atomic.c standard \ - compile-with "${NORMAL_C} -fomit-frame-pointer ${WERROR}" cpu/x86_64/misc/cputimer_tsc.c standard platform/pc64/x86_64/autoconf.c standard platform/pc64/x86_64/mpboot.S standard diff --git a/sys/platform/vkernel64/conf/files b/sys/platform/vkernel64/conf/files index c02b143bd3..1ff7e6aa94 100644 --- a/sys/platform/vkernel64/conf/files +++ b/sys/platform/vkernel64/conf/files @@ -12,8 +12,6 @@ vfs/smbfs/smbfs_smb.c optional smbfs vfs/smbfs/smbfs_subr.c optional smbfs vfs/smbfs/smbfs_vfsops.c optional smbfs vfs/smbfs/smbfs_vnops.c optional smbfs -cpu/x86_64/misc/atomic.c standard \ - compile-with "${NORMAL_C} -fomit-frame-pointer ${WERROR}" cpu/x86_64/misc/cputimer_tsc.c standard platform/vkernel64/x86_64/autoconf.c standard platform/vkernel64/x86_64/mp.c standard \ -- 2.41.0