Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Jan 2011 12:11:11 -0500
From:      John Baldwin <jhb@freebsd.org>
To:        current@freebsd.org
Subject:   HEADSUP: Realtime thread scheduling changed
Message-ID:  <201101141211.11674.jhb@freebsd.org>

next in thread | raw e-mail | index | archive | help
--Boundary-00=_vOIMNWWPyz9Y4cO
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit

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

--Boundary-00=_vOIMNWWPyz9Y4cO
Content-Type: message/rfc822;
  name="forwarded message"
Content-Transfer-Encoding: 7bit
Content-Description: John Baldwin <jhb@freebsd.org>: svn commit: r217410 - in
	head/sys: kern sys
Content-Disposition: inline

Return-Path: <owner-src-committers@FreeBSD.org>
Received: from bigwig.baldwin.cx ([unix socket])
	by bigwig.baldwin.cx (Cyrus v2.3.16) with LMTPA;
	Fri, 14 Jan 2011 12:08:14 -0500
X-Sieve: CMU Sieve 2.3
Received: from bigwig.baldwin.cx (localhost [IPv6:::1])
	by bigwig.baldwin.cx (Postfix) with ESMTP id 343138A01D
	for <john@localhost>; Fri, 14 Jan 2011 12:08:13 -0500 (EST)
Received: from cyrus.watson.org [65.122.17.42]
	by bigwig.baldwin.cx with POP3 (fetchmail-6.3.17)
	for <john@localhost> (single-drop);
	Fri, 14 Jan 2011 12:08:13 -0500 (EST)
Received: from cyrus.watson.org ([unix socket])
	by cyrus.watson.org (Cyrus v2.3.13) with LMTPA;
	Fri, 14 Jan 2011 12:07:07 -0500
X-Sieve: CMU Sieve 2.3
Received: from mx2.freebsd.org (mx2.freebsd.org [69.147.83.53])
	by cyrus.watson.org (Postfix) with ESMTP id 02EFB46B09
	for <jhb@cyrus.watson.org>; Fri, 14 Jan 2011 12:07:07 -0500 (EST)
Received: from hub.freebsd.org (hub.freebsd.org [IPv6:2001:4f8:fff6::36])
	by mx2.freebsd.org (Postfix) with ESMTP id 444C5153A6C
	for <jhb@cyrus.watson.org>; Fri, 14 Jan 2011 17:06:59 +0000 (UTC)
Received: by hub.freebsd.org (Postfix)
	id BD9B0106566B; Fri, 14 Jan 2011 17:06:56 +0000 (UTC)
Delivered-To: jhb@freebsd.org
Received: by hub.freebsd.org (Postfix, from userid 538)
	id 0F20C1065675; Fri, 14 Jan 2011 17:06:56 +0000 (UTC)
Delivered-To: src-committers@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 6999610656A6;
	Fri, 14 Jan 2011 17:06:54 +0000 (UTC) (envelope-from jhb@FreeBSD.org)
Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c])
	by mx1.freebsd.org (Postfix) with ESMTP id 57D1A8FC34;
	Fri, 14 Jan 2011 17:06:54 +0000 (UTC)
Received: from svn.freebsd.org (localhost [127.0.0.1])
	by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p0EH6sae094828;
	Fri, 14 Jan 2011 17:06:54 GMT (envelope-from jhb@svn.freebsd.org)
Received: (from jhb@localhost)
	by svn.freebsd.org (8.14.3/8.14.3/Submit) id p0EH6sXq094823;
	Fri, 14 Jan 2011 17:06:54 GMT (envelope-from jhb@svn.freebsd.org)
Message-Id: <201101141706.p0EH6sXq094823@svn.freebsd.org>
From: John Baldwin <jhb@FreeBSD.org>
Date: Fri, 14 Jan 2011 17:06:54 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
	svn-src-head@freebsd.org
Subject: svn commit: r217410 - in head/sys: kern sys
X-SVN-Group: head
MIME-Version: 1.0
Content-Type: text/plain;
  charset=UTF-8
Content-Transfer-Encoding: 8bit
Sender: owner-src-committers@FreeBSD.org
Precedence: bulk
X-Loop: FreeBSD.ORG
X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.2.6
	(bigwig.baldwin.cx); Fri, 14 Jan 2011 12:08:13 -0500 (EST)
X-Virus-Scanned: clamav-milter 0.96.3 at bigwig.baldwin.cx
X-Virus-Status: Clean
X-Spam-Status: No, score=-1.9 required=4.2 tests=BAYES_00,
	TVD_RCVD_SPACE_BRACKET, T_RP_MATCHES_RCVD,
	UNPARSEABLE_RELAY autolearn=ham version=3.3.1
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on bigwig.baldwin.cx
X-Length: 9004
X-UID: 54245

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)
@@ -908,7 +908,7 @@ 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)
@@ -118,11 +118,17 @@ 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
 
 /*
@@ -1893,6 +1899,8 @@ 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)
@@ -745,7 +745,8 @@ 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)
@@ -67,10 +67,10 @@
  * 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
@@ -81,7 +81,7 @@
 #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)
@@ -92,8 +92,11 @@
 #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)
@@ -106,10 +109,7 @@
 #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)

--Boundary-00=_vOIMNWWPyz9Y4cO--



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