diff options
| -rw-r--r-- | fs/proc/array.c | 21 | ||||
| -rw-r--r-- | include/linux/sched.h | 12 | ||||
| -rw-r--r-- | include/trace/events/sched.h | 7 |
3 files changed, 27 insertions, 13 deletions
diff --git a/fs/proc/array.c b/fs/proc/array.c index 01196d3ad452..a120a4549d48 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c | |||
| @@ -119,18 +119,23 @@ static inline void task_name(struct seq_file *m, struct task_struct *p) | |||
| 119 | * simple bit tests. | 119 | * simple bit tests. |
| 120 | */ | 120 | */ |
| 121 | static const char * const task_state_array[] = { | 121 | static const char * const task_state_array[] = { |
| 122 | "R (running)", /* 0 */ | 122 | |
| 123 | "S (sleeping)", /* 1 */ | 123 | /* states in TASK_REPORT: */ |
| 124 | "D (disk sleep)", /* 2 */ | 124 | "R (running)", /* 0x00 */ |
| 125 | "T (stopped)", /* 4 */ | 125 | "S (sleeping)", /* 0x01 */ |
| 126 | "t (tracing stop)", /* 8 */ | 126 | "D (disk sleep)", /* 0x02 */ |
| 127 | "X (dead)", /* 16 */ | 127 | "T (stopped)", /* 0x04 */ |
| 128 | "Z (zombie)", /* 32 */ | 128 | "t (tracing stop)", /* 0x08 */ |
| 129 | "X (dead)", /* 0x10 */ | ||
| 130 | "Z (zombie)", /* 0x20 */ | ||
| 131 | |||
| 132 | /* states beyond TASK_REPORT: */ | ||
| 133 | "I (idle)", /* 0x40 */ | ||
| 129 | }; | 134 | }; |
| 130 | 135 | ||
| 131 | static inline const char *get_task_state(struct task_struct *tsk) | 136 | static inline const char *get_task_state(struct task_struct *tsk) |
| 132 | { | 137 | { |
| 133 | BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != ARRAY_SIZE(task_state_array) - 1); | 138 | BUILD_BUG_ON(1 + ilog2(TASK_REPORT_MAX) != ARRAY_SIZE(task_state_array)); |
| 134 | return task_state_array[__get_task_state(tsk)]; | 139 | return task_state_array[__get_task_state(tsk)]; |
| 135 | } | 140 | } |
| 136 | 141 | ||
diff --git a/include/linux/sched.h b/include/linux/sched.h index bc7807933415..286fc1117046 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
| @@ -1241,22 +1241,30 @@ static inline pid_t task_pgrp_nr(struct task_struct *tsk) | |||
| 1241 | return task_pgrp_nr_ns(tsk, &init_pid_ns); | 1241 | return task_pgrp_nr_ns(tsk, &init_pid_ns); |
| 1242 | } | 1242 | } |
| 1243 | 1243 | ||
| 1244 | #define TASK_REPORT_IDLE (TASK_REPORT + 1) | ||
| 1245 | #define TASK_REPORT_MAX (TASK_REPORT_IDLE << 1) | ||
| 1246 | |||
| 1244 | static inline unsigned int __get_task_state(struct task_struct *tsk) | 1247 | static inline unsigned int __get_task_state(struct task_struct *tsk) |
| 1245 | { | 1248 | { |
| 1246 | unsigned int tsk_state = READ_ONCE(tsk->state); | 1249 | unsigned int tsk_state = READ_ONCE(tsk->state); |
| 1247 | unsigned int state = (tsk_state | tsk->exit_state) & TASK_REPORT; | 1250 | unsigned int state = (tsk_state | tsk->exit_state) & TASK_REPORT; |
| 1248 | 1251 | ||
| 1252 | BUILD_BUG_ON_NOT_POWER_OF_2(TASK_REPORT_MAX); | ||
| 1253 | |||
| 1249 | if (tsk_state == TASK_PARKED) | 1254 | if (tsk_state == TASK_PARKED) |
| 1250 | state = TASK_INTERRUPTIBLE; | 1255 | state = TASK_INTERRUPTIBLE; |
| 1251 | 1256 | ||
| 1257 | if (tsk_state == TASK_IDLE) | ||
| 1258 | state = TASK_REPORT_IDLE; | ||
| 1259 | |||
| 1252 | return fls(state); | 1260 | return fls(state); |
| 1253 | } | 1261 | } |
| 1254 | 1262 | ||
| 1255 | static inline char __task_state_to_char(unsigned int state) | 1263 | static inline char __task_state_to_char(unsigned int state) |
| 1256 | { | 1264 | { |
| 1257 | static const char state_char[] = "RSDTtXZ"; | 1265 | static const char state_char[] = "RSDTtXZI"; |
| 1258 | 1266 | ||
| 1259 | BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != sizeof(state_char) - 2); | 1267 | BUILD_BUG_ON(1 + ilog2(TASK_REPORT_MAX) != sizeof(state_char) - 1); |
| 1260 | 1268 | ||
| 1261 | return state_char[state]; | 1269 | return state_char[state]; |
| 1262 | } | 1270 | } |
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index c63e20c9ef24..b371ef8206e1 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h | |||
| @@ -156,10 +156,11 @@ TRACE_EVENT(sched_switch, | |||
| 156 | TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d", | 156 | TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d", |
| 157 | __entry->prev_comm, __entry->prev_pid, __entry->prev_prio, | 157 | __entry->prev_comm, __entry->prev_pid, __entry->prev_prio, |
| 158 | 158 | ||
| 159 | (__entry->prev_state & TASK_REPORT) ? | 159 | (__entry->prev_state & (TASK_REPORT_MAX - 1)) ? |
| 160 | __print_flags(__entry->prev_state & TASK_REPORT, "|", | 160 | __print_flags(__entry->prev_state & (TASK_REPORT_MAX - 1), "|", |
| 161 | { 0x01, "S" }, { 0x02, "D" }, { 0x04, "T" }, | 161 | { 0x01, "S" }, { 0x02, "D" }, { 0x04, "T" }, |
| 162 | { 0x08, "t" }, { 0x10, "X" }, { 0x20, "Z" }) : | 162 | { 0x08, "t" }, { 0x10, "X" }, { 0x20, "Z" }, |
| 163 | { 0x40, "I" }) : | ||
| 163 | "R", | 164 | "R", |
| 164 | 165 | ||
| 165 | __entry->prev_state & TASK_STATE_MAX ? "+" : "", | 166 | __entry->prev_state & TASK_STATE_MAX ? "+" : "", |
