aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/lock.h
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2016-08-01 21:48:37 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2016-08-01 21:48:37 +0000
commit1ada904147c50b3aad694c25fd46409324e79f36 (patch)
treeb028139badd977a970d22c6915536a75e4786fcf /sys/sys/lock.h
parente72a746a6edb54194f8c97ff967c6ea489e26dc8 (diff)
downloadsrc-1ada904147c50b3aad694c25fd46409324e79f36.tar.gz
src-1ada904147c50b3aad694c25fd46409324e79f36.zip
Implement trivial backoff for locking primitives.
All current spinning loops retry an atomic op the first chance they get, which leads to performance degradation under load. One classic solution to the problem consists of delaying the test to an extent. This implementation has a trivial linear increment and a random factor for each attempt. For simplicity, this first thouch implementation only modifies spinning loops where the lock owner is running. spin mutexes and thread lock were not modified. Current parameters are autotuned on boot based on mp_cpus. Autotune factors are very conservative and are subject to change later. Reviewed by: kib, jhb Tested by: pho MFC after: 1 week
Notes
Notes: svn path=/head/; revision=303643
Diffstat (limited to 'sys/sys/lock.h')
-rw-r--r--sys/sys/lock.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/sys/sys/lock.h b/sys/sys/lock.h
index 8d7a068500db..dbe715a31540 100644
--- a/sys/sys/lock.h
+++ b/sys/sys/lock.h
@@ -201,9 +201,33 @@ extern struct lock_class lock_class_lockmgr;
extern struct lock_class *lock_classes[];
+struct lock_delay_config {
+ u_int initial;
+ u_int step;
+ u_int min;
+ u_int max;
+};
+
+struct lock_delay_arg {
+ struct lock_delay_config *config;
+ u_int delay;
+ u_int spin_cnt;
+};
+
+static inline void
+lock_delay_arg_init(struct lock_delay_arg *la, struct lock_delay_config *lc) {
+ la->config = lc;
+ la->delay = 0;
+ la->spin_cnt = 0;
+}
+
+#define LOCK_DELAY_SYSINIT(func) \
+ SYSINIT(func##_ld, SI_SUB_LOCK, SI_ORDER_ANY, func, NULL)
+
void lock_init(struct lock_object *, struct lock_class *,
const char *, const char *, int);
void lock_destroy(struct lock_object *);
+void lock_delay(struct lock_delay_arg *);
void spinlock_enter(void);
void spinlock_exit(void);
void witness_init(struct lock_object *, const char *);