From nobody Wed Jun 18 02:13:33 2025 X-Original-To: dev-commits-src-main@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 4bMS2k2q5cz5q6sg; Wed, 18 Jun 2025 02:13:34 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bMS2j5QT5z41sw; Wed, 18 Jun 2025 02:13:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750212813; 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=OZ2nwnU/0gnGI1OYgJHH0/UBK5TqjzlasPLYq0zbbLk=; b=xbttQS5RAPcdWTy8383V9oUvHBiXX9iHEu+f5Z24CYo85a9U55FqZHQME4IF+Y1QvUM9Tj bAaMXcMK5cPybtQ8+CmTLA0aFY/NVn1alaPXi0pT55Hi0W++frM5U3X7dkYJ8AX3yypj+U /+fYrDfBpj6+KKlMMvVcfBrK3sjnLQS3mfyczrn5atFmyG0c8/8hXnZZD1QYx4kf9TPX84 2gKppk8rFodfeQRZcTIUHpLw15BwsN1oipCuPAsfw2/nEoMbVVyeonGJPjsmz/UPO0wIzs Cr878xYUsRakJ2i+IT5o3pH04txwIV97/zRpFJwEP5ErQcLbWcmuPewP//ZMvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750212813; 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=OZ2nwnU/0gnGI1OYgJHH0/UBK5TqjzlasPLYq0zbbLk=; b=DPUwIEgeW2HkyV0SFUZjDOlIXfBNLCKE/voGriJLOmFXux7aQmxaVVhR4PbCE8yYNN3ngy 0fO7VIcxv2QO3vjqwEEt8z7X9gtSj7WyZGAJeMThNny4HDz/poLsobrAb2ZvhCuHLrs1EC FwKi0fUBRQNzT/t6lEw7VKJBGTScvFfJNfDrdI61TMIfkadLZEzT4rE8TFreyvctrYBKsM ttmC+WjrrWZ28SOyl4l0/Vi8XId94BaiVi+aaN7GyOXDR8nPHMLXwo4ZzkRGDiNof6qkc6 9gRXCvDZy4CoY/vM3pxD8Bt7QvJkARXhSfAauFKEb2GCMEmvWu8bPkOAaWPcSg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750212813; a=rsa-sha256; cv=none; b=V77Ngq2smUNraB0S3X9yu5tCqwxiZl/hLtNR77Fd8jDGXX1PPpBU5+gSKpzIqd78ahZ05G oGirXgmIloqYjHyMCyLC87PKehGU/oMqB76UQy8GdBTKHoqPzZWsnbsipsq4xEOYiRnHxg eOdxg+UrOg20/ovUi8oUuRy0vZ8kOjqxP297MlD3YoXKino2wcX5LuoiEHW4s9xUy1x6bk jQos2n/lG6uGAXOQSMQqN+P2D/oi/fJ3GRZs7iGhUALpUUCiqGbzqTo7zutKB7AGw2Gbes DGnBS2/otyrNPRUKcWxJoQLvlMuRfEmp42zrmrPugKqJhHgAzRjWLCVISrDBvA== 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 4bMS2j51ljz18mP; Wed, 18 Jun 2025 02:13: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 55I2DX6t024719; Wed, 18 Jun 2025 02:13:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55I2DXA2024716; Wed, 18 Jun 2025 02:13:33 GMT (envelope-from git) Date: Wed, 18 Jun 2025 02:13:33 GMT Message-Id: <202506180213.55I2DXA2024716@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: dee257c28d93 - main - sched: Internal priority ranges: Reduce kernel, increase timeshare List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: dee257c28d936bb7b459d3eda207531b3cf1bd4e Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=dee257c28d936bb7b459d3eda207531b3cf1bd4e commit dee257c28d936bb7b459d3eda207531b3cf1bd4e Author: Olivier Certner AuthorDate: 2024-05-22 20:32:18 +0000 Commit: Olivier Certner CommitDate: 2025-06-18 02:09:37 +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 --- 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)