diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2017-04-16 14:28:08 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2017-04-16 14:28:08 +0000 |
commit | c0f49ca59c2f30be3746038928791a80ab410a8d (patch) | |
tree | 022233bc52469fc8bc3d508933d1d0ad85eeefc0 | |
parent | ce4805b5f46006e6586d912a0e0f42343900b477 (diff) |
Replace fetch_and_add() with atomic_inc_int_nv() from <sys/atomic.h>
to make the code more similar to sparc64's.
OK mpi@, guenther@, kettenis@
-rw-r--r-- | sys/arch/amd64/amd64/lock_machdep.c | 19 | ||||
-rw-r--r-- | sys/arch/i386/i386/lock_machdep.c | 19 |
2 files changed, 8 insertions, 30 deletions
diff --git a/sys/arch/amd64/amd64/lock_machdep.c b/sys/arch/amd64/amd64/lock_machdep.c index 7588e24ef62..f02efe0bb04 100644 --- a/sys/arch/amd64/amd64/lock_machdep.c +++ b/sys/arch/amd64/amd64/lock_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lock_machdep.c,v 1.11 2017/03/07 14:41:57 visa Exp $ */ +/* $OpenBSD: lock_machdep.c,v 1.12 2017/04/16 14:28:07 visa Exp $ */ /* * Copyright (c) 2007 Artur Grabowski <art@openbsd.org> @@ -19,8 +19,8 @@ #include <sys/param.h> #include <sys/systm.h> +#include <sys/atomic.h> -#include <machine/atomic.h> #include <machine/lock.h> #include <machine/cpufunc.h> @@ -31,7 +31,7 @@ __mp_lock_init(struct __mp_lock *mpl) { memset(mpl->mpl_cpus, 0, sizeof(mpl->mpl_cpus)); mpl->mpl_users = 0; - mpl->mpl_ticket = 0; + mpl->mpl_ticket = 1; } #if defined(MP_LOCKDEBUG) @@ -64,17 +64,6 @@ __mp_lock_spin(struct __mp_lock *mpl, u_int me) #endif } -static inline u_int -fetch_and_add(u_int *var, u_int value) -{ - asm volatile("lock; xaddl %%eax, %2;" - : "=a" (value) - : "a" (value), "m" (*var) - : "memory"); - - return (value); -} - void __mp_lock(struct __mp_lock *mpl) { @@ -83,7 +72,7 @@ __mp_lock(struct __mp_lock *mpl) disable_intr(); if (cpu->mplc_depth++ == 0) - cpu->mplc_ticket = fetch_and_add(&mpl->mpl_users, 1); + cpu->mplc_ticket = atomic_inc_int_nv(&mpl->mpl_users); write_rflags(rf); __mp_lock_spin(mpl, cpu->mplc_ticket); diff --git a/sys/arch/i386/i386/lock_machdep.c b/sys/arch/i386/i386/lock_machdep.c index 17d402658e2..9ab26924484 100644 --- a/sys/arch/i386/i386/lock_machdep.c +++ b/sys/arch/i386/i386/lock_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lock_machdep.c,v 1.20 2017/03/07 14:41:57 visa Exp $ */ +/* $OpenBSD: lock_machdep.c,v 1.21 2017/04/16 14:28:07 visa Exp $ */ /* $NetBSD: lock_machdep.c,v 1.1.2.3 2000/05/03 14:40:30 sommerfeld Exp $ */ /*- @@ -37,8 +37,8 @@ #include <sys/param.h> #include <sys/systm.h> +#include <sys/atomic.h> -#include <machine/atomic.h> #include <machine/lock.h> #include <machine/cpufunc.h> @@ -50,7 +50,7 @@ __mp_lock_init(struct __mp_lock *mpl) { memset(mpl->mpl_cpus, 0, sizeof(mpl->mpl_cpus)); mpl->mpl_users = 0; - mpl->mpl_ticket = 0; + mpl->mpl_ticket = 1; } #if defined(MP_LOCKDEBUG) @@ -62,17 +62,6 @@ __mp_lock_init(struct __mp_lock *mpl) extern int __mp_lock_spinout; #endif -static inline u_int -fetch_and_add(u_int *var, u_int value) -{ - asm volatile("lock; xaddl %%eax, %2;" - : "=a" (value) - : "a" (value), "m" (*var) - : "memory"); - - return (value); -} - static __inline void __mp_lock_spin(struct __mp_lock *mpl, u_int me) { @@ -102,7 +91,7 @@ __mp_lock(struct __mp_lock *mpl) disable_intr(); if (cpu->mplc_depth++ == 0) - cpu->mplc_ticket = fetch_and_add(&mpl->mpl_users, 1); + cpu->mplc_ticket = atomic_inc_int_nv(&mpl->mpl_users); write_eflags(ef); __mp_lock_spin(mpl, cpu->mplc_ticket); |