Commit dc52ddc0e6f45b04780b26fc0813509f8e798c42

Authored by Matt Helsley
Committed by Linus Torvalds
1 parent 8174f1503f

container freezer: implement freezer cgroup subsystem

This patch implements a new freezer subsystem in the control groups
framework.  It provides a way to stop and resume execution of all tasks in
a cgroup by writing in the cgroup filesystem.

The freezer subsystem in the container filesystem defines a file named
freezer.state.  Writing "FROZEN" to the state file will freeze all tasks
in the cgroup.  Subsequently writing "RUNNING" will unfreeze the tasks in
the cgroup.  Reading will return the current state.

* Examples of usage :

   # mkdir /containers/freezer
   # mount -t cgroup -ofreezer freezer  /containers
   # mkdir /containers/0
   # echo $some_pid > /containers/0/tasks

to get status of the freezer subsystem :

   # cat /containers/0/freezer.state
   RUNNING

to freeze all tasks in the container :

   # echo FROZEN > /containers/0/freezer.state
   # cat /containers/0/freezer.state
   FREEZING
   # cat /containers/0/freezer.state
   FROZEN

to unfreeze all tasks in the container :

   # echo RUNNING > /containers/0/freezer.state
   # cat /containers/0/freezer.state
   RUNNING

This is the basic mechanism which should do the right thing for user space
task in a simple scenario.

It's important to note that freezing can be incomplete.  In that case we
return EBUSY.  This means that some tasks in the cgroup are busy doing
something that prevents us from completely freezing the cgroup at this
time.  After EBUSY, the cgroup will remain partially frozen -- reflected
by freezer.state reporting "FREEZING" when read.  The state will remain
"FREEZING" until one of these things happens:

	1) Userspace cancels the freezing operation by writing "RUNNING" to
		the freezer.state file
	2) Userspace retries the freezing operation by writing "FROZEN" to
		the freezer.state file (writing "FREEZING" is not legal
		and returns EIO)
	3) The tasks that blocked the cgroup from entering the "FROZEN"
		state disappear from the cgroup's set of tasks.

[akpm@linux-foundation.org: coding-style fixes]
[akpm@linux-foundation.org: export thaw_process]
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Matt Helsley <matthltc@us.ibm.com>
Acked-by: Serge E. Hallyn <serue@us.ibm.com>
Tested-by: Matt Helsley <matthltc@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 30 changed files with 465 additions and 22 deletions Side-by-side Diff

... ... @@ -70,6 +70,7 @@
70 70 default y
71 71  
72 72 source "init/Kconfig"
  73 +source "kernel/Kconfig.freezer"
73 74  
74 75  
75 76 menu "System setup"
... ... @@ -192,6 +192,8 @@
192 192  
193 193 source "init/Kconfig"
194 194  
  195 +source "kernel/Kconfig.freezer"
  196 +
195 197 menu "System Type"
196 198  
197 199 choice
... ... @@ -72,6 +72,8 @@
72 72  
73 73 source "init/Kconfig"
74 74  
  75 +source "kernel/Kconfig.freezer"
  76 +
75 77 menu "System Type and features"
76 78  
77 79 source "kernel/time/Kconfig"
arch/blackfin/Kconfig
... ... @@ -64,7 +64,10 @@
64 64 depends on OPROFILE
65 65  
66 66 source "init/Kconfig"
  67 +
67 68 source "kernel/Kconfig.preempt"
  69 +
  70 +source "kernel/Kconfig.freezer"
68 71  
69 72 menu "Blackfin Processor Options"
70 73  
... ... @@ -62,6 +62,8 @@
62 62  
63 63 source "init/Kconfig"
64 64  
  65 +source "kernel/Kconfig.freezer"
  66 +
65 67 menu "General setup"
66 68  
67 69 source "fs/Kconfig.binfmt"
... ... @@ -66,6 +66,8 @@
66 66  
67 67 source "init/Kconfig"
68 68  
  69 +source "kernel/Kconfig.freezer"
  70 +
69 71  
70 72 menu "Fujitsu FR-V system setup"
71 73  
... ... @@ -90,6 +90,8 @@
90 90  
91 91 source "init/Kconfig"
92 92  
  93 +source "kernel/Kconfig.freezer"
  94 +
93 95 source "arch/h8300/Kconfig.cpu"
94 96  
95 97 menu "Executable file formats"
... ... @@ -7,6 +7,8 @@
7 7  
8 8 source "init/Kconfig"
9 9  
  10 +source "kernel/Kconfig.freezer"
  11 +
10 12 menu "Processor type and features"
11 13  
12 14 config IA64
... ... @@ -42,6 +42,8 @@
42 42  
43 43 source "init/Kconfig"
44 44  
  45 +source "kernel/Kconfig.freezer"
  46 +
45 47  
46 48 menu "Processor type and features"
47 49  
... ... @@ -62,6 +62,8 @@
62 62  
63 63 source "init/Kconfig"
64 64  
  65 +source "kernel/Kconfig.freezer"
  66 +
65 67 menu "Platform dependent setup"
66 68  
67 69 config EISA
arch/m68knommu/Kconfig
... ... @@ -75,6 +75,8 @@
75 75  
76 76 source "init/Kconfig"
77 77  
  78 +source "kernel/Kconfig.freezer"
  79 +
78 80 menu "Processor type and features"
79 81  
80 82 choice
... ... @@ -1885,6 +1885,8 @@
1885 1885 add initrd or initramfs image to the kernel image.
1886 1886 Otherwise, say N.
1887 1887  
  1888 +source "kernel/Kconfig.freezer"
  1889 +
1888 1890 menu "Bus options (PCI, PCMCIA, EISA, ISA, TC)"
1889 1891  
1890 1892 config HW_HAS_EISA
arch/mn10300/Kconfig
... ... @@ -68,6 +68,8 @@
68 68  
69 69 source "init/Kconfig"
70 70  
  71 +source "kernel/Kconfig.freezer"
  72 +
71 73  
72 74 menu "Matsushita MN10300 system setup"
73 75  
... ... @@ -90,6 +90,8 @@
90 90  
91 91 source "init/Kconfig"
92 92  
  93 +source "kernel/Kconfig.freezer"
  94 +
93 95  
94 96 menu "Processor type and features"
95 97  
arch/powerpc/Kconfig
... ... @@ -230,6 +230,8 @@
230 230  
231 231 source "init/Kconfig"
232 232  
  233 +source "kernel/Kconfig.freezer"
  234 +
233 235 source "arch/powerpc/sysdev/Kconfig"
234 236 source "arch/powerpc/platforms/Kconfig"
235 237  
... ... @@ -78,6 +78,8 @@
78 78  
79 79 source "init/Kconfig"
80 80  
  81 +source "kernel/Kconfig.freezer"
  82 +
81 83 menu "Base setup"
82 84  
83 85 comment "Processor type and features"
... ... @@ -106,6 +106,8 @@
106 106  
107 107 source "init/Kconfig"
108 108  
  109 +source "kernel/Kconfig.freezer"
  110 +
109 111 menu "System type"
110 112  
111 113 #
... ... @@ -37,6 +37,8 @@
37 37  
38 38 source "init/Kconfig"
39 39  
  40 +source "kernel/Kconfig.freezer"
  41 +
40 42 menu "General machine setup"
41 43  
42 44 config SMP
arch/sparc64/Kconfig
... ... @@ -96,6 +96,7 @@
96 96 def_bool y
97 97  
98 98 source "init/Kconfig"
  99 +source "kernel/Kconfig.freezer"
99 100  
100 101 menu "Processor type and features"
101 102  
... ... @@ -229,6 +229,8 @@
229 229  
230 230 source "init/Kconfig"
231 231  
  232 +source "kernel/Kconfig.freezer"
  233 +
232 234 source "drivers/block/Kconfig"
233 235  
234 236 source "arch/um/Kconfig.char"
... ... @@ -193,6 +193,7 @@
193 193 config KTIME_SCALAR
194 194 def_bool X86_32
195 195 source "init/Kconfig"
  196 +source "kernel/Kconfig.freezer"
196 197  
197 198 menu "Processor type and features"
198 199  
... ... @@ -55,6 +55,7 @@
55 55 default 100
56 56  
57 57 source "init/Kconfig"
  58 +source "kernel/Kconfig.freezer"
58 59  
59 60 menu "Processor type and features"
60 61  
include/linux/cgroup_subsys.h
... ... @@ -48,4 +48,10 @@
48 48 #endif
49 49  
50 50 /* */
  51 +
  52 +#ifdef CONFIG_CGROUP_FREEZER
  53 +SUBSYS(freezer)
  54 +#endif
  55 +
  56 +/* */
include/linux/freezer.h
... ... @@ -46,27 +46,12 @@
46 46  
47 47 /*
48 48 * Wake up a frozen process
49   - *
50   - * task_lock() is taken to prevent the race with refrigerator() which may
51   - * occur if the freezing of tasks fails. Namely, without the lock, if the
52   - * freezing of tasks failed, thaw_tasks() might have run before a task in
53   - * refrigerator() could call frozen_process(), in which case the task would be
54   - * frozen and no one would thaw it.
55 49 */
56   -static inline int thaw_process(struct task_struct *p)
57   -{
58   - task_lock(p);
59   - if (frozen(p)) {
60   - p->flags &= ~PF_FROZEN;
61   - task_unlock(p);
62   - wake_up_process(p);
63   - return 1;
64   - }
65   - clear_freeze_flag(p);
66   - task_unlock(p);
67   - return 0;
68   -}
  50 +extern int __thaw_process(struct task_struct *p);
69 51  
  52 +/* Takes and releases task alloc lock using task_lock() */
  53 +extern int thaw_process(struct task_struct *p);
  54 +
70 55 extern void refrigerator(void);
71 56 extern int freeze_processes(void);
72 57 extern void thaw_processes(void);
... ... @@ -82,6 +67,12 @@
82 67  
83 68 extern bool freeze_task(struct task_struct *p, bool sig_only);
84 69 extern void cancel_freezing(struct task_struct *p);
  70 +
  71 +#ifdef CONFIG_CGROUP_FREEZER
  72 +extern int cgroup_frozen(struct task_struct *task);
  73 +#else /* !CONFIG_CGROUP_FREEZER */
  74 +static inline int cgroup_frozen(struct task_struct *task) { return 0; }
  75 +#endif /* !CONFIG_CGROUP_FREEZER */
85 76  
86 77 /*
87 78 * The PF_FREEZER_SKIP flag should be set by a vfork parent right before it
... ... @@ -299,6 +299,13 @@
299 299 for instance virtual servers and checkpoint/restart
300 300 jobs.
301 301  
  302 +config CGROUP_FREEZER
  303 + bool "control group freezer subsystem"
  304 + depends on CGROUPS
  305 + help
  306 + Provides a way to freeze and unfreeze all tasks in a
  307 + cgroup.
  308 +
302 309 config CGROUP_DEVICE
303 310 bool "Device controller for cgroups"
304 311 depends on CGROUPS && EXPERIMENTAL
kernel/Kconfig.freezer
  1 +config FREEZER
  2 + def_bool PM_SLEEP || CGROUP_FREEZER
... ... @@ -56,6 +56,7 @@
56 56 obj-$(CONFIG_COMPAT) += compat.o
57 57 obj-$(CONFIG_CGROUPS) += cgroup.o
58 58 obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o
  59 +obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o
59 60 obj-$(CONFIG_CPUSETS) += cpuset.o
60 61 obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o
61 62 obj-$(CONFIG_UTS_NS) += utsname.o
kernel/cgroup_freezer.c
  1 +/*
  2 + * cgroup_freezer.c - control group freezer subsystem
  3 + *
  4 + * Copyright IBM Corporation, 2007
  5 + *
  6 + * Author : Cedric Le Goater <clg@fr.ibm.com>
  7 + *
  8 + * This program is free software; you can redistribute it and/or modify it
  9 + * under the terms of version 2.1 of the GNU Lesser General Public License
  10 + * as published by the Free Software Foundation.
  11 + *
  12 + * This program is distributed in the hope that it would be useful, but
  13 + * WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15 + */
  16 +
  17 +#include <linux/module.h>
  18 +#include <linux/cgroup.h>
  19 +#include <linux/fs.h>
  20 +#include <linux/uaccess.h>
  21 +#include <linux/freezer.h>
  22 +#include <linux/seq_file.h>
  23 +
  24 +enum freezer_state {
  25 + STATE_RUNNING = 0,
  26 + STATE_FREEZING,
  27 + STATE_FROZEN,
  28 +};
  29 +
  30 +struct freezer {
  31 + struct cgroup_subsys_state css;
  32 + enum freezer_state state;
  33 + spinlock_t lock; /* protects _writes_ to state */
  34 +};
  35 +
  36 +static inline struct freezer *cgroup_freezer(
  37 + struct cgroup *cgroup)
  38 +{
  39 + return container_of(
  40 + cgroup_subsys_state(cgroup, freezer_subsys_id),
  41 + struct freezer, css);
  42 +}
  43 +
  44 +static inline struct freezer *task_freezer(struct task_struct *task)
  45 +{
  46 + return container_of(task_subsys_state(task, freezer_subsys_id),
  47 + struct freezer, css);
  48 +}
  49 +
  50 +int cgroup_frozen(struct task_struct *task)
  51 +{
  52 + struct freezer *freezer;
  53 + enum freezer_state state;
  54 +
  55 + task_lock(task);
  56 + freezer = task_freezer(task);
  57 + state = freezer->state;
  58 + task_unlock(task);
  59 +
  60 + return state == STATE_FROZEN;
  61 +}
  62 +
  63 +/*
  64 + * cgroups_write_string() limits the size of freezer state strings to
  65 + * CGROUP_LOCAL_BUFFER_SIZE
  66 + */
  67 +static const char *freezer_state_strs[] = {
  68 + "RUNNING",
  69 + "FREEZING",
  70 + "FROZEN",
  71 +};
  72 +
  73 +/*
  74 + * State diagram
  75 + * Transitions are caused by userspace writes to the freezer.state file.
  76 + * The values in parenthesis are state labels. The rest are edge labels.
  77 + *
  78 + * (RUNNING) --FROZEN--> (FREEZING) --FROZEN--> (FROZEN)
  79 + * ^ ^ | |
  80 + * | \_______RUNNING_______/ |
  81 + * \_____________________________RUNNING___________/
  82 + */
  83 +
  84 +struct cgroup_subsys freezer_subsys;
  85 +
  86 +/* Locks taken and their ordering
  87 + * ------------------------------
  88 + * css_set_lock
  89 + * cgroup_mutex (AKA cgroup_lock)
  90 + * task->alloc_lock (AKA task_lock)
  91 + * freezer->lock
  92 + * task->sighand->siglock
  93 + *
  94 + * cgroup code forces css_set_lock to be taken before task->alloc_lock
  95 + *
  96 + * freezer_create(), freezer_destroy():
  97 + * cgroup_mutex [ by cgroup core ]
  98 + *
  99 + * can_attach():
  100 + * cgroup_mutex
  101 + *
  102 + * cgroup_frozen():
  103 + * task->alloc_lock (to get task's cgroup)
  104 + *
  105 + * freezer_fork() (preserving fork() performance means can't take cgroup_mutex):
  106 + * task->alloc_lock (to get task's cgroup)
  107 + * freezer->lock
  108 + * sighand->siglock (if the cgroup is freezing)
  109 + *
  110 + * freezer_read():
  111 + * cgroup_mutex
  112 + * freezer->lock
  113 + * read_lock css_set_lock (cgroup iterator start)
  114 + *
  115 + * freezer_write() (freeze):
  116 + * cgroup_mutex
  117 + * freezer->lock
  118 + * read_lock css_set_lock (cgroup iterator start)
  119 + * sighand->siglock
  120 + *
  121 + * freezer_write() (unfreeze):
  122 + * cgroup_mutex
  123 + * freezer->lock
  124 + * read_lock css_set_lock (cgroup iterator start)
  125 + * task->alloc_lock (to prevent races with freeze_task())
  126 + * sighand->siglock
  127 + */
  128 +static struct cgroup_subsys_state *freezer_create(struct cgroup_subsys *ss,
  129 + struct cgroup *cgroup)
  130 +{
  131 + struct freezer *freezer;
  132 +
  133 + freezer = kzalloc(sizeof(struct freezer), GFP_KERNEL);
  134 + if (!freezer)
  135 + return ERR_PTR(-ENOMEM);
  136 +
  137 + spin_lock_init(&freezer->lock);
  138 + freezer->state = STATE_RUNNING;
  139 + return &freezer->css;
  140 +}
  141 +
  142 +static void freezer_destroy(struct cgroup_subsys *ss,
  143 + struct cgroup *cgroup)
  144 +{
  145 + kfree(cgroup_freezer(cgroup));
  146 +}
  147 +
  148 +
  149 +static int freezer_can_attach(struct cgroup_subsys *ss,
  150 + struct cgroup *new_cgroup,
  151 + struct task_struct *task)
  152 +{
  153 + struct freezer *freezer;
  154 + int retval = 0;
  155 +
  156 + /*
  157 + * The call to cgroup_lock() in the freezer.state write method prevents
  158 + * a write to that file racing against an attach, and hence the
  159 + * can_attach() result will remain valid until the attach completes.
  160 + */
  161 + freezer = cgroup_freezer(new_cgroup);
  162 + if (freezer->state == STATE_FROZEN)
  163 + retval = -EBUSY;
  164 + return retval;
  165 +}
  166 +
  167 +static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task)
  168 +{
  169 + struct freezer *freezer;
  170 +
  171 + task_lock(task);
  172 + freezer = task_freezer(task);
  173 + task_unlock(task);
  174 +
  175 + BUG_ON(freezer->state == STATE_FROZEN);
  176 + spin_lock_irq(&freezer->lock);
  177 + /* Locking avoids race with FREEZING -> RUNNING transitions. */
  178 + if (freezer->state == STATE_FREEZING)
  179 + freeze_task(task, true);
  180 + spin_unlock_irq(&freezer->lock);
  181 +}
  182 +
  183 +/*
  184 + * caller must hold freezer->lock
  185 + */
  186 +static void check_if_frozen(struct cgroup *cgroup,
  187 + struct freezer *freezer)
  188 +{
  189 + struct cgroup_iter it;
  190 + struct task_struct *task;
  191 + unsigned int nfrozen = 0, ntotal = 0;
  192 +
  193 + cgroup_iter_start(cgroup, &it);
  194 + while ((task = cgroup_iter_next(cgroup, &it))) {
  195 + ntotal++;
  196 + /*
  197 + * Task is frozen or will freeze immediately when next it gets
  198 + * woken
  199 + */
  200 + if (frozen(task) ||
  201 + (task_is_stopped_or_traced(task) && freezing(task)))
  202 + nfrozen++;
  203 + }
  204 +
  205 + /*
  206 + * Transition to FROZEN when no new tasks can be added ensures
  207 + * that we never exist in the FROZEN state while there are unfrozen
  208 + * tasks.
  209 + */
  210 + if (nfrozen == ntotal)
  211 + freezer->state = STATE_FROZEN;
  212 + cgroup_iter_end(cgroup, &it);
  213 +}
  214 +
  215 +static int freezer_read(struct cgroup *cgroup, struct cftype *cft,
  216 + struct seq_file *m)
  217 +{
  218 + struct freezer *freezer;
  219 + enum freezer_state state;
  220 +
  221 + if (!cgroup_lock_live_group(cgroup))
  222 + return -ENODEV;
  223 +
  224 + freezer = cgroup_freezer(cgroup);
  225 + spin_lock_irq(&freezer->lock);
  226 + state = freezer->state;
  227 + if (state == STATE_FREEZING) {
  228 + /* We change from FREEZING to FROZEN lazily if the cgroup was
  229 + * only partially frozen when we exitted write. */
  230 + check_if_frozen(cgroup, freezer);
  231 + state = freezer->state;
  232 + }
  233 + spin_unlock_irq(&freezer->lock);
  234 + cgroup_unlock();
  235 +
  236 + seq_puts(m, freezer_state_strs[state]);
  237 + seq_putc(m, '\n');
  238 + return 0;
  239 +}
  240 +
  241 +static int try_to_freeze_cgroup(struct cgroup *cgroup, struct freezer *freezer)
  242 +{
  243 + struct cgroup_iter it;
  244 + struct task_struct *task;
  245 + unsigned int num_cant_freeze_now = 0;
  246 +
  247 + freezer->state = STATE_FREEZING;
  248 + cgroup_iter_start(cgroup, &it);
  249 + while ((task = cgroup_iter_next(cgroup, &it))) {
  250 + if (!freeze_task(task, true))
  251 + continue;
  252 + if (task_is_stopped_or_traced(task) && freezing(task))
  253 + /*
  254 + * The freeze flag is set so these tasks will
  255 + * immediately go into the fridge upon waking.
  256 + */
  257 + continue;
  258 + if (!freezing(task) && !freezer_should_skip(task))
  259 + num_cant_freeze_now++;
  260 + }
  261 + cgroup_iter_end(cgroup, &it);
  262 +
  263 + return num_cant_freeze_now ? -EBUSY : 0;
  264 +}
  265 +
  266 +static int unfreeze_cgroup(struct cgroup *cgroup, struct freezer *freezer)
  267 +{
  268 + struct cgroup_iter it;
  269 + struct task_struct *task;
  270 +
  271 + cgroup_iter_start(cgroup, &it);
  272 + while ((task = cgroup_iter_next(cgroup, &it))) {
  273 + int do_wake;
  274 +
  275 + task_lock(task);
  276 + do_wake = __thaw_process(task);
  277 + task_unlock(task);
  278 + if (do_wake)
  279 + wake_up_process(task);
  280 + }
  281 + cgroup_iter_end(cgroup, &it);
  282 + freezer->state = STATE_RUNNING;
  283 +
  284 + return 0;
  285 +}
  286 +
  287 +static int freezer_change_state(struct cgroup *cgroup,
  288 + enum freezer_state goal_state)
  289 +{
  290 + struct freezer *freezer;
  291 + int retval = 0;
  292 +
  293 + freezer = cgroup_freezer(cgroup);
  294 + spin_lock_irq(&freezer->lock);
  295 + check_if_frozen(cgroup, freezer); /* may update freezer->state */
  296 + if (goal_state == freezer->state)
  297 + goto out;
  298 + switch (freezer->state) {
  299 + case STATE_RUNNING:
  300 + retval = try_to_freeze_cgroup(cgroup, freezer);
  301 + break;
  302 + case STATE_FREEZING:
  303 + if (goal_state == STATE_FROZEN) {
  304 + /* Userspace is retrying after
  305 + * "/bin/echo FROZEN > freezer.state" returned -EBUSY */
  306 + retval = try_to_freeze_cgroup(cgroup, freezer);
  307 + break;
  308 + }
  309 + /* state == FREEZING and goal_state == RUNNING, so unfreeze */
  310 + case STATE_FROZEN:
  311 + retval = unfreeze_cgroup(cgroup, freezer);
  312 + break;
  313 + default:
  314 + break;
  315 + }
  316 +out:
  317 + spin_unlock_irq(&freezer->lock);
  318 +
  319 + return retval;
  320 +}
  321 +
  322 +static int freezer_write(struct cgroup *cgroup,
  323 + struct cftype *cft,
  324 + const char *buffer)
  325 +{
  326 + int retval;
  327 + enum freezer_state goal_state;
  328 +
  329 + if (strcmp(buffer, freezer_state_strs[STATE_RUNNING]) == 0)
  330 + goal_state = STATE_RUNNING;
  331 + else if (strcmp(buffer, freezer_state_strs[STATE_FROZEN]) == 0)
  332 + goal_state = STATE_FROZEN;
  333 + else
  334 + return -EIO;
  335 +
  336 + if (!cgroup_lock_live_group(cgroup))
  337 + return -ENODEV;
  338 + retval = freezer_change_state(cgroup, goal_state);
  339 + cgroup_unlock();
  340 + return retval;
  341 +}
  342 +
  343 +static struct cftype files[] = {
  344 + {
  345 + .name = "state",
  346 + .read_seq_string = freezer_read,
  347 + .write_string = freezer_write,
  348 + },
  349 +};
  350 +
  351 +static int freezer_populate(struct cgroup_subsys *ss, struct cgroup *cgroup)
  352 +{
  353 + return cgroup_add_files(cgroup, ss, files, ARRAY_SIZE(files));
  354 +}
  355 +
  356 +struct cgroup_subsys freezer_subsys = {
  357 + .name = "freezer",
  358 + .create = freezer_create,
  359 + .destroy = freezer_destroy,
  360 + .populate = freezer_populate,
  361 + .subsys_id = freezer_subsys_id,
  362 + .can_attach = freezer_can_attach,
  363 + .attach = NULL,
  364 + .fork = freezer_fork,
  365 + .exit = NULL,
  366 +};
... ... @@ -120,4 +120,36 @@
120 120 spin_unlock_irqrestore(&p->sighand->siglock, flags);
121 121 }
122 122 }
  123 +
  124 +/*
  125 + * Wake up a frozen process
  126 + *
  127 + * task_lock() is needed to prevent the race with refrigerator() which may
  128 + * occur if the freezing of tasks fails. Namely, without the lock, if the
  129 + * freezing of tasks failed, thaw_tasks() might have run before a task in
  130 + * refrigerator() could call frozen_process(), in which case the task would be
  131 + * frozen and no one would thaw it.
  132 + */
  133 +int __thaw_process(struct task_struct *p)
  134 +{
  135 + if (frozen(p)) {
  136 + p->flags &= ~PF_FROZEN;
  137 + return 1;
  138 + }
  139 + clear_freeze_flag(p);
  140 + return 0;
  141 +}
  142 +
  143 +int thaw_process(struct task_struct *p)
  144 +{
  145 + task_lock(p);
  146 + if (__thaw_process(p) == 1) {
  147 + task_unlock(p);
  148 + wake_up_process(p);
  149 + return 1;
  150 + }
  151 + task_unlock(p);
  152 + return 0;
  153 +}
  154 +EXPORT_SYMBOL(thaw_process);
kernel/power/Kconfig
... ... @@ -85,9 +85,6 @@
85 85 depends on SUSPEND || HIBERNATION || XEN_SAVE_RESTORE
86 86 default y
87 87  
88   -config FREEZER
89   - def_bool PM_SLEEP
90   -
91 88 config SUSPEND
92 89 bool "Suspend to RAM and standby"
93 90 depends on PM && ARCH_SUSPEND_POSSIBLE