Patch "sched: Fix UCLAMP_FLAG_IDLE setting" has been added to the 5.14-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    sched: Fix UCLAMP_FLAG_IDLE setting

to the 5.14-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     sched-fix-uclamp_flag_idle-setting.patch
and it can be found in the queue-5.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit e75d43f86e7dd116ce34cfaf5124e2bc42ec6a51
Author: Quentin Perret <qperret@xxxxxxxxxx>
Date:   Thu Aug 5 11:21:53 2021 +0100

    sched: Fix UCLAMP_FLAG_IDLE setting
    
    [ Upstream commit ca4984a7dd863f3e1c0df775ae3e744bff24c303 ]
    
    The UCLAMP_FLAG_IDLE flag is set on a runqueue when dequeueing the last
    uclamp active task (that is, when buckets.tasks reaches 0 for all
    buckets) to maintain the last uclamp.max and prevent blocked util from
    suddenly becoming visible.
    
    However, there is an asymmetry in how the flag is set and cleared which
    can lead to having the flag set whilst there are active tasks on the rq.
    Specifically, the flag is cleared in the uclamp_rq_inc() path, which is
    called at enqueue time, but set in uclamp_rq_dec_id() which is called
    both when dequeueing a task _and_ in the update_uclamp_active() path. As
    a result, when both uclamp_rq_{dec,ind}_id() are called from
    update_uclamp_active(), the flag ends up being set but not cleared,
    hence leaving the runqueue in a broken state.
    
    Fix this by clearing the flag in update_uclamp_active() as well.
    
    Fixes: e496187da710 ("sched/uclamp: Enforce last task's UCLAMP_MAX")
    Reported-by: Rick Yiu <rickyiu@xxxxxxxxxx>
    Signed-off-by: Quentin Perret <qperret@xxxxxxxxxx>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
    Reviewed-by: Qais Yousef <qais.yousef@xxxxxxx>
    Tested-by: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
    Link: https://lore.kernel.org/r/20210805102154.590709-2-qperret@xxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f3b27c6c5153..a2403432f3ab 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1633,6 +1633,23 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
 		uclamp_rq_dec_id(rq, p, clamp_id);
 }
 
+static inline void uclamp_rq_reinc_id(struct rq *rq, struct task_struct *p,
+				      enum uclamp_id clamp_id)
+{
+	if (!p->uclamp[clamp_id].active)
+		return;
+
+	uclamp_rq_dec_id(rq, p, clamp_id);
+	uclamp_rq_inc_id(rq, p, clamp_id);
+
+	/*
+	 * Make sure to clear the idle flag if we've transiently reached 0
+	 * active tasks on rq.
+	 */
+	if (clamp_id == UCLAMP_MAX && (rq->uclamp_flags & UCLAMP_FLAG_IDLE))
+		rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
+}
+
 static inline void
 uclamp_update_active(struct task_struct *p)
 {
@@ -1656,12 +1673,8 @@ uclamp_update_active(struct task_struct *p)
 	 * affecting a valid clamp bucket, the next time it's enqueued,
 	 * it will already see the updated clamp bucket value.
 	 */
-	for_each_clamp_id(clamp_id) {
-		if (p->uclamp[clamp_id].active) {
-			uclamp_rq_dec_id(rq, p, clamp_id);
-			uclamp_rq_inc_id(rq, p, clamp_id);
-		}
-	}
+	for_each_clamp_id(clamp_id)
+		uclamp_rq_reinc_id(rq, p, clamp_id);
 
 	task_rq_unlock(rq, p, &rf);
 }



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux