? arch/macppc/conf/DEBUG.MP Index: arch/macppc/include/lock.h =================================================================== RCS file: /cvs/src/sys/arch/macppc/include/lock.h,v retrieving revision 1.1 diff -u -p -r1.1 lock.h --- arch/macppc/include/lock.h 20 Mar 2007 20:59:53 -0000 1.1 +++ arch/macppc/include/lock.h 1 Jul 2015 03:46:20 -0000 @@ -1,3 +1,5 @@ /* $OpenBSD: lock.h,v 1.1 2007/03/20 20:59:53 kettenis Exp $ */ #include + +u_int32_t __mftbl_per_sec(void); Index: arch/macppc/macppc/clock.c =================================================================== RCS file: /cvs/src/sys/arch/macppc/macppc/clock.c,v retrieving revision 1.40 diff -u -p -r1.40 clock.c --- arch/macppc/macppc/clock.c 13 Jun 2015 07:16:36 -0000 1.40 +++ arch/macppc/macppc/clock.c 1 Jul 2015 03:46:20 -0000 @@ -324,6 +324,12 @@ cpu_initclocks() ppc_intr_enable(intrstate); } +u_int32_t +__mftbl_per_sec(void) +{ + return (tb_timecounter.tc_frequency); +} + void cpu_startclock() { Index: arch/macppc/macppc/genassym.cf =================================================================== RCS file: /cvs/src/sys/arch/macppc/macppc/genassym.cf,v retrieving revision 1.24 diff -u -p -r1.24 genassym.cf --- arch/macppc/macppc/genassym.cf 6 Sep 2014 10:45:29 -0000 1.24 +++ arch/macppc/macppc/genassym.cf 1 Jul 2015 03:46:20 -0000 @@ -97,8 +97,3 @@ member ci_disisave ifdef DIAGNOSTIC member ci_mutex_level endif - -struct mutex -member mtx_wantipl -member mtx_oldcpl -member mtx_owner Index: arch/powerpc/conf/files.powerpc =================================================================== RCS file: /cvs/src/sys/arch/powerpc/conf/files.powerpc,v retrieving revision 1.51 diff -u -p -r1.51 files.powerpc --- arch/powerpc/conf/files.powerpc 26 Jun 2015 11:15:32 -0000 1.51 +++ arch/powerpc/conf/files.powerpc 1 Jul 2015 03:46:20 -0000 @@ -13,8 +13,8 @@ file arch/powerpc/powerpc/process_machde file arch/powerpc/powerpc/sys_machdep.c file arch/powerpc/powerpc/trap.c file arch/powerpc/powerpc/vm_machdep.c +file arch/powerpc/powerpc/mutex.c file arch/powerpc/powerpc/lock_machdep.c multiprocessor -file arch/powerpc/powerpc/mutex.S file arch/powerpc/powerpc/intr.c file arch/powerpc/powerpc/softintr.c Index: arch/powerpc/include/lock.h =================================================================== RCS file: /cvs/src/sys/arch/powerpc/include/lock.h,v retrieving revision 1.6 diff -u -p -r1.6 lock.h --- arch/powerpc/include/lock.h 26 Jun 2015 12:46:13 -0000 1.6 +++ arch/powerpc/include/lock.h 1 Jul 2015 03:46:20 -0000 @@ -37,4 +37,6 @@ #ifndef _POWERPC_LOCK_H_ #define _POWERPC_LOCK_H_ +#define SPINLOCK_SPIN_HOOK do { } while (0) + #endif /* _POWERPC_LOCK_H_ */ Index: arch/powerpc/include/mutex.h =================================================================== RCS file: /cvs/src/sys/arch/powerpc/include/mutex.h,v retrieving revision 1.4 diff -u -p -r1.4 mutex.h --- arch/powerpc/include/mutex.h 29 Mar 2014 18:09:30 -0000 1.4 +++ arch/powerpc/include/mutex.h 1 Jul 2015 03:46:20 -0000 @@ -28,9 +28,9 @@ #define _POWERPC_MUTEX_H_ struct mutex { - int mtx_wantipl; - int mtx_oldcpl; volatile void *mtx_owner; + int mtx_wantipl; + int mtx_oldipl; }; /* @@ -47,7 +47,7 @@ struct mutex { #define __MUTEX_IPL(ipl) (ipl) #endif -#define MUTEX_INITIALIZER(ipl) { __MUTEX_IPL((ipl)), 0, NULL } +#define MUTEX_INITIALIZER(ipl) { NULL, __MUTEX_IPL(ipl), IPL_NONE } void __mtx_init(struct mutex *, int); #define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl))) @@ -67,6 +67,6 @@ void __mtx_init(struct mutex *, int); #define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0) #endif -#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldcpl +#define MUTEX_OLDIPL(mtx) ((mtx)->mtx_oldipl) #endif Index: arch/powerpc/powerpc/lock_machdep.c =================================================================== RCS file: /cvs/src/sys/arch/powerpc/powerpc/lock_machdep.c,v retrieving revision 1.2 diff -u -p -r1.2 lock_machdep.c --- arch/powerpc/powerpc/lock_machdep.c 26 Jun 2015 12:46:13 -0000 1.2 +++ arch/powerpc/powerpc/lock_machdep.c 1 Jul 2015 03:46:20 -0000 @@ -33,34 +33,23 @@ __mp_lock_init(struct __mp_lock *lock) lock->mpl_count = 0; } -#if defined(MP_LOCKDEBUG) -#ifndef DDB -#error "MP_LOCKDEBUG requires DDB" -#endif - -/* CPU-dependent timing, needs this to be settable from ddb. */ -extern int __mp_lock_spinout; -#endif - -#define SPINLOCK_SPIN_HOOK /**/ - -static __inline void +static inline void __mp_lock_spin(struct __mp_lock *mpl) { -#ifndef MP_LOCKDEBUG - while (mpl->mpl_count != 0) - SPINLOCK_SPIN_HOOK; -#else - int ticks = __mp_lock_spinout; +#if defined(MP_LOCKDEBUG) + int target = ppc_mftbl() + __mftbl_per_sec() * 8; +#endif - while (mpl->mpl_count != 0 && --ticks > 0) + while (mpl->mpl_count != 0) { SPINLOCK_SPIN_HOOK; - if (ticks == 0) { - db_printf("__mp_lock(%p): lock spun out", mpl); - Debugger(); - } +#if defined(MP_LOCKDEBUG) + if ((int)ppc_mftbl() - target > 0) { + db_printf("%s: %p spun out", __func__, mpl); + Debugger(); + } #endif + } } void @@ -122,7 +111,7 @@ __mp_unlock(struct __mp_lock *mpl) int __mp_release_all(struct __mp_lock *mpl) { - int rv = mpl->mpl_count - 1; + int count; int s; #ifdef MP_LOCKDEBUG @@ -133,12 +122,13 @@ __mp_release_all(struct __mp_lock *mpl) #endif s = ppc_intr_disable(); + count = mpl->mpl_count; mpl->mpl_cpu = NULL; membar_exit(); mpl->mpl_count = 0; ppc_intr_enable(s); - return (rv); + return (count - 1); } int @@ -168,5 +158,5 @@ __mp_acquire_count(struct __mp_lock *mpl int __mp_lock_held(struct __mp_lock *mpl) { - return mpl->mpl_cpu == curcpu(); + return (mpl->mpl_cpu == curcpu()); } Index: arch/powerpc/powerpc/mutex.S =================================================================== RCS file: arch/powerpc/powerpc/mutex.S diff -N arch/powerpc/powerpc/mutex.S --- arch/powerpc/powerpc/mutex.S 18 Jun 2014 18:42:29 -0000 1.16 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,182 +0,0 @@ -/* $OpenBSD: mutex.S,v 1.16 2014/06/18 18:42:29 kettenis Exp $ */ - -/* - * Copyright (c) 2007 Dale Rahn - * Copyright (c) 2007 Mark Kettenis - * - * 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 "assym.h" - -#include - -/* XXX */ -#define GET_CPUINFO(r) mfsprg r,0 - -ENTRY(__mtx_init) - li %r5,0 - stw %r4,MTX_WANTIPL(%r3) - stw %r5,MTX_OLDCPL(%r3) - stw %r5,MTX_OWNER(%r3) - blr - - -ENTRY(mtx_enter) - stwu %r1,-16(%r1) # reserve stack - mflr %r0 - stw %r0,20(%r1) # save return address -.L_retry: - stw %r3, 12(%r1) - lwz %r3,MTX_WANTIPL(%r3) # load new ipl - bl _C_LABEL(splraise) - mr %r7, %r3 - GET_CPUINFO(%r4) - lwz %r3,12(%r1) - li %r5,MTX_OWNER # load offset constant - lwarx %r6,%r5,%r3 # load reserve owner - cmpwi 0,%r6,0 # test owner == 0 - beq+ 0,.L_mutex_free # if owner == 0 branch free -.L_mutex_locked: -#ifdef DIAGNOSTIC - cmpl 0,%r4,%r6 - beq- .L_mutex_selflocked -#endif - stw %r3,12(%r1) # save mtx during lcsplx - la %r4,12(%r1) - stwcx. %r3,0,%r4 # unreserve owner - mr %r3,%r7 # move old cpl to arg0 - bl _C_LABEL(lcsplx) # call splx on old cpl - lwz %r3,12(%r1) - b .L_retry - -.L_mutex_free: - stwcx. %r4,%r5,%r3 # old owner was 0 cond store - bne- .L_mutex_locked # branch if reserve cancelled - isync # memory barrier -#ifdef DIAGNOSTIC - lwz %r6,CI_MUTEX_LEVEL(%r4) - addi %r6,%r6,1 # curpcu->ci_mutex_level++ - stw %r6,CI_MUTEX_LEVEL(%r4) -#endif - stw %r7,MTX_OLDCPL(%r3) # save old ipl - lwz %r0,20(%r1) # load return address - mtlr %r0 - addi %r1,%r1,16 # restore stack - blr - -#ifdef DIAGNOSTIC -.L_mutex_selflocked: - mr %r5, %r3 - lis %r3,.L_paniclocked@ha - la %r3,.L_paniclocked@l(%r3) - bl panic -.L_paniclocked: - .string "mtx_enter: recursed %x %x\n" -#endif - - -ENTRY(mtx_enter_try) - stwu %r1,-16(%r1) # reserve stack - mflr %r0 - stw %r0,20(%r1) # save return address - stw %r3, 12(%r1) - lwz %r3,MTX_WANTIPL(%r3) # load new ipl - bl _C_LABEL(splraise) - mr %r7, %r3 - GET_CPUINFO(%r4) - lwz %r3,12(%r1) - li %r5,MTX_OWNER # load offset constant - lwarx %r6,%r5,%r3 # load reserve owner - cmpwi 0,%r6,0 # test owner == 0 - beq+ 0,.L_mutex_try_free # if owner == 0 branch free -.L_mutex_try_locked: -#ifdef DIAGNOSTIC - cmpl 0,%r4,%r6 - beq- .L_mutex_try_selflocked -#endif - stw %r3,12(%r1) # save mtx during lcsplx - la %r4,12(%r1) - stwcx. %r3,0,%r4 # unreserve owner - mr %r3,%r7 # move old cpl to arg0 - bl _C_LABEL(lcsplx) # call splx on old cpl - - lwz %r0,20(%r1) # load return address - mtlr %r0 - addi %r1,%r1,16 # restore stack - li %r3,0 # return zero - blr - -.L_mutex_try_free: - stwcx. %r4,%r5,%r3 # old owner was 0 cond store - bne- .L_mutex_try_locked # branch if reserve cancelled - isync # memory barrier -#ifdef DIAGNOSTIC - lwz %r6,CI_MUTEX_LEVEL(%r4) - addi %r6,%r6,1 # curpcu->ci_mutex_level++ - stw %r6,CI_MUTEX_LEVEL(%r4) -#endif - stw %r7,MTX_OLDCPL(%r3) # save old ipl - lwz %r0,20(%r1) # load return address - mtlr %r0 - addi %r1,%r1,16 # restore stack - li %r3,1 # return nonzero - blr - -#ifdef DIAGNOSTIC -.L_mutex_try_selflocked: - mr %r5, %r3 - lis %r3,.L_panictrylocked@ha - la %r3,.L_panictrylocked@l(%r3) - bl panic -.L_panictrylocked: - .string "mtx_enter_try: recursed %x %x\n" -#endif - - -ENTRY(mtx_leave) -#ifdef DIAGNOSTIC - lwz %r6,MTX_OWNER(%r3) - cmpwi 0,%r6,0 # test owner == 0 - - beq- .L_mutex_notlocked -#endif - li %r4,0 - lwz %r5,MTX_OLDCPL(%r3) - stw %r4,MTX_OLDCPL(%r3) - sync # memory barrier - stw %r4,MTX_OWNER(%r3) - GET_CPUINFO(%r4) -#ifdef DIAGNOSTIC - lwz %r6,CI_MUTEX_LEVEL(%r4) - addi %r6,%r6,-1 # curpcu->ci_mutex_level-- - stw %r6,CI_MUTEX_LEVEL(%r4) -#endif - mr %r3,%r5 - lwz %r5,CI_CPL(%r4) - cmpl 0,%r3,%r5 - beq 1f - b _C_LABEL(lcsplx) -1: - blr - -#ifdef DIAGNOSTIC -.L_mutex_notlocked: - GET_CPUINFO(%r4) - mr %r5, %r3 - lis %r3,.L_panicnotlocked@ha - la %r3,.L_panicnotlocked@l(%r3) - bl panic -.L_panicnotlocked: - .string "mtx_leave: not locked %x %x\n" -#endif Index: arch/powerpc/powerpc/mutex.c =================================================================== RCS file: arch/powerpc/powerpc/mutex.c diff -N arch/powerpc/powerpc/mutex.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ arch/powerpc/powerpc/mutex.c 1 Jul 2015 03:46:20 -0000 @@ -0,0 +1,141 @@ +/* $OpenBSD: mutex.c,v 1.14 2015/04/17 12:38:54 dlg Exp $ */ + +/* + * Copyright (c) 2004 Artur Grabowski + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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. + */ + +#include +#include +#include +#include + +#include +#include + +#include + +void +__mtx_init(struct mutex *mtx, int ipl) +{ + mtx->mtx_owner = NULL; + mtx->mtx_wantipl = ipl; + mtx->mtx_oldipl = IPL_NONE; +} + +#ifdef MULTIPROCESSOR +void +mtx_enter(struct mutex *mtx) +{ +#if defined(MP_LOCKDEBUG) + int target = ppc_mftbl() + __mftbl_per_sec() * 8; +#endif + + while (mtx_enter_try(mtx) == 0) { + SPINLOCK_SPIN_HOOK; + +#if defined(MP_LOCKDEBUG) + if ((int)ppc_mftbl() - target > 0) { + db_printf("%s: %p lock spun out", __func__, mtx); + Debugger(); + } +#endif + } +} + +int +mtx_enter_try(struct mutex *mtx) +{ + struct cpu_info *owner, *ci = curcpu(); + int s; + + if (mtx->mtx_wantipl != IPL_NONE) + s = splraise(mtx->mtx_wantipl); + + owner = atomic_cas_ptr(&mtx->mtx_owner, NULL, ci); +#ifdef DIAGNOSTIC + if (__predict_false(owner == ci)) + panic("mtx %p: locking against myself", mtx); +#endif + if (owner == NULL) { + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = s; +#ifdef DIAGNOSTIC + ci->ci_mutex_level++; +#endif + membar_enter(); + return (1); + } + + if (mtx->mtx_wantipl != IPL_NONE) + splx(s); + + return (0); +} +#else +void +mtx_enter(struct mutex *mtx) +{ + struct cpu_info *ci = curcpu(); + +#ifdef DIAGNOSTIC + if (__predict_false(mtx->mtx_owner == ci)) + panic("mtx %p: locking against myself", mtx); +#endif + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); + + mtx->mtx_owner = ci; + +#ifdef DIAGNOSTIC + ci->ci_mutex_level++; +#endif +} + +int +mtx_enter_try(struct mutex *mtx) +{ + mtx_enter(mtx); + return (1); +} +#endif + +void +mtx_leave(struct mutex *mtx) +{ + int s; + + MUTEX_ASSERT_LOCKED(mtx); + +#ifdef MULTIPROCESSOR + membar_exit(); +#endif +#ifdef DIAGNOSTIC + curcpu()->ci_mutex_level--; +#endif + + s = mtx->mtx_oldipl; + mtx->mtx_owner = NULL; + if (mtx->mtx_wantipl != IPL_NONE) + splx(s); +} Index: conf/GENERIC =================================================================== RCS file: /cvs/src/sys/conf/GENERIC,v retrieving revision 1.216 diff -u -p -r1.216 GENERIC --- conf/GENERIC 12 Mar 2015 23:54:15 -0000 1.216 +++ conf/GENERIC 1 Jul 2015 03:46:20 -0000 @@ -18,6 +18,7 @@ option PTRACE # ptrace(2) system call #option KVA_GUARDPAGES # slow virtual address recycling (+ guarding) option POOL_DEBUG # pool corruption detection +option MP_LOCKDEBUG # SMP lock debugging #option VFSLCKDEBUG # VFS locking checks option CRYPTO # Cryptographic framework Index: kern/init_main.c =================================================================== RCS file: /cvs/src/sys/kern/init_main.c,v retrieving revision 1.240 diff -u -p -r1.240 init_main.c --- kern/init_main.c 18 May 2015 04:07:26 -0000 1.240 +++ kern/init_main.c 1 Jul 2015 03:46:23 -0000 @@ -525,7 +525,7 @@ main(void *framep) if (kthread_create(uvm_aiodone_daemon, NULL, NULL, "aiodoned")) panic("fork aiodoned"); -#if !defined(__hppa__) +#if 0 /* Create the page zeroing kernel thread. */ if (kthread_create(uvm_pagezero_thread, NULL, NULL, "zerothread")) panic("fork zerothread"); @@ -551,9 +551,7 @@ main(void *framep) /* * Start the idle pool page garbage collector */ -#if notyet pool_gc_pages(NULL); -#endif /* * proc0: nothing to do, back to sleep Index: kern/subr_pool.c =================================================================== RCS file: /cvs/src/sys/kern/subr_pool.c,v retrieving revision 1.185 diff -u -p -r1.185 subr_pool.c --- kern/subr_pool.c 21 Apr 2015 13:15:54 -0000 1.185 +++ kern/subr_pool.c 1 Jul 2015 03:46:23 -0000 @@ -241,7 +241,7 @@ pool_init(struct pool *pp, size_t size, size = roundup(size, align); if (palloc == NULL) { - while (size > pgsize) + while (size * 8 > pgsize) pgsize <<= 1; if (pgsize > PAGE_SIZE) {