sched: Remove select_task_rq()'s sd_flag parameter
authorValentin Schneider <valentin.schneider@arm.com>
Mon, 2 Nov 2020 18:45:13 +0000 (18:45 +0000)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 10 Nov 2020 17:39:06 +0000 (18:39 +0100)
Only select_task_rq_fair() uses that parameter to do an actual domain
search, other classes only care about what kind of wakeup is happening
(fork, exec, or "regular") and thus just translate the flag into a wakeup
type.

WF_TTWU and WF_EXEC have just been added, use these along with WF_FORK to
encode the wakeup types we care about. For select_task_rq_fair(), we can
simply use the shiny new WF_flag : SD_flag mapping.

Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20201102184514.2733-3-valentin.schneider@arm.com
kernel/sched/core.c
kernel/sched/deadline.c
kernel/sched/fair.c
kernel/sched/idle.c
kernel/sched/rt.c
kernel/sched/sched.h
kernel/sched/stop_task.c

index 622f343413a63b44bac43535aaa661861b4ef657..a6aaf9fb3400bf10d1819e68469102dca549b753 100644 (file)
@@ -2769,12 +2769,12 @@ out:
  * The caller (fork, wakeup) owns p->pi_lock, ->cpus_ptr is stable.
  */
 static inline
-int select_task_rq(struct task_struct *p, int cpu, int sd_flags, int wake_flags)
+int select_task_rq(struct task_struct *p, int cpu, int wake_flags)
 {
        lockdep_assert_held(&p->pi_lock);
 
        if (p->nr_cpus_allowed > 1 && !is_migration_disabled(p))
-               cpu = p->sched_class->select_task_rq(p, cpu, sd_flags, wake_flags);
+               cpu = p->sched_class->select_task_rq(p, cpu, wake_flags);
        else
                cpu = cpumask_any(p->cpus_ptr);
 
@@ -3409,7 +3409,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
         */
        smp_cond_load_acquire(&p->on_cpu, !VAL);
 
-       cpu = select_task_rq(p, p->wake_cpu, SD_BALANCE_WAKE, wake_flags);
+       cpu = select_task_rq(p, p->wake_cpu, wake_flags | WF_TTWU);
        if (task_cpu(p) != cpu) {
                wake_flags |= WF_MIGRATED;
                psi_ttwu_dequeue(p);
@@ -3793,7 +3793,7 @@ void wake_up_new_task(struct task_struct *p)
         */
        p->recent_used_cpu = task_cpu(p);
        rseq_migrate(p);
-       __set_task_cpu(p, select_task_rq(p, task_cpu(p), SD_BALANCE_FORK, 0));
+       __set_task_cpu(p, select_task_rq(p, task_cpu(p), WF_FORK));
 #endif
        rq = __task_rq_lock(p, &rf);
        update_rq_clock(rq);
@@ -4384,7 +4384,7 @@ void sched_exec(void)
        int dest_cpu;
 
        raw_spin_lock_irqsave(&p->pi_lock, flags);
-       dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), SD_BALANCE_EXEC, 0);
+       dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC);
        if (dest_cpu == smp_processor_id())
                goto unlock;
 
index cc1feb79d7864977dc269647ad8b5a3224c0e8c3..2a5836f440e071a9f9026782170651918342e347 100644 (file)
@@ -1683,13 +1683,13 @@ static void yield_task_dl(struct rq *rq)
 static int find_later_rq(struct task_struct *task);
 
 static int
-select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
+select_task_rq_dl(struct task_struct *p, int cpu, int flags)
 {
        struct task_struct *curr;
        bool select_rq;
        struct rq *rq;
 
-       if (sd_flag != SD_BALANCE_WAKE)
+       if (!(flags & WF_TTWU))
                goto out;
 
        rq = cpu_rq(cpu);
index 3e5d98f861a1835fc4d3b07f1db5ffa8d5f45783..b1596fa21bbe72e4c1d02f7533be3a52caa4a4e7 100644 (file)
@@ -6684,7 +6684,7 @@ fail:
 
 /*
  * select_task_rq_fair: Select target runqueue for the waking task in domains
- * that have the 'sd_flag' flag set. In practice, this is SD_BALANCE_WAKE,
+ * that have the relevant SD flag set. In practice, this is SD_BALANCE_WAKE,
  * SD_BALANCE_FORK, or SD_BALANCE_EXEC.
  *
  * Balances load by selecting the idlest CPU in the idlest group, or under
@@ -6695,13 +6695,15 @@ fail:
  * preempt must be disabled.
  */
 static int
-select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_flags)
+select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)
 {
+       int sync = (wake_flags & WF_SYNC) && !(current->flags & PF_EXITING);
        struct sched_domain *tmp, *sd = NULL;
        int cpu = smp_processor_id();
        int new_cpu = prev_cpu;
        int want_affine = 0;
-       int sync = (wake_flags & WF_SYNC) && !(current->flags & PF_EXITING);
+       /* SD_flags and WF_flags share the first nibble */
+       int sd_flag = wake_flags & 0xF;
 
        if (sd_flag & SD_BALANCE_WAKE) {
                record_wakee(p);
index 9da69c4e0ee9905dc7d4db59c64ec323288f6a5e..df91b198a74c10193e8a1bd8bac42cf051c3e64f 100644 (file)
@@ -376,7 +376,7 @@ void cpu_startup_entry(enum cpuhp_state state)
 
 #ifdef CONFIG_SMP
 static int
-select_task_rq_idle(struct task_struct *p, int cpu, int sd_flag, int flags)
+select_task_rq_idle(struct task_struct *p, int cpu, int flags)
 {
        return task_cpu(p); /* IDLE tasks as never migrated */
 }
index c961a3fc0166b7b7d58bff2e2b8f608e54e10033..dbe4629cf7ba46211746531a2fd72c3ec11f1970 100644 (file)
@@ -1430,14 +1430,14 @@ static void yield_task_rt(struct rq *rq)
 static int find_lowest_rq(struct task_struct *task);
 
 static int
-select_task_rq_rt(struct task_struct *p, int cpu, int sd_flag, int flags)
+select_task_rq_rt(struct task_struct *p, int cpu, int flags)
 {
        struct task_struct *curr;
        struct rq *rq;
        bool test;
 
        /* For anything but wake ups, just return the task_cpu */
-       if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
+       if (!(flags & (WF_TTWU | WF_FORK)))
                goto out;
 
        rq = cpu_rq(cpu);
index 47258735a93f09b9a0340cba89d927dfc0fe2d6e..590e6f27068cba844143faf6d31b97d6891f05c3 100644 (file)
@@ -1833,7 +1833,7 @@ struct sched_class {
 
 #ifdef CONFIG_SMP
        int (*balance)(struct rq *rq, struct task_struct *prev, struct rq_flags *rf);
-       int  (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags);
+       int  (*select_task_rq)(struct task_struct *p, int task_cpu, int flags);
        void (*migrate_task_rq)(struct task_struct *p, int new_cpu);
 
        void (*task_woken)(struct rq *this_rq, struct task_struct *task);
index 91bb10cc070e953d8c9dcf7c595f7d368b289c73..55f39125c0e1c9acd2c612fb62981432fe4f8539 100644 (file)
@@ -11,7 +11,7 @@
 
 #ifdef CONFIG_SMP
 static int
-select_task_rq_stop(struct task_struct *p, int cpu, int sd_flag, int flags)
+select_task_rq_stop(struct task_struct *p, int cpu, int flags)
 {
        return task_cpu(p); /* stop tasks as never migrate */
 }