Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / kernel / freezer.c
index 95a1238..11f82a4 100644 (file)
@@ -39,7 +39,7 @@ bool freezing_slow_path(struct task_struct *p)
        if (pm_nosig_freezing || cgroup_freezing(p))
                return true;
 
-       if (pm_freezing && !(p->flags & PF_FREEZER_NOSIG))
+       if (pm_freezing && !(p->flags & PF_KTHREAD))
                return true;
 
        return false;
@@ -52,40 +52,26 @@ bool __refrigerator(bool check_kthr_stop)
        /* Hmm, should we be allowed to suspend when there are realtime
           processes around? */
        bool was_frozen = false;
-       long save;
+       long save = current->state;
 
-       /*
-        * No point in checking freezing() again - the caller already did.
-        * Proceed to enter FROZEN.
-        */
-       spin_lock_irq(&freezer_lock);
-repeat:
-       current->flags |= PF_FROZEN;
-       spin_unlock_irq(&freezer_lock);
-
-       save = current->state;
        pr_debug("%s entered refrigerator\n", current->comm);
 
-       spin_lock_irq(&current->sighand->siglock);
-       recalc_sigpending(); /* We sent fake signal, clean it up */
-       spin_unlock_irq(&current->sighand->siglock);
-
        for (;;) {
                set_current_state(TASK_UNINTERRUPTIBLE);
+
+               spin_lock_irq(&freezer_lock);
+               current->flags |= PF_FROZEN;
                if (!freezing(current) ||
                    (check_kthr_stop && kthread_should_stop()))
+                       current->flags &= ~PF_FROZEN;
+               spin_unlock_irq(&freezer_lock);
+
+               if (!(current->flags & PF_FROZEN))
                        break;
                was_frozen = true;
                schedule();
        }
 
-       /* leave FROZEN */
-       spin_lock_irq(&freezer_lock);
-       if (freezing(current))
-               goto repeat;
-       current->flags &= ~PF_FROZEN;
-       spin_unlock_irq(&freezer_lock);
-
        pr_debug("%s left refrigerator\n", current->comm);
 
        /*
@@ -103,26 +89,24 @@ static void fake_signal_wake_up(struct task_struct *p)
 {
        unsigned long flags;
 
-       spin_lock_irqsave(&p->sighand->siglock, flags);
-       signal_wake_up(p, 0);
-       spin_unlock_irqrestore(&p->sighand->siglock, flags);
+       if (lock_task_sighand(p, &flags)) {
+               signal_wake_up(p, 0);
+               unlock_task_sighand(p, &flags);
+       }
 }
 
 /**
- *     freeze_task - send a freeze request to given task
- *     @p: task to send the request to
- *     @sig_only: if set, the request will only be sent if the task has the
- *             PF_FREEZER_NOSIG flag unset
- *     Return value: 'false', if @sig_only is set and the task has
- *             PF_FREEZER_NOSIG set or the task is frozen, 'true', otherwise
+ * freeze_task - send a freeze request to given task
+ * @p: task to send the request to
+ *
+ * If @p is freezing, the freeze request is sent either by sending a fake
+ * signal (if it's not a kernel thread) or waking it up (if it's a kernel
+ * thread).
  *
- *     The freeze request is sent by setting the tasks's TIF_FREEZE flag and
- *     either sending a fake signal to it or waking it up, depending on whether
- *     or not it has PF_FREEZER_NOSIG set.  If @sig_only is set and the task
- *     has PF_FREEZER_NOSIG set (ie. it is a typical kernel thread), its
- *     TIF_FREEZE flag will not be set.
+ * RETURNS:
+ * %false, if @p is not freezing or already frozen; %true, otherwise
  */
-bool freeze_task(struct task_struct *p, bool sig_only)
+bool freeze_task(struct task_struct *p)
 {
        unsigned long flags;
 
@@ -132,7 +116,7 @@ bool freeze_task(struct task_struct *p, bool sig_only)
                return false;
        }
 
-       if (!(p->flags & PF_FREEZER_NOSIG)) {
+       if (!(p->flags & PF_KTHREAD)) {
                fake_signal_wake_up(p);
                /*
                 * fake_signal_wake_up() goes through p's scheduler
@@ -157,17 +141,31 @@ void __thaw_task(struct task_struct *p)
         * be visible to @p as waking up implies wmb.  Waking up inside
         * freezer_lock also prevents wakeups from leaking outside
         * refrigerator.
-        *
-        * If !FROZEN, @p hasn't reached refrigerator, recalc sigpending to
-        * avoid leaving dangling TIF_SIGPENDING behind.
         */
        spin_lock_irqsave(&freezer_lock, flags);
-       if (frozen(p)) {
+       if (frozen(p))
                wake_up_process(p);
-       } else {
-               spin_lock(&p->sighand->siglock);
-               recalc_sigpending_and_wake(p);
-               spin_unlock(&p->sighand->siglock);
-       }
        spin_unlock_irqrestore(&freezer_lock, flags);
 }
+
+/**
+ * set_freezable - make %current freezable
+ *
+ * Mark %current freezable and enter refrigerator if necessary.
+ */
+bool set_freezable(void)
+{
+       might_sleep();
+
+       /*
+        * Modify flags while holding freezer_lock.  This ensures the
+        * freezer notices that we aren't frozen yet or the freezing
+        * condition is visible to try_to_freeze() below.
+        */
+       spin_lock_irq(&freezer_lock);
+       current->flags &= ~PF_NOFREEZE;
+       spin_unlock_irq(&freezer_lock);
+
+       return try_to_freeze();
+}
+EXPORT_SYMBOL(set_freezable);