diff options
author | kib <kib@FreeBSD.org> | 2017-01-29 10:36:43 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2017-01-29 10:36:43 +0000 |
commit | 3ca4bd7038bc932860d497e767cea75877f48792 (patch) | |
tree | 910e375bb13191a20480bc5e20bbc67d8bd08fe7 /sys/kern/kern_switch.c | |
parent | 2e7e51bf20e15bc18031d492da74e0ddefbf1691 (diff) | |
download | FreeBSD-src-3ca4bd7038bc932860d497e767cea75877f48792.zip FreeBSD-src-3ca4bd7038bc932860d497e767cea75877f48792.tar.gz |
MFC r312647:
Add comments explaining unobvious td_critnest adjustments in
critical_exit().
Diffstat (limited to 'sys/kern/kern_switch.c')
-rw-r--r-- | sys/kern/kern_switch.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/sys/kern/kern_switch.c b/sys/kern/kern_switch.c index d0009b1..f58acd5 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--; |