Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Nov 2017 02:45:38 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325924 - head/sys/kern
Message-ID:  <201711170245.vAH2jceC055359@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Fri Nov 17 02:45:38 2017
New Revision: 325924
URL: https://svnweb.freebsd.org/changeset/base/325924

Log:
  sched: move panic handling code out of choosethread
  
  This avoids jumps in the common case of the kernel not being panicked.

Modified:
  head/sys/kern/kern_switch.c

Modified: head/sys/kern/kern_switch.c
==============================================================================
--- head/sys/kern/kern_switch.c	Fri Nov 17 02:29:06 2017	(r325923)
+++ head/sys/kern/kern_switch.c	Fri Nov 17 02:45:38 2017	(r325924)
@@ -150,24 +150,37 @@ SYSCTL_PROC(_kern_sched_stats, OID_AUTO, reset, CTLTYP
 /*
  * Select the thread that will be run next.
  */
-struct thread *
-choosethread(void)
+
+static __noinline struct thread *
+choosethread_panic(struct thread *td)
 {
-	struct thread *td;
 
-retry:
-	td = sched_choose();
-
 	/*
 	 * 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;
 	}
+
+	TD_SET_RUNNING(td);
+	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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711170245.vAH2jceC055359>