Skip to contentSkip to conversation

sched/fair: remove next_buddy_marked

PATCH Applied Wang Jinchao 4 participants 7 messages Dec 14, 2023 – Dec 23, 2023 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/fair: remove next_buddy_marked

Remove unused next_buddy_marked in check_preempt_wakeup_fair

---
 kernel/sched/fair.c | 2 --
 1 file changed, 2 deletions(-)
kernel/sched/fair.c +0 -2
index d7a3c63a2171..d2028bfa4e94 100644
@@ -8210,7 +8210,6 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
 	struct task_struct *curr = rq->curr;
 	struct sched_entity *se = &curr->se, *pse = &p->se;
 	struct cfs_rq *cfs_rq = task_cfs_rq(curr);
-	int next_buddy_marked = 0;
 	int cse_is_idle, pse_is_idle;
 
 	if (unlikely(se == pse))
@@ -8227,7 +8226,6 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
 
 	if (sched_feat(NEXT_BUDDY) && !(wake_flags & WF_FORK)) {
 		set_next_buddy(pse);
-		next_buddy_marked = 1;
 	}
 
 	/*
Signature · 1 line
2.40.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Wang Jinchao

Remove unused next_buddy_marked in check_preempt_wakeup_fair

Fixes 5e963f2bd465 ("sched/fair: Commit to EEVDF")
Quoted 1 line
Quoted 27 lines
---
 kernel/sched/fair.c | 2 --
 1 file changed, 2 deletions(-)
kernel/sched/fair.c +0 -3
index d7a3c63a2171..d2028bfa4e94 100644
@@ -8210,7 +8210,6 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
        struct task_struct *curr = rq->curr;
        struct sched_entity *se = &curr->se, *pse = &p->se;
        struct cfs_rq *cfs_rq = task_cfs_rq(curr);
-       int next_buddy_marked = 0;
        int cse_is_idle, pse_is_idle;
 
        if (unlikely(se == pse))
@@ -8227,7 +8226,6 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
 
        if (sched_feat(NEXT_BUDDY) && !(wake_flags & WF_FORK)) {
                set_next_buddy(pse);
-               next_buddy_marked = 1;
        }
 
        /*
--

2.40.0

#2 lore raw

On 12/14/23 4:18 PM, Vincent Guittot Wrote:

Quoted 6 lines · Wang Jinchao
Quoted 3 lines

Remove unused next_buddy_marked in check_preempt_wakeup_fair

Fixes 5e963f2bd465 ("sched/fair: Commit to EEVDF")

After this commit @pse preempts curr without being the NEXT_BUDDY, but IMHO it should be, so how about this?

@@ -8259,8 +8259,11 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int

        /*
         * XXX pick_eevdf(cfs_rq) != se ?
         */
-       if (pick_eevdf(cfs_rq) == pse)
+       if (pick_eevdf(cfs_rq) == pse) {
+               if (!next_buddy_marked)
+                       set_next_buddy(pse);
                goto preempt;

+ }

        return;

which will align with before.

#3 lore raw
Quoted 24 lines · Abel Wu

On 12/14/23 4:18 PM, Vincent Guittot Wrote:

Quoted 6 lines · Wang Jinchao
Quoted 3 lines

Remove unused next_buddy_marked in check_preempt_wakeup_fair

Fixes 5e963f2bd465 ("sched/fair: Commit to EEVDF")

After this commit @pse preempts curr without being the NEXT_BUDDY, but IMHO it should be, so how about this?

(quoted diff) +4 -1
@@ -8259,8 +8259,11 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
        /*
         * XXX pick_eevdf(cfs_rq) != se ?
         */
-       if (pick_eevdf(cfs_rq) == pse)
+       if (pick_eevdf(cfs_rq) == pse) {
+               if (!next_buddy_marked)
+                       set_next_buddy(pse);
                goto preempt;
+       }
 
        return;
 
Quoted 1 line

which will align with before.

Seizing this opportunity to inquire about a question:
What does "buddy" mean in the context of the scheduler?

Is the effect the same between

    preempting after pick_evfd(cfs_rq) == pse 
and 
    preempting after set_next_buddy(pse) followed by pick_evfd(cfs_rq) == pse?

Would both scenarios result in pse becoming the next scheduled se?"

#4 lore raw

On 12/14/23 9:02 PM, Wang Jinchao Wrote:

Quoted 23 lines · Abel Wu
Quoted 22 lines

On 12/14/23 4:18 PM, Vincent Guittot Wrote:

Quoted 6 lines · Wang Jinchao
Quoted 3 lines

Remove unused next_buddy_marked in check_preempt_wakeup_fair

Fixes 5e963f2bd465 ("sched/fair: Commit to EEVDF")

After this commit @pse preempts curr without being the NEXT_BUDDY, but IMHO it should be, so how about this?

(quoted diff) +4 -1
@@ -8259,8 +8259,11 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
         /*
          * XXX pick_eevdf(cfs_rq) != se ?
          */
-       if (pick_eevdf(cfs_rq) == pse)
+       if (pick_eevdf(cfs_rq) == pse) {
+               if (!next_buddy_marked)
+                       set_next_buddy(pse);
                 goto preempt;
+       }
 
Quoted 5 lines
Quoted 3 lines
(quoted diff) +0 -0
         return;
 

which will align with before.

Seizing this opportunity to inquire about a question:
What does "buddy" mean in the context of the scheduler?

struct sched_entity

Quoted 6 lines

Is the effect the same between

     preempting after pick_evfd(cfs_rq) == pse
and
     preempting after set_next_buddy(pse) followed by pick_evfd(cfs_rq) == pse?

Would both scenarios result in pse becoming the next scheduled se?"

Probably, since pse is the one preempts curr, pick_next_entity() could return pse directly without walking the rbtree. So the difference is in performance.

maintainer
#5 lore raw
In reply to Abel Wu
Quoted 13 lines · Abel Wu

On 12/14/23 4:18 PM, Vincent Guittot Wrote:

Quoted 6 lines · Wang Jinchao
Quoted 3 lines

Remove unused next_buddy_marked in check_preempt_wakeup_fair

Fixes 5e963f2bd465 ("sched/fair: Commit to EEVDF")

After this commit @pse preempts curr without being the NEXT_BUDDY, but IMHO it should be, so how about this?

Review static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int · line 8264

Quoted 7 lines
(quoted diff) +3 -1
@@ -8259,8 +8259,11 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
         /*
          * XXX pick_eevdf(cfs_rq) != se ?
          */
-       if (pick_eevdf(cfs_rq) == pse)
+       if (pick_eevdf(cfs_rq) == pse) {
+               if (!next_buddy_marked)
+                       set_next_buddy(pse);

I don't think this is needed because :
- NEXT_BUDDY is false by default so pick_next_entity() will not take care of this
- pick_next_entity() will call pick_eevdf() which should return pse unless another se that want to run 1st, wakes up in the meantime and we should probably not take into account next buddy in this case

Quoted 6 lines
(quoted diff) +1 -0
                 goto preempt;
+       }
 
         return;
 

which will align with before.

merge bot Applied
#6 lore raw

[tip: sched/core] sched/fair: Remove unused 'next_buddy_marked' local variable in check_preempt_wakeup_fair()

In reply to Wang Jinchao
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     fbb66ce0b1d670c72def736a13ac9176b860df4e
Gitweb:        https://git.kernel.org/tip/fbb66ce0b1d670c72def736a13ac9176b860df4e
Author:        Wang Jinchao <[email protected]>
AuthorDate:    Thu, 14 Dec 2023 13:20:29 +08:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Sat, 23 Dec 2023 16:12:21 +01:00

sched/fair: Remove unused 'next_buddy_marked' local variable in check_preempt_wakeup_fair()

This variable became unused in:

    5e963f2bd465 ("sched/fair: Commit to EEVDF")
---
 kernel/sched/fair.c | 2 --
 1 file changed, 2 deletions(-)
kernel/sched/fair.c +0 -2
index 1d561b5..9cc2085 100644
@@ -8221,7 +8221,6 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int 
 	struct task_struct *curr = rq->curr;
 	struct sched_entity *se = &curr->se, *pse = &p->se;
 	struct cfs_rq *cfs_rq = task_cfs_rq(curr);
-	int next_buddy_marked = 0;
 	int cse_is_idle, pse_is_idle;
 
 	if (unlikely(se == pse))
@@ -8238,7 +8237,6 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int 
 
 	if (sched_feat(NEXT_BUDDY) && !(wake_flags & WF_FORK)) {
 		set_next_buddy(pse);
-		next_buddy_marked = 1;
 	}
 
 	/*