Index: alpha/clock.c =================================================================== RCS file: /cvs/src/sys/arch/alpha/alpha/clock.c,v retrieving revision 1.21 diff -u -p -r1.21 clock.c --- alpha/clock.c 23 Mar 2012 15:51:25 -0000 1.21 +++ alpha/clock.c 24 Jun 2015 00:21:51 -0000 @@ -70,6 +70,12 @@ struct timecounter rpcc_timecounter = { rpcc_get_timecount, NULL, ~0u, 0, "rpcc", 0, NULL }; +unsigned long +__rpcc_per_second(void) +{ + return (rpcc_timecounter.tc_frequency); +} + void clockattach(dev, fns) struct device *dev; Index: alpha/lock_machdep.c =================================================================== RCS file: /cvs/src/sys/arch/alpha/alpha/lock_machdep.c,v retrieving revision 1.3 diff -u -p -r1.3 lock_machdep.c --- alpha/lock_machdep.c 11 Feb 2015 03:56:00 -0000 1.3 +++ alpha/lock_machdep.c 24 Jun 2015 00:21:51 -0000 @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -34,29 +35,6 @@ 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) { @@ -67,22 +45,20 @@ __mp_lock_init(struct __mp_lock *lock) 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 (!CPU_IS_PRIMARY(curcpu())) /* XXX */ - ticks += ticks; /* XXX */ +#if defined(MP_LOCKDEBUG) + long target = (long)(alpha_rpcc() + __rpcc_per_second() * 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 ((long)alpha_rpcc() - target > 0) { + db_printf("%s: %p spun out", __func__, mpl); + Debugger(); + } #endif + } } void @@ -104,7 +80,7 @@ __mp_lock(struct __mp_lock *mpl) */ while (1) { s = splhigh(); - if (__cpu_cas(&mpl->mpl_count, 0, 1) == 0) { + if (atomic_cas_ulong(&mpl->mpl_count, 0, 1) == 0) { alpha_mb(); mpl->mpl_cpu = ci; } Index: alpha/mutex.c =================================================================== RCS file: /cvs/src/sys/arch/alpha/alpha/mutex.c,v retrieving revision 1.14 diff -u -p -r1.14 mutex.c --- alpha/mutex.c 17 Apr 2015 12:38:54 -0000 1.14 +++ alpha/mutex.c 24 Jun 2015 00:21:51 -0000 @@ -47,8 +47,20 @@ __mtx_init(struct mutex *mtx, int wantip void mtx_enter(struct mutex *mtx) { - while (mtx_enter_try(mtx) == 0) +#if defined(MP_LOCKDEBUG) + long target = (long)(alpha_rpcc() + __rpcc_per_second() * 8); +#endif + + while (mtx_enter_try(mtx) == 0) { SPINLOCK_SPIN_HOOK; + +#if defined(MP_LOCKDEBUG) + if ((long)alpha_rpcc() - target > 0) { + db_printf("%s: %p spun out", __func__, mtx); + Debugger(); + } +#endif + } } int Index: include/lock.h =================================================================== RCS file: /cvs/src/sys/arch/alpha/include/lock.h,v retrieving revision 1.9 diff -u -p -r1.9 lock.h --- include/lock.h 11 Feb 2015 03:56:00 -0000 1.9 +++ include/lock.h 24 Jun 2015 00:21:51 -0000 @@ -59,6 +59,9 @@ do { \ splx(__s); \ } \ } while (0) + +unsigned long __rpcc_per_second(void); + #endif /* MULTIPROCESSOR */ #endif /* _MACHINE_LOCK_H_ */