aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2007-07-17 07:03:35 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-17 13:23:02 -0400
commit831441862956fffa17b9801db37e6ea1650b0f69 (patch)
treeb0334921341f8f1734bdd3243de76d676329d21c
parent787d2214c19bcc9b6ac48af0ce098277a801eded (diff)
Freezer: make kernel threads nonfreezable by default
Currently, the freezer treats all tasks as freezable, except for the kernel threads that explicitly set the PF_NOFREEZE flag for themselves. This approach is problematic, since it requires every kernel thread to either set PF_NOFREEZE explicitly, or call try_to_freeze(), even if it doesn't care for the freezing of tasks at all. It seems better to only require the kernel threads that want to or need to be frozen to use some freezer-related code and to remove any freezer-related code from the other (nonfreezable) kernel threads, which is done in this patch. The patch causes all kernel threads to be nonfreezable by default (ie. to have PF_NOFREEZE set by default) and introduces the set_freezable() function that should be called by the freezable kernel threads in order to unset PF_NOFREEZE. It also makes all of the currently freezable kernel threads call set_freezable(), so it shouldn't cause any (intentional) change of behaviour to appear. Additionally, it updates documentation to describe the freezing of tasks more accurately. [akpm@linux-foundation.org: build fixes] Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Nigel Cunningham <nigel@nigel.suspend2.net> Cc: Pavel Machek <pavel@ucw.cz> Cc: Oleg Nesterov <oleg@tv-sign.ru> Cc: Gautham R Shenoy <ego@in.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--Documentation/power/freezing-of-tasks.txt160
-rw-r--r--Documentation/power/kernel_threads.txt40
-rw-r--r--Documentation/power/swsusp.txt18
-rw-r--r--arch/i386/kernel/apm.c2
-rw-r--r--arch/i386/kernel/io_apic.c1
-rw-r--r--drivers/block/loop.c8
-rw-r--r--drivers/block/pktcdvd.c1
-rw-r--r--drivers/char/apm-emulation.c12
-rw-r--r--drivers/char/hvc_console.c1
-rw-r--r--drivers/edac/edac_mc.c1
-rw-r--r--drivers/ieee1394/ieee1394_core.c3
-rw-r--r--drivers/ieee1394/nodemgr.c1
-rw-r--r--drivers/input/gameport/gameport.c1
-rw-r--r--drivers/input/serio/serio.c1
-rw-r--r--drivers/input/touchscreen/ucb1400_ts.c1
-rw-r--r--drivers/macintosh/therm_adt746x.c1
-rw-r--r--drivers/macintosh/windfarm_core.c1
-rw-r--r--drivers/md/md.c1
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c1
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c1
-rw-r--r--drivers/media/video/msp3400-kthreads.c6
-rw-r--r--drivers/media/video/tvaudio.c2
-rw-r--r--drivers/media/video/video-buf-dvb.c1
-rw-r--r--drivers/media/video/vivi.c1
-rw-r--r--drivers/mfd/ucb1x00-ts.c1
-rw-r--r--drivers/mmc/card/queue.c7
-rw-r--r--drivers/mtd/mtd_blkdevs.c3
-rw-r--r--drivers/mtd/ubi/wl.c1
-rw-r--r--drivers/net/wireless/airo.c3
-rw-r--r--drivers/net/wireless/libertas/main.c1
-rw-r--r--drivers/pcmcia/cs.c1
-rw-r--r--drivers/pnp/pnpbios/core.c1
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c3
-rw-r--r--drivers/scsi/scsi_error.c3
-rw-r--r--drivers/usb/atm/ueagle-atm.c1
-rw-r--r--drivers/usb/core/hub.c1
-rw-r--r--drivers/usb/gadget/file_storage.c3
-rw-r--r--drivers/usb/storage/usb.c3
-rw-r--r--drivers/video/ps3fb.c1
-rw-r--r--drivers/w1/w1.c1
-rw-r--r--fs/cifs/cifsfs.c1
-rw-r--r--fs/cifs/connect.c1
-rw-r--r--fs/jffs2/background.c1
-rw-r--r--fs/lockd/svc.c2
-rw-r--r--fs/nfs/callback.c2
-rw-r--r--fs/nfsd/nfssvc.c2
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c1
-rw-r--r--include/linux/freezer.h14
-rw-r--r--init/do_mounts_initrd.c7
-rw-r--r--kernel/audit.c1
-rw-r--r--kernel/exit.c6
-rw-r--r--kernel/fork.c2
-rw-r--r--kernel/rcutorture.c4
-rw-r--r--kernel/rtmutex-tester.c1
-rw-r--r--kernel/sched.c3
-rw-r--r--kernel/softirq.c3
-rw-r--r--kernel/softlockup.c2
-rw-r--r--kernel/workqueue.c4
-rw-r--r--mm/pdflush.c1
-rw-r--r--mm/vmscan.c1
-rw-r--r--net/bluetooth/bnep/core.c2
-rw-r--r--net/bluetooth/cmtp/core.c2
-rw-r--r--net/bluetooth/hidp/core.c2
-rw-r--r--net/bluetooth/rfcomm/core.c2
-rw-r--r--net/core/pktgen.c2
65 files changed, 256 insertions, 113 deletions
diff --git a/Documentation/power/freezing-of-tasks.txt b/Documentation/power/freezing-of-tasks.txt
new file mode 100644
index 000000000000..af1a282c71a3
--- /dev/null
+++ b/Documentation/power/freezing-of-tasks.txt
@@ -0,0 +1,160 @@
1Freezing of tasks
2 (C) 2007 Rafael J. Wysocki <rjw@sisk.pl>, GPL
3
4I. What is the freezing of tasks?
5
6The freezing of tasks is a mechanism by which user space processes and some
7kernel threads are controlled during hibernation or system-wide suspend (on some
8architectures).
9
10II. How does it work?
11
12There are four per-task flags used for that, PF_NOFREEZE, PF_FROZEN, TIF_FREEZE
13and PF_FREEZER_SKIP (the last one is auxiliary). The tasks that have
14PF_NOFREEZE unset (all user space processes and some kernel threads) are
15regarded as 'freezable' and treated in a special way before the system enters a
16suspend state as well as before a hibernation image is created (in what follows
17we only consider hibernation, but the description also applies to suspend).
18
19Namely, as the first step of the hibernation procedure the function
20freeze_processes() (defined in kernel/power/process.c) is called. It executes
21try_to_freeze_tasks() that sets TIF_FREEZE for all of the freezable tasks and
22sends a fake signal to each of them. A task that receives such a signal and has
23TIF_FREEZE set, should react to it by calling the refrigerator() function
24(defined in kernel/power/process.c), which sets the task's PF_FROZEN flag,
25changes its state to TASK_UNINTERRUPTIBLE and makes it loop until PF_FROZEN is
26cleared for it. Then, we say that the task is 'frozen' and therefore the set of
27functions handling this mechanism is called 'the freezer' (these functions are
28defined in kernel/power/process.c and include/linux/freezer.h). User space
29processes are generally frozen before kernel threads.
30
31It is not recommended to call refrigerator() directly. Instead, it is
32recommended to use the try_to_freeze() function (defined in
33include/linux/freezer.h), that checks the task's TIF_FREEZE flag and makes the
34task enter refrigerator() if the flag is set.
35
36For user space processes try_to_freeze() is called automatically from the
37signal-handling code, but the freezable kernel threads need to call it
38explicitly in suitable places. The code to do this may look like the following:
39
40 do {
41 hub_events();
42 wait_event_interruptible(khubd_wait,
43 !list_empty(&hub_event_list));
44 try_to_freeze();
45 } while (!signal_pending(current));
46
47(from drivers/usb/core/hub.c::hub_thread()).
48
49If a freezable kernel thread fails to call try_to_freeze() after the freezer has
50set TIF_FREEZE for it, the freezing of tasks will fail and the entire
51hibernation operation will be cancelled. For this reason, freezable kernel
52threads must call try_to_freeze() somewhere.
53
54After the system memory state has been restored from a hibernation image and
55devices have been reinitialized, the function thaw_processes() is called in
56order to clear the PF_FROZEN flag for each frozen task. Then, the tasks that
57have been frozen leave refrigerator() and continue running.
58
59III. Which kernel threads are freezable?
60
61Kernel threads are not freezable by default. However, a kernel thread may clear
62PF_NOFREEZE for itself by calling set_freezable() (the resetting of PF_NOFREEZE
63directly is strongly discouraged). From this point it is regarded as freezable
64and must call try_to_freeze() in a suitable place.
65
66IV. Why do we do that?
67
68Generally speaking, there is a couple of reasons to use the freezing of tasks:
69
701. The principal reason is to prevent filesystems from being damaged after
71hibernation. At the moment we have no simple means of checkpointing
72filesystems, so if there are any modifications made to filesystem data and/or
73metadata on disks, we cannot bring them back to the state from before the
74modifications. At the same time each hibernation image contains some
75filesystem-related information that must be consistent with the state of the
76on-disk data and metadata after the system memory state has been restored from
77the image (otherwise the filesystems will be damaged in a nasty way, usually
78making them almost impossible to repair). We therefore freeze tasks that might
79cause the on-disk filesystems' data and metadata to be modified after the
80hibernation image has been created and before the system is finally powered off.