From nobody Mon Jul 28 13:31:33 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4brKBb4FD5z634Y1; Mon, 28 Jul 2025 13:31:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4brKBY75pkz3v8F; Mon, 28 Jul 2025 13:31:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753709494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KQIu/wePMU3/VBIVBIw7ILszwtPn0f9yDpes47Stbx8=; b=nsu9ArgeWuNW1kZeGuyCHYLbiGzTuF6lN+lOp8ykJwuOB7ELfS1prq+QRRaBv2lrGwjEma JESgggDapLDjUDdkS7iXNjVhdCQZkFczykbPIQSG1FwNfYiaiEskn70GZar/0frEXrt1+i MGL6gLmUd9RZKTHR49pckBF0F+jnl7y3PzDawZa3XQfKWEZvcpqtZMOfPBJ+xDlGpZNWzF LbclfMjdRBITFAbytXHIXqZdQRLffGBTo+AFWkYqO1ItNJFGgYR5jgWyLu+8lThzbID8hO 6qJ9OkLNCJMHG/YKsHGaoOuakUL4nyQC8UEdse8m342IFxfwJb+G1trDgBXHnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753709494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KQIu/wePMU3/VBIVBIw7ILszwtPn0f9yDpes47Stbx8=; b=Ww3PtNLc0ynjccoVYgWsE3iHP1DwYg86sGZukXsEIkZH9yh/KPoZ8Y3/iZXBQAPXuUpyxP c8sJBsq/wvzYtcQ18rnPzmSolvYjzyVH7HXbV62U9SnT1UNxF0e2njDheq+rrreWvF0F0q QIRIgR/Cw+fE/giGIeYnX+dZ/sZfhIsHIqSi6Tq/XfirZPqQiY7meL5Rl226GkkQhS1DpP DkCUCJb/e05vea02df7OWOgbgJTjuxcDCMCrhuv8MeM8mU9Xg7g1EOpKPBoYR2UtNjAkJZ tz5hD0wPhx6o9LJ7jrkLlemmFWIdC85v8lJzQPWCCMqnj+bA4GljcoK2B6/GSg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753709494; a=rsa-sha256; cv=none; b=MB/rwloxkaKJIwtl6cl4NBDJ4WN8/UL6MuTTY8C5ykzRnDRA8031t/8hC5UNATHwGKQe2a MqvfhSiHHYoQUm7ShgimZwmwg6iRXR0MyZMf6Hrj7SjTB6FmiofK6wMvaSLuSbjJlSVsGt zDOgtEBYi/jP64FscbSMvVZWlHYVt8Ka7cQeBdlwIzLiaxrbKWlxJTPGyi15WU0+0J9X1P XhIVdLq6kNEMUIb9cECyMG1HjYZ9NXkBaITB97U1wLODCmtupVZ9zdrWpAZgGtP37VANfj NpL/p+GJmBYAGPvquCpsnZ9OGUm+KcVRsWUCRXREtgbThH6ui7Mku50TM2ymbQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4brKBY6cKrznJd; Mon, 28 Jul 2025 13:31:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56SDVXTC081977; Mon, 28 Jul 2025 13:31:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56SDVXax081973; Mon, 28 Jul 2025 13:31:33 GMT (envelope-from git) Date: Mon, 28 Jul 2025 13:31:33 GMT Message-Id: <202507281331.56SDVXax081973@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: d83f27fe7378 - stable/14 - sched: Internal priority ranges: Reduce kernel, increase timeshare List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: d83f27fe73787a3625aae3f36fd50bd4662db483 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=d83f27fe73787a3625aae3f36fd50bd4662db483 commit d83f27fe73787a3625aae3f36fd50bd4662db483 Author: Olivier Certner AuthorDate: 2024-05-22 20:32:18 +0000 Commit: Olivier Certner CommitDate: 2025-07-28 13:28:39 +0000 sched: Internal priority ranges: Reduce kernel, increase timeshare Now that a difference of 1 in priority level is significant, we can shrink the priority range reserved for kernel threads. Only four distinct levels are necessary for the bottom half (3 base levels and arguably an additional one for demoted interrupt threads that run for full time slices so that they finally don't compete with other ones). To leave room for other possible uses, we settle on 8 levels. Given the symbolic constants for the top half, 10 levels are currently necessary. We settle on 16 levels. This allows to enlarge the timesharing range, which covers ULE's both interactive and batch range, to 168 distinct levels from less than 64 ones for ULE (as of before the changes to make it use a single runqueue and have 256 distinct levels per runqueue) and 34 ones for 4BSD. While here, note that the realtime range is required to have at least 32 priority levels since: - POSIX mandates at least 32 distinct levels for the SCHED_RR/SCHED_FIFO scheduling policies. - We directly map contiguous priority levels ('sched_priority') of these scheduling policies to distinct, contiguous internal priority levels. Conversely, having at least 32 priority levels is enough to guarantee compliance to the POSIX requirement mentioned above because different internal priority levels are treated differently since commit "runq: Switch to 256 levels". While here, list explicit change restrictions for the realtime and idle range. MFC after: 1 month Event: Kitchener-Waterloo Hackathon 202506 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45391 (cherry picked from commit dee257c28d936bb7b459d3eda207531b3cf1bd4e) --- sys/sys/priority.h | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/sys/sys/priority.h b/sys/sys/priority.h index 4428a85c0987..93dd5aa90d95 100644 --- a/sys/sys/priority.h +++ b/sys/sys/priority.h @@ -64,17 +64,23 @@ */ /* - * Priorities range from 0 to 255, but differences of less then 4 (RQ_PPQ) - * are insignificant. Ranges are as follows: + * Priorities range from 0 to 255. Ranges are as follows: * - * Interrupt threads: 0 - 15 - * Realtime user threads: 16 - 47 - * Top half kernel threads: 48 - 87 - * Time sharing user threads: 88 - 223 + * Interrupt threads: 0 - 7 + * Realtime user threads: 8 - 39 + * Top half kernel threads: 40 - 55 + * Time sharing user threads: 56 - 223 * Idle user threads: 224 - 255 * - * XXX If/When the specific interrupt thread and top half thread ranges - * disappear, a larger range can be used for user processes. + * Priority levels of rtprio(2)'s RTP_PRIO_FIFO and RTP_PRIO_REALTIME and + * POSIX's SCHED_FIFO and SCHED_RR are directly mapped to the internal realtime + * range mentioned above by a simple translation. This range's length + * consequently cannot be changed without impacts on the scheduling priority + * code, and in any case must never be smaller than 32 for POSIX compliance and + * rtprio(2) backwards compatibility. Similarly, priority levels of rtprio(2)'s + * RTP_PRIO_IDLE are directly mapped to the internal idle range above (and, + * soon, those of the to-be-introduced SCHED_IDLE policy as well), so changing + * that range is subject to the same caveats and restrictions. */ #define PRI_MIN (0) /* Highest priority. */ @@ -88,34 +94,34 @@ * decay to lower priorities if they run for full time slices. */ #define PI_REALTIME (PRI_MIN_ITHD + 0) -#define PI_INTR (PRI_MIN_ITHD + 4) +#define PI_INTR (PRI_MIN_ITHD + 1) #define PI_AV PI_INTR #define PI_NET PI_INTR #define PI_DISK PI_INTR #define PI_TTY PI_INTR #define PI_DULL PI_INTR -#define PI_SOFT (PRI_MIN_ITHD + 8) +#define PI_SOFT (PRI_MIN_ITHD + 2) #define PI_SOFTCLOCK PI_SOFT #define PI_SWI(x) PI_SOFT -#define PRI_MIN_REALTIME (16) +#define PRI_MIN_REALTIME (8) #define PRI_MAX_REALTIME (PRI_MIN_KERN - 1) -#define PRI_MIN_KERN (48) +#define PRI_MIN_KERN (40) #define PRI_MAX_KERN (PRI_MIN_TIMESHARE - 1) #define PSWP (PRI_MIN_KERN + 0) -#define PVM (PRI_MIN_KERN + 4) -#define PINOD (PRI_MIN_KERN + 8) -#define PRIBIO (PRI_MIN_KERN + 12) -#define PVFS (PRI_MIN_KERN + 16) -#define PZERO (PRI_MIN_KERN + 20) -#define PSOCK (PRI_MIN_KERN + 24) -#define PWAIT (PRI_MIN_KERN + 28) -#define PLOCK (PRI_MIN_KERN + 32) -#define PPAUSE (PRI_MIN_KERN + 36) - -#define PRI_MIN_TIMESHARE (88) +#define PVM (PRI_MIN_KERN + 1) +#define PINOD (PRI_MIN_KERN + 2) +#define PRIBIO (PRI_MIN_KERN + 3) +#define PVFS (PRI_MIN_KERN + 4) +#define PZERO (PRI_MIN_KERN + 5) +#define PSOCK (PRI_MIN_KERN + 6) +#define PWAIT (PRI_MIN_KERN + 7) +#define PLOCK (PRI_MIN_KERN + 8) +#define PPAUSE (PRI_MIN_KERN + 9) + +#define PRI_MIN_TIMESHARE (56) #define PRI_MAX_TIMESHARE (PRI_MIN_IDLE - 1) #define PUSER (PRI_MIN_TIMESHARE)