Skip to contentSkip to conversation

sched/eevdf: Fix vprot across reweighting

PATCH Superseded Kayra Cizmeci 2 participants 2 messages Oct 16 Scheduler

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 sched/eevdf: Fix vprot across reweighting

Currently in reweighting, while a tasks vruntime changes dead protection could go alive, or alive protection could decrease, increase and go dead. Fix it in reweight_eevdf(), and just cancel it in the sched_change_end() path.

Fixes 80390ead2080 ("sched/fair: Separate se->vlag from se->vprot")
Fixes bcd74b2ffdd0 ("sched/fair: Only set slice protection at pick time")

---

Changes v3->v4:

* Change enqueue_task_fair() block so that instead of extending the protection in sched_change_end() path just cancel the protection if it is active. (Vincent)

v3: https://lore.kernel.org/lkml/[email protected]/

Compile tested only.

 kernel/sched/fair.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
kernel/sched/fair.c +12 -2
index 0feec172fd37..61266c3a7f2f 100644
@@ -4892,12 +4892,15 @@ static void reweight_eevdf(struct cfs_rq *cfs_rq, struct sched_entity *se,
 	update_load_set(&se->h_load, weight);
 
 	if (on_rq) {
-		if (rel_vprot)
-			se->vprot += avruntime;
 		se->deadline += avruntime;
 		se->rel_deadline = 0;
 		se->vruntime = avruntime - se->vlag;
 
+		if (rel_vprot)
+			se->vprot += avruntime;
+		else if (curr)
+			se->vprot = se->vruntime;
+
 		if (!curr)
 			__enqueue_entity(cfs_rq, se);
 		cfs_rq->h_nr_queued++;
@@ -8202,6 +8205,13 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 	if (!curr) {
 		reweight_eevdf(cfs_rq, se, weight, false);
 		place_entity(cfs_rq, se, flags | ENQUEUE_QUEUED);
+		/*
+		 * This happens in sched_change_end(), while cfs_rq->curr == NULL
+		 * and rq->donor == p. In this case, cancel the protection rather
+		 * than extending it.
+		 */
+		if (task_current_donor(rq, p))
+			cancel_protect_slice(se);
 		__enqueue_entity(cfs_rq, se);
 	}
 
Signature · 1 line
2.53.0
maintainer Reviewed-by on v4 1/1
#1 lore raw
Quoted 10 lines · Kayra Cizmeci

Currently in reweighting, while a tasks vruntime changes dead protection could go alive, or alive protection could decrease, increase and go dead. Fix it in reweight_eevdf(), and just cancel it in the sched_change_end() path.

Fixes 80390ead2080 ("sched/fair: Separate se->vlag from se->vprot")
Fixes bcd74b2ffdd0 ("sched/fair: Only set slice protection at pick time")

Besides the comment below, this looks good to me.

Quoted 37 lines

---

Changes v3->v4:

* Change enqueue_task_fair() block so that instead of extending the protection in sched_change_end() path just cancel the protection if it is active. (Vincent)

v3: https://lore.kernel.org/lkml/[email protected]/

Compile tested only.

 kernel/sched/fair.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
kernel/sched/fair.c +5 -2
index 0feec172fd37..61266c3a7f2f 100644
@@ -4892,12 +4892,15 @@ static void reweight_eevdf(struct cfs_rq *cfs_rq, struct sched_entity *se,
        update_load_set(&se->h_load, weight);
 
        if (on_rq) {
-               if (rel_vprot)
-                       se->vprot += avruntime;
                se->deadline += avruntime;
                se->rel_deadline = 0;
                se->vruntime = avruntime - se->vlag;
 
+               if (rel_vprot)
+                       se->vprot += avruntime;
+               else if (curr)
+                       se->vprot = se->vruntime;
+
                if (!curr)
                        __enqueue_entity(cfs_rq, se);
                cfs_rq->h_nr_queued++;

kernel/sched/fair.c enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) · line 8212

Quoted 8 lines
kernel/sched/fair.c +5 -0
@@ -8202,6 +8205,13 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
        if (!curr) {
                reweight_eevdf(cfs_rq, se, weight, false);
                place_entity(cfs_rq, se, flags | ENQUEUE_QUEUED);
+               /*
+                * This happens in sched_change_end(), while cfs_rq->curr == NULL
+                * and rq->donor == p. In this case, cancel the protection rather
+                * than extending it.
+                */

what about :

/*
* During a sched_change pattern, current is dequeued and
* cfs_rq->curr becomes NULL while rq->donor == p. As all
* properties can change, cancel slice protection which is
* not reliable anymore.
*/

Quoted 8 lines
kernel/sched/fair.c +2 -1
+               if (task_current_donor(rq, p))
+                       cancel_protect_slice(se);
                __enqueue_entity(cfs_rq, se);
        }
 
--

2.53.0