Skip to contentSkip to conversation

kernel/sched:use the enum code replace of the int variable

PATCH In review [email protected] 2 participants 2 messages Sep 7, 2020 – Sep 11, 2020 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/sched:use the enum code replace of the int variable

From: jun qian <[email protected]>

It is hard to understand what the meaning of the value from the return value of wakeup_preempt_entity, so I fix it.

---
 kernel/sched/fair.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
kernel/sched/fair.c +16 -10
index 658aa7a..60bb184 100644
@@ -86,6 +86,12 @@
 
 const_debug unsigned int sysctl_sched_migration_cost	= 500000UL;
 
+enum preempt_curr_code {
+	NO_NEED_PREEMPT = -1,
+	MAY_NEED_PREEMPT = 0,
+	NEED_PREEMPT = 1,
+};
+
 int sched_thermal_decay_shift;
 static int __init setup_sched_thermal_decay_shift(char *str)
 {
@@ -4445,20 +4451,20 @@ static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
 				second = curr;
 		}
 
-		if (second && wakeup_preempt_entity(second, left) < 1)
+		if (second && wakeup_preempt_entity(second, left) != NEED_PREEMPT)
 			se = second;
 	}
 
 	/*
 	 * Prefer last buddy, try to return the CPU to a preempted task.
 	 */
-	if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1)
+	if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) != NEED_PREEMPT)
 		se = cfs_rq->last;
 
 	/*
 	 * Someone really wants this to run. If it's not unfair, run it.
 	 */
-	if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1)
+	if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) != NEED_PREEMPT)
 		se = cfs_rq->next;
 
 	clear_buddies(cfs_rq, se);
@@ -6822,9 +6828,9 @@ static unsigned long wakeup_gran(struct sched_entity *se)
  *         g
  *      |<--->|c
  *
- *  w(c, s1) = -1
- *  w(c, s2) =  0
- *  w(c, s3) =  1
+ *  w(c, s1) = NO_NEED_PREEMPT
+ *  w(c, s2) = MAY_NEED_PREEMPT
+ *  w(c, s3) = NEED_PREEMPT
  *
  */
 static int
@@ -6833,13 +6839,13 @@ static unsigned long wakeup_gran(struct sched_entity *se)
 	s64 gran, vdiff = curr->vruntime - se->vruntime;
 
 	if (vdiff <= 0)
-		return -1;
+		return NO_NEED_PREEMPT;
 
 	gran = wakeup_gran(se);
 	if (vdiff > gran)
-		return 1;
+		return NEED_PREEMPT;
 
-	return 0;
+	return MAY_NEED_PREEMPT;
 }
 
 static void set_last_buddy(struct sched_entity *se)
@@ -6928,7 +6934,7 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
 	find_matching_se(&se, &pse);
 	update_curr(cfs_rq_of(se));
 	BUG_ON(!pse);
-	if (wakeup_preempt_entity(se, pse) == 1) {
+	if (wakeup_preempt_entity(se, pse) == NEED_PREEMPT) {
 		/*
 		 * Bias pick_next to pick the sched entity that is
 		 * triggering this preemption.
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 7 lines · On Mon, Sep 07, 2020 at 09:05:02PM +0800, [email protected] wrote:

From: jun qian <[email protected]>

It is hard to understand what the meaning of the value from the return value of wakeup_preempt_entity, so I fix it.

kernel/sched/fair.c +0 -0
@@ -6822,9 +6828,9 @@ static unsigned long wakeup_gran(struct sched_entity *se)
  *         g

kernel/sched/fair.c static unsigned long wakeup_gran(struct sched_entity *se) · line 6835

Quoted 10 lines
kernel/sched/fair.c +3 -3
  *      |<--->|c
  *
- *  w(c, s1) = -1
- *  w(c, s2) =  0
- *  w(c, s3) =  1
+ *  w(c, s1) = NO_NEED_PREEMPT
+ *  w(c, s2) = MAY_NEED_PREEMPT
+ *  w(c, s3) = NEED_PREEMPT
  *
  */

Yeah, I don't think so. The function is a simple C style compare, where negative is less, 0 is equal and positive is more than.