PM / AVS: rockchip-cpu-avs: add driver handling Rockchip cpu avs
[firefly-linux-kernel-4.4.55.git] / kernel / freezer.c
index c38893b0efbaa39d770b11546dba9e97ec53ff51..a8900a3bc27a895b65580a23a144e581bfe0149d 100644 (file)
@@ -19,6 +19,12 @@ EXPORT_SYMBOL(system_freezing_cnt);
 bool pm_freezing;
 bool pm_nosig_freezing;
 
+/*
+ * Temporary export for the deadlock workaround in ata_scsi_hotplug().
+ * Remove once the hack becomes unnecessary.
+ */
+EXPORT_SYMBOL_GPL(pm_freezing);
+
 /* protects freezing and frozen transitions */
 static DEFINE_SPINLOCK(freezer_lock);
 
@@ -33,7 +39,10 @@ static DEFINE_SPINLOCK(freezer_lock);
  */
 bool freezing_slow_path(struct task_struct *p)
 {
-       if (p->flags & PF_NOFREEZE)
+       if (p->flags & (PF_NOFREEZE | PF_SUSPEND_TASK))
+               return false;
+
+       if (test_thread_flag(TIF_MEMDIE))
                return false;
 
        if (pm_nosig_freezing || cgroup_freezing(p))
@@ -110,6 +119,18 @@ bool freeze_task(struct task_struct *p)
 {
        unsigned long flags;
 
+       /*
+        * This check can race with freezer_do_not_count, but worst case that
+        * will result in an extra wakeup being sent to the task.  It does not
+        * race with freezer_count(), the barriers in freezer_count() and
+        * freezer_should_skip() ensure that either freezer_count() sees
+        * freezing == true in try_to_freeze() and freezes, or
+        * freezer_should_skip() sees !PF_FREEZE_SKIP and freezes the task
+        * normally.
+        */
+       if (freezer_should_skip(p))
+               return false;
+
        spin_lock_irqsave(&freezer_lock, flags);
        if (!freezing(p) || frozen(p)) {
                spin_unlock_irqrestore(&freezer_lock, flags);
@@ -129,12 +150,6 @@ void __thaw_task(struct task_struct *p)
 {
        unsigned long flags;
 
-       /*
-        * Clear freezing and kick @p if FROZEN.  Clearing is guaranteed to
-        * be visible to @p as waking up implies wmb.  Waking up inside
-        * freezer_lock also prevents wakeups from leaking outside
-        * refrigerator.
-        */
        spin_lock_irqsave(&freezer_lock, flags);
        if (frozen(p))
                wake_up_process(p);