aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/lock.h
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2017-10-05 19:18:02 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2017-10-05 19:18:02 +0000
commitd07e22cdd8b156267a70d2be0f2af2c5081d6dd5 (patch)
treecf91f68e2025c93b6be0272f1ce506e5d858c51a /sys/sys/lock.h
parent6cdf28b7ad1410ac40403ba0efcbe10836b01234 (diff)
downloadsrc-d07e22cdd8b156267a70d2be0f2af2c5081d6dd5.tar.gz
src-d07e22cdd8b156267a70d2be0f2af2c5081d6dd5.zip
locks: take the number of readers into account when waiting
Previous code would always spin once before checking the lock. But a lock with e.g. 6 readers is not going to become free in the duration of once spin even if they start draining immediately. Conservatively perform one for each reader. Note that the total number of allowed spins is still extremely small and is subject to change later. MFC after: 1 week
Notes
Notes: svn path=/head/; revision=324335
Diffstat (limited to 'sys/sys/lock.h')
-rw-r--r--sys/sys/lock.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/sys/sys/lock.h b/sys/sys/lock.h
index a5beba116fca..fb3ad3101e88 100644
--- a/sys/sys/lock.h
+++ b/sys/sys/lock.h
@@ -226,6 +226,13 @@ lock_delay_arg_init(struct lock_delay_arg *la, struct lock_delay_config *lc)
la->spin_cnt = 0;
}
+#define lock_delay_spin(n) do { \
+ u_int _i; \
+ \
+ for (_i = (n); _i > 0; _i--) \
+ cpu_spinwait(); \
+} while (0)
+
#define LOCK_DELAY_SYSINIT(func) \
SYSINIT(func##_ld, SI_SUB_LOCK, SI_ORDER_ANY, func, NULL)