Merge remote-tracking branch 'lsk/v3.10/topic/gator' into linux-linaro-lsk
[firefly-linux-kernel-4.4.55.git] / kernel / sched / fair.c
index 71da724449ee84f3af5de13117c37d84f5682548..97ed132c809a9c203567a7e28833757beab65aef 100644 (file)
@@ -3587,10 +3587,12 @@ static enum hrtimer_restart hmp_cpu_keepalive_notify(struct hrtimer *hrtimer)
  * If there are any, set ns_delay to
  * ('target_residency of state with shortest too-big latency' - 1) * 1000.
  */
-static void hmp_keepalive_delay(unsigned int *ns_delay)
+static void hmp_keepalive_delay(int cpu, unsigned int *ns_delay)
 {
+       struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu);
        struct cpuidle_driver *drv;
-       drv = cpuidle_driver_ref();
+
+       drv = cpuidle_get_cpu_driver(dev);
        if (drv) {
                unsigned int us_delay = UINT_MAX;
                unsigned int us_max_delay = *ns_delay / 1000;
@@ -3609,7 +3611,6 @@ static void hmp_keepalive_delay(unsigned int *ns_delay)
                else
                        *ns_delay = 1000 * (us_delay - 1);
        }
-       cpuidle_driver_unref();
 }
 
 static void hmp_cpu_keepalive_trigger(void)
@@ -3623,7 +3624,7 @@ static void hmp_cpu_keepalive_trigger(void)
                                CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED);
                keepalive->timer.function = hmp_cpu_keepalive_notify;
 
-               hmp_keepalive_delay(&ns_delay);
+               hmp_keepalive_delay(cpu, &ns_delay);
                keepalive->delay = ns_to_ktime(ns_delay);
                keepalive->init = true;
        }
@@ -4483,7 +4484,11 @@ unlock:
 #else
                new_cpu = hmp_select_slower_cpu(p, prev_cpu);
 #endif
-               if (new_cpu != prev_cpu) {
+               /*
+                * we might have no suitable CPU
+                * in which case new_cpu == NR_CPUS
+                */
+               if (new_cpu < NR_CPUS && new_cpu != prev_cpu) {
                        hmp_next_down_delay(&p->se, new_cpu);
                        trace_sched_hmp_migrate(p, new_cpu, HMP_MIGRATE_WAKEUP);
                        return new_cpu;