diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2019-12-07 00:28:08 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2019-12-07 00:28:08 +0000 |
| commit | ff326a187907ebc1d6ebb6b0d40caf1137e20377 (patch) | |
| tree | abf826f1fbb6dcc19d28ba463576d7b9cd4ed940 | |
| parent | 3e5b13991cd4e7febcc4165fe7bddfae8bcf5ba8 (diff) | |
x86: Restore the critical section around whole ipi_bitmap_handler() if
hardclock IPI is delivered.
In the current code after r355311, critical section is taken only
around hardclockintr() call, and sched_preempt() is called after the
section is exited. If we reschedule after exit, as we typically would
due to conditions that caused IPI, in ULE the runq tdq_ipipending is
not cleared, which blocks generation of further preempt IPIs.
Since all relatively modern (10 years) hardware has per-cpu event
timers, restoring the critical section conditionally does not affect
it.
Reported and tested by: cy
Diagnosed and reviewed by: jeff (previous version)
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D22716
Notes
svn path=/head/; revision=355475
| -rw-r--r-- | sys/x86/x86/mp_x86.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c index d3065144dbc2..ad64a163c145 100644 --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -1262,10 +1262,28 @@ ipi_bitmap_handler(struct trapframe frame) u_int ipi_bitmap; td = curthread; + ipi_bitmap = atomic_readandclear_int(&cpuid_to_pcpu[cpu]-> + pc_ipi_bitmap); + + /* + * sched_preempt() must be called to clear the pending preempt + * IPI to enable delivery of further preempts. However, the + * critical section will cause extra scheduler lock thrashing + * when used unconditionally. Only critical_enter() if + * hardclock must also run, which requires the section entry. + */ + if (ipi_bitmap & (1 << IPI_HARDCLOCK)) + critical_enter(); + td->td_intr_nesting_level++; oldframe = td->td_intr_frame; td->td_intr_frame = &frame; - ipi_bitmap = atomic_readandclear_int(&cpuid_to_pcpu[cpu]->pc_ipi_bitmap); + if (ipi_bitmap & (1 << IPI_PREEMPT)) { +#ifdef COUNT_IPIS + (*ipi_preempt_counts[cpu])++; +#endif + sched_preempt(td); + } if (ipi_bitmap & (1 << IPI_AST)) { #ifdef COUNT_IPIS (*ipi_ast_counts[cpu])++; @@ -1273,23 +1291,15 @@ ipi_bitmap_handler(struct trapframe frame) /* Nothing to do for AST */ } if (ipi_bitmap & (1 << IPI_HARDCLOCK)) { - critical_enter(); #ifdef COUNT_IPIS (*ipi_hardclock_counts[cpu])++; #endif hardclockintr(); - critical_exit(); - } - - /* Run preempt after clock handlers since it may switch. */ - if (ipi_bitmap & (1 << IPI_PREEMPT)) { -#ifdef COUNT_IPIS - (*ipi_preempt_counts[cpu])++; -#endif - sched_preempt(td); } td->td_intr_frame = oldframe; td->td_intr_nesting_level--; + if (ipi_bitmap & (1 << IPI_HARDCLOCK)) + critical_exit(); } /* |
