Skip to content

Commit c7ecc8a

Browse files
committed
Promote __mp_lock_spinout to long
This lets us implement larger MP_LOCKDEBUG thresholds on very fast machines, so that we can tell transient contentions apart from actual lockups. deraadt@ expressed concerns that bumping the threshold might hide actual problems, but this diff doesn't change the threshold. As mentioned by mpi@ and claudio@ MP_LOCKDEBUG is a very crude tool, but it's the only tool we have right now. ok miod@ claudio@
1 parent 9dd6953 commit c7ecc8a

File tree

7 files changed

+22
-19
lines changed

7 files changed

+22
-19
lines changed

sys/arch/amd64/amd64/pmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: pmap.c,v 1.179 2025/06/18 15:05:53 jca Exp $ */
1+
/* $OpenBSD: pmap.c,v 1.180 2025/06/19 12:01:08 jca Exp $ */
22
/* $NetBSD: pmap.c,v 1.3 2003/05/08 18:13:13 thorpej Exp $ */
33

44
/*
@@ -3208,7 +3208,7 @@ pmap_start_tlb_shoot(long wait, const char *func)
32083208

32093209
while (atomic_cas_ulong(&tlb_shoot_wait, 0, wait) != 0) {
32103210
#ifdef MP_LOCKDEBUG
3211-
int nticks = __mp_lock_spinout;
3211+
long nticks = __mp_lock_spinout;
32123212
#endif
32133213
while (tlb_shoot_wait != 0) {
32143214
CPU_BUSY_CYCLE();
@@ -3421,7 +3421,7 @@ void
34213421
pmap_tlb_shootwait(void)
34223422
{
34233423
#ifdef MP_LOCKDEBUG
3424-
int nticks = __mp_lock_spinout;
3424+
long nticks = __mp_lock_spinout;
34253425
#endif
34263426
while (tlb_shoot_wait != 0) {
34273427
CPU_BUSY_CYCLE();

sys/arch/amd64/amd64/vmm_machdep.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: vmm_machdep.c,v 1.58 2025/06/18 15:05:53 jca Exp $ */
1+
/* $OpenBSD: vmm_machdep.c,v 1.59 2025/06/19 12:01:08 jca Exp $ */
22
/*
33
* Copyright (c) 2014 Mike Larkin <[email protected]>
44
*
@@ -635,7 +635,7 @@ vmm_start(void)
635635
struct cpu_info *ci;
636636
CPU_INFO_ITERATOR cii;
637637
#ifdef MP_LOCKDEBUG
638-
int nticks;
638+
long nticks;
639639
#endif /* MP_LOCKDEBUG */
640640
#endif /* MULTIPROCESSOR */
641641

@@ -695,7 +695,7 @@ vmm_stop(void)
695695
struct cpu_info *ci;
696696
CPU_INFO_ITERATOR cii;
697697
#ifdef MP_LOCKDEBUG
698-
int nticks;
698+
long nticks;
699699
#endif /* MP_LOCKDEBUG */
700700
#endif /* MULTIPROCESSOR */
701701

@@ -868,7 +868,7 @@ static int
868868
vmx_remote_vmclear(struct cpu_info *ci, struct vcpu *vcpu)
869869
{
870870
#ifdef MP_LOCKDEBUG
871-
int nticks = __mp_lock_spinout;
871+
long nticks = __mp_lock_spinout;
872872
#endif /* MP_LOCKDEBUG */
873873

874874
rw_enter_write(&ci->ci_vmcs_lock);

sys/arch/hppa/hppa/lock_machdep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: lock_machdep.c,v 1.16 2025/06/18 15:05:53 jca Exp $ */
1+
/* $OpenBSD: lock_machdep.c,v 1.17 2025/06/19 12:01:08 jca Exp $ */
22

33
/*
44
* Copyright (c) 2007 Artur Grabowski <[email protected]>
@@ -79,7 +79,7 @@ __mp_lock_spin(struct __mp_lock *mpl)
7979
while (mpl->mpl_count != 0)
8080
CPU_BUSY_CYCLE();
8181
#else
82-
int nticks = __mp_lock_spinout;
82+
long nticks = __mp_lock_spinout;
8383

8484
while (mpl->mpl_count != 0 && --nticks > 0)
8585
CPU_BUSY_CYCLE();

sys/arch/m88k/m88k/mutex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: mutex.c,v 1.2 2025/06/18 15:05:53 jca Exp $ */
1+
/* $OpenBSD: mutex.c,v 1.3 2025/06/19 12:01:08 jca Exp $ */
22

33
/*
44
* Copyright (c) 2020 Miodrag Vallat
@@ -52,7 +52,7 @@ mtx_enter(struct mutex *mtx)
5252
{
5353
struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
5454
#ifdef MP_LOCKDEBUG
55-
int nticks = __mp_lock_spinout;
55+
long nticks = __mp_lock_spinout;
5656
#endif
5757

5858
WITNESS_CHECKORDER(MUTEX_LOCK_OBJECT(mtx),

sys/arch/powerpc/powerpc/lock_machdep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: lock_machdep.c,v 1.13 2025/06/18 15:05:53 jca Exp $ */
1+
/* $OpenBSD: lock_machdep.c,v 1.14 2025/06/19 12:01:08 jca Exp $ */
22

33
/*
44
* Copyright (c) 2021 George Koehler <[email protected]>
@@ -51,7 +51,7 @@ __ppc_lock_spin(struct __ppc_lock *mpl)
5151
while (mpl->mpl_cpu != NULL)
5252
CPU_BUSY_CYCLE();
5353
#else
54-
int nticks = __mp_lock_spinout;
54+
long nticks = __mp_lock_spinout;
5555

5656
while (mpl->mpl_cpu != NULL && --nticks > 0)
5757
CPU_BUSY_CYCLE();

sys/kern/kern_lock.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: kern_lock.c,v 1.79 2025/06/10 08:56:21 mpi Exp $ */
1+
/* $OpenBSD: kern_lock.c,v 1.80 2025/06/19 12:01:08 jca Exp $ */
22

33
/*
44
* Copyright (c) 2017 Visa Hankala
@@ -33,8 +33,11 @@
3333
#error "MP_LOCKDEBUG requires DDB"
3434
#endif
3535

36-
/* CPU-dependent timing, this needs to be settable from ddb. */
37-
int __mp_lock_spinout = INT_MAX;
36+
/*
37+
* CPU-dependent timing, this needs to be settable from ddb.
38+
* Use a "long" to allow larger thresholds on fast 64 bits machines.
39+
*/
40+
long __mp_lock_spinout = 1L * INT_MAX;
3841
#endif /* MP_LOCKDEBUG */
3942

4043
extern int ncpusfound;
@@ -124,7 +127,7 @@ __mp_lock_spin(struct __mp_lock *mpl, u_int me)
124127
{
125128
struct schedstate_percpu *spc = &curcpu()->ci_schedstate;
126129
#ifdef MP_LOCKDEBUG
127-
int nticks = __mp_lock_spinout;
130+
long nticks = __mp_lock_spinout;
128131
#endif
129132

130133
spc->spc_spinning++;

sys/sys/systm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: systm.h,v 1.175 2025/06/18 15:05:53 jca Exp $ */
1+
/* $OpenBSD: systm.h,v 1.176 2025/06/19 12:01:08 jca Exp $ */
22
/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */
33

44
/*-
@@ -108,7 +108,7 @@ extern struct vnode *swapdev_vp;/* vnode equivalent to above */
108108
extern int nowake; /* dead wakeup(9) channel */
109109

110110
#ifdef MP_LOCKDEBUG
111-
extern int __mp_lock_spinout;
111+
extern long __mp_lock_spinout;
112112
#endif
113113

114114
struct proc;

0 commit comments

Comments
 (0)