aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2005-09-13 04:25:14 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-09-13 11:22:29 -0400
commit498d0c5711094b0e1fd93f5355d270ccebdec706 (patch)
treee155f09b6f5b752171638028e574947e275cc3d9 /include
parent921717a2a1cde78c9b2aa971c16510d63efe7320 (diff)
[PATCH] set_current_state() commentary
Explain the mysteries of set_current_state(). Quoth Linus: The scheduler itself never needs the memory barrier at all. The barrier is needed only if the user itself ends up testing some other thing afterwards, ie if you have set_process_state(TASK_INTERRUPTIBLE); if (still_need_to_sleep()) schedule(); then the "still_need_to_sleep()" thing may test flags and wakeup events, and then you _may_ want to (and often do) make sure that the write of TASK_INTERRUPTIBLE is serialized wrt the reads of any wakeup data (since the wakeup may have happened on another CPU). So the comment is somewhat wrong. We don't really _care_ whether the state propagates out to other CPU's since all of our actions are purely local, and there is nothing we do that is conditional on any other CPU: we're going to sleep unconditionally, and the scheduler only cares about _our_ state, not about somebody elses state. Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/sched.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 38c8654aaa96..49e617fa0f66 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -121,6 +121,17 @@ extern unsigned long nr_iowait(void);
121#define set_task_state(tsk, state_value) \ 121#define set_task_state(tsk, state_value) \
122 set_mb((tsk)->state, (state_value)) 122 set_mb((tsk)->state, (state_value))
123 123
124/*
125 * set_current_state() includes a barrier so that the write of current->state
126 * is correctly serialised wrt the caller's subsequent test of whether to
127 * actually sleep:
128 *
129 * set_current_state(TASK_UNINTERRUPTIBLE);
130 * if (do_i_need_to_sleep())
131 * schedule();
132 *
133 * If the caller does not need such serialisation then use __set_current_state()
134 */
124#define __set_current_state(state_value) \ 135#define __set_current_state(state_value) \
125 do { current->state = (state_value); } while (0) 136 do { current->state = (state_value); } while (0)
126#define set_current_state(state_value) \ 137#define set_current_state(state_value) \