aboutsummaryrefslogtreecommitdiff
path: root/sys/sys
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2017-02-07 14:49:36 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2017-02-07 14:49:36 +0000
commit8e5a3e9a9d926ac36fbc43133ed9e1d03e5d47e9 (patch)
tree9a9906685ffe17df8862adb359e8a58be41c303f /sys/sys
parent5267f6243d05744730cb1ab7be660d2f3972dda9 (diff)
downloadsrc-8e5a3e9a9d926ac36fbc43133ed9e1d03e5d47e9.tar.gz
src-8e5a3e9a9d926ac36fbc43133ed9e1d03e5d47e9.zip
locks: change backoff to exponential
Previous implementation would use a random factor to spread readers and reduce chances of starvation. This visibly reduces effectiveness of the mechanism. Switch to the more traditional exponential variant. Try to limit starvation by imposing an upper limit of spins after which spinning is half of what other threads get. Note the mechanism is turned off by default. Reviewed by: kib (previous version)
Notes
Notes: svn path=/head/; revision=313386
Diffstat (limited to 'sys/sys')
-rw-r--r--sys/sys/lock.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/sys/sys/lock.h b/sys/sys/lock.h
index dbe715a31540..89b61ab73ddd 100644
--- a/sys/sys/lock.h
+++ b/sys/sys/lock.h
@@ -202,9 +202,7 @@ 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 base;
u_int max;
};
@@ -215,19 +213,25 @@ struct lock_delay_arg {
};
static inline void
-lock_delay_arg_init(struct lock_delay_arg *la, struct lock_delay_config *lc) {
+lock_delay_arg_init(struct lock_delay_arg *la, struct lock_delay_config *lc)
+{
la->config = lc;
- la->delay = 0;
+ la->delay = lc->base;
la->spin_cnt = 0;
}
#define LOCK_DELAY_SYSINIT(func) \
SYSINIT(func##_ld, SI_SUB_LOCK, SI_ORDER_ANY, func, NULL)
+#define LOCK_DELAY_SYSINIT_DEFAULT(lc) \
+ SYSINIT(lock_delay_##lc##_ld, SI_SUB_LOCK, SI_ORDER_ANY, \
+ lock_delay_default_init, &lc)
+
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 lock_delay_default_init(struct lock_delay_config *);
void spinlock_enter(void);
void spinlock_exit(void);
void witness_init(struct lock_object *, const char *);