aboutsummaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2017-01-22 19:41:42 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2017-01-22 19:41:42 +0000
commit3467f88cd67c19360f4e8662e6f35701aa4921ce (patch)
treedf2a3c0988b663e8e633cab2a42d61847d672404 /sys/kern
parent25c6816845534edfc308efb67a2efa943b87dfc8 (diff)
downloadsrc-3467f88cd67c19360f4e8662e6f35701aa4921ce.tar.gz
src-3467f88cd67c19360f4e8662e6f35701aa4921ce.zip
Add comments explaining unobvious td_critnest adjustments in
critical_exit(). Based on the discussion with: jhb Reviewed by: imp Sponsored by: The FreeBSD Foundation Differential revision: D9276 MFC after: 1 week
Notes
Notes: svn path=/head/; revision=312647
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_switch.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/sys/kern/kern_switch.c b/sys/kern/kern_switch.c
index d0009b1042f3..f58acd5ed4c6 100644
--- a/sys/kern/kern_switch.c
+++ b/sys/kern/kern_switch.c
@@ -206,7 +206,22 @@ critical_exit(void)
if (td->td_critnest == 1) {
td->td_critnest = 0;
+
+ /*
+ * Interrupt handlers execute critical_exit() on
+ * leave, and td_owepreempt may be left set by an
+ * interrupt handler only when td_critnest > 0. If we
+ * are decrementing td_critnest from 1 to 0, read
+ * td_owepreempt after decrementing, to not miss the
+ * preempt. Disallow compiler to reorder operations.
+ */
+ __compiler_membar();
if (td->td_owepreempt && !kdb_active) {
+ /*
+ * Microoptimization: we committed to switch,
+ * disable preemption in interrupt handlers
+ * while spinning for the thread lock.
+ */
td->td_critnest = 1;
thread_lock(td);
td->td_critnest--;