]> err.no Git - linux-2.6/commitdiff
[PATCH] Cleanup patch for process freezing
authorChristoph Lameter <christoph@lameter.com>
Sat, 25 Jun 2005 06:13:50 +0000 (23:13 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Sun, 26 Jun 2005 00:10:13 +0000 (17:10 -0700)
1. Establish a simple API for process freezing defined in linux/include/sched.h:

   frozen(process) Check for frozen process
   freezing(process) Check if a process is being frozen
   freeze(process) Tell a process to freeze (go to refrigerator)
   thaw_process(process) Restart process
   frozen_process(process) Process is frozen now

2. Remove all references to PF_FREEZE and PF_FROZEN from all
   kernel sources except sched.h

3. Fix numerous locations where try_to_freeze is manually done by a driver

4. Remove the argument that is no longer necessary from two function calls.

5. Some whitespace cleanup

6. Clear potential race in refrigerator (provides an open window of PF_FREEZE
   cleared before setting PF_FROZEN, recalc_sigpending does not check
   PF_FROZEN).

This patch does not address the problem of freeze_processes() violating the rule
that a task may only modify its own flags by setting PF_FREEZE. This is not clean
in an SMP environment. freeze(process) is therefore not SMP safe!

Signed-off-by: Christoph Lameter <christoph@lameter.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
47 files changed:
Documentation/power/kernel_threads.txt
Documentation/power/swsusp.txt
arch/frv/kernel/signal.c
arch/h8300/kernel/signal.c
arch/i386/kernel/io_apic.c
arch/i386/kernel/signal.c
arch/m32r/kernel/signal.c
arch/ppc/kernel/signal.c
arch/x86_64/kernel/signal.c
drivers/block/pktcdvd.c
drivers/ieee1394/ieee1394_core.c
drivers/ieee1394/nodemgr.c
drivers/input/gameport/gameport.c
drivers/input/serio/serio.c
drivers/macintosh/therm_adt746x.c
drivers/md/md.c
drivers/media/dvb/dvb-core/dvb_frontend.c
drivers/media/video/msp3400.c
drivers/media/video/video-buf-dvb.c
drivers/net/8139too.c
drivers/net/irda/sir_kthread.c
drivers/net/irda/stir4200.c
drivers/net/wireless/airo.c
drivers/pcmcia/cs.c
drivers/pnp/pnpbios/core.c
drivers/usb/core/hub.c
drivers/usb/gadget/file_storage.c
drivers/usb/storage/usb.c
drivers/w1/w1.c
fs/afs/kafsasyncd.c
fs/afs/kafstimod.c
fs/jbd/journal.c
fs/jfs/jfs_logmgr.c
fs/jfs/jfs_txnmgr.c
fs/lockd/clntproc.c
fs/xfs/linux-2.6/xfs_buf.c
fs/xfs/linux-2.6/xfs_super.c
include/linux/sched.h
kernel/power/process.c
kernel/sched.c
kernel/signal.c
mm/pdflush.c
mm/vmscan.c
net/rxrpc/krxiod.c
net/rxrpc/krxsecd.c
net/rxrpc/krxtimod.c
net/sunrpc/svcsock.c

index 60b548105edf7052501fa43ab299dbbc44208fd8..fb57784986b1fcdee6b76048fb9c9703939bc849 100644 (file)
@@ -12,8 +12,7 @@ refrigerator. Code to do this looks like this:
        do {
                hub_events();
                wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list));
-               if (current->flags & PF_FREEZE)
-                       refrigerator(PF_FREEZE);
+               try_to_freeze();
        } while (!signal_pending(current));
 
 from drivers/usb/core/hub.c::hub_thread()
index c7c3459fde4343fa3823db8ce21acb8830638df7..4e1627cc5b51abe91cf776a4265484d5716e1868 100644 (file)
@@ -164,8 +164,7 @@ place where the thread is safe to be frozen (no kernel semaphores
 should be held at that point and it must be safe to sleep there), and
 add:
 
-            if (current->flags & PF_FREEZE)
-                    refrigerator(PF_FREEZE);
+            try_to_freeze();
 
 If the thread is needed for writing the image to storage, you should
 instead set the PF_NOFREEZE process flag when creating the thread.
index d8d8f3d4304d9c11387b09d892c032049e7f9f4f..36a2dffc8ebd953618a70a4f365b23ce3349ea3f 100644 (file)
@@ -536,10 +536,8 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
        if (!user_mode(regs))
                return 1;
 
-       if (current->flags & PF_FREEZE) {
-               refrigerator(0);
+       if (try_to_freeze())
                goto no_signal;
-       }
 
        if (!oldset)
                oldset = &current->blocked;
index a4799d633ef40e74a820bfef240a3e97be65c177..5aab87eae1f941f8373d8ea1db5882ced9b447d0 100644 (file)
@@ -517,10 +517,8 @@ asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset)
        if ((regs->ccr & 0x10))
                return 1;
 
-       if (current->flags & PF_FREEZE) {
-               refrigerator(0);
+       if (try_to_freeze())
                goto no_signal;
-       }
 
        current->thread.esp0 = (unsigned long) regs;
 
index 08540bc4ba3e19494a51f7424dddc3753726f9e9..2451a3a9944052d611ceb61faad79f641847a6c4 100644 (file)
@@ -573,7 +573,7 @@ static int balanced_irq(void *unused)
        for ( ; ; ) {
                set_current_state(TASK_INTERRUPTIBLE);
                time_remaining = schedule_timeout(time_remaining);
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
                if (time_after(jiffies,
                                prev_balance_time+balanced_irq_interval)) {
                        do_irq_balance();
index b9b8f4e20fad6e79fbc5acef91115415cd3aaace..ac5b1e975c5c9ac82c5bc77c9cd1150750a3936a 100644 (file)
@@ -608,10 +608,8 @@ int fastcall do_signal(struct pt_regs *regs, sigset_t *oldset)
        if (!user_mode(regs))
                return 1;
 
-       if (current->flags & PF_FREEZE) {
-               refrigerator(0);
+       if (try_to_freeze)
                goto no_signal;
-       }
 
        if (!oldset)
                oldset = &current->blocked;
index 50311eb07a2485f940288ff25127b36062d5d572..5aef7e406ef5f2a0a74e90a334ee4a5ad2817ffd 100644 (file)
@@ -371,10 +371,8 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
        if (!user_mode(regs))
                return 1;
 
-       if (current->flags & PF_FREEZE) {
-               refrigerator(0);
+       if (try_to_freeze()) 
                goto no_signal;
-       }
 
        if (!oldset)
                oldset = &current->blocked;
index 7c8437da09d5d470407dee3eb07680e97404433a..8aaeb6f4e750249026e257b3e416604eb09c075f 100644 (file)
@@ -705,8 +705,7 @@ int do_signal(sigset_t *oldset, struct pt_regs *regs)
        unsigned long frame, newsp;
        int signr, ret;
 
-       if (current->flags & PF_FREEZE) {
-               refrigerator(PF_FREEZE);
+       if (try_to_freeze()) {
                signr = 0;
                if (!signal_pending(current))
                        goto no_signal;
index 98b7ba95d581519edb84a263d5f18f8cca8e12df..98590a989f3d759311935f6142191761bd42c376 100644 (file)
@@ -425,7 +425,7 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset)
        if (!user_mode(regs))
                return 1;
 
-       if (try_to_freeze(0))
+       if (try_to_freeze())
                goto no_signal;
 
        if (!oldset)
index 7f3d78de265c389af02d763ba0ddb0ea339404b3..7b838342f0a353939324c228212074b15ea48c76 100644 (file)
@@ -1251,8 +1251,7 @@ static int kcdrwd(void *foobar)
                        VPRINTK("kcdrwd: wake up\n");
 
                        /* make swsusp happy with our thread */
-                       if (current->flags & PF_FREEZE)
-                               refrigerator(PF_FREEZE);
+                       try_to_freeze();
 
                        list_for_each_entry(pkt, &pd->cdrw.pkt_active_list, list) {
                                if (!pkt->sleep_time)
index 2d9a9b74e687ce51a19b7d026ca4b73155083d5f..629070b83a3360c03abc5a76a752e4ed7ba57902 100644 (file)
@@ -1041,10 +1041,8 @@ static int hpsbpkt_thread(void *__hi)
 
        while (1) {
                if (down_interruptible(&khpsbpkt_sig)) {
-                       if (current->flags & PF_FREEZE) {
-                               refrigerator(0);
+                       if (try_to_freeze())
                                continue;
-                       }
                        printk("khpsbpkt: received unexpected signal?!\n" );
                        break;
                }
index 32abb6dda888cbbb480b1ebf19ab3a5f45f24b17..9a46c3b44bf8b616aaf9c8755725b90af433610c 100644 (file)
@@ -1510,7 +1510,7 @@ static int nodemgr_host_thread(void *__hi)
 
                if (down_interruptible(&hi->reset_sem) ||
                    down_interruptible(&nodemgr_serialize)) {
-                       if (try_to_freeze(PF_FREEZE))
+                       if (try_to_freeze())
                                continue;
                        printk("NodeMgr: received unexpected signal?!\n" );
                        break;
index e152d0fa0cdd25d4d4ac4de364eaf80b9502a0cc..c77a82e460554186ecca8550d53d9a3bf3a47b4a 100644 (file)
@@ -439,7 +439,7 @@ static int gameport_thread(void *nothing)
        do {
                gameport_handle_events();
                wait_event_interruptible(gameport_wait, !list_empty(&gameport_event_list));
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
        } while (!signal_pending(current));
 
        printk(KERN_DEBUG "gameport: kgameportd exiting\n");
index feab4970406e39423711da9e9b9f55180abea9d7..341824c485293014e93b62ce6f4f5c63bb8a8f8e 100644 (file)
@@ -344,7 +344,7 @@ static int serio_thread(void *nothing)
        do {
                serio_handle_events();
                wait_event_interruptible(serio_wait, !list_empty(&serio_event_list));
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
        } while (!signal_pending(current));
 
        printk(KERN_DEBUG "serio: kseriod exiting\n");
index 5ba190ce14a07dbc8a17607d5dce10bc919f8b29..c9ca1118e449207c2dca58a742b0ddd204a556d7 100644 (file)
@@ -328,9 +328,7 @@ static int monitor_task(void *arg)
        struct thermostat* th = arg;
 
        while(!kthread_should_stop()) {
-               if (current->flags & PF_FREEZE)
-                       refrigerator(PF_FREEZE);
-
+               try_to_freeze();
                msleep_interruptible(2000);
 
 #ifndef DEBUG
index 0c6b5b6baff60ded7fb24d2f71988711d723c604..3802f7a17f1635c17f2bcd6fe426e994e0871cf4 100644 (file)
@@ -2976,8 +2976,7 @@ static int md_thread(void * arg)
                wait_event_interruptible_timeout(thread->wqueue,
                                                 test_bit(THREAD_WAKEUP, &thread->flags),
                                                 thread->timeout);
-               if (current->flags & PF_FREEZE)
-                       refrigerator(PF_FREEZE);
+               try_to_freeze();
 
                clear_bit(THREAD_WAKEUP, &thread->flags);
 
index d6b7a9de471eebf50fa9c5bb04ec52c63350b535..f11daae91cd4e07ce54bdb375f5f10aed22aa104 100644 (file)
@@ -391,8 +391,7 @@ static int dvb_frontend_thread(void *data)
                        break;
                }
 
-               if (current->flags & PF_FREEZE)
-                       refrigerator(PF_FREEZE);
+               try_to_freeze();
 
                if (down_interruptible(&fepriv->sem))
                        break;
index 1b7d38e96f14ca6f7c4505ee3273eabf46364ea5..b4ee9dfe6d4247e1cfcdc47ac8bcdb2082140290 100644 (file)
@@ -750,8 +750,7 @@ static int msp34xx_sleep(struct msp3400c *msp, int timeout)
 #endif
                }
        }
-       if (current->flags & PF_FREEZE)
-               refrigerator(PF_FREEZE);
+       try_to_freeze();
        remove_wait_queue(&msp->wq, &wait);
        return msp->restart;
 }
index 5f870075b55e595df3e8384d0812279092ed3259..15f5bb4869638a78a1dcc94f1196d251d350e361 100644 (file)
@@ -62,8 +62,7 @@ static int videobuf_dvb_thread(void *data)
                        break;
                if (kthread_should_stop())
                        break;
-               if (current->flags & PF_FREEZE)
-                       refrigerator(PF_FREEZE);
+               try_to_freeze();
 
                /* feed buffer data to demux */
                if (buf->state == STATE_DONE)
index 047202c4d9a8b23bd150eae38654c211485f3ccf..5a4a08a7c9518da338ce6f0fcea40bfad4b36d8b 100644 (file)
@@ -1606,7 +1606,7 @@ static int rtl8139_thread (void *data)
                do {
                        timeout = interruptible_sleep_on_timeout (&tp->thr_wait, timeout);
                        /* make swsusp happy with our thread */
-                       try_to_freeze(PF_FREEZE);
+                       try_to_freeze();
                } while (!signal_pending (current) && (timeout > 0));
 
                if (signal_pending (current)) {
index 18cea1099530a1131552879fa42fb304e6264e48..c65054364bca45cb49630df0b13682b90c1b0e6e 100644 (file)
@@ -135,8 +135,7 @@ static int irda_thread(void *startup)
                remove_wait_queue(&irda_rq_queue.kick, &wait);
 
                /* make swsusp happy with our thread */
-               if (current->flags & PF_FREEZE)
-                       refrigerator(PF_FREEZE);
+               try_to_freeze();
 
                run_irda_queue();
        }
index 66f488c13717415b151c1bb1ad5442c09e4486e5..15f207323d97043b124dd6282835447804abf5aa 100644 (file)
@@ -763,7 +763,7 @@ static int stir_transmit_thread(void *arg)
        {
 #ifdef CONFIG_PM
                /* if suspending, then power off and wait */
-               if (unlikely(current->flags & PF_FREEZE)) {
+               if (unlikely(freezing(current))) {
                        if (stir->receiving)
                                receive_stop(stir);
                        else
@@ -771,7 +771,7 @@ static int stir_transmit_thread(void *arg)
 
                        write_reg(stir, REG_CTRL1, CTRL1_TXPWD|CTRL1_RXPWD);
 
-                       refrigerator(PF_FREEZE);
+                       refrigerator();
 
                        if (change_speed(stir, stir->speed))
                                break;
index fb10a2db63ad018623c2781be4da42db970cf434..d72e0385e4f2690bf90268d080e275b32e56cb50 100644 (file)
@@ -2918,7 +2918,7 @@ static int airo_thread(void *data) {
                        flush_signals(current);
 
                /* make swsusp happy with our thread */
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
 
                if (test_bit(JOB_DIE, &ai->flags))
                        break;
index d136b3c8fac99299c9d1b2cf4d7f00dce8d39d16..48e4f04530d886d14d1ad9e3fa0f92a762b40614 100644 (file)
@@ -718,7 +718,7 @@ static int pccardd(void *__skt)
                }
 
                schedule();
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
 
                if (!skt->thread)
                        break;
index e939c93a931cf6ea29d3c5be86bf6f81455fb8da..778a324028f4135bdb90bb4e655bac513c17e43d 100644 (file)
@@ -182,7 +182,7 @@ static int pnp_dock_thread(void * unused)
                msleep_interruptible(2000);
 
                if(signal_pending(current)) {
-                       if (try_to_freeze(PF_FREEZE))
+                       if (try_to_freeze())
                                continue;
                        break;
                }
index d2d648ee864009cc028d2ce539ffede88f9bf17f..a8d879a85d04a26d6d6b50d03cbbd47445ad9c8a 100644 (file)
@@ -2808,7 +2808,7 @@ static int hub_thread(void *__unused)
        do {
                hub_events();
                wait_event_interruptible(khubd_wait, !list_empty(&hub_event_list)); 
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
        } while (!signal_pending(current));
 
        pr_debug ("%s: khubd exiting\n", usbcore_name);
index 037a7f163822d6c74c4a671d0a904b5e02a577e8..a9be85103d2342a920c892f3a3952ef663e37ecd 100644 (file)
@@ -1554,8 +1554,7 @@ static int sleep_thread(struct fsg_dev *fsg)
        rc = wait_event_interruptible(fsg->thread_wqh,
                        fsg->thread_wakeup_needed);
        fsg->thread_wakeup_needed = 0;
-       if (current->flags & PF_FREEZE)
-               refrigerator(PF_FREEZE);
+       try_to_freeze();
        return (rc ? -EINTR : 0);
 }
 
index 35c1ca6b5a8eb828613fe87fbfac1dfeaaa918fe..77e7fc258aa2a7c104da2ba0a74a203525849d4d 100644 (file)
@@ -847,10 +847,8 @@ retry:
                wait_event_interruptible_timeout(us->delay_wait,
                                test_bit(US_FLIDX_DISCONNECTING, &us->flags),
                                delay_use * HZ);
-               if (current->flags & PF_FREEZE) {
-                       refrigerator(PF_FREEZE);
+               if (try_to_freeze())
                        goto retry;
-               }
        }
 
        /* If the device is still connected, perform the scanning */
index b460927ec32ad78432660372a7fa20ab49dedfef..312cf3220f12dfa9f81f1515cb793efa3fa7db32 100644 (file)
@@ -646,7 +646,7 @@ static int w1_control(void *data)
        while (!control_needs_exit || have_to_wait) {
                have_to_wait = 0;
 
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
                msleep_interruptible(w1_timeout * 1000);
 
                if (signal_pending(current))
@@ -725,7 +725,7 @@ int w1_process(void *data)
        allow_signal(SIGTERM);
 
        while (!test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
                msleep_interruptible(w1_timeout * 1000);
 
                if (signal_pending(current))
index 6fc88ae8ad9477fd3e12d5d151ef7a142266dfee..7ac07d0d47b91b90e4c40dc16216e50b5876d0af 100644 (file)
@@ -116,7 +116,7 @@ static int kafsasyncd(void *arg)
                remove_wait_queue(&kafsasyncd_sleepq, &myself);
                set_current_state(TASK_RUNNING);
 
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
 
                /* discard pending signals */
                afs_discard_my_signals();
index 86e710dd057e766ed89a59c83c8d4ea3c02ff5e0..65bc05ab81826b417513f203a5b7e930d7b9fed7 100644 (file)
@@ -91,7 +91,7 @@ static int kafstimod(void *arg)
                        complete_and_exit(&kafstimod_dead, 0);
                }
 
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
 
                /* discard pending signals */
                afs_discard_my_signals();
index 1e6f2e2ad4a33d48b6ed38d8e21f0ed68f865b88..5e7b439495171c9d0fcfa7f28b2fa51aab489823 100644 (file)
@@ -167,7 +167,7 @@ loop:
        }
 
        wake_up(&journal->j_wait_done_commit);
-       if (current->flags & PF_FREEZE) {
+       if (freezing(current)) {
                /*
                 * The simpler the better. Flushing journal isn't a
                 * good idea, because that depends on threads that may
@@ -175,7 +175,7 @@ loop:
                 */
                jbd_debug(1, "Now suspending kjournald\n");
                spin_unlock(&journal->j_state_lock);
-               refrigerator(PF_FREEZE);
+               refrigerator();
                spin_lock(&journal->j_state_lock);
        } else {
                /*
index 7c8387ed4192be68cd090956e430cf12eb5ac936..79d07624bfe1787fff2b5ee3b3c8e1479b34ffe3 100644 (file)
@@ -2359,9 +2359,9 @@ int jfsIOWait(void *arg)
                        lbmStartIO(bp);
                        spin_lock_irq(&log_redrive_lock);
                }
-               if (current->flags & PF_FREEZE) {
+               if (freezing(current)) {
                        spin_unlock_irq(&log_redrive_lock);
-                       refrigerator(PF_FREEZE);
+                       refrigerator();
                } else {
                        add_wait_queue(&jfs_IO_thread_wait, &wq);
                        set_current_state(TASK_INTERRUPTIBLE);
index 8cbaaff1d5fa05628f18b0e8213e0ce66dfe3839..121c981ff45363bef9af40c859132ba3e03007f0 100644 (file)
@@ -2788,9 +2788,9 @@ int jfs_lazycommit(void *arg)
                /* In case a wakeup came while all threads were active */
                jfs_commit_thread_waking = 0;
 
-               if (current->flags & PF_FREEZE) {
+               if (freezing(current)) {
                        LAZY_UNLOCK(flags);
-                       refrigerator(PF_FREEZE);
+                       refrigerator();
                } else {
                        DECLARE_WAITQUEUE(wq, current);
 
@@ -2987,9 +2987,9 @@ int jfs_sync(void *arg)
                /* Add anon_list2 back to anon_list */
                list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list);
 
-               if (current->flags & PF_FREEZE) {
+               if (freezing(current)) {
                        TXN_UNLOCK();
-                       refrigerator(PF_FREEZE);
+                       refrigerator();
                } else {
                        DECLARE_WAITQUEUE(wq, current);
 
index fd77ed1d710de4f198c275960f1bb4898f19ef3e..14b3ce87fa29cd96162678fb754936e22c99caec 100644 (file)
@@ -313,7 +313,7 @@ static int nlm_wait_on_grace(wait_queue_head_t *queue)
        prepare_to_wait(queue, &wait, TASK_INTERRUPTIBLE);
        if (!signalled ()) {
                schedule_timeout(NLMCLNT_GRACE_WAIT);
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
                if (!signalled ())
                        status = 0;
        }
index c60e69431e11d746abc9b41d3c525c0ac65116d7..df0cba239dd589b2ac7b9fbb90aa0909190a5ac3 100644 (file)
@@ -1771,9 +1771,9 @@ xfsbufd(
 
        INIT_LIST_HEAD(&tmp);
        do {
-               if (unlikely(current->flags & PF_FREEZE)) {
+               if (unlikely(freezing(current))) {
                        xfsbufd_force_sleep = 1;
-                       refrigerator(PF_FREEZE);
+                       refrigerator();
                } else {
                        xfsbufd_force_sleep = 0;
                }
index 5fe9af38aa2063ac56c23ef7faa39a539b4161d1..f6dd7de2592748c95dee026e0f865ec37d5ca89b 100644 (file)
@@ -483,7 +483,7 @@ xfssyncd(
                set_current_state(TASK_INTERRUPTIBLE);
                timeleft = schedule_timeout(timeleft);
                /* swsusp */
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
                if (vfsp->vfs_flag & VFS_UMOUNT)
                        break;
 
index 2c69682b0444623ab7fea6d6ace03174b8ce79c0..e7fd09b0557f5f952296241ad4c4baa28437c15d 100644 (file)
@@ -1245,33 +1245,78 @@ extern void normalize_rt_tasks(void);
 
 #endif
 
-/* try_to_freeze
- *
- * Checks whether we need to enter the refrigerator
- * and returns 1 if we did so.
- */
 #ifdef CONFIG_PM
-extern void refrigerator(unsigned long);
+/*
+ * Check if a process has been frozen
+ */
+static inline int frozen(struct task_struct *p)
+{
+       return p->flags & PF_FROZEN;
+}
+
+/*
+ * Check if there is a request to freeze a process
+ */
+static inline int freezing(struct task_struct *p)
+{
+       return p->flags & PF_FREEZE;
+}
+
+/*
+ * Request that a process be frozen
+ * FIXME: SMP problem. We may not modify other process' flags!
+ */
+static inline void freeze(struct task_struct *p)
+{
+       p->flags |= PF_FREEZE;
+}
+
+/*
+ * Wake up a frozen process
+ */
+static inline int thaw_process(struct task_struct *p)
+{
+       if (frozen(p)) {
+               p->flags &= ~PF_FROZEN;
+               wake_up_process(p);
+               return 1;
+       }
+       return 0;
+}
+
+/*
+ * freezing is complete, mark process as frozen
+ */
+static inline void frozen_process(struct task_struct *p)
+{
+       p->flags = (p->flags & ~PF_FREEZE) | PF_FROZEN;
+}
+
+extern void refrigerator(void);
 extern int freeze_processes(void);
 extern void thaw_processes(void);
 
-static inline int try_to_freeze(unsigned long refrigerator_flags)
+static inline int try_to_freeze(void)
 {
-       if (unlikely(current->flags & PF_FREEZE)) {
-               refrigerator(refrigerator_flags);
+       if (freezing(current)) {
+               refrigerator();
                return 1;
        } else
                return 0;
 }
 #else
-static inline void refrigerator(unsigned long flag) {}
+static inline int frozen(struct task_struct *p) { return 0; }
+static inline int freezing(struct task_struct *p) { return 0; }
+static inline void freeze(struct task_struct *p) { BUG(); }
+static inline int thaw_process(struct task_struct *p) { return 1; }
+static inline void frozen_process(struct task_struct *p) { BUG(); }
+
+static inline void refrigerator(void) {}
 static inline int freeze_processes(void) { BUG(); return 0; }
 static inline void thaw_processes(void) {}
 
-static inline int try_to_freeze(unsigned long refrigerator_flags)
-{
-       return 0;
-}
+static inline int try_to_freeze(void) { return 0; }
+
 #endif /* CONFIG_PM */
 #endif /* __KERNEL__ */
 
index 78d92dc6a1edc8119ae616bf184e83ae26ec27e8..0a086640bcfc15cce008901702549fd0061a498c 100644 (file)
@@ -32,7 +32,7 @@ static inline int freezeable(struct task_struct * p)
 }
 
 /* Refrigerator is place where frozen processes are stored :-). */
-void refrigerator(unsigned long flag)
+void refrigerator(void)
 {
        /* Hmm, should we be allowed to suspend when there are realtime
           processes around? */
@@ -41,14 +41,13 @@ void refrigerator(unsigned long flag)
        current->state = TASK_UNINTERRUPTIBLE;
        pr_debug("%s entered refrigerator\n", current->comm);
        printk("=");
-       current->flags &= ~PF_FREEZE;
 
+       frozen_process(current);
        spin_lock_irq(&current->sighand->siglock);
        recalc_sigpending(); /* We sent fake signal, clean it up */
        spin_unlock_irq(&current->sighand->siglock);
 
-       current->flags |= PF_FROZEN;
-       while (current->flags & PF_FROZEN)
+       while (frozen(current))
                schedule();
        pr_debug("%s left refrigerator\n", current->comm);
        current->state = save;
@@ -57,10 +56,10 @@ void refrigerator(unsigned long flag)
 /* 0 = success, else # of processes that we failed to stop */
 int freeze_processes(void)
 {
-       int todo;
-       unsigned long start_time;
+       int todo;
+       unsigned long start_time;
        struct task_struct *g, *p;
-       
+
        printk( "Stopping tasks: " );
        start_time = jiffies;
        do {
@@ -70,14 +69,12 @@ int freeze_processes(void)
                        unsigned long flags;
                        if (!freezeable(p))
                                continue;
-                       if ((p->flags & PF_FROZEN) ||
+                       if ((frozen(p)) ||
                            (p->state == TASK_TRACED) ||
                            (p->state == TASK_STOPPED))
                                continue;
 
-                       /* FIXME: smp problem here: we may not access other process' flags
-                          without locking */
-                       p->flags |= PF_FREEZE;
+                       freeze(p);
                        spin_lock_irqsave(&p->sighand->siglock, flags);
                        signal_wake_up(p, 0);
                        spin_unlock_irqrestore(&p->sighand->siglock, flags);
@@ -91,7 +88,7 @@ int freeze_processes(void)
                        return todo;
                }
        } while(todo);
-       
+
        printk( "|\n" );
        BUG_ON(in_atomic());
        return 0;
@@ -106,10 +103,7 @@ void thaw_processes(void)
        do_each_thread(g, p) {
                if (!freezeable(p))
                        continue;
-               if (p->flags & PF_FROZEN) {
-                       p->flags &= ~PF_FROZEN;
-                       wake_up_process(p);
-               } else
+               if (!thaw_process(p))
                        printk(KERN_INFO " Strange, %s not stopped\n", p->comm );
        } while_each_thread(g, p);
 
index 76080d142e3d9c08897e7b713d23dd0e2f809db0..6fa9ea4ae44c9cc24e6146ab0d992856370e6c2a 100644 (file)
@@ -4174,8 +4174,7 @@ static int migration_thread(void * data)
                struct list_head *head;
                migration_req_t *req;
 
-               if (current->flags & PF_FREEZE)
-                       refrigerator(PF_FREEZE);
+               try_to_freeze();
 
                spin_lock_irq(&rq->lock);
 
index d1258729a5f9cdf6674b897b273036e1dee29291..ca1186eef9380cd5e633f644a0891d1dacc5bd16 100644 (file)
@@ -213,7 +213,7 @@ static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked)
 fastcall void recalc_sigpending_tsk(struct task_struct *t)
 {
        if (t->signal->group_stop_count > 0 ||
-           (t->flags & PF_FREEZE) ||
+           (freezing(t)) ||
            PENDING(&t->pending, &t->blocked) ||
            PENDING(&t->signal->shared_pending, &t->blocked))
                set_tsk_thread_flag(t, TIF_SIGPENDING);
@@ -2231,8 +2231,7 @@ sys_rt_sigtimedwait(const sigset_t __user *uthese,
                        current->state = TASK_INTERRUPTIBLE;
                        timeout = schedule_timeout(timeout);
 
-                       if (current->flags & PF_FREEZE)
-                               refrigerator(PF_FREEZE);
+                       try_to_freeze();
                        spin_lock_irq(&current->sighand->siglock);
                        sig = dequeue_signal(current, &these, &info);
                        current->blocked = current->real_blocked;
index 38ce279cc8cdf4fa3a83e29a8ffb509a0551c447..d6781951267eb654a522529658aaa06199d1772f 100644 (file)
@@ -105,7 +105,7 @@ static int __pdflush(struct pdflush_work *my_work)
                spin_unlock_irq(&pdflush_lock);
 
                schedule();
-               if (try_to_freeze(PF_FREEZE)) {
+               if (try_to_freeze()) {
                        spin_lock_irq(&pdflush_lock);
                        continue;
                }
index 4b8e62a193708b7c12808cdb0eccfad61a38bce5..1fa312a8db7751aee563a9c6affaa0e1aa26007f 100644 (file)
@@ -1216,8 +1216,8 @@ static int kswapd(void *p)
        order = 0;
        for ( ; ; ) {
                unsigned long new_order;
-               if (current->flags & PF_FREEZE)
-                       refrigerator(PF_FREEZE);
+
+               try_to_freeze();
 
                prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
                new_order = pgdat->kswapd_max_order;
index 2b537f425a17d6bd7d9485299cc72bc96bed2998..dada34a77b2194ab9750d2cdc518032f0fa413df 100644 (file)
@@ -138,7 +138,7 @@ static int rxrpc_krxiod(void *arg)
 
                _debug("### End Work");
 
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
 
                 /* discard pending signals */
                rxrpc_discard_my_signals();
index 6020c89d9228846b6478e03dacd7860e7beb01ce..1aadd026d3542151e0eeb8b6c99f35a24c6779e0 100644 (file)
@@ -107,7 +107,7 @@ static int rxrpc_krxsecd(void *arg)
 
                _debug("### End Inbound Calls");
 
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
 
                 /* discard pending signals */
                rxrpc_discard_my_signals();
index 249c2b0290bbfeae3bedccecf82af87301769b7f..3ac81cdd1211ce2c58fa4729b65fabe464097294 100644 (file)
@@ -90,7 +90,7 @@ static int krxtimod(void *arg)
                        complete_and_exit(&krxtimod_dead, 0);
                }
 
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
 
                /* discard pending signals */
                rxrpc_discard_my_signals();
index 05907035bc96105d67fe124eef6793647b696d43..56db8f13e6cb40c4cf9ecb765923993564c16c7e 100644 (file)
@@ -1185,8 +1185,8 @@ svc_recv(struct svc_serv *serv, struct svc_rqst *rqstp, long timeout)
        arg->page_len = (pages-2)*PAGE_SIZE;
        arg->len = (pages-1)*PAGE_SIZE;
        arg->tail[0].iov_len = 0;
-       
-       try_to_freeze(PF_FREEZE);
+
+       try_to_freeze();
        if (signalled())
                return -EINTR;
 
@@ -1227,7 +1227,7 @@ svc_recv(struct svc_serv *serv, struct svc_rqst *rqstp, long timeout)
 
                schedule_timeout(timeout);
 
-               try_to_freeze(PF_FREEZE);
+               try_to_freeze();
 
                spin_lock_bh(&serv->sv_lock);
                remove_wait_queue(&rqstp->rq_wait, &wait);