Commit c8a37751 authored by Ingo Molnar's avatar Ingo Molnar

perf sched: Sanity check context switch events

Use 'perf sched latency' to track the current task based on
context-switch events, and flag the cases where there's some
impossible transition: such as a PID being switched out that
was not switched in.

Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent dc02bf71
...@@ -119,6 +119,7 @@ static unsigned long replay_repeat = 10; ...@@ -119,6 +119,7 @@ static unsigned long replay_repeat = 10;
static unsigned long nr_timestamps; static unsigned long nr_timestamps;
static unsigned long nr_unordered_timestamps; static unsigned long nr_unordered_timestamps;
static unsigned long nr_state_machine_bugs; static unsigned long nr_state_machine_bugs;
static unsigned long nr_context_switch_bugs;
static unsigned long nr_events; static unsigned long nr_events;
static unsigned long nr_lost_chunks; static unsigned long nr_lost_chunks;
static unsigned long nr_lost_events; static unsigned long nr_lost_events;
...@@ -1399,6 +1400,14 @@ static void __cmd_lat(void) ...@@ -1399,6 +1400,14 @@ static void __cmd_lat(void)
printf(" (due to lost events?)"); printf(" (due to lost events?)");
printf("\n"); printf("\n");
} }
if (nr_context_switch_bugs && nr_timestamps) {
printf(" INFO: %.3f%% context switch bugs (%ld out of %ld)",
(double)nr_context_switch_bugs/(double)nr_timestamps*100.0,
nr_context_switch_bugs, nr_timestamps);
if (nr_lost_events)
printf(" (due to lost events?)");
printf("\n");
}
printf("\n"); printf("\n");
} }
...@@ -1425,10 +1434,16 @@ process_sched_wakeup_event(struct raw_event_sample *raw, ...@@ -1425,10 +1434,16 @@ process_sched_wakeup_event(struct raw_event_sample *raw,
trace_handler->wakeup_event(&wakeup_event, event, cpu, timestamp, thread); trace_handler->wakeup_event(&wakeup_event, event, cpu, timestamp, thread);
} }
/*
* Track the current task - that way we can know whether there's any
* weird events, such as a task being switched away that is not current.
*/
static u32 curr_pid[MAX_CPUS] = { [0 ... MAX_CPUS-1] = -1 };
static void static void
process_sched_switch_event(struct raw_event_sample *raw, process_sched_switch_event(struct raw_event_sample *raw,
struct event *event, struct event *event,
int cpu __used, int cpu,
u64 timestamp __used, u64 timestamp __used,
struct thread *thread __used) struct thread *thread __used)
{ {
...@@ -1444,6 +1459,16 @@ process_sched_switch_event(struct raw_event_sample *raw, ...@@ -1444,6 +1459,16 @@ process_sched_switch_event(struct raw_event_sample *raw,
FILL_FIELD(switch_event, next_pid, event, raw->data); FILL_FIELD(switch_event, next_pid, event, raw->data);
FILL_FIELD(switch_event, next_prio, event, raw->data); FILL_FIELD(switch_event, next_prio, event, raw->data);
if (curr_pid[cpu] != (u32)-1) {
/*
* Are we trying to switch away a PID that is
* not current?
*/
if (curr_pid[cpu] != switch_event.prev_pid)
nr_context_switch_bugs++;
}
curr_pid[cpu] = switch_event.next_pid;
trace_handler->switch_event(&switch_event, event, cpu, timestamp, thread); trace_handler->switch_event(&switch_event, event, cpu, timestamp, thread);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment