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.