From 6b2d8873dfc07c9680f24ec522ca06478ed74174 Mon Sep 17 00:00:00 2001 From: miod Date: Fri, 23 Aug 2024 18:45:28 +0000 Subject: [PATCH] Switch alpha to MI mplock code. --- sys/arch/alpha/alpha/lock_machdep.c | 176 ---------------------------- sys/arch/alpha/conf/files.alpha | 3 +- sys/arch/alpha/include/mplock.h | 47 +------- 3 files changed, 4 insertions(+), 222 deletions(-) delete mode 100644 sys/arch/alpha/alpha/lock_machdep.c diff --git a/sys/arch/alpha/alpha/lock_machdep.c b/sys/arch/alpha/alpha/lock_machdep.c deleted file mode 100644 index 4edcd536c41..00000000000 --- a/sys/arch/alpha/alpha/lock_machdep.c +++ /dev/null @@ -1,176 +0,0 @@ -/* $OpenBSD: lock_machdep.c,v 1.9 2024/07/03 01:36:50 jsg Exp $ */ - -/* - * Copyright (c) 2007 Artur Grabowski - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - - -#include -#include - -#include -#include - -#if defined(MP_LOCKDEBUG) -#ifndef DDB -#error "MP_LOCKDEBUG requires DDB" -#endif -#include - -/* CPU-dependent timing, needs this to be settable from ddb. */ -extern int __mp_lock_spinout; -#endif - -static inline int -__cpu_cas(volatile unsigned long *addr, unsigned long old, unsigned long new) -{ - unsigned long t0, v0; - - __asm volatile( - "1: ldq_l %1, 0(%2) \n" /* v0 = *addr */ - " cmpeq %1, %3, %0 \n" /* t0 = v0 == old */ - " beq %0, 2f \n" - " mov %4, %0 \n" /* t0 = new */ - " stq_c %0, 0(%2) \n" /* *addr = new */ - " beq %0, 3f \n" - " mb \n" - "2: br 4f \n" - "3: br 1b \n" /* update failed */ - "4: \n" - : "=&r" (t0), "=&r" (v0) - : "r" (addr), "r" (old), "r" (new) - : "memory"); - - return (v0 != old); -} - -void -__mp_lock_init(struct __mp_lock *lock) -{ - lock->mpl_cpu = NULL; - lock->mpl_count = 0; -} - -static inline void -__mp_lock_spin(struct __mp_lock *mpl) -{ -#ifndef MP_LOCKDEBUG - while (mpl->mpl_count != 0) - CPU_BUSY_CYCLE(); -#else - int nticks = __mp_lock_spinout; - if (!CPU_IS_PRIMARY(curcpu())) - nticks += nticks; - - while (mpl->mpl_count != 0 && --nticks > 0) - CPU_BUSY_CYCLE(); - - if (nticks == 0) { - db_printf("__mp_lock(%p): lock spun out\n", mpl); - db_enter(); - } -#endif -} - -void -__mp_lock(struct __mp_lock *mpl) -{ - int s; - struct cpu_info *ci = curcpu(); - - /* - * Please notice that mpl_count gets incremented twice for the - * first lock. This is on purpose. The way we release the lock - * in mp_unlock is to decrement the mpl_count and then check if - * the lock should be released. Since mpl_count is what we're - * spinning on, decrementing it in mpl_unlock to 0 means that - * we can't clear mpl_cpu, because we're no longer holding the - * lock. In theory mpl_cpu doesn't need to be cleared, but it's - * safer to clear it and besides, setting mpl_count to 2 on the - * first lock makes most of this code much simpler. - */ - while (1) { - s = splhigh(); - if (__cpu_cas(&mpl->mpl_count, 0, 1) == 0) { - alpha_mb(); - mpl->mpl_cpu = ci; - } - - if (mpl->mpl_cpu == ci) { - mpl->mpl_count++; - splx(s); - break; - } - splx(s); - - __mp_lock_spin(mpl); - } -} - -void -__mp_unlock(struct __mp_lock *mpl) -{ - int s; - -#ifdef MP_LOCKDEBUG - if (mpl->mpl_cpu != curcpu()) { - db_printf("__mp_unlock(%p): not held lock\n", mpl); - db_enter(); - } -#endif - - s = splhigh(); - if (--mpl->mpl_count == 1) { - mpl->mpl_cpu = NULL; - alpha_mb(); - mpl->mpl_count = 0; - } - splx(s); -} - -int -__mp_release_all(struct __mp_lock *mpl) -{ - int rv = mpl->mpl_count - 1; - int s; - -#ifdef MP_LOCKDEBUG - if (mpl->mpl_cpu != curcpu()) { - db_printf("__mp_release_all(%p): not held lock\n", mpl); - db_enter(); - } -#endif - - s = splhigh(); - mpl->mpl_cpu = NULL; - alpha_mb(); - mpl->mpl_count = 0; - splx(s); - - return (rv); -} - -void -__mp_acquire_count(struct __mp_lock *mpl, int count) -{ - while (count--) - __mp_lock(mpl); -} - -int -__mp_lock_held(struct __mp_lock *mpl, struct cpu_info *ci) -{ - return (mpl->mpl_cpu == ci); -} diff --git a/sys/arch/alpha/conf/files.alpha b/sys/arch/alpha/conf/files.alpha index 8a450d06962..19ee813e659 100644 --- a/sys/arch/alpha/conf/files.alpha +++ b/sys/arch/alpha/conf/files.alpha @@ -1,4 +1,4 @@ -# $OpenBSD: files.alpha,v 1.108 2023/02/06 11:16:22 miod Exp $ +# $OpenBSD: files.alpha,v 1.109 2024/08/23 18:45:28 miod Exp $ # $NetBSD: files.alpha,v 1.32 1996/11/25 04:03:21 cgd Exp $ # # alpha-specific configuration info @@ -279,7 +279,6 @@ file arch/alpha/alpha/db_interface.c ddb file arch/alpha/alpha/db_trace.c ddb file arch/alpha/alpha/interrupt.c file arch/alpha/alpha/ipifuncs.c multiprocessor -file arch/alpha/alpha/lock_machdep.c multiprocessor file arch/alpha/alpha/machdep.c file arch/alpha/alpha/mainbus.c file arch/alpha/alpha/locore.s diff --git a/sys/arch/alpha/include/mplock.h b/sys/arch/alpha/include/mplock.h index 32fb7305d97..193541a6ae5 100644 --- a/sys/arch/alpha/include/mplock.h +++ b/sys/arch/alpha/include/mplock.h @@ -1,51 +1,10 @@ -/* $OpenBSD: mplock.h,v 1.3 2024/07/03 01:36:50 jsg Exp $ */ +/* $OpenBSD: mplock.h,v 1.4 2024/08/23 18:45:28 miod Exp $ */ -/* - * Copyright (c) 2004 Niklas Hallqvist. 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 ``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 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. - */ +/* public domain */ #ifndef _MACHINE_MPLOCK_H_ #define _MACHINE_MPLOCK_H_ -/* - * Really simple spinlock implementation with recursive capabilities. - * Correctness is paramount, no fancyness allowed. - */ - -struct __mp_lock { - volatile struct cpu_info *mpl_cpu; - volatile long mpl_count; -}; - -#ifndef _LOCORE - -void __mp_lock_init(struct __mp_lock *); -void __mp_lock(struct __mp_lock *); -void __mp_unlock(struct __mp_lock *); -int __mp_release_all(struct __mp_lock *); -void __mp_acquire_count(struct __mp_lock *, int); -int __mp_lock_held(struct __mp_lock *, struct cpu_info *); - -#endif +#define __USE_MI_MPLOCK #endif /* !_MACHINE_MPLOCK_H */ -- 2.20.1