diff options
author | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2009-12-17 07:16:30 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-12-17 07:22:45 -0500 |
commit | e1781538cf5c870ab696e9b8f0a5c498d3900f2f (patch) | |
tree | 42027696b4bc241194299b29cef2ae814b087acd | |
parent | 464763cf1c6df632dccc8f2f4c7e50163154a2c0 (diff) |
sched: Assert task state bits at build time
Since everybody is lazy and prone to forgetting things, make the
compiler help us a bit.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <20091217121830.060186433@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | fs/proc/array.c | 18 | ||||
-rw-r--r-- | include/linux/sched.h | 4 |
2 files changed, 14 insertions, 8 deletions
diff --git a/fs/proc/array.c b/fs/proc/array.c index 96361e8fa3a8..f560325c444f 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c | |||
@@ -134,14 +134,14 @@ static inline void task_name(struct seq_file *m, struct task_struct *p) | |||
134 | * simple bit tests. | 134 | * simple bit tests. |
135 | */ | 135 | */ |
136 | static const char *task_state_array[] = { | 136 | static const char *task_state_array[] = { |
137 | "R (running)", /* 0 */ | 137 | "R (running)", /* 0 */ |
138 | "S (sleeping)", /* 1 */ | 138 | "S (sleeping)", /* 1 */ |
139 | "D (disk sleep)", /* 2 */ | 139 | "D (disk sleep)", /* 2 */ |
140 | "T (stopped)", /* 4 */ | 140 | "T (stopped)", /* 4 */ |
141 | "t (tracing stop)", /* 8 */ | 141 | "t (tracing stop)", /* 8 */ |
142 | "Z (zombie)", /* 16 */ | 142 | "Z (zombie)", /* 16 */ |
143 | "X (dead)", /* 32 */ | 143 | "X (dead)", /* 32 */ |
144 | "x (dead)", /* 64 */ | 144 | "x (dead)", /* 64 */ |
145 | "K (wakekill)", /* 128 */ | 145 | "K (wakekill)", /* 128 */ |
146 | "W (waking)", /* 256 */ | 146 | "W (waking)", /* 256 */ |
147 | }; | 147 | }; |
@@ -151,6 +151,8 @@ static inline const char *get_task_state(struct task_struct *tsk) | |||
151 | unsigned int state = (tsk->state & TASK_REPORT) | tsk->exit_state; | 151 | unsigned int state = (tsk->state & TASK_REPORT) | tsk->exit_state; |
152 | const char **p = &task_state_array[0]; | 152 | const char **p = &task_state_array[0]; |
153 | 153 | ||
154 | BUILD_BUG_ON(1 + ilog2(TASK_STATE_MAX) != ARRAY_SIZE(task_state_array)); | ||
155 | |||
154 | while (state) { | 156 | while (state) { |
155 | p++; | 157 | p++; |
156 | state >>= 1; | 158 | state >>= 1; |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 94858df38a87..37543876ddf5 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -192,9 +192,13 @@ print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) | |||
192 | #define TASK_DEAD 64 | 192 | #define TASK_DEAD 64 |
193 | #define TASK_WAKEKILL 128 | 193 | #define TASK_WAKEKILL 128 |
194 | #define TASK_WAKING 256 | 194 | #define TASK_WAKING 256 |
195 | #define TASK_STATE_MAX 512 | ||
195 | 196 | ||
196 | #define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW" | 197 | #define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW" |
197 | 198 | ||
199 | extern char ___assert_task_state[1 - 2*!!( | ||
200 | sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)]; | ||
201 | |||
198 | /* Convenience macros for the sake of set_task_state */ | 202 | /* Convenience macros for the sake of set_task_state */ |
199 | #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) | 203 | #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) |
200 | #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) | 204 | #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) |