| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * drivers/power/process.c - Functions for starting/stopping processes on  | 
 | 3 |  *                           suspend transitions. | 
 | 4 |  * | 
 | 5 |  * Originally from swsusp. | 
 | 6 |  */ | 
 | 7 |  | 
 | 8 |  | 
 | 9 | #undef DEBUG | 
 | 10 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/interrupt.h> | 
 | 12 | #include <linux/suspend.h> | 
 | 13 | #include <linux/module.h> | 
| Rafael J. Wysocki | 02aaeb9 | 2006-03-23 03:00:04 -0800 | [diff] [blame] | 14 | #include <linux/syscalls.h> | 
| Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 15 | #include <linux/freezer.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 |  | 
 | 17 | /*  | 
 | 18 |  * Timeout for stopping processes | 
 | 19 |  */ | 
| Rafael J. Wysocki | 02aaeb9 | 2006-03-23 03:00:04 -0800 | [diff] [blame] | 20 | #define TIMEOUT	(20 * HZ) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 |  | 
| Rafael J. Wysocki | a9b6f56 | 2006-12-06 20:34:37 -0800 | [diff] [blame] | 22 | #define FREEZER_KERNEL_THREADS 0 | 
 | 23 | #define FREEZER_USER_SPACE 1 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 |  | 
 | 25 | static inline int freezeable(struct task_struct * p) | 
 | 26 | { | 
| Oleg Nesterov | 1065d13 | 2007-05-08 00:24:01 -0700 | [diff] [blame] | 27 | 	if ((p == current) || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | 	    (p->flags & PF_NOFREEZE) || | 
| Oleg Nesterov | 1065d13 | 2007-05-08 00:24:01 -0700 | [diff] [blame] | 29 | 	    (p->exit_state != 0)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | 		return 0; | 
 | 31 | 	return 1; | 
 | 32 | } | 
 | 33 |  | 
| Gautham R Shenoy | 88f18ba | 2007-05-23 13:57:29 -0700 | [diff] [blame] | 34 | /* | 
 | 35 |  * freezing is complete, mark current process as frozen | 
 | 36 |  */ | 
 | 37 | static inline void frozen_process(void) | 
 | 38 | { | 
 | 39 | 	if (!unlikely(current->flags & PF_NOFREEZE)) { | 
 | 40 | 		current->flags |= PF_FROZEN; | 
 | 41 | 		wmb(); | 
 | 42 | 	} | 
| Rafael J. Wysocki | 0c1eecf | 2007-07-19 01:47:33 -0700 | [diff] [blame] | 43 | 	clear_freeze_flag(current); | 
| Gautham R Shenoy | 88f18ba | 2007-05-23 13:57:29 -0700 | [diff] [blame] | 44 | } | 
 | 45 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* Refrigerator is place where frozen processes are stored :-). */ | 
| Christoph Lameter | 3e1d1d2 | 2005-06-24 23:13:50 -0700 | [diff] [blame] | 47 | void refrigerator(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { | 
 | 49 | 	/* Hmm, should we be allowed to suspend when there are realtime | 
 | 50 | 	   processes around? */ | 
 | 51 | 	long save; | 
| Rafael J. Wysocki | 33e1c28 | 2007-05-23 13:57:24 -0700 | [diff] [blame] | 52 |  | 
 | 53 | 	task_lock(current); | 
 | 54 | 	if (freezing(current)) { | 
| Gautham R Shenoy | 88f18ba | 2007-05-23 13:57:29 -0700 | [diff] [blame] | 55 | 		frozen_process(); | 
| Rafael J. Wysocki | 33e1c28 | 2007-05-23 13:57:24 -0700 | [diff] [blame] | 56 | 		task_unlock(current); | 
 | 57 | 	} else { | 
 | 58 | 		task_unlock(current); | 
 | 59 | 		return; | 
 | 60 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | 	save = current->state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | 	pr_debug("%s entered refrigerator\n", current->comm); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 |  | 
 | 64 | 	spin_lock_irq(¤t->sighand->siglock); | 
 | 65 | 	recalc_sigpending(); /* We sent fake signal, clean it up */ | 
 | 66 | 	spin_unlock_irq(¤t->sighand->siglock); | 
 | 67 |  | 
| Oleg Nesterov | 433ecb4 | 2007-05-06 14:50:40 -0700 | [diff] [blame] | 68 | 	for (;;) { | 
 | 69 | 		set_current_state(TASK_UNINTERRUPTIBLE); | 
 | 70 | 		if (!frozen(current)) | 
 | 71 | 			break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | 		schedule(); | 
| Pavel Machek | 2a23b5d | 2005-09-03 15:56:53 -0700 | [diff] [blame] | 73 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | 	pr_debug("%s left refrigerator\n", current->comm); | 
| Rafael J. Wysocki | f4a3a7d | 2007-07-19 01:47:33 -0700 | [diff] [blame] | 75 | 	__set_current_state(save); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } | 
 | 77 |  | 
| Roland McGrath | 13b1c3d | 2008-03-03 20:22:05 -0800 | [diff] [blame] | 78 | static void fake_signal_wake_up(struct task_struct *p) | 
| Rafael J. Wysocki | 02aaeb9 | 2006-03-23 03:00:04 -0800 | [diff] [blame] | 79 | { | 
 | 80 | 	unsigned long flags; | 
 | 81 |  | 
| Rafael J. Wysocki | d5d8c59 | 2007-10-18 03:04:46 -0700 | [diff] [blame] | 82 | 	spin_lock_irqsave(&p->sighand->siglock, flags); | 
| Roland McGrath | 13b1c3d | 2008-03-03 20:22:05 -0800 | [diff] [blame] | 83 | 	signal_wake_up(p, 0); | 
| Rafael J. Wysocki | d5d8c59 | 2007-10-18 03:04:46 -0700 | [diff] [blame] | 84 | 	spin_unlock_irqrestore(&p->sighand->siglock, flags); | 
 | 85 | } | 
 | 86 |  | 
| Rafael J. Wysocki | d5d8c59 | 2007-10-18 03:04:46 -0700 | [diff] [blame] | 87 | static int has_mm(struct task_struct *p) | 
 | 88 | { | 
 | 89 | 	return (p->mm && !(p->flags & PF_BORROWED_MM)); | 
 | 90 | } | 
 | 91 |  | 
 | 92 | /** | 
 | 93 |  *	freeze_task - send a freeze request to given task | 
 | 94 |  *	@p: task to send the request to | 
 | 95 |  *	@with_mm_only: if set, the request will only be sent if the task has its | 
 | 96 |  *		own mm | 
 | 97 |  *	Return value: 0, if @with_mm_only is set and the task has no mm of its | 
 | 98 |  *		own or the task is frozen, 1, otherwise | 
 | 99 |  * | 
 | 100 |  *	The freeze request is sent by seting the tasks's TIF_FREEZE flag and | 
 | 101 |  *	either sending a fake signal to it or waking it up, depending on whether | 
 | 102 |  *	or not it has its own mm (ie. it is a user land task).  If @with_mm_only | 
 | 103 |  *	is set and the task has no mm of its own (ie. it is a kernel thread), | 
 | 104 |  *	its TIF_FREEZE flag should not be set. | 
 | 105 |  * | 
 | 106 |  *	The task_lock() is necessary to prevent races with exit_mm() or | 
 | 107 |  *	use_mm()/unuse_mm() from occuring. | 
 | 108 |  */ | 
 | 109 | static int freeze_task(struct task_struct *p, int with_mm_only) | 
 | 110 | { | 
 | 111 | 	int ret = 1; | 
 | 112 |  | 
 | 113 | 	task_lock(p); | 
 | 114 | 	if (freezing(p)) { | 
 | 115 | 		if (has_mm(p)) { | 
 | 116 | 			if (!signal_pending(p)) | 
| Roland McGrath | 13b1c3d | 2008-03-03 20:22:05 -0800 | [diff] [blame] | 117 | 				fake_signal_wake_up(p); | 
| Rafael J. Wysocki | d5d8c59 | 2007-10-18 03:04:46 -0700 | [diff] [blame] | 118 | 		} else { | 
 | 119 | 			if (with_mm_only) | 
 | 120 | 				ret = 0; | 
 | 121 | 			else | 
 | 122 | 				wake_up_state(p, TASK_INTERRUPTIBLE); | 
 | 123 | 		} | 
 | 124 | 	} else { | 
| Rafael J. Wysocki | 8a102ee | 2006-12-13 00:34:30 -0800 | [diff] [blame] | 125 | 		rmb(); | 
| Rafael J. Wysocki | d5d8c59 | 2007-10-18 03:04:46 -0700 | [diff] [blame] | 126 | 		if (frozen(p)) { | 
 | 127 | 			ret = 0; | 
 | 128 | 		} else { | 
 | 129 | 			if (has_mm(p)) { | 
 | 130 | 				set_freeze_flag(p); | 
| Roland McGrath | 13b1c3d | 2008-03-03 20:22:05 -0800 | [diff] [blame] | 131 | 				fake_signal_wake_up(p); | 
| Rafael J. Wysocki | d5d8c59 | 2007-10-18 03:04:46 -0700 | [diff] [blame] | 132 | 			} else { | 
 | 133 | 				if (with_mm_only) { | 
 | 134 | 					ret = 0; | 
 | 135 | 				} else { | 
 | 136 | 					set_freeze_flag(p); | 
 | 137 | 					wake_up_state(p, TASK_INTERRUPTIBLE); | 
 | 138 | 				} | 
 | 139 | 			} | 
| Rafael J. Wysocki | 8a102ee | 2006-12-13 00:34:30 -0800 | [diff] [blame] | 140 | 		} | 
| Rafael J. Wysocki | 02aaeb9 | 2006-03-23 03:00:04 -0800 | [diff] [blame] | 141 | 	} | 
| Rafael J. Wysocki | d5d8c59 | 2007-10-18 03:04:46 -0700 | [diff] [blame] | 142 | 	task_unlock(p); | 
 | 143 | 	return ret; | 
| Rafael J. Wysocki | 02aaeb9 | 2006-03-23 03:00:04 -0800 | [diff] [blame] | 144 | } | 
 | 145 |  | 
| Rafael J. Wysocki | a7ef787 | 2006-08-05 12:13:42 -0700 | [diff] [blame] | 146 | static void cancel_freezing(struct task_struct *p) | 
 | 147 | { | 
 | 148 | 	unsigned long flags; | 
 | 149 |  | 
 | 150 | 	if (freezing(p)) { | 
 | 151 | 		pr_debug("  clean up: %s\n", p->comm); | 
| Rafael J. Wysocki | 0c1eecf | 2007-07-19 01:47:33 -0700 | [diff] [blame] | 152 | 		clear_freeze_flag(p); | 
| Rafael J. Wysocki | a7ef787 | 2006-08-05 12:13:42 -0700 | [diff] [blame] | 153 | 		spin_lock_irqsave(&p->sighand->siglock, flags); | 
| Roland McGrath | 7bb44ad | 2007-05-23 13:57:44 -0700 | [diff] [blame] | 154 | 		recalc_sigpending_and_wake(p); | 
| Rafael J. Wysocki | a7ef787 | 2006-08-05 12:13:42 -0700 | [diff] [blame] | 155 | 		spin_unlock_irqrestore(&p->sighand->siglock, flags); | 
 | 156 | 	} | 
 | 157 | } | 
 | 158 |  | 
| Rafael J. Wysocki | e7cd8a7 | 2007-07-19 01:47:34 -0700 | [diff] [blame] | 159 | static int try_to_freeze_tasks(int freeze_user_space) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | 	struct task_struct *g, *p; | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 162 | 	unsigned long end_time; | 
 | 163 | 	unsigned int todo; | 
| Rafael J. Wysocki | 438e2ce | 2007-10-18 03:04:49 -0700 | [diff] [blame] | 164 | 	struct timeval start, end; | 
 | 165 | 	s64 elapsed_csecs64; | 
 | 166 | 	unsigned int elapsed_csecs; | 
 | 167 |  | 
 | 168 | 	do_gettimeofday(&start); | 
| Christoph Lameter | 3e1d1d2 | 2005-06-24 23:13:50 -0700 | [diff] [blame] | 169 |  | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 170 | 	end_time = jiffies + TIMEOUT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | 	do { | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 172 | 		todo = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | 		read_lock(&tasklist_lock); | 
 | 174 | 		do_each_thread(g, p) { | 
| Rafael J. Wysocki | 0c1eecf | 2007-07-19 01:47:33 -0700 | [diff] [blame] | 175 | 			if (frozen(p) || !freezeable(p)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | 				continue; | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 177 |  | 
| Rafael J. Wysocki | d5d8c59 | 2007-10-18 03:04:46 -0700 | [diff] [blame] | 178 | 			if (!freeze_task(p, freeze_user_space)) | 
 | 179 | 				continue; | 
 | 180 |  | 
| Roland McGrath | 13b1c3d | 2008-03-03 20:22:05 -0800 | [diff] [blame] | 181 | 			/* | 
 | 182 | 			 * Now that we've done set_freeze_flag, don't | 
 | 183 | 			 * perturb a task in TASK_STOPPED or TASK_TRACED. | 
 | 184 | 			 * It is "frozen enough".  If the task does wake | 
 | 185 | 			 * up, it will immediately call try_to_freeze. | 
 | 186 | 			 */ | 
 | 187 | 			if (!task_is_stopped_or_traced(p) && | 
 | 188 | 			    !freezer_should_skip(p)) | 
| Rafael J. Wysocki | ba96a0c | 2007-05-23 13:57:25 -0700 | [diff] [blame] | 189 | 				todo++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | 		} while_each_thread(g, p); | 
 | 191 | 		read_unlock(&tasklist_lock); | 
| Rafael J. Wysocki | 02aaeb9 | 2006-03-23 03:00:04 -0800 | [diff] [blame] | 192 | 		yield();			/* Yield is okay here */ | 
| Rafael J. Wysocki | c2cf7d8 | 2007-07-19 01:47:35 -0700 | [diff] [blame] | 193 | 		if (time_after(jiffies, end_time)) | 
| Rafael J. Wysocki | 02aaeb9 | 2006-03-23 03:00:04 -0800 | [diff] [blame] | 194 | 			break; | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 195 | 	} while (todo); | 
| Christoph Lameter | 3e1d1d2 | 2005-06-24 23:13:50 -0700 | [diff] [blame] | 196 |  | 
| Rafael J. Wysocki | 438e2ce | 2007-10-18 03:04:49 -0700 | [diff] [blame] | 197 | 	do_gettimeofday(&end); | 
 | 198 | 	elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start); | 
 | 199 | 	do_div(elapsed_csecs64, NSEC_PER_SEC / 100); | 
 | 200 | 	elapsed_csecs = elapsed_csecs64; | 
 | 201 |  | 
| Pavel Machek | 6161b2c | 2005-09-03 15:57:05 -0700 | [diff] [blame] | 202 | 	if (todo) { | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 203 | 		/* This does not unfreeze processes that are already frozen | 
 | 204 | 		 * (we have slightly ugly calling convention in that respect, | 
 | 205 | 		 * and caller must call thaw_processes() if something fails), | 
 | 206 | 		 * but it cleans up leftover PF_FREEZE requests. | 
 | 207 | 		 */ | 
| Nigel Cunningham | 14b5b7c | 2006-12-06 20:34:26 -0800 | [diff] [blame] | 208 | 		printk("\n"); | 
| Rafael J. Wysocki | 438e2ce | 2007-10-18 03:04:49 -0700 | [diff] [blame] | 209 | 		printk(KERN_ERR "Freezing of tasks failed after %d.%02d seconds " | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 210 | 				"(%d tasks refusing to freeze):\n", | 
| Rafael J. Wysocki | 438e2ce | 2007-10-18 03:04:49 -0700 | [diff] [blame] | 211 | 				elapsed_csecs / 100, elapsed_csecs % 100, todo); | 
| Andrew Morton | 328616e | 2007-07-19 01:47:26 -0700 | [diff] [blame] | 212 | 		show_state(); | 
| Pavel Machek | 6161b2c | 2005-09-03 15:57:05 -0700 | [diff] [blame] | 213 | 		read_lock(&tasklist_lock); | 
| Rafael J. Wysocki | 02aaeb9 | 2006-03-23 03:00:04 -0800 | [diff] [blame] | 214 | 		do_each_thread(g, p) { | 
| Rafael J. Wysocki | 33e1c28 | 2007-05-23 13:57:24 -0700 | [diff] [blame] | 215 | 			task_lock(p); | 
| Rafael J. Wysocki | 0c1eecf | 2007-07-19 01:47:33 -0700 | [diff] [blame] | 216 | 			if (freezing(p) && !freezer_should_skip(p)) | 
| Nigel Cunningham | 14b5b7c | 2006-12-06 20:34:26 -0800 | [diff] [blame] | 217 | 				printk(KERN_ERR " %s\n", p->comm); | 
| Rafael J. Wysocki | a7ef787 | 2006-08-05 12:13:42 -0700 | [diff] [blame] | 218 | 			cancel_freezing(p); | 
| Rafael J. Wysocki | 33e1c28 | 2007-05-23 13:57:24 -0700 | [diff] [blame] | 219 | 			task_unlock(p); | 
| Rafael J. Wysocki | 02aaeb9 | 2006-03-23 03:00:04 -0800 | [diff] [blame] | 220 | 		} while_each_thread(g, p); | 
| Pavel Machek | 6161b2c | 2005-09-03 15:57:05 -0700 | [diff] [blame] | 221 | 		read_unlock(&tasklist_lock); | 
| Rafael J. Wysocki | 438e2ce | 2007-10-18 03:04:49 -0700 | [diff] [blame] | 222 | 	} else { | 
 | 223 | 		printk("(elapsed %d.%02d seconds) ", elapsed_csecs / 100, | 
 | 224 | 			elapsed_csecs % 100); | 
| Pavel Machek | 6161b2c | 2005-09-03 15:57:05 -0700 | [diff] [blame] | 225 | 	} | 
 | 226 |  | 
| Rafael J. Wysocki | e7cd8a7 | 2007-07-19 01:47:34 -0700 | [diff] [blame] | 227 | 	return todo ? -EBUSY : 0; | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 228 | } | 
 | 229 |  | 
 | 230 | /** | 
 | 231 |  *	freeze_processes - tell processes to enter the refrigerator | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 232 |  */ | 
 | 233 | int freeze_processes(void) | 
 | 234 | { | 
| Rafael J. Wysocki | e7cd8a7 | 2007-07-19 01:47:34 -0700 | [diff] [blame] | 235 | 	int error; | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 236 |  | 
| Rafael J. Wysocki | b842ee5 | 2007-10-18 03:04:48 -0700 | [diff] [blame] | 237 | 	printk("Freezing user space processes ... "); | 
| Rafael J. Wysocki | e7cd8a7 | 2007-07-19 01:47:34 -0700 | [diff] [blame] | 238 | 	error = try_to_freeze_tasks(FREEZER_USER_SPACE); | 
 | 239 | 	if (error) | 
| Rafael J. Wysocki | b842ee5 | 2007-10-18 03:04:48 -0700 | [diff] [blame] | 240 | 		goto Exit; | 
 | 241 | 	printk("done.\n"); | 
| Rafael J. Wysocki | 11b2ce2 | 2006-12-06 20:34:40 -0800 | [diff] [blame] | 242 |  | 
| Rafael J. Wysocki | b842ee5 | 2007-10-18 03:04:48 -0700 | [diff] [blame] | 243 | 	printk("Freezing remaining freezable tasks ... "); | 
| Rafael J. Wysocki | e7cd8a7 | 2007-07-19 01:47:34 -0700 | [diff] [blame] | 244 | 	error = try_to_freeze_tasks(FREEZER_KERNEL_THREADS); | 
 | 245 | 	if (error) | 
| Rafael J. Wysocki | b842ee5 | 2007-10-18 03:04:48 -0700 | [diff] [blame] | 246 | 		goto Exit; | 
 | 247 | 	printk("done."); | 
 | 248 |  Exit: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | 	BUG_ON(in_atomic()); | 
| Rafael J. Wysocki | b842ee5 | 2007-10-18 03:04:48 -0700 | [diff] [blame] | 250 | 	printk("\n"); | 
 | 251 | 	return error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } | 
 | 253 |  | 
| Rafael J. Wysocki | a9b6f56 | 2006-12-06 20:34:37 -0800 | [diff] [blame] | 254 | static void thaw_tasks(int thaw_user_space) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { | 
 | 256 | 	struct task_struct *g, *p; | 
 | 257 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | 	read_lock(&tasklist_lock); | 
| Rafael J. Wysocki | a9b6f56 | 2006-12-06 20:34:37 -0800 | [diff] [blame] | 259 | 	do_each_thread(g, p) { | 
 | 260 | 		if (!freezeable(p)) | 
 | 261 | 			continue; | 
| Nigel Cunningham | ff39593 | 2006-12-06 20:34:28 -0800 | [diff] [blame] | 262 |  | 
| Rafael J. Wysocki | 0c1eecf | 2007-07-19 01:47:33 -0700 | [diff] [blame] | 263 | 		if (!p->mm == thaw_user_space) | 
| Rafael J. Wysocki | a9b6f56 | 2006-12-06 20:34:37 -0800 | [diff] [blame] | 264 | 			continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 |  | 
| Rafael J. Wysocki | ba96a0c | 2007-05-23 13:57:25 -0700 | [diff] [blame] | 266 | 		thaw_process(p); | 
| Rafael J. Wysocki | a9b6f56 | 2006-12-06 20:34:37 -0800 | [diff] [blame] | 267 | 	} while_each_thread(g, p); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | 	read_unlock(&tasklist_lock); | 
| Rafael J. Wysocki | a9b6f56 | 2006-12-06 20:34:37 -0800 | [diff] [blame] | 269 | } | 
 | 270 |  | 
 | 271 | void thaw_processes(void) | 
 | 272 | { | 
 | 273 | 	printk("Restarting tasks ... "); | 
 | 274 | 	thaw_tasks(FREEZER_KERNEL_THREADS); | 
 | 275 | 	thaw_tasks(FREEZER_USER_SPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | 	schedule(); | 
| Nigel Cunningham | 14b5b7c | 2006-12-06 20:34:26 -0800 | [diff] [blame] | 277 | 	printk("done.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } | 
 | 279 |  | 
 | 280 | EXPORT_SYMBOL(refrigerator); |