sched, trace: Fix sched_switch() prev_state argument

For CONFIG_PREEMPT=y kernels the sched_switch(.prev_state) argument isn't
useful because we can get preempted with current->state != TASK_RUNNING
without actually getting removed from the runqueue.

Cure this by treating all preempted tasks as runnable from the tracer's
point of view.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cautiously-acked-by: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1275322715.27810.23323.camel@twins>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by Peter Zijlstra and committed by Ingo Molnar 02f72694 e51fd5e2

+18 -1
+18 -1
include/trace/events/sched.h
··· 115 115 TP_PROTO(struct task_struct *p, int success), 116 116 TP_ARGS(p, success)); 117 117 118 + #ifdef CREATE_TRACE_POINTS 119 + static inline long __trace_sched_switch_state(struct task_struct *p) 120 + { 121 + long state = p->state; 122 + 123 + #ifdef CONFIG_PREEMPT 124 + /* 125 + * For all intents and purposes a preempted task is a running task. 126 + */ 127 + if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE) 128 + state = TASK_RUNNING; 129 + #endif 130 + 131 + return state; 132 + } 133 + #endif 134 + 118 135 /* 119 136 * Tracepoint for task switches, performed by the scheduler: 120 137 */ ··· 156 139 memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); 157 140 __entry->prev_pid = prev->pid; 158 141 __entry->prev_prio = prev->prio; 159 - __entry->prev_state = prev->state; 142 + __entry->prev_state = __trace_sched_switch_state(prev); 160 143 memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); 161 144 __entry->next_pid = next->pid; 162 145 __entry->next_prio = next->prio;