Merge branch 'misc' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
[firefly-linux-kernel-4.4.55.git] / drivers / acpi / acpi_pad.c
index 37d73024b82e4f9a7df2820e331bd873e0805947..f148a0580e0404b64b9fe1a104e05c0c1aaa498b 100644 (file)
@@ -156,12 +156,13 @@ static int power_saving_thread(void *data)
 
        while (!kthread_should_stop()) {
                int cpu;
-               u64 expire_time;
+               unsigned long expire_time;
 
                try_to_freeze();
 
                /* round robin to cpus */
-               if (last_jiffies + round_robin_time * HZ < jiffies) {
+               expire_time = last_jiffies + round_robin_time * HZ;
+               if (time_before(expire_time, jiffies)) {
                        last_jiffies = jiffies;
                        round_robin_cpu(tsk_index);
                }
@@ -200,7 +201,7 @@ static int power_saving_thread(void *data)
                                        CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
                        local_irq_enable();
 
-                       if (jiffies > expire_time) {
+                       if (time_before(expire_time, jiffies)) {
                                do_sleep = 1;
                                break;
                        }
@@ -215,8 +216,15 @@ static int power_saving_thread(void *data)
                 * borrow CPU time from this CPU and cause RT task use > 95%
                 * CPU time. To make 'avoid starvation' work, takes a nap here.
                 */
-               if (do_sleep)
+               if (unlikely(do_sleep))
                        schedule_timeout_killable(HZ * idle_pct / 100);
+
+               /* If an external event has set the need_resched flag, then
+                * we need to deal with it, or this loop will continue to
+                * spin without calling __mwait().
+                */
+               if (unlikely(need_resched()))
+                       schedule();
        }
 
        exit_round_robin(tsk_index);