aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cpu.c
diff options
context:
space:
mode:
authorAnton Vorontsov <anton.vorontsov@linaro.org>2012-05-31 19:26:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-31 20:49:30 -0400
commite4cc2f873ad0833aa5c4aca56bebe15b9603a1e7 (patch)
treef649dffdeb819f64434362f93cb42a7506866751 /kernel/cpu.c
parent2c922c51e6924298f8271d75732964f1ffdecaf2 (diff)
kernel/cpu.c: document clear_tasks_mm_cpumask()
Add more comments on clear_tasks_mm_cpumask, plus adds a runtime check: the function is only suitable for offlined CPUs, and if called inappropriately, the kernel should scream aloud. [akpm@linux-foundation.org: tweak comment: s/walks up/walks/, use 80 cols] Suggested-by: Andrew Morton <akpm@linux-foundation.org> Suggested-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/cpu.c')
-rw-r--r--kernel/cpu.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 0575197deb4a..a4eb5227a19e 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -13,6 +13,7 @@
13#include <linux/oom.h> 13#include <linux/oom.h>
14#include <linux/rcupdate.h> 14#include <linux/rcupdate.h>
15#include <linux/export.h> 15#include <linux/export.h>
16#include <linux/bug.h>
16#include <linux/kthread.h> 17#include <linux/kthread.h>
17#include <linux/stop_machine.h> 18#include <linux/stop_machine.h>
18#include <linux/mutex.h> 19#include <linux/mutex.h>
@@ -175,6 +176,18 @@ void __ref unregister_cpu_notifier(struct notifier_block *nb)
175} 176}
176EXPORT_SYMBOL(unregister_cpu_notifier); 177EXPORT_SYMBOL(unregister_cpu_notifier);
177 178
179/**
180 * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU
181 * @cpu: a CPU id
182 *
183 * This function walks all processes, finds a valid mm struct for each one and
184 * then clears a corresponding bit in mm's cpumask. While this all sounds
185 * trivial, there are various non-obvious corner cases, which this function
186 * tries to solve in a safe manner.
187 *
188 * Also note that the function uses a somewhat relaxed locking scheme, so it may
189 * be called only for an already offlined CPU.
190 */
178void clear_tasks_mm_cpumask(int cpu) 191void clear_tasks_mm_cpumask(int cpu)
179{ 192{
180 struct task_struct *p; 193 struct task_struct *p;
@@ -186,10 +199,15 @@ void clear_tasks_mm_cpumask(int cpu)
186 * Thus, we may use rcu_read_lock() here, instead of grabbing 199 * Thus, we may use rcu_read_lock() here, instead of grabbing
187 * full-fledged tasklist_lock. 200 * full-fledged tasklist_lock.
188 */ 201 */
202 WARN_ON(cpu_online(cpu));
189 rcu_read_lock(); 203 rcu_read_lock();
190 for_each_process(p) { 204 for_each_process(p) {
191 struct task_struct *t; 205 struct task_struct *t;
192 206
207 /*
208 * Main thread might exit, but other threads may still have
209 * a valid mm. Find one.
210 */
193 t = find_lock_task_mm(p); 211 t = find_lock_task_mm(p);
194 if (!t) 212 if (!t)
195 continue; 213 continue;