HEADSUP: Realtime thread scheduling changed

From: John Baldwin <jhb_at_freebsd.org>
Date: Fri, 14 Jan 2011 12:11:11 -0500
This is just a heads up that I've committed some changes to how the scheduler 
handles realtime thread priorities.  Please let me know of any issues you 
encounter with nice, rtprio, or idprio.  Note that as a result of these 
changes, rtprio threads will no longer share priorities with interactive 
timeshare threads.  Instead, rtprio threads are now always more important than 
non-rt threads.

-- 
John Baldwin

attached mail follows:


Author: jhb
Date: Fri Jan 14 17:06:54 2011
New Revision: 217410
URL: http://svn.freebsd.org/changeset/base/217410

Log:
  Rework realtime priority support:
  - Move the realtime priority range up above kernel sleep priorities and
    just below interrupt thread priorities.
  - Contract the interrupt and kernel sleep priority ranges a bit so that
    the timesharing priority band can be increased.  The new timeshare range
    is now slightly larger than the old realtime + timeshare ranges.
  - Change the ULE scheduler to no longer use realtime priorities for
    interactive threads.  Instead, the larger timeshare range is now split
    into separate subranges for interactive and non-interactive ("batch")
    threads.  The end result is that interactive threads and non-interactive
    threads still use the same priority ranges as before, but realtime
    threads now have a separate, dedicated priority range.
  - Do not modify the priority of non-timeshare threads in sched_sleep()
    or via cv_broadcastpri().  Realtime and idle priority threads will
    no longer have their priorities affected by sleeping in the kernel.
  
  Reviewed by:	jeff

Modified:
  head/sys/kern/sched_4bsd.c
  head/sys/kern/sched_ule.c
  head/sys/kern/subr_sleepqueue.c
  head/sys/sys/priority.h

Modified: head/sys/kern/sched_4bsd.c
==============================================================================
--- head/sys/kern/sched_4bsd.c	Fri Jan 14 16:42:13 2011	(r217409)
+++ head/sys/kern/sched_4bsd.c	Fri Jan 14 17:06:54 2011	(r217410)
_at__at_ -908,7 +908,7 _at__at_ sched_sleep(struct thread *td, int pri)
 	THREAD_LOCK_ASSERT(td, MA_OWNED);
 	td->td_slptick = ticks;
 	td->td_sched->ts_slptime = 0;
-	if (pri)
+	if (pri != 0 && PRI_BASE(td->td_pri_class) == PRI_TIMESHARE)
 		sched_prio(td, pri);
 	if (TD_IS_SUSPENDED(td) || pri >= PSOCK)
 		td->td_flags |= TDF_CANSWAP;

Modified: head/sys/kern/sched_ule.c
==============================================================================
--- head/sys/kern/sched_ule.c	Fri Jan 14 16:42:13 2011	(r217409)
+++ head/sys/kern/sched_ule.c	Fri Jan 14 17:06:54 2011	(r217410)
_at__at_ -118,11 +118,17 _at__at_ static struct td_sched td_sched0;
 
 /*
  * Priority ranges used for interactive and non-interactive timeshare
- * threads.  Interactive threads use realtime priorities.
- */
-#define	PRI_MIN_INTERACT	PRI_MIN_REALTIME
-#define	PRI_MAX_INTERACT	PRI_MAX_REALTIME
-#define	PRI_MIN_BATCH		PRI_MIN_TIMESHARE
+ * threads.  The timeshare priorities are split up into four ranges.
+ * The first range handles interactive threads.  The last three ranges
+ * (NHALF, x, and NHALF) handle non-interactive threads with the outer
+ * ranges supporting nice values.
+ */
+#define	PRI_TIMESHARE_RANGE	(PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE + 1)
+#define	PRI_INTERACT_RANGE	((PRI_TIMESHARE_RANGE - SCHED_PRI_NRESV) / 2)
+
+#define	PRI_MIN_INTERACT	PRI_MIN_TIMESHARE
+#define	PRI_MAX_INTERACT	(PRI_MIN_TIMESHARE + PRI_INTERACT_RANGE - 1)
+#define	PRI_MIN_BATCH		(PRI_MIN_TIMESHARE + PRI_INTERACT_RANGE)
 #define	PRI_MAX_BATCH		PRI_MAX_TIMESHARE
 
 /*
_at__at_ -1893,6 +1899,8 _at__at_ sched_sleep(struct thread *td, int prio)
 	td->td_slptick = ticks;
 	if (TD_IS_SUSPENDED(td) || prio >= PSOCK)
 		td->td_flags |= TDF_CANSWAP;
+	if (PRI_BASE(td->td_pri_class) != PRI_TIMESHARE)
+		return;
 	if (static_boost == 1 && prio)
 		sched_prio(td, prio);
 	else if (static_boost && td->td_priority > static_boost)

Modified: head/sys/kern/subr_sleepqueue.c
==============================================================================
--- head/sys/kern/subr_sleepqueue.c	Fri Jan 14 16:42:13 2011	(r217409)
+++ head/sys/kern/subr_sleepqueue.c	Fri Jan 14 17:06:54 2011	(r217410)
_at__at_ -745,7 +745,8 _at__at_ sleepq_resume_thread(struct sleepqueue *
 
 	/* Adjust priority if requested. */
 	MPASS(pri == 0 || (pri >= PRI_MIN && pri <= PRI_MAX));
-	if (pri != 0 && td->td_priority > pri)
+	if (pri != 0 && td->td_priority > pri &&
+	    PRI_BASE(td->td_pri_class) == PRI_TIMESHARE)
 		sched_prio(td, pri);
 
 	/*

Modified: head/sys/sys/priority.h
==============================================================================
--- head/sys/sys/priority.h	Fri Jan 14 16:42:13 2011	(r217409)
+++ head/sys/sys/priority.h	Fri Jan 14 17:06:54 2011	(r217410)
_at__at_ -67,10 +67,10 _at__at_
  * Priorities range from 0 to 255, but differences of less then 4 (RQ_PPQ)
  * are insignificant.  Ranges are as follows:
  *
- * Interrupt threads:		0 - 63
- * Top half kernel threads:	64 - 127
- * Realtime user threads:	128 - 159
- * Time sharing user threads:	160 - 223
+ * Interrupt threads:		0 - 47
+ * Realtime user threads:	48 - 79
+ * Top half kernel threads:	80 - 119
+ * Time sharing user threads:	120 - 223
  * Idle user threads:		224 - 255
  *
  * XXX If/When the specific interrupt thread and top half thread ranges
_at__at_ -81,7 +81,7 _at__at_
 #define	PRI_MAX			(255)		/* Lowest priority. */
 
 #define	PRI_MIN_ITHD		(PRI_MIN)
-#define	PRI_MAX_ITHD		(PRI_MIN_KERN - 1)
+#define	PRI_MAX_ITHD		(PRI_MIN_REALTIME - 1)
 
 #define	PI_REALTIME		(PRI_MIN_ITHD + 0)
 #define	PI_AV			(PRI_MIN_ITHD + 4)
_at__at_ -92,8 +92,11 _at__at_
 #define	PI_SOFT			(PRI_MIN_ITHD + 24)
 #define	PI_SWI(x)		(PI_SOFT + (x) * RQ_PPQ)
 
-#define	PRI_MIN_KERN		(64)
-#define	PRI_MAX_KERN		(PRI_MIN_REALTIME - 1)
+#define	PRI_MIN_REALTIME	(48)
+#define	PRI_MAX_REALTIME	(PRI_MIN_KERN - 1)
+
+#define	PRI_MIN_KERN		(80)
+#define	PRI_MAX_KERN		(PRI_MIN_TIMESHARE - 1)
 
 #define	PSWP			(PRI_MIN_KERN + 0)
 #define	PVM			(PRI_MIN_KERN + 4)
_at__at_ -106,10 +109,7 _at__at_
 #define	PLOCK			(PRI_MIN_KERN + 32)
 #define	PPAUSE			(PRI_MIN_KERN + 36)
 
-#define	PRI_MIN_REALTIME	(128)
-#define	PRI_MAX_REALTIME	(PRI_MIN_TIMESHARE - 1)
-
-#define	PRI_MIN_TIMESHARE	(160)
+#define	PRI_MIN_TIMESHARE	(120)
 #define	PRI_MAX_TIMESHARE	(PRI_MIN_IDLE - 1)
 
 #define	PUSER			(PRI_MIN_TIMESHARE)
Received on Fri Jan 14 2011 - 16:11:18 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:10 UTC