Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Oct 2023 20:38:53 GMT
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: bd572be78436 - main - setusercontext(): Fix gap when setting a realtime-class priority
Message-ID:  <202310022038.392Kcrrf003015@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=bd572be78436473a2ad4c1b78728b739c74ef238

commit bd572be78436473a2ad4c1b78728b739c74ef238
Author:     Olivier Certner <olce.freebsd@certner.fr>
AuthorDate: 2023-05-25 07:10:27 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-10-02 20:38:03 +0000

    setusercontext(): Fix gap when setting a realtime-class priority
    
    The login.conf's "priority" capability allows to set priorities in the
    idle or realtime classes in addition to the classical nice values (-20
    to 20), through a natural extension where values greater than 20 put the
    processes in the idle class (with priority adjusted within RTP_PRIO_MIN
    and RTP_PRIO_MAX, 21 being converted to 0, 22 to 1, etc.) and values
    lower than -20 put the process in the realtime class (with priority
    adjusted within RTP_PRIO_MIN and RTP_PRIO_MAX, -21 being converted to
    RTP_PRIO_MAX (31), -22 to 30, etc.).
    
    Before this fix, in the latter case (realtime class), -21 was converted
    to 30, and RTP_PRIO_MAX (31) could never be specified.
    
    While here, change the priority computation for the idle-class case to
    be symmetrical and use RTP_PRIO_MIN (in practice, this changes nothing
    at all, since RTP_PRIO_MIN is 0; but this is the correct theoretical
    formula, which would work as well with other values of RTP_PRIO_MIN).
    
    PR:                     271727
    Reviewed by:            imp, kib
    MFC after:              2 weeks
    Sponsored by:           Kumacom SAS
    Differential Revision:  https://reviews.freebsd.org/D40339
---
 lib/libutil/login_class.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c
index f561479690c1..90a3ec5d106a 100644
--- a/lib/libutil/login_class.c
+++ b/lib/libutil/login_class.c
@@ -452,7 +452,7 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
 
 	if (p > PRIO_MAX) {
 	    rtp.type = RTP_PRIO_IDLE;
-	    p -= PRIO_MAX + 1;
+	    p += RTP_PRIO_MIN - (PRIO_MAX + 1);
 	    rtp.prio = p > RTP_PRIO_MAX ? RTP_PRIO_MAX : p;
 	    if (rtprio(RTP_SET, 0, &rtp))
 		syslog(LOG_WARNING, "rtprio '%s' (%s): %m",
@@ -460,7 +460,7 @@ setusercontext(login_cap_t *lc, const struct passwd *pwd, uid_t uid, unsigned in
 		    lc ? lc->lc_class : LOGIN_DEFCLASS);
 	} else if (p < PRIO_MIN) {
 	    rtp.type = RTP_PRIO_REALTIME;
-	    p -= PRIO_MIN - RTP_PRIO_MAX;
+	    p += RTP_PRIO_MAX - (PRIO_MIN - 1);
 	    rtp.prio = p < RTP_PRIO_MIN ? RTP_PRIO_MIN : p;
 	    if (rtprio(RTP_SET, 0, &rtp))
 		syslog(LOG_WARNING, "rtprio '%s' (%s): %m",



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