summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2018-04-26 06:51:48 +0000
committermpi <mpi@openbsd.org>2018-04-26 06:51:48 +0000
commit6dae24f41ad5c55e1c4b5d401c02ac60379625f1 (patch)
treea712220c7b848d752ae4408fb10a43875c7b1868
parentRewrite fdcopy() to avoid memcpy()s. (diff)
downloadwireguard-openbsd-6dae24f41ad5c55e1c4b5d401c02ac60379625f1.tar.xz
wireguard-openbsd-6dae24f41ad5c55e1c4b5d401c02ac60379625f1.zip
Drop into ddb(4) if pmap_tlb_shoot*() take too much time in MP_LOCKDEBUG
kernels. While here sync all MP_LOCKDEBUG/while loops. ok mlarkin@, visa@
-rw-r--r--sys/arch/amd64/amd64/pmap.c63
-rw-r--r--sys/kern/kern_lock.c13
2 files changed, 63 insertions, 13 deletions
diff --git a/sys/arch/amd64/amd64/pmap.c b/sys/arch/amd64/amd64/pmap.c
index 83c00098922..adc8366722e 100644
--- a/sys/arch/amd64/amd64/pmap.c
+++ b/sys/arch/amd64/amd64/pmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pmap.c,v 1.113 2018/04/17 06:31:55 mlarkin Exp $ */
+/* $OpenBSD: pmap.c,v 1.114 2018/04/26 06:51:48 mpi Exp $ */
/* $NetBSD: pmap.c,v 1.3 2003/05/08 18:13:13 thorpej Exp $ */
/*
@@ -2832,6 +2832,10 @@ pmap_convert(struct pmap *pmap, int mode)
* doesn't hold since we can end up in situations where noone will
* release the lock if we get an interrupt in a bad moment.
*/
+#ifdef MP_LOCKDEBUG
+#include <ddb/db_output.h>
+extern int __mp_lock_spinout;
+#endif
volatile long tlb_shoot_wait __attribute__((section(".kudata")));
@@ -2858,8 +2862,20 @@ pmap_tlb_shootpage(struct pmap *pm, vaddr_t va, int shootself)
int s = splvm();
while (atomic_cas_ulong(&tlb_shoot_wait, 0, wait) != 0) {
- while (tlb_shoot_wait != 0)
+#ifdef MP_LOCKDEBUG
+ int nticks = __mp_lock_spinout;
+#endif
+ while (tlb_shoot_wait != 0) {
CPU_BUSY_CYCLE();
+#ifdef MP_LOCKDEBUG
+
+ if (--nticks <= 0) {
+ db_printf("%s: spun out", __func__);
+ db_enter();
+ nticks = __mp_lock_spinout;
+ }
+#endif
+ }
}
tlb_shoot_addr1 = va;
CPU_INFO_FOREACH(cii, ci) {
@@ -2896,8 +2912,20 @@ pmap_tlb_shootrange(struct pmap *pm, vaddr_t sva, vaddr_t eva, int shootself)
int s = splvm();
while (atomic_cas_ulong(&tlb_shoot_wait, 0, wait) != 0) {
- while (tlb_shoot_wait != 0)
+#ifdef MP_LOCKDEBUG
+ int nticks = __mp_lock_spinout;
+#endif
+ while (tlb_shoot_wait != 0) {
CPU_BUSY_CYCLE();
+#ifdef MP_LOCKDEBUG
+
+ if (--nticks <= 0) {
+ db_printf("%s: spun out", __func__);
+ db_enter();
+ nticks = __mp_lock_spinout;
+ }
+#endif
+ }
}
tlb_shoot_addr1 = sva;
tlb_shoot_addr2 = eva;
@@ -2935,8 +2963,20 @@ pmap_tlb_shoottlb(struct pmap *pm, int shootself)
int s = splvm();
while (atomic_cas_ulong(&tlb_shoot_wait, 0, wait) != 0) {
- while (tlb_shoot_wait != 0)
+#ifdef MP_LOCKDEBUG
+ int nticks = __mp_lock_spinout;
+#endif
+ while (tlb_shoot_wait != 0) {
CPU_BUSY_CYCLE();
+#ifdef MP_LOCKDEBUG
+
+ if (--nticks <= 0) {
+ db_printf("%s: spun out", __func__);
+ db_enter();
+ nticks = __mp_lock_spinout;
+ }
+#endif
+ }
}
CPU_INFO_FOREACH(cii, ci) {
@@ -2955,11 +2995,22 @@ pmap_tlb_shoottlb(struct pmap *pm, int shootself)
void
pmap_tlb_shootwait(void)
{
- while (tlb_shoot_wait != 0)
+#ifdef MP_LOCKDEBUG
+ int nticks = __mp_lock_spinout;
+#endif
+ while (tlb_shoot_wait != 0) {
CPU_BUSY_CYCLE();
+#ifdef MP_LOCKDEBUG
+ if (--nticks <= 0) {
+ db_printf("%s: spun out", __func__);
+ db_enter();
+ nticks = __mp_lock_spinout;
+ }
+#endif
+ }
}
-#else
+#else /* MULTIPROCESSOR */
void
pmap_tlb_shootpage(struct pmap *pm, vaddr_t va, int shootself)
diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c
index 53a6603ff7a..e1a8adc59a7 100644
--- a/sys/kern/kern_lock.c
+++ b/sys/kern/kern_lock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_lock.c,v 1.62 2018/04/25 10:30:41 mpi Exp $ */
+/* $OpenBSD: kern_lock.c,v 1.63 2018/04/26 06:51:48 mpi Exp $ */
/*
* Copyright (c) 2017 Visa Hankala
@@ -113,22 +113,21 @@ ___mp_lock_init(struct __mp_lock *mpl, struct lock_type *type)
static __inline void
__mp_lock_spin(struct __mp_lock *mpl, u_int me)
{
-#ifndef MP_LOCKDEBUG
- while (mpl->mpl_ticket != me)
- CPU_BUSY_CYCLE();
-#else
+#ifdef MP_LOCKDEBUG
int nticks = __mp_lock_spinout;
+#endif
while (mpl->mpl_ticket != me) {
CPU_BUSY_CYCLE();
+#ifdef MP_LOCKDEBUG
if (--nticks <= 0) {
- db_printf("__mp_lock(%p): lock spun out", mpl);
+ db_printf("%s: %p lock spun out", __func__, mpl);
db_enter();
nticks = __mp_lock_spinout;
}
- }
#endif
+ }
}
void