diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Kconfig.freezer | 2 | ||||
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | kernel/cgroup.c | 265 | ||||
-rw-r--r-- | kernel/cgroup_debug.c | 4 | ||||
-rw-r--r-- | kernel/cgroup_freezer.c | 379 | ||||
-rw-r--r-- | kernel/configs.c | 9 | ||||
-rw-r--r-- | kernel/cpuset.c | 17 | ||||
-rw-r--r-- | kernel/freezer.c | 154 | ||||
-rw-r--r-- | kernel/kexec.c | 2 | ||||
-rw-r--r-- | kernel/kthread.c | 5 | ||||
-rw-r--r-- | kernel/power/process.c | 119 | ||||
-rw-r--r-- | kernel/ptrace.c | 2 | ||||
-rw-r--r-- | kernel/rcupreempt.c | 2 | ||||
-rw-r--r-- | kernel/sysctl.c | 10 |
14 files changed, 723 insertions, 249 deletions
diff --git a/kernel/Kconfig.freezer b/kernel/Kconfig.freezer new file mode 100644 index 00000000000..a3bb4cb5253 --- /dev/null +++ b/kernel/Kconfig.freezer | |||
@@ -0,0 +1,2 @@ | |||
1 | config FREEZER | ||
2 | def_bool PM_SLEEP || CGROUP_FREEZER | ||
diff --git a/kernel/Makefile b/kernel/Makefile index 4e1d7df7c3e..066550aa61c 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
@@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg | |||
24 | CFLAGS_REMOVE_sched.o = -mno-spe -pg | 24 | CFLAGS_REMOVE_sched.o = -mno-spe -pg |
25 | endif | 25 | endif |
26 | 26 | ||
27 | obj-$(CONFIG_FREEZER) += freezer.o | ||
27 | obj-$(CONFIG_PROFILING) += profile.o | 28 | obj-$(CONFIG_PROFILING) += profile.o |
28 | obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o | 29 | obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o |
29 | obj-$(CONFIG_STACKTRACE) += stacktrace.o | 30 | obj-$(CONFIG_STACKTRACE) += stacktrace.o |
@@ -55,6 +56,7 @@ obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o | |||
55 | obj-$(CONFIG_COMPAT) += compat.o | 56 | obj-$(CONFIG_COMPAT) += compat.o |
56 | obj-$(CONFIG_CGROUPS) += cgroup.o | 57 | obj-$(CONFIG_CGROUPS) += cgroup.o |
57 | obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o | 58 | obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o |
59 | obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o | ||
58 | obj-$(CONFIG_CPUSETS) += cpuset.o | 60 | obj-$(CONFIG_CPUSETS) += cpuset.o |
59 | obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o | 61 | obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o |
60 | obj-$(CONFIG_UTS_NS) += utsname.o | 62 | obj-$(CONFIG_UTS_NS) += utsname.o |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 8c6e1c17e6d..046c1609606 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -241,7 +241,6 @@ static void unlink_css_set(struct css_set *cg) | |||
241 | struct cg_cgroup_link *link; | 241 | struct cg_cgroup_link *link; |
242 | struct cg_cgroup_link *saved_link; | 242 | struct cg_cgroup_link *saved_link; |
243 | 243 | ||
244 | write_lock(&css_set_lock); | ||
245 | hlist_del(&cg->hlist); | 244 | hlist_del(&cg->hlist); |
246 | css_set_count--; | 245 | css_set_count--; |
247 | 246 | ||
@@ -251,16 +250,25 @@ static void unlink_css_set(struct css_set *cg) | |||
251 | list_del(&link->cgrp_link_list); | 250 | list_del(&link->cgrp_link_list); |
252 | kfree(link); | 251 | kfree(link); |
253 | } | 252 | } |
254 | |||
255 | write_unlock(&css_set_lock); | ||
256 | } | 253 | } |
257 | 254 | ||
258 | static void __release_css_set(struct kref *k, int taskexit) | 255 | static void __put_css_set(struct css_set *cg, int taskexit) |
259 | { | 256 | { |
260 | int i; | 257 | int i; |
261 | struct css_set *cg = container_of(k, struct css_set, ref); | 258 | /* |
262 | 259 | * Ensure that the refcount doesn't hit zero while any readers | |
260 | * can see it. Similar to atomic_dec_and_lock(), but for an | ||
261 | * rwlock | ||
262 | */ | ||
263 | if (atomic_add_unless(&cg->refcount, -1, 1)) | ||
264 | return; | ||
265 | write_lock(&css_set_lock); | ||
266 | if (!atomic_dec_and_test(&cg->refcount)) { | ||
267 | write_unlock(&css_set_lock); | ||
268 | return; | ||
269 | } | ||
263 | unlink_css_set(cg); | 270 | unlink_css_set(cg); |
271 | write_unlock(&css_set_lock); | ||
264 | 272 | ||
265 | rcu_read_lock(); | 273 | rcu_read_lock(); |
266 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | 274 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { |
@@ -276,32 +284,22 @@ static void __release_css_set(struct kref *k, int taskexit) | |||
276 | kfree(cg); | 284 | kfree(cg); |
277 | } | 285 | } |
278 | 286 | ||
279 | static void release_css_set(struct kref *k) | ||
280 | { | ||
281 | __release_css_set(k, 0); | ||
282 | } | ||
283 | |||
284 | static void release_css_set_taskexit(struct kref *k) | ||
285 | { | ||
286 | __release_css_set(k, 1); | ||
287 | } | ||
288 | |||
289 | /* | 287 | /* |
290 | * refcounted get/put for css_set objects | 288 | * refcounted get/put for css_set objects |
291 | */ | 289 | */ |
292 | static inline void get_css_set(struct css_set *cg) | 290 | static inline void get_css_set(struct css_set *cg) |
293 | { | 291 | { |
294 | kref_get(&cg->ref); | 292 | atomic_inc(&cg->refcount); |
295 | } | 293 | } |
296 | 294 | ||
297 | static inline void put_css_set(struct css_set *cg) | 295 | static inline void put_css_set(struct css_set *cg) |
298 | { | 296 | { |
299 | kref_put(&cg->ref, release_css_set); | 297 | __put_css_set(cg, 0); |
300 | } | 298 | } |
301 | 299 | ||
302 | static inline void put_css_set_taskexit(struct css_set *cg) | 300 | static inline void put_css_set_taskexit(struct css_set *cg) |
303 | { | 301 | { |
304 | kref_put(&cg->ref, release_css_set_taskexit); | 302 | __put_css_set(cg, 1); |
305 | } | 303 | } |
306 | 304 | ||
307 | /* | 305 | /* |
@@ -427,7 +425,7 @@ static struct css_set *find_css_set( | |||
427 | return NULL; | 425 | return NULL; |
428 | } | 426 | } |
429 | 427 | ||
430 | kref_init(&res->ref); | 428 | atomic_set(&res->refcount, 1); |
431 | INIT_LIST_HEAD(&res->cg_links); | 429 | INIT_LIST_HEAD(&res->cg_links); |
432 | INIT_LIST_HEAD(&res->tasks); | 430 | INIT_LIST_HEAD(&res->tasks); |
433 | INIT_HLIST_NODE(&res->hlist); | 431 | INIT_HLIST_NODE(&res->hlist); |
@@ -870,6 +868,14 @@ static struct super_operations cgroup_ops = { | |||
870 | .remount_fs = cgroup_remount, | 868 | .remount_fs = cgroup_remount, |
871 | }; | 869 | }; |
872 | 870 | ||
871 | static void init_cgroup_housekeeping(struct cgroup *cgrp) | ||
872 | { | ||
873 | INIT_LIST_HEAD(&cgrp->sibling); | ||
874 | INIT_LIST_HEAD(&cgrp->children); | ||
875 | INIT_LIST_HEAD(&cgrp->css_sets); | ||
876 | INIT_LIST_HEAD(&cgrp->release_list); | ||
877 | init_rwsem(&cgrp->pids_mutex); | ||
878 | } | ||
873 | static void init_cgroup_root(struct cgroupfs_root *root) | 879 | static void init_cgroup_root(struct cgroupfs_root *root) |
874 | { | 880 | { |
875 | struct cgroup *cgrp = &root->top_cgroup; | 881 | struct cgroup *cgrp = &root->top_cgroup; |
@@ -878,10 +884,7 @@ static void init_cgroup_root(struct cgroupfs_root *root) | |||
878 | root->number_of_cgroups = 1; | 884 | root->number_of_cgroups = 1; |
879 | cgrp->root = root; | 885 | cgrp->root = root; |
880 | cgrp->top_cgroup = cgrp; | 886 | cgrp->top_cgroup = cgrp; |
881 | INIT_LIST_HEAD(&cgrp->sibling); | 887 | init_cgroup_housekeeping(cgrp); |
882 | INIT_LIST_HEAD(&cgrp->children); | ||
883 | INIT_LIST_HEAD(&cgrp->css_sets); | ||
884 | INIT_LIST_HEAD(&cgrp->release_list); | ||
885 | } | 888 | } |
886 | 889 | ||
887 | static int cgroup_test_super(struct super_block *sb, void *data) | 890 | static int cgroup_test_super(struct super_block *sb, void *data) |
@@ -1728,7 +1731,7 @@ int cgroup_task_count(const struct cgroup *cgrp) | |||
1728 | 1731 | ||
1729 | read_lock(&css_set_lock); | 1732 | read_lock(&css_set_lock); |
1730 | list_for_each_entry(link, &cgrp->css_sets, cgrp_link_list) { | 1733 | list_for_each_entry(link, &cgrp->css_sets, cgrp_link_list) { |
1731 | count += atomic_read(&link->cg->ref.refcount); | 1734 | count += atomic_read(&link->cg->refcount); |
1732 | } | 1735 | } |
1733 | read_unlock(&css_set_lock); | 1736 | read_unlock(&css_set_lock); |
1734 | return count; | 1737 | return count; |
@@ -1997,16 +2000,7 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan) | |||
1997 | * but we cannot guarantee that the information we produce is correct | 2000 | * but we cannot guarantee that the information we produce is correct |
1998 | * unless we produce it entirely atomically. | 2001 | * unless we produce it entirely atomically. |
1999 | * | 2002 | * |
2000 | * Upon tasks file open(), a struct ctr_struct is allocated, that | ||
2001 | * will have a pointer to an array (also allocated here). The struct | ||
2002 | * ctr_struct * is stored in file->private_data. Its resources will | ||
2003 | * be freed by release() when the file is closed. The array is used | ||
2004 | * to sprintf the PIDs and then used by read(). | ||
2005 | */ | 2003 | */ |
2006 | struct ctr_struct { | ||
2007 | char *buf; | ||
2008 | int bufsz; | ||
2009 | }; | ||
2010 | 2004 | ||
2011 | /* | 2005 | /* |
2012 | * Load into 'pidarray' up to 'npids' of the tasks using cgroup | 2006 | * Load into 'pidarray' up to 'npids' of the tasks using cgroup |
@@ -2088,42 +2082,132 @@ static int cmppid(const void *a, const void *b) | |||
2088 | return *(pid_t *)a - *(pid_t *)b; | 2082 | return *(pid_t *)a - *(pid_t *)b; |
2089 | } | 2083 | } |
2090 | 2084 | ||
2085 | |||
2091 | /* | 2086 | /* |
2092 | * Convert array 'a' of 'npids' pid_t's to a string of newline separated | 2087 | * seq_file methods for the "tasks" file. The seq_file position is the |
2093 | * decimal pids in 'buf'. Don't write more than 'sz' chars, but return | 2088 | * next pid to display; the seq_file iterator is a pointer to the pid |
2094 | * count 'cnt' of how many chars would be written if buf were large enough. | 2089 | * in the cgroup->tasks_pids array. |
2095 | */ | 2090 | */ |
2096 | static int pid_array_to_buf(char *buf, int sz, pid_t *a, int npids) | 2091 | |
2092 | static void *cgroup_tasks_start(struct seq_file *s, loff_t *pos) | ||
2097 | { | 2093 | { |
2098 | int cnt = 0; | 2094 | /* |
2099 | int i; | 2095 | * Initially we receive a position value that corresponds to |
2096 | * one more than the last pid shown (or 0 on the first call or | ||
2097 | * after a seek to the start). Use a binary-search to find the | ||
2098 | * next pid to display, if any | ||
2099 | */ | ||
2100 | struct cgroup *cgrp = s->private; | ||
2101 | int index = 0, pid = *pos; | ||
2102 | int *iter; | ||
2100 | 2103 | ||
2101 | for (i = 0; i < npids; i++) | 2104 | down_read(&cgrp->pids_mutex); |
2102 | cnt += snprintf(buf + cnt, max(sz - cnt, 0), "%d\n", a[i]); | 2105 | if (pid) { |
2103 | return cnt; | 2106 | int end = cgrp->pids_length; |
2107 | int i; | ||
2108 | while (index < end) { | ||
2109 | int mid = (index + end) / 2; | ||
2110 | if (cgrp->tasks_pids[mid] == pid) { | ||
2111 | index = mid; | ||
2112 | break; | ||
2113 | } else if (cgrp->tasks_pids[mid] <= pid) | ||
2114 | index = mid + 1; | ||
2115 | else | ||
2116 | end = mid; | ||
2117 | } | ||
2118 | } | ||
2119 | /* If we're off the end of the array, we're done */ | ||
2120 | if (index >= cgrp->pids_length) | ||
2121 | return NULL; | ||
2122 | /* Update the abstract position to be the actual pid that we found */ | ||
2123 | iter = cgrp->tasks_pids + index; | ||
2124 | *pos = *iter; | ||
2125 | return iter; | ||
2126 | } | ||
2127 | |||
2128 | static void cgroup_tasks_stop(struct seq_file *s, void *v) | ||
2129 | { | ||
2130 | struct cgroup *cgrp = s->private; | ||
2131 | up_read(&cgrp->pids_mutex); | ||
2104 | } | 2132 | } |
2105 | 2133 | ||
2134 | static void *cgroup_tasks_next(struct seq_file *s, void *v, loff_t *pos) | ||
2135 | { | ||
2136 | struct cgroup *cgrp = s->private; | ||
2137 | int *p = v; | ||
2138 | int *end = cgrp->tasks_pids + cgrp->pids_length; | ||
2139 | |||
2140 | /* | ||
2141 | * Advance to the next pid in the array. If this goes off the | ||
2142 | * end, we're done | ||
2143 | */ | ||
2144 | p++; | ||
2145 | if (p >= end) { | ||
2146 | return NULL; | ||
2147 | } else { | ||
2148 | *pos = *p; | ||
2149 | return p; | ||
2150 | } | ||
2151 | } | ||
2152 | |||
2153 | static int cgroup_tasks_show(struct seq_file *s, void *v) | ||
2154 | { | ||
2155 | return seq_printf(s, "%d\n", *(int *)v); | ||
2156 | } | ||
2157 | |||
2158 | static struct seq_operations cgroup_tasks_seq_operations = { | ||
2159 | .start = cgroup_tasks_start, | ||
2160 | .stop = cgroup_tasks_stop, | ||
2161 | .next = cgroup_tasks_next, | ||
2162 | .show = cgroup_tasks_show, | ||
2163 | }; | ||
2164 | |||
2165 | static void release_cgroup_pid_array(struct cgroup *cgrp) | ||
2166 | { | ||
2167 | down_write(&cgrp->pids_mutex); | ||
2168 | BUG_ON(!cgrp->pids_use_count); | ||
2169 | if (!--cgrp->pids_use_count) { | ||
2170 | kfree(cgrp->tasks_pids); | ||
2171 | cgrp->tasks_pids = NULL; | ||
2172 | cgrp->pids_length = 0; | ||
2173 | } | ||
2174 | up_write(&cgrp->pids_mutex); | ||
2175 | } | ||
2176 | |||
2177 | static int cgroup_tasks_release(struct inode *inode, struct file *file) | ||
2178 | { | ||
2179 | struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent); | ||
2180 | |||
2181 | if (!(file->f_mode & FMODE_READ)) | ||
2182 | return 0; | ||
2183 | |||
2184 | release_cgroup_pid_array(cgrp); | ||
2185 | return seq_release(inode, file); | ||
2186 | } | ||
2187 | |||
2188 | static struct file_operations cgroup_tasks_operations = { | ||
2189 | .read = seq_read, | ||
2190 | .llseek = seq_lseek, | ||
2191 | .write = cgroup_file_write, | ||
2192 | .release = cgroup_tasks_release, | ||
2193 | }; | ||
2194 | |||
2106 | /* | 2195 | /* |
2107 | * Handle an open on 'tasks' file. Prepare a buffer listing the | 2196 | * Handle an open on 'tasks' file. Prepare an array containing the |
2108 | * process id's of tasks currently attached to the cgroup being opened. | 2197 | * process id's of tasks currently attached to the cgroup being opened. |
2109 | * | ||
2110 | * Does not require any specific cgroup mutexes, and does not take any. | ||
2111 | */ | 2198 | */ |
2199 | |||
2112 | static int cgroup_tasks_open(struct inode *unused, struct file *file) | 2200 | static int cgroup_tasks_open(struct inode *unused, struct file *file) |
2113 | { | 2201 | { |
2114 | struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent); | 2202 | struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent); |
2115 | struct ctr_struct *ctr; | ||
2116 | pid_t *pidarray; | 2203 | pid_t *pidarray; |
2117 | int npids; | 2204 | int npids; |
2118 | char c; | 2205 | int retval; |
2119 | 2206 | ||
2207 | /* Nothing to do for write-only files */ | ||
2120 | if (!(file->f_mode & FMODE_READ)) | 2208 | if (!(file->f_mode & FMODE_READ)) |
2121 | return 0; | 2209 | return 0; |
2122 | 2210 | ||
2123 | ctr = kmalloc(sizeof(*ctr), GFP_KERNEL); | ||
2124 | if (!ctr) | ||
2125 | goto err0; | ||
2126 | |||
2127 | /* | 2211 | /* |
2128 | * If cgroup gets more users after we read count, we won't have | 2212 | * If cgroup gets more users after we read count, we won't have |
2129 | * enough space - tough. This race is indistinguishable to the | 2213 | * enough space - tough. This race is indistinguishable to the |
@@ -2131,57 +2215,31 @@ static int cgroup_tasks_open(struct inode *unused, struct file *file) | |||
2131 | * show up until sometime later on. | 2215 | * show up until sometime later on. |
2132 | */ | 2216 | */ |
2133 | npids = cgroup_task_count(cgrp); | 2217 | npids = cgroup_task_count(cgrp); |
2134 | if (npids) { | 2218 | pidarray = kmalloc(npids * sizeof(pid_t), GFP_KERNEL); |
2135 | pidarray = kmalloc(npids * sizeof(pid_t), GFP_KERNEL); | 2219 | if (!pidarray) |
2136 | if (!pidarray) | 2220 | return -ENOMEM; |
2137 | goto err1; | 2221 | npids = pid_array_load(pidarray, npids, cgrp); |
2138 | 2222 | sort(pidarray, npids, sizeof(pid_t), cmppid, NULL); | |
2139 | npids = pid_array_load(pidarray, npids, cgrp); | ||
2140 | sort(pidarray, npids, sizeof(pid_t), cmppid, NULL); | ||
2141 | |||
2142 | /* Call pid_array_to_buf() twice, first just to get bufsz */ | ||
2143 | ctr->bufsz = pid_array_to_buf(&c, sizeof(c), pidarray, npids) + 1; | ||
2144 | ctr->buf = kmalloc(ctr->bufsz, GFP_KERNEL); | ||
2145 | if (!ctr->buf) | ||
2146 | goto err2; | ||
2147 | ctr->bufsz = pid_array_to_buf(ctr->buf, ctr->bufsz, pidarray, npids); | ||
2148 | |||
2149 | kfree(pidarray); | ||
2150 | } else { | ||
2151 | ctr->buf = NULL; | ||
2152 | ctr->bufsz = 0; | ||
2153 | } | ||
2154 | file->private_data = ctr; | ||
2155 | return 0; | ||
2156 | |||
2157 | err2: | ||
2158 | kfree(pidarray); | ||
2159 | err1: | ||
2160 | kfree(ctr); | ||
2161 | err0: | ||
2162 | return -ENOMEM; | ||
2163 | } | ||
2164 | 2223 | ||
2165 | static ssize_t cgroup_tasks_read(struct cgroup *cgrp, | 2224 | /* |
2166 | struct cftype *cft, | 2225 | * Store the array in the cgroup, freeing the old |
2167 | struct file *file, char __user *buf, | 2226 | * array if necessary |
2168 | size_t nbytes, loff_t *ppos) | 2227 | */ |
2169 | { | 2228 | down_write(&cgrp->pids_mutex); |
2170 | struct ctr_struct *ctr = file->private_data; | 2229 | kfree(cgrp->tasks_pids); |
2230 | cgrp->tasks_pids = pidarray; | ||
2231 | cgrp->pids_length = npids; | ||
2232 | cgrp->pids_use_count++; | ||
2233 | up_write(&cgrp->pids_mutex); | ||
2171 | 2234 | ||
2172 | return simple_read_from_buffer(buf, nbytes, ppos, ctr->buf, ctr->bufsz); | 2235 | file->f_op = &cgroup_tasks_operations; |
2173 | } | ||
2174 | 2236 | ||
2175 | static int cgroup_tasks_release(struct inode *unused_inode, | 2237 | retval = seq_open(file, &cgroup_tasks_seq_operations); |
2176 | struct file *file) | 2238 | if (retval) { |
2177 | { | 2239 | release_cgroup_pid_array(cgrp); |
2178 | struct ctr_struct *ctr; | 2240 | return retval; |
2179 | |||
2180 | if (file->f_mode & FMODE_READ) { | ||
2181 | ctr = file->private_data; | ||
2182 | kfree(ctr->buf); | ||
2183 | kfree(ctr); | ||
2184 | } | 2241 | } |
2242 | ((struct seq_file *)file->private_data)->private = cgrp; | ||
2185 | return 0; | 2243 | return 0; |
2186 | } | 2244 | } |
2187 | 2245 | ||
@@ -2210,7 +2268,6 @@ static struct cftype files[] = { | |||
2210 | { | 2268 | { |
2211 | .name = "tasks", | 2269 | .name = "tasks", |
2212 | .open = cgroup_tasks_open, | 2270 | .open = cgroup_tasks_open, |
2213 | .read = cgroup_tasks_read, | ||
2214 | .write_u64 = cgroup_tasks_write, | 2271 | .write_u64 = cgroup_tasks_write, |
2215 | .release = cgroup_tasks_release, | 2272 | .release = cgroup_tasks_release, |
2216 | .private = FILE_TASKLIST, | 2273 | .private = FILE_TASKLIST, |
@@ -2300,10 +2357,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
2300 | 2357 | ||
2301 | mutex_lock(&cgroup_mutex); | 2358 | mutex_lock(&cgroup_mutex); |
2302 | 2359 | ||
2303 | INIT_LIST_HEAD(&cgrp->sibling); | 2360 | init_cgroup_housekeeping(cgrp); |
2304 | INIT_LIST_HEAD(&cgrp->children); | ||
2305 | INIT_LIST_HEAD(&cgrp->css_sets); | ||
2306 | INIT_LIST_HEAD(&cgrp->release_list); | ||
2307 | 2361 | ||
2308 | cgrp->parent = parent; | 2362 | cgrp->parent = parent; |
2309 | cgrp->root = parent->root; | 2363 | cgrp->root = parent->root; |
@@ -2495,8 +2549,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss) | |||
2495 | int __init cgroup_init_early(void) | 2549 | int __init cgroup_init_early(void) |
2496 | { | 2550 | { |
2497 | int i; | 2551 | int i; |
2498 | kref_init(&init_css_set.ref); | 2552 | atomic_set(&init_css_set.refcount, 1); |
2499 | kref_get(&init_css_set.ref); | ||
2500 | INIT_LIST_HEAD(&init_css_set.cg_links); | 2553 | INIT_LIST_HEAD(&init_css_set.cg_links); |
2501 | INIT_LIST_HEAD(&init_css_set.tasks); | 2554 | INIT_LIST_HEAD(&init_css_set.tasks); |
2502 | INIT_HLIST_NODE(&init_css_set.hlist); | 2555 | INIT_HLIST_NODE(&init_css_set.hlist); |
diff --git a/kernel/cgroup_debug.c b/kernel/cgroup_debug.c index c3dc3aba4c0..daca6209202 100644 --- a/kernel/cgroup_debug.c +++ b/kernel/cgroup_debug.c | |||
@@ -57,7 +57,7 @@ static u64 current_css_set_refcount_read(struct cgroup *cont, | |||
57 | u64 count; | 57 | u64 count; |
58 | 58 | ||
59 | rcu_read_lock(); | 59 | rcu_read_lock(); |
60 | count = atomic_read(¤t->cgroups->ref.refcount); | 60 | count = atomic_read(¤t->cgroups->refcount); |
61 | rcu_read_unlock(); | 61 | rcu_read_unlock(); |
62 | return count; | 62 | return count; |
63 | } | 63 | } |
@@ -90,7 +90,7 @@ static struct cftype files[] = { | |||
90 | { | 90 | { |
91 | .name = "releasable", | 91 | .name = "releasable", |
92 | .read_u64 = releasable_read, | 92 | .read_u64 = releasable_read, |
93 | } | 93 | }, |
94 | }; | 94 | }; |
95 | 95 | ||
96 | static int debug_populate(struct cgroup_subsys *ss, struct cgroup *cont) | 96 | static int debug_populate(struct cgroup_subsys *ss, struct cgroup *cont) |
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c new file mode 100644 index 00000000000..e9505695449 --- /dev/null +++ b/kernel/cgroup_freezer.c | |||
@@ -0,0 +1,379 @@ | |||
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 | CGROUP_THAWED = 0, | ||
26 | CGROUP_FREEZING, | ||
27 | CGROUP_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 == CGROUP_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 | "THAWED", | ||
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 | * (THAWED) --FROZEN--> (FREEZING) --FROZEN--> (FROZEN) | ||
79 | * ^ ^ | | | ||
80 | * | \_______THAWED_______/ | | ||
81 | * \__________________________THAWED____________/ | ||
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 = CGROUP_THAWED; | ||
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 | /* Task is frozen or will freeze immediately when next it gets woken */ | ||
149 | static bool is_task_frozen_enough(struct task_struct *task) | ||
150 | { | ||
151 | return frozen(task) || | ||
152 | (task_is_stopped_or_traced(task) && freezing(task)); | ||
153 | } | ||
154 | |||
155 | /* | ||
156 | * The call to cgroup_lock() in the freezer.state write method prevents | ||
157 | * a write to that file racing against an attach, and hence the | ||
158 | * can_attach() result will remain valid until the attach completes. | ||
159 | */ | ||
160 | static int freezer_can_attach(struct cgroup_subsys *ss, | ||
161 | struct cgroup *new_cgroup, | ||
162 | struct task_struct *task) | ||
163 | { | ||
164 | struct freezer *freezer; | ||
165 | int retval; | ||
166 | |||
167 | /* Anything frozen can't move or be moved to/from */ | ||
168 | |||
169 | if (is_task_frozen_enough(task)) | ||
170 | return -EBUSY; | ||
171 | |||
172 | freezer = cgroup_freezer(new_cgroup); | ||
173 | if (freezer->state == CGROUP_FROZEN) | ||
174 | return -EBUSY; | ||
175 | |||
176 | retval = 0; | ||
177 | task_lock(task); | ||
178 | freezer = task_freezer(task); | ||
179 | if (freezer->state == CGROUP_FROZEN) | ||
180 | retval = -EBUSY; | ||
181 | task_unlock(task); | ||
182 | return retval; | ||
183 | } | ||
184 | |||
185 | static void freezer_fork(struct cgroup_subsys *ss, struct task_struct *task) | ||
186 | { | ||
187 | struct freezer *freezer; | ||
188 | |||
189 | task_lock(task); | ||
190 | freezer = task_freezer(task); | ||
191 | task_unlock(task); | ||
192 | |||
193 | BUG_ON(freezer->state == CGROUP_FROZEN); | ||
194 | spin_lock_irq(&freezer->lock); | ||
195 | /* Locking avoids race with FREEZING -> THAWED transitions. */ | ||
196 | if (freezer->state == CGROUP_FREEZING) | ||
197 | freeze_task(task, true); | ||
198 | spin_unlock_irq(&freezer->lock); | ||
199 | } | ||
200 | |||
201 | /* | ||
202 | * caller must hold freezer->lock | ||
203 | */ | ||
204 | static void update_freezer_state(struct cgroup *cgroup, | ||
205 | struct freezer *freezer) | ||
206 | { | ||
207 | struct cgroup_iter it; | ||
208 | struct task_struct *task; | ||
209 | unsigned int nfrozen = 0, ntotal = 0; | ||
210 | |||
211 | cgroup_iter_start(cgroup, &it); | ||
212 | while ((task = cgroup_iter_next(cgroup, &it))) { | ||
213 | ntotal++; | ||
214 | if (is_task_frozen_enough(task)) | ||
215 | nfrozen++; | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * Transition to FROZEN when no new tasks can be added ensures | ||
220 | * that we never exist in the FROZEN state while there are unfrozen | ||
221 | * tasks. | ||
222 | */ | ||
223 | if (nfrozen == ntotal) | ||
224 | freezer->state = CGROUP_FROZEN; | ||
225 | else if (nfrozen > 0) | ||
226 | freezer->state = CGROUP_FREEZING; | ||
227 | else | ||
228 | freezer->state = CGROUP_THAWED; | ||
229 | cgroup_iter_end(cgroup, &it); | ||
230 | } | ||
231 | |||
232 | static int freezer_read(struct cgroup *cgroup, struct cftype *cft, | ||
233 | struct seq_file *m) | ||
234 | { | ||
235 | struct freezer *freezer; | ||
236 | enum freezer_state state; | ||
237 | |||
238 | if (!cgroup_lock_live_group(cgroup)) | ||
239 | return -ENODEV; | ||
240 | |||
241 | freezer = cgroup_freezer(cgroup); | ||
242 | spin_lock_irq(&freezer->lock); | ||
243 | state = freezer->state; | ||
244 | if (state == CGROUP_FREEZING) { | ||
245 | /* We change from FREEZING to FROZEN lazily if the cgroup was | ||
246 | * only partially frozen when we exitted write. */ | ||
247 | update_freezer_state(cgroup, freezer); | ||
248 | state = freezer->state; | ||
249 | } | ||
250 | spin_unlock_irq(&freezer->lock); | ||
251 | cgroup_unlock(); | ||
252 | |||
253 | seq_puts(m, freezer_state_strs[state]); | ||
254 | seq_putc(m, '\n'); | ||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | static int try_to_freeze_cgroup(struct cgroup *cgroup, struct freezer *freezer) | ||
259 | { | ||
260 | struct cgroup_iter it; | ||
261 | struct task_struct *task; | ||
262 | unsigned int num_cant_freeze_now = 0; | ||
263 | |||
264 | freezer->state = CGROUP_FREEZING; | ||
265 | cgroup_iter_start(cgroup, &it); | ||
266 | while ((task = cgroup_iter_next(cgroup, &it))) { | ||
267 | if (!freeze_task(task, true)) | ||
268 | continue; | ||
269 | if (is_task_frozen_enough(task)) | ||
270 | continue; | ||
271 | if (!freezing(task) && !freezer_should_skip(task)) | ||
272 | num_cant_freeze_now++; | ||
273 | } | ||
274 | cgroup_iter_end(cgroup, &it); | ||
275 | |||
276 | return num_cant_freeze_now ? -EBUSY : 0; | ||
277 | } | ||
278 | |||
279 | static int unfreeze_cgroup(struct cgroup *cgroup, struct freezer *freezer) | ||
280 | { | ||
281 | struct cgroup_iter it; | ||
282 | struct task_struct *task; | ||
283 | |||
284 | cgroup_iter_start(cgroup, &it); | ||
285 | while ((task = cgroup_iter_next(cgroup, &it))) { | ||
286 | int do_wake; | ||
287 | |||
288 | task_lock(task); | ||
289 | do_wake = __thaw_process(task); | ||
290 | task_unlock(task); | ||
291 | if (do_wake) | ||
292 | wake_up_process(task); | ||
293 | } | ||
294 | cgroup_iter_end(cgroup, &it); | ||
295 | freezer->state = CGROUP_THAWED; | ||
296 | |||
297 | return 0; | ||
298 | } | ||
299 | |||
300 | static int freezer_change_state(struct cgroup *cgroup, | ||
301 | enum freezer_state goal_state) | ||
302 | { | ||
303 | struct freezer *freezer; | ||
304 | int retval = 0; | ||
305 | |||
306 | freezer = cgroup_freezer(cgroup); | ||
307 | spin_lock_irq(&freezer->lock); | ||
308 | update_freezer_state(cgroup, freezer); | ||
309 | if (goal_state == freezer->state) | ||
310 | goto out; | ||
311 | switch (freezer->state) { | ||
312 | case CGROUP_THAWED: | ||
313 | retval = try_to_freeze_cgroup(cgroup, freezer); | ||
314 | break; | ||
315 | case CGROUP_FREEZING: | ||
316 | if (goal_state == CGROUP_FROZEN) { | ||
317 | /* Userspace is retrying after | ||
318 | * "/bin/echo FROZEN > freezer.state" returned -EBUSY */ | ||
319 | retval = try_to_freeze_cgroup(cgroup, freezer); | ||
320 | break; | ||
321 | } | ||
322 | /* state == FREEZING and goal_state == THAWED, so unfreeze */ | ||
323 | case CGROUP_FROZEN: | ||
324 | retval = unfreeze_cgroup(cgroup, freezer); | ||
325 | break; | ||
326 | default: | ||
327 | break; | ||
328 | } | ||
329 | out: | ||
330 | spin_unlock_irq(&freezer->lock); | ||
331 | |||
332 | return retval; | ||
333 | } | ||
334 | |||
335 | static int freezer_write(struct cgroup *cgroup, | ||
336 | struct cftype *cft, | ||
337 | const char *buffer) | ||
338 | { | ||
339 | int retval; | ||
340 | enum freezer_state goal_state; | ||
341 | |||
342 | if (strcmp(buffer, freezer_state_strs[CGROUP_THAWED]) == 0) | ||
343 | goal_state = CGROUP_THAWED; | ||
344 | else if (strcmp(buffer, freezer_state_strs[CGROUP_FROZEN]) == 0) | ||
345 | goal_state = CGROUP_FROZEN; | ||
346 | else | ||
347 | return -EIO; | ||
348 | |||
349 | if (!cgroup_lock_live_group(cgroup)) | ||
350 | return -ENODEV; | ||
351 | retval = freezer_change_state(cgroup, goal_state); | ||
352 | cgroup_unlock(); | ||
353 | return retval; | ||
354 | } | ||
355 | |||
356 | static struct cftype files[] = { | ||
357 | { | ||
358 | .name = "state", | ||
359 | .read_seq_string = freezer_read, | ||
360 | .write_string = freezer_write, | ||
361 | }, | ||
362 | }; | ||
363 | |||
364 | static int freezer_populate(struct cgroup_subsys *ss, struct cgroup *cgroup) | ||
365 | { | ||
366 | return cgroup_add_files(cgroup, ss, files, ARRAY_SIZE(files)); | ||
367 | } | ||
368 | |||
369 | struct cgroup_subsys freezer_subsys = { | ||
370 | .name = "freezer", | ||
371 | .create = freezer_create, | ||
372 | .destroy = freezer_destroy, | ||
373 | .populate = freezer_populate, | ||
374 | .subsys_id = freezer_subsys_id, | ||
375 | .can_attach = freezer_can_attach, | ||
376 | .attach = NULL, | ||
377 | .fork = freezer_fork, | ||
378 | .exit = NULL, | ||
379 | }; | ||
diff --git a/kernel/configs.c b/kernel/configs.c index 4c345210ed8..abaee684ecb 100644 --- a/kernel/configs.c +++ b/kernel/configs.c | |||
@@ -54,9 +54,6 @@ | |||
54 | 54 | ||
55 | #ifdef CONFIG_IKCONFIG_PROC | 55 | #ifdef CONFIG_IKCONFIG_PROC |
56 | 56 | ||
57 | /**************************************************/ | ||
58 | /* globals and useful constants */ | ||
59 | |||
60 | static ssize_t | 57 | static ssize_t |
61 | ikconfig_read_current(struct file *file, char __user *buf, | 58 | ikconfig_read_current(struct file *file, char __user *buf, |
62 | size_t len, loff_t * offset) | 59 | size_t len, loff_t * offset) |
@@ -71,9 +68,6 @@ static const struct file_operations ikconfig_file_ops = { | |||
71 | .read = ikconfig_read_current, | 68 | .read = ikconfig_read_current, |
72 | }; | 69 | }; |
73 | 70 | ||
74 | /***************************************************/ | ||
75 | /* ikconfig_init: start up everything we need to */ | ||
76 | |||
77 | static int __init ikconfig_init(void) | 71 | static int __init ikconfig_init(void) |
78 | { | 72 | { |
79 | struct proc_dir_entry *entry; | 73 | struct proc_dir_entry *entry; |
@@ -89,9 +83,6 @@ static int __init ikconfig_init(void) | |||
89 | return 0; | 83 | return 0; |
90 | } | 84 | } |
91 | 85 | ||
92 | /***************************************************/ | ||
93 | /* ikconfig_cleanup: clean up our mess */ | ||
94 | |||
95 | static void __exit ikconfig_cleanup(void) | 86 | static void __exit ikconfig_cleanup(void) |
96 | { | 87 | { |
97 | remove_proc_entry("config.gz", NULL); | 88 | remove_proc_entry("config.gz", NULL); |
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index eab7bd6628e..3e00526f52e 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -1172,7 +1172,7 @@ static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, | |||
1172 | { | 1172 | { |
1173 | struct cpuset trialcs; | 1173 | struct cpuset trialcs; |
1174 | int err; | 1174 | int err; |
1175 | int cpus_nonempty, balance_flag_changed; | 1175 | int balance_flag_changed; |
1176 | 1176 | ||
1177 | trialcs = *cs; | 1177 | trialcs = *cs; |
1178 | if (turning_on) | 1178 | if (turning_on) |
@@ -1184,7 +1184,6 @@ static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, | |||
1184 | if (err < 0) | 1184 | if (err < 0) |
1185 | return err; | 1185 | return err; |
1186 | 1186 | ||
1187 | cpus_nonempty = !cpus_empty(trialcs.cpus_allowed); | ||
1188 | balance_flag_changed = (is_sched_load_balance(cs) != | 1187 | balance_flag_changed = (is_sched_load_balance(cs) != |
1189 | is_sched_load_balance(&trialcs)); | 1188 | is_sched_load_balance(&trialcs)); |
1190 | 1189 | ||
@@ -1192,7 +1191,7 @@ static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs, | |||
1192 | cs->flags = trialcs.flags; | 1191 | cs->flags = trialcs.flags; |
1193 | mutex_unlock(&callback_mutex); | 1192 | mutex_unlock(&callback_mutex); |
1194 | 1193 | ||
1195 | if (cpus_nonempty && balance_flag_changed) | 1194 | if (!cpus_empty(trialcs.cpus_allowed) && balance_flag_changed) |
1196 | async_rebuild_sched_domains(); | 1195 | async_rebuild_sched_domains(); |
1197 | 1196 | ||
1198 | return 0; | 1197 | return 0; |
@@ -2437,19 +2436,15 @@ const struct file_operations proc_cpuset_operations = { | |||
2437 | void cpuset_task_status_allowed(struct seq_file *m, struct task_struct *task) | 2436 | void cpuset_task_status_allowed(struct seq_file *m, struct task_struct *task) |
2438 | { | 2437 | { |
2439 | seq_printf(m, "Cpus_allowed:\t"); | 2438 | seq_printf(m, "Cpus_allowed:\t"); |
2440 | m->count += cpumask_scnprintf(m->buf + m->count, m->size - m->count, | 2439 | seq_cpumask(m, &task->cpus_allowed); |
2441 | task->cpus_allowed); | ||
2442 | seq_printf(m, "\n"); | 2440 | seq_printf(m, "\n"); |
2443 | seq_printf(m, "Cpus_allowed_list:\t"); | 2441 | seq_printf(m, "Cpus_allowed_list:\t"); |
2444 | m->count += cpulist_scnprintf(m->buf + m->count, m->size - m->count, | 2442 | seq_cpumask_list(m, &task->cpus_allowed); |
2445 | task->cpus_allowed); | ||
2446 | seq_printf(m, "\n"); | 2443 | seq_printf(m, "\n"); |
2447 | seq_printf(m, "Mems_allowed:\t"); | 2444 | seq_printf(m, "Mems_allowed:\t"); |
2448 | m->count += nodemask_scnprintf(m->buf + m->count, m->size - m->count, | 2445 | seq_nodemask(m, &task->mems_allowed); |
2449 | task->mems_allowed); | ||
2450 | seq_printf(m, "\n"); | 2446 | seq_printf(m, "\n"); |
2451 | seq_printf(m, "Mems_allowed_list:\t"); | 2447 | seq_printf(m, "Mems_allowed_list:\t"); |
2452 | m->count += nodelist_scnprintf(m->buf + m->count, m->size - m->count, | 2448 | seq_nodemask_list(m, &task->mems_allowed); |
2453 | task->mems_allowed); | ||
2454 | seq_printf(m, "\n"); | 2449 | seq_printf(m, "\n"); |
2455 | } | 2450 | } |
diff --git a/kernel/freezer.c b/kernel/freezer.c new file mode 100644 index 00000000000..ba6248b323e --- /dev/null +++ b/kernel/freezer.c | |||
@@ -0,0 +1,154 @@ | |||
1 | /* | ||
2 | * kernel/freezer.c - Function to freeze a process | ||
3 | * | ||
4 | * Originally from kernel/power/process.c | ||
5 | */ | ||
6 | |||
7 | #include <linux/interrupt.h> | ||
8 | #include <linux/suspend.h> | ||
9 | #include <linux/module.h> | ||
10 | #include <linux/syscalls.h> | ||
11 | #include <linux/freezer.h> | ||
12 | |||
13 | /* | ||
14 | * freezing is complete, mark current process as frozen | ||
15 | */ | ||
16 | static inline void frozen_process(void) | ||
17 | { | ||
18 | if (!unlikely(current->flags & PF_NOFREEZE)) { | ||
19 | current->flags |= PF_FROZEN; | ||
20 | wmb(); | ||
21 | } | ||
22 | clear_freeze_flag(current); | ||
23 | } | ||
24 | |||
25 | /* Refrigerator is place where frozen processes are stored :-). */ | ||
26 | void refrigerator(void) | ||
27 | { | ||
28 | /* Hmm, should we be allowed to suspend when there are realtime | ||
29 | processes around? */ | ||
30 | long save; | ||
31 | |||
32 | task_lock(current); | ||
33 | if (freezing(current)) { | ||
34 | frozen_process(); | ||
35 | task_unlock(current); | ||
36 | } else { | ||
37 | task_unlock(current); | ||
38 | return; | ||
39 | } | ||
40 | save = current->state; | ||
41 | pr_debug("%s entered refrigerator\n", current->comm); | ||
42 | |||
43 | spin_lock_irq(¤t->sighand->siglock); | ||
44 | recalc_sigpending(); /* We sent fake signal, clean it up */ | ||
45 | spin_unlock_irq(¤t->sighand->siglock); | ||
46 | |||
47 | for (;;) { | ||
48 | set_current_state(TASK_UNINTERRUPTIBLE); | ||
49 | if (!frozen(current)) | ||
50 | break; | ||
51 | schedule(); | ||
52 | } | ||
53 | pr_debug("%s left refrigerator\n", current->comm); | ||
54 | __set_current_state(save); | ||
55 | } | ||
56 | EXPORT_SYMBOL(refrigerator); | ||
57 | |||
58 | static void fake_signal_wake_up(struct task_struct *p) | ||
59 | { | ||
60 | unsigned long flags; | ||
61 | |||
62 | spin_lock_irqsave(&p->sighand->siglock, flags); | ||
63 | signal_wake_up(p, 0); | ||
64 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | ||
65 | } | ||
66 | |||
67 | /** | ||
68 | * freeze_task - send a freeze request to given task | ||
69 | * @p: task to send the request to | ||
70 | * @sig_only: if set, the request will only be sent if the task has the | ||
71 | * PF_FREEZER_NOSIG flag unset | ||
72 | * Return value: 'false', if @sig_only is set and the task has | ||
73 | * PF_FREEZER_NOSIG set or the task is frozen, 'true', otherwise | ||
74 | * | ||
75 | * The freeze request is sent by setting the tasks's TIF_FREEZE flag and | ||
76 | * either sending a fake signal to it or waking it up, depending on whether | ||
77 | * or not it has PF_FREEZER_NOSIG set. If @sig_only is set and the task | ||
78 | * has PF_FREEZER_NOSIG set (ie. it is a typical kernel thread), its | ||
79 | * TIF_FREEZE flag will not be set. | ||
80 | */ | ||
81 | bool freeze_task(struct task_struct *p, bool sig_only) | ||
82 | { | ||
83 | /* | ||
84 | * We first check if the task is freezing and next if it has already | ||
85 | * been frozen to avoid the race with frozen_process() which first marks | ||
86 | * the task as frozen and next clears its TIF_FREEZE. | ||
87 | */ | ||
88 | if (!freezing(p)) { | ||
89 | rmb(); | ||
90 | if (frozen(p)) | ||
91 | return false; | ||
92 | |||
93 | if (!sig_only || should_send_signal(p)) | ||
94 | set_freeze_flag(p); | ||
95 | else | ||
96 | return false; | ||
97 | } | ||
98 | |||
99 | if (should_send_signal(p)) { | ||
100 | if (!signal_pending(p)) | ||
101 | fake_signal_wake_up(p); | ||
102 | } else if (sig_only) { | ||
103 | return false; | ||
104 | } else { | ||
105 | wake_up_state(p, TASK_INTERRUPTIBLE); | ||
106 | } | ||
107 | |||
108 | return true; | ||
109 | } | ||
110 | |||
111 | void cancel_freezing(struct task_struct *p) | ||
112 | { | ||
113 | unsigned long flags; | ||
114 | |||
115 | if (freezing(p)) { | ||
116 | pr_debug(" clean up: %s\n", p->comm); | ||
117 | clear_freeze_flag(p); | ||
118 | spin_lock_irqsave(&p->sighand->siglock, flags); | ||
119 | recalc_sigpending_and_wake(p); | ||
120 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | ||
121 | } | ||
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); | ||
diff --git a/kernel/kexec.c b/kernel/kexec.c index aef265325cd..777ac458ac9 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c | |||
@@ -1371,6 +1371,7 @@ static int __init crash_save_vmcoreinfo_init(void) | |||
1371 | VMCOREINFO_SYMBOL(node_online_map); | 1371 | VMCOREINFO_SYMBOL(node_online_map); |
1372 | VMCOREINFO_SYMBOL(swapper_pg_dir); | 1372 | VMCOREINFO_SYMBOL(swapper_pg_dir); |
1373 | VMCOREINFO_SYMBOL(_stext); | 1373 | VMCOREINFO_SYMBOL(_stext); |
1374 | VMCOREINFO_SYMBOL(vmlist); | ||
1374 | 1375 | ||
1375 | #ifndef CONFIG_NEED_MULTIPLE_NODES | 1376 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
1376 | VMCOREINFO_SYMBOL(mem_map); | 1377 | VMCOREINFO_SYMBOL(mem_map); |
@@ -1406,6 +1407,7 @@ static int __init crash_save_vmcoreinfo_init(void) | |||
1406 | VMCOREINFO_OFFSET(free_area, free_list); | 1407 | VMCOREINFO_OFFSET(free_area, free_list); |
1407 | VMCOREINFO_OFFSET(list_head, next); | 1408 | VMCOREINFO_OFFSET(list_head, next); |
1408 | VMCOREINFO_OFFSET(list_head, prev); | 1409 | VMCOREINFO_OFFSET(list_head, prev); |
1410 | VMCOREINFO_OFFSET(vm_struct, addr); | ||
1409 | VMCOREINFO_LENGTH(zone.free_area, MAX_ORDER); | 1411 | VMCOREINFO_LENGTH(zone.free_area, MAX_ORDER); |
1410 | VMCOREINFO_LENGTH(free_area.free_list, MIGRATE_TYPES); | 1412 | VMCOREINFO_LENGTH(free_area.free_list, MIGRATE_TYPES); |
1411 | VMCOREINFO_NUMBER(NR_FREE_PAGES); | 1413 | VMCOREINFO_NUMBER(NR_FREE_PAGES); |
diff --git a/kernel/kthread.c b/kernel/kthread.c index 96cff2f8710..14ec64fe175 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c | |||
@@ -171,12 +171,11 @@ EXPORT_SYMBOL(kthread_create); | |||
171 | */ | 171 | */ |
172 | void kthread_bind(struct task_struct *k, unsigned int cpu) | 172 | void kthread_bind(struct task_struct *k, unsigned int cpu) |
173 | { | 173 | { |
174 | if (k->state != TASK_UNINTERRUPTIBLE) { | 174 | /* Must have done schedule() in kthread() before we set_task_cpu */ |
175 | if (!wait_task_inactive(k, TASK_UNINTERRUPTIBLE)) { | ||
175 | WARN_ON(1); | 176 | WARN_ON(1); |
176 | return; | 177 | return; |
177 | } | 178 | } |
178 | /* Must have done schedule() in kthread() before we set_task_cpu */ | ||
179 | wait_task_inactive(k, 0); | ||
180 | set_task_cpu(k, cpu); | 179 | set_task_cpu(k, cpu); |
181 | k->cpus_allowed = cpumask_of_cpu(cpu); | 180 | k->cpus_allowed = cpumask_of_cpu(cpu); |
182 | k->rt.nr_cpus_allowed = 1; | 181 | k->rt.nr_cpus_allowed = 1; |
diff --git a/kernel/power/process.c b/kernel/power/process.c index 278946aecaf..ca634019497 100644 --- a/kernel/power/process.c +++ b/kernel/power/process.c | |||
@@ -28,121 +28,6 @@ static inline int freezeable(struct task_struct * p) | |||
28 | return 1; | 28 | return 1; |
29 | } | 29 | } |
30 | 30 | ||
31 | /* | ||
32 | * freezing is complete, mark current process as frozen | ||
33 | */ | ||
34 | static inline void frozen_process(void) | ||
35 | { | ||
36 | if (!unlikely(current->flags & PF_NOFREEZE)) { | ||
37 | current->flags |= PF_FROZEN; | ||
38 | wmb(); | ||
39 | } | ||
40 | clear_freeze_flag(current); | ||
41 | } | ||
42 | |||
43 | /* Refrigerator is place where frozen processes are stored :-). */ | ||
44 | void refrigerator(void) | ||
45 | { | ||
46 | /* Hmm, should we be allowed to suspend when there are realtime | ||
47 | processes around? */ | ||
48 | long save; | ||
49 | |||
50 | task_lock(current); | ||
51 | if (freezing(current)) { | ||
52 | frozen_process(); | ||
53 | task_unlock(current); | ||
54 | } else { | ||
55 | task_unlock(current); | ||
56 | return; | ||
57 | } | ||
58 | save = current->state; | ||
59 | pr_debug("%s entered refrigerator\n", current->comm); | ||
60 | |||
61 | spin_lock_irq(¤t->sighand->siglock); | ||
62 | recalc_sigpending(); /* We sent fake signal, clean it up */ | ||
63 | spin_unlock_irq(¤t->sighand->siglock); | ||
64 | |||
65 | for (;;) { | ||
66 | set_current_state(TASK_UNINTERRUPTIBLE); | ||
67 | if (!frozen(current)) | ||
68 | break; | ||
69 | schedule(); | ||
70 | } | ||
71 | pr_debug("%s left refrigerator\n", current->comm); | ||
72 | __set_current_state(save); | ||
73 | } | ||
74 | |||
75 | static void fake_signal_wake_up(struct task_struct *p) | ||
76 | { | ||
77 | unsigned long flags; | ||
78 | |||
79 | spin_lock_irqsave(&p->sighand->siglock, flags); | ||
80 | signal_wake_up(p, 0); | ||
81 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | ||
82 | } | ||
83 | |||
84 | static inline bool should_send_signal(struct task_struct *p) | ||
85 | { | ||
86 | return !(p->flags & PF_FREEZER_NOSIG); | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * freeze_task - send a freeze request to given task | ||
91 | * @p: task to send the request to | ||
92 | * @sig_only: if set, the request will only be sent if the task has the | ||
93 | * PF_FREEZER_NOSIG flag unset | ||
94 | * Return value: 'false', if @sig_only is set and the task has | ||
95 | * PF_FREEZER_NOSIG set or the task is frozen, 'true', otherwise | ||
96 | * | ||
97 | * The freeze request is sent by setting the tasks's TIF_FREEZE flag and | ||
98 | * either sending a fake signal to it or waking it up, depending on whether | ||
99 | * or not it has PF_FREEZER_NOSIG set. If @sig_only is set and the task | ||
100 | * has PF_FREEZER_NOSIG set (ie. it is a typical kernel thread), its | ||
101 | * TIF_FREEZE flag will not be set. | ||
102 | */ | ||
103 | static bool freeze_task(struct task_struct *p, bool sig_only) | ||
104 | { | ||
105 | /* | ||
106 | * We first check if the task is freezing and next if it has already | ||
107 | * been frozen to avoid the race with frozen_process() which first marks | ||
108 | * the task as frozen and next clears its TIF_FREEZE. | ||
109 | */ | ||
110 | if (!freezing(p)) { | ||
111 | rmb(); | ||
112 | if (frozen(p)) | ||
113 | return false; | ||
114 | |||
115 | if (!sig_only || should_send_signal(p)) | ||
116 | set_freeze_flag(p); | ||
117 | else | ||
118 | return false; | ||
119 | } | ||
120 | |||
121 | if (should_send_signal(p)) { | ||
122 | if (!signal_pending(p)) | ||
123 | fake_signal_wake_up(p); | ||
124 | } else if (sig_only) { | ||
125 | return false; | ||
126 | } else { | ||
127 | wake_up_state(p, TASK_INTERRUPTIBLE); | ||
128 | } | ||
129 | |||
130 | return true; | ||
131 | } | ||
132 | |||
133 | static void cancel_freezing(struct task_struct *p) | ||
134 | { | ||
135 | unsigned long flags; | ||
136 | |||
137 | if (freezing(p)) { | ||
138 | pr_debug(" clean up: %s\n", p->comm); | ||
139 | clear_freeze_flag(p); | ||
140 | spin_lock_irqsave(&p->sighand->siglock, flags); | ||
141 | recalc_sigpending_and_wake(p); | ||
142 | spin_unlock_irqrestore(&p->sighand->siglock, flags); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | static int try_to_freeze_tasks(bool sig_only) | 31 | static int try_to_freeze_tasks(bool sig_only) |
147 | { | 32 | { |
148 | struct task_struct *g, *p; | 33 | struct task_struct *g, *p; |
@@ -250,6 +135,9 @@ static void thaw_tasks(bool nosig_only) | |||
250 | if (nosig_only && should_send_signal(p)) | 135 | if (nosig_only && should_send_signal(p)) |
251 | continue; | 136 | continue; |
252 | 137 | ||
138 | if (cgroup_frozen(p)) | ||
139 | continue; | ||
140 | |||
253 | thaw_process(p); | 141 | thaw_process(p); |
254 | } while_each_thread(g, p); | 142 | } while_each_thread(g, p); |
255 | read_unlock(&tasklist_lock); | 143 | read_unlock(&tasklist_lock); |
@@ -264,4 +152,3 @@ void thaw_processes(void) | |||
264 | printk("done.\n"); | 152 | printk("done.\n"); |
265 | } | 153 | } |
266 | 154 | ||
267 | EXPORT_SYMBOL(refrigerator); | ||
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 356699a96d5..1e68e4c39e2 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
@@ -45,7 +45,7 @@ void __ptrace_link(struct task_struct *child, struct task_struct *new_parent) | |||
45 | * TASK_TRACED, resume it now. | 45 | * TASK_TRACED, resume it now. |
46 | * Requires that irqs be disabled. | 46 | * Requires that irqs be disabled. |
47 | */ | 47 | */ |
48 | void ptrace_untrace(struct task_struct *child) | 48 | static void ptrace_untrace(struct task_struct *child) |
49 | { | 49 | { |
50 | spin_lock(&child->sighand->siglock); | 50 | spin_lock(&child->sighand->siglock); |
51 | if (task_is_traced(child)) { | 51 | if (task_is_traced(child)) { |
diff --git a/kernel/rcupreempt.c b/kernel/rcupreempt.c index ca4bbbe04aa..59236e8b9da 100644 --- a/kernel/rcupreempt.c +++ b/kernel/rcupreempt.c | |||
@@ -54,9 +54,9 @@ | |||
54 | #include <linux/cpu.h> | 54 | #include <linux/cpu.h> |
55 | #include <linux/random.h> | 55 | #include <linux/random.h> |
56 | #include <linux/delay.h> | 56 | #include <linux/delay.h> |
57 | #include <linux/byteorder/swabb.h> | ||
58 | #include <linux/cpumask.h> | 57 | #include <linux/cpumask.h> |
59 | #include <linux/rcupreempt_trace.h> | 58 | #include <linux/rcupreempt_trace.h> |
59 | #include <asm/byteorder.h> | ||
60 | 60 | ||
61 | /* | 61 | /* |
62 | * PREEMPT_RCU data structures. | 62 | * PREEMPT_RCU data structures. |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 617d41e4d6a..b3cc73931d1 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -833,6 +833,16 @@ static struct ctl_table kern_table[] = { | |||
833 | .proc_handler = &proc_dointvec, | 833 | .proc_handler = &proc_dointvec, |
834 | }, | 834 | }, |
835 | #endif | 835 | #endif |
836 | #ifdef CONFIG_UNEVICTABLE_LRU | ||
837 | { | ||
838 | .ctl_name = CTL_UNNUMBERED, | ||
839 | .procname = "scan_unevictable_pages", | ||
840 | .data = &scan_unevictable_pages, | ||
841 | .maxlen = sizeof(scan_unevictable_pages), | ||
842 | .mode = 0644, | ||
843 | .proc_handler = &scan_unevictable_handler, | ||
844 | }, | ||
845 | #endif | ||
836 | /* | 846 | /* |
837 | * NOTE: do not add new entries to this table unless you have read | 847 | * NOTE: do not add new entries to this table unless you have read |
838 | * Documentation/sysctl/ctl_unnumbered.txt | 848 | * Documentation/sysctl/ctl_unnumbered.txt |