aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2017-11-17 02:45:38 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2017-11-17 02:45:38 +0000
commit32aef9ff05d6dda84bd8924efca2f5fb30e602d2 (patch)
tree84cecf385e7c6ef1f57ec0a68b266bef7ab73fcb /sys
parent997131646f75f696f4fd2e066896da7f552f87eb (diff)
downloadsrc-32aef9ff05d6dda84bd8924efca2f5fb30e602d2.tar.gz
src-32aef9ff05d6dda84bd8924efca2f5fb30e602d2.zip
sched: move panic handling code out of choosethread
This avoids jumps in the common case of the kernel not being panicked.
Notes
Notes: svn path=/head/; revision=325924
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_switch.c27
1 files 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.