From 32aef9ff05d6dda84bd8924efca2f5fb30e602d2 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Fri, 17 Nov 2017 02:45:38 +0000 Subject: [PATCH] sched: move panic handling code out of choosethread This avoids jumps in the common case of the kernel not being panicked. --- sys/kern/kern_switch.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/sys/kern/kern_switch.c b/sys/kern/kern_switch.c index f58acd5ed4c6..2cdec8d930f9 100644 --- a/sys/kern/kern_switch.c +++ b/sys/kern/kern_switch.c @@ -150,22 +150,21 @@ SYSCTL_PROC(_kern_sched_stats, OID_AUTO, reset, CTLTYPE_INT | CTLFLAG_WR, NULL, /* * Select the thread that will be run next. */ -struct thread * -choosethread(void) -{ - struct thread *td; -retry: - td = sched_choose(); +static __noinline struct thread * +choosethread_panic(struct thread *td) +{ /* * If we are in panic, only allow system threads, * plus the one we are running in, to be run. */ - if (panicstr && ((td->td_proc->p_flag & P_SYSTEM) == 0 && +retry: + if (((td->td_proc->p_flag & P_SYSTEM) == 0 && (td->td_flags & TDF_INPANIC) == 0)) { /* note that it is no longer on the run queue */ TD_SET_CAN_RUN(td); + td = sched_choose(); goto retry; } @@ -173,6 +172,20 @@ retry: return (td); } +struct thread * +choosethread(void) +{ + struct thread *td; + + td = sched_choose(); + + if (__predict_false(panicstr != NULL)) + return (choosethread_panic(td)); + + TD_SET_RUNNING(td); + return (td); +} + /* * Kernel thread preemption implementation. Critical sections mark * regions of code in which preemptions are not allowed.