Skip to contentSkip to conversation

sched/fair:Reduce unnecessary check preempt in the sched tick

PATCH In review [email protected] 2 participants 2 messages Apr 14, 2021 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sched/fair:Reduce unnecessary check preempt in the sched tick

From: jun qian <[email protected]>

As you are already set the TIF_NEED_RESCHED, there is no need to check resched again.

---
 kernel/sched/fair.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/sched/fair.c +9 -2
index 794c2cb945f8..1a69b5fffe4a 100644
@@ -4360,19 +4360,26 @@ check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
 {
 	unsigned long ideal_runtime, delta_exec;
 	struct sched_entity *se;
+	struct rq *rq = rq_of(cfs_rq);
 	s64 delta;
 
 	ideal_runtime = sched_slice(cfs_rq, curr);
 	delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
 	if (delta_exec > ideal_runtime) {
-		resched_curr(rq_of(cfs_rq));
+		if (!test_tsk_need_resched(rq->curr))
+			resched_curr(rq_of(cfs_rq));
 		/*
 		 * The current task ran long enough, ensure it doesn't get
 		 * re-elected due to buddy favours.
 		 */
 		clear_buddies(cfs_rq, curr);
 		return;
-	}
+	/*
+	 * If here with TIF_NEED_RESCHED already set from the early entity_tick,
+	 * there is no need to check again.
+	 */
+	} else if (test_tsk_need_resched(rq->curr))
+		return;
 
 	/*
 	 * Ensure that a task that missed wakeup preemption by a
Signature · 1 line
2.18.2
maintainer
#1 lore raw
Quoted 4 lines · On Wed, Apr 14, 2021 at 10:22:29AM +0800, [email protected] wrote:

From: jun qian <[email protected]>

As you are already set the TIF_NEED_RESCHED, there is no need to check resched again.

Still no justification; does this actually help anything?

Quoted 25 lines
---
 kernel/sched/fair.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/sched/fair.c +3 -1
index 794c2cb945f8..1a69b5fffe4a 100644
@@ -4360,19 +4360,26 @@ check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
 {
 	unsigned long ideal_runtime, delta_exec;
 	struct sched_entity *se;
+	struct rq *rq = rq_of(cfs_rq);
 	s64 delta;
 
 	ideal_runtime = sched_slice(cfs_rq, curr);
 	delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
 	if (delta_exec > ideal_runtime) {
-		resched_curr(rq_of(cfs_rq));
+		if (!test_tsk_need_resched(rq->curr))
+			resched_curr(rq_of(cfs_rq));
 		/*
 		 * The current task ran long enough, ensure it doesn't get
 		 * re-elected due to buddy favours.

kernel/sched/fair.c check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr) · line 4382

Quoted 10 lines
kernel/sched/fair.c +6 -1
 		 */
 		clear_buddies(cfs_rq, curr);
 		return;
-	}
+	/*
+	 * If here with TIF_NEED_RESCHED already set from the early entity_tick,
+	 * there is no need to check again.
+	 */
+	} else if (test_tsk_need_resched(rq->curr))
+		return;

This is horrific style. And, afaict, completely unnecessary.