sched/fair: Optimize min_vruntime update on unchanged vruntime

Message ID 202401031216+0800-wangjinchao@xfusion.com
State New
Headers
Series sched/fair: Optimize min_vruntime update on unchanged vruntime |

Commit Message

Wang Jinchao Jan. 3, 2024, 4:18 a.m. UTC
  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 <wangjinchao@xfusion.com>
---
 kernel/sched/fair.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
  

Patch

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,