2024-01-03 04:34:47

by Wang Jinchao

[permalink] [raw]
Subject: [PATCH] sched/fair: Optimize min_vruntime update on unchanged vruntime

When (!(curr && curr->on_rq) && !se) is true, there is no need
to update min_vruntime.
Simplify the if-else logic accordingly.

Signed-off-by: Wang Jinchao <[email protected]>
---
kernel/sched/fair.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index d7a3c63a2171..a4afdeee515d 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -755,21 +755,16 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq)
struct sched_entity *se = __pick_first_entity(cfs_rq);
struct sched_entity *curr = cfs_rq->curr;

- u64 vruntime = cfs_rq->min_vruntime;
+ u64 vruntime = U64_MAX;

- if (curr) {
- if (curr->on_rq)
- vruntime = curr->vruntime;
- else
- curr = NULL;
- }
+ if (curr && curr->on_rq)
+ vruntime = curr->vruntime;
+ if (se)
+ vruntime = min_vruntime(vruntime, se->vruntime);

- if (se) {
- if (!curr)
- vruntime = se->vruntime;
- else
- vruntime = min_vruntime(vruntime, se->vruntime);
- }
+ /* no need to update if vruntime is unchanged */
+ if (vruntime == U64_MAX)
+ return;

/* ensure we never gain time by being placed backwards. */
u64_u32_store(cfs_rq->min_vruntime,
--
2.40.0