sched/core: Create task_has_idle_policy() helper
[linux-2.6-block.git] / kernel / sched / core.c
index fe02231218833359b6e5828ac13d7860e923150c..5afb868f7339de7b3e024187c9f85e80828325a3 100644 (file)
@@ -697,7 +697,7 @@ static void set_load_weight(struct task_struct *p, bool update_load)
        /*
         * SCHED_IDLE tasks get minimal weight:
         */
-       if (idle_policy(p->policy)) {
+       if (task_has_idle_policy(p)) {
                load->weight = scale_load(WEIGHT_IDLEPRIO);
                load->inv_weight = WMULT_IDLEPRIO;
                p->se.runnable_weight = load->weight;
@@ -722,8 +722,10 @@ static inline void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
        if (!(flags & ENQUEUE_NOCLOCK))
                update_rq_clock(rq);
 
-       if (!(flags & ENQUEUE_RESTORE))
+       if (!(flags & ENQUEUE_RESTORE)) {
                sched_info_queued(rq, p);
+               psi_enqueue(p, flags & ENQUEUE_WAKEUP);
+       }
 
        p->sched_class->enqueue_task(rq, p, flags);
 }
@@ -733,8 +735,10 @@ static inline void dequeue_task(struct rq *rq, struct task_struct *p, int flags)
        if (!(flags & DEQUEUE_NOCLOCK))
                update_rq_clock(rq);
 
-       if (!(flags & DEQUEUE_SAVE))
+       if (!(flags & DEQUEUE_SAVE)) {
                sched_info_dequeued(rq, p);
+               psi_dequeue(p, flags & DEQUEUE_SLEEP);
+       }
 
        p->sched_class->dequeue_task(rq, p, flags);
 }
@@ -2037,6 +2041,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
        cpu = select_task_rq(p, p->wake_cpu, SD_BALANCE_WAKE, wake_flags);
        if (task_cpu(p) != cpu) {
                wake_flags |= WF_MIGRATED;
+               psi_ttwu_dequeue(p);
                set_task_cpu(p, cpu);
        }
 
@@ -3051,6 +3056,7 @@ void scheduler_tick(void)
        curr->sched_class->task_tick(rq, curr, 0);
        cpu_load_update_active(rq);
        calc_global_load_tick(rq);
+       psi_task_tick(rq);
 
        rq_unlock(rq, &rf);
 
@@ -4193,7 +4199,7 @@ recheck:
                 * Treat SCHED_IDLE as nice 20. Only allow a switch to
                 * SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
                 */
-               if (idle_policy(p->policy) && !idle_policy(policy)) {
+               if (task_has_idle_policy(p) && !idle_policy(policy)) {
                        if (!can_nice(p, task_nice(p)))
                                return -EPERM;
                }
@@ -4933,9 +4939,7 @@ static void do_sched_yield(void)
        struct rq_flags rf;
        struct rq *rq;
 
-       local_irq_disable();
-       rq = this_rq();
-       rq_lock(rq, &rf);
+       rq = this_rq_lock_irq(&rf);
 
        schedstat_inc(rq->yld_count);
        current->sched_class->yield_task(rq);
@@ -5244,7 +5248,7 @@ out_unlock:
  * an error code.
  */
 SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
-               struct timespec __user *, interval)
+               struct __kernel_timespec __user *, interval)
 {
        struct timespec64 t;
        int retval = sched_rr_get_interval(pid, &t);
@@ -5255,16 +5259,16 @@ SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
        return retval;
 }
 
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_COMPAT_32BIT_TIME
 COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
                       compat_pid_t, pid,
-                      struct compat_timespec __user *, interval)
+                      struct old_timespec32 __user *, interval)
 {
        struct timespec64 t;
        int retval = sched_rr_get_interval(pid, &t);
 
        if (retval == 0)
-               retval = compat_put_timespec64(&t, interval);
+               retval = put_old_timespec32(&t, interval);
        return retval;
 }
 #endif
@@ -5855,11 +5859,14 @@ void __init sched_init_smp(void)
        /*
         * There's no userspace yet to cause hotplug operations; hence all the
         * CPU masks are stable and all blatant races in the below code cannot
-        * happen.
+        * happen. The hotplug lock is nevertheless taken to satisfy lockdep,
+        * but there won't be any contention on it.
         */
+       cpus_read_lock();
        mutex_lock(&sched_domains_mutex);
        sched_init_domains(cpu_active_mask);
        mutex_unlock(&sched_domains_mutex);
+       cpus_read_unlock();
 
        /* Move init over to a non-isolated CPU */
        if (set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0)
@@ -6069,6 +6076,8 @@ void __init sched_init(void)
 
        init_schedstats();
 
+       psi_init();
+
        scheduler_running = 1;
 }