Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Oct 2021 04:09:53 GMT
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 1c119e173ddc - main - sched_ule(4): Fix possible significance loss.
Message-ID:  <202110020409.19249rMZ099018@gitrepo.freebsd.org>

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

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

commit 1c119e173ddc7f5603a3b6cf940dc524e494a667
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2021-10-02 03:47:18 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2021-10-02 04:09:45 +0000

    sched_ule(4): Fix possible significance loss.
    
    Before this change kern.sched.interact sysctl setting above 32 gave
    all interactive threads identical priority of PRI_MIN_INTERACT due to
    ((PRI_MAX_INTERACT - PRI_MIN_INTERACT + 1) / sched_interact) turning
    zero.  Setting the sysctl lower reduced the range of used priority
    levels up to half, that is not great either.
    
    Change of the operations order should fix the issue, always using full
    range of priorities, while overflow is impossible there since both
    score and priority values are small.  While there, make the variables
    unsigned as they really are.
    
    MFC after:      1 month
---
 sys/kern/sched_ule.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c
index 0f873a6a30b6..1b9473b93773 100644
--- a/sys/kern/sched_ule.c
+++ b/sys/kern/sched_ule.c
@@ -207,7 +207,7 @@ _Static_assert(sizeof(struct thread) + sizeof(struct td_sched) <=
  * sched_slice:		Runtime of each thread before rescheduling.
  * preempt_thresh:	Priority threshold for preemption and remote IPIs.
  */
-static int __read_mostly sched_interact = SCHED_INTERACT_THRESH;
+static u_int __read_mostly sched_interact = SCHED_INTERACT_THRESH;
 static int __read_mostly tickincr = 8 << SCHED_TICK_SHIFT;
 static int __read_mostly realstathz = 127;	/* reset during boot. */
 static int __read_mostly sched_slice = 10;	/* reset during boot. */
@@ -1616,8 +1616,7 @@ sched_interact_score(struct thread *td)
 static void
 sched_priority(struct thread *td)
 {
-	int score;
-	int pri;
+	u_int pri, score;
 
 	if (PRI_BASE(td->td_pri_class) != PRI_TIMESHARE)
 		return;
@@ -1637,10 +1636,10 @@ sched_priority(struct thread *td)
 	score = imax(0, sched_interact_score(td) + td->td_proc->p_nice);
 	if (score < sched_interact) {
 		pri = PRI_MIN_INTERACT;
-		pri += ((PRI_MAX_INTERACT - PRI_MIN_INTERACT + 1) /
-		    sched_interact) * score;
+		pri += (PRI_MAX_INTERACT - PRI_MIN_INTERACT + 1) * score /
+		    sched_interact;
 		KASSERT(pri >= PRI_MIN_INTERACT && pri <= PRI_MAX_INTERACT,
-		    ("sched_priority: invalid interactive priority %d score %d",
+		    ("sched_priority: invalid interactive priority %u score %u",
 		    pri, score));
 	} else {
 		pri = SCHED_PRI_MIN;
@@ -1649,7 +1648,7 @@ sched_priority(struct thread *td)
 			    SCHED_PRI_RANGE - 1);
 		pri += SCHED_PRI_NICE(td->td_proc->p_nice);
 		KASSERT(pri >= PRI_MIN_BATCH && pri <= PRI_MAX_BATCH,
-		    ("sched_priority: invalid priority %d: nice %d, " 
+		    ("sched_priority: invalid priority %u: nice %d, "
 		    "ticks %d ftick %d ltick %d tick pri %d",
 		    pri, td->td_proc->p_nice, td_get_sched(td)->ts_ticks,
 		    td_get_sched(td)->ts_ftick, td_get_sched(td)->ts_ltick,
@@ -3174,7 +3173,7 @@ SYSCTL_PROC(_kern_sched, OID_AUTO, quantum,
     "Quantum for timeshare threads in microseconds");
 SYSCTL_INT(_kern_sched, OID_AUTO, slice, CTLFLAG_RW, &sched_slice, 0,
     "Quantum for timeshare threads in stathz ticks");
-SYSCTL_INT(_kern_sched, OID_AUTO, interact, CTLFLAG_RW, &sched_interact, 0,
+SYSCTL_UINT(_kern_sched, OID_AUTO, interact, CTLFLAG_RW, &sched_interact, 0,
     "Interactivity score threshold");
 SYSCTL_INT(_kern_sched, OID_AUTO, preempt_thresh, CTLFLAG_RW,
     &preempt_thresh, 0,



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