aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-09-16 08:07:00 -0400
committerIngo Molnar <mingo@elte.hu>2009-09-16 06:08:28 -0400
commitc8a37751043427c6e4397a2cbfd617cb5f215c72 (patch)
treeb4399844d7064741c4df4098509b7dc3bd7d3493 /tools
parentdc02bf7178c8e2cb3d442ae19027b736d51c7dd5 (diff)
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: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-sched.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 1f0f9be34faa..2d542368de3c 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -119,6 +119,7 @@ static unsigned long replay_repeat = 10;
119static unsigned long nr_timestamps; 119static unsigned long nr_timestamps;
120static unsigned long nr_unordered_timestamps; 120static unsigned long nr_unordered_timestamps;
121static unsigned long nr_state_machine_bugs; 121static unsigned long nr_state_machine_bugs;
122static unsigned long nr_context_switch_bugs;
122static unsigned long nr_events; 123static unsigned long nr_events;
123static unsigned long nr_lost_chunks; 124static unsigned long nr_lost_chunks;
124static unsigned long nr_lost_events; 125static unsigned long nr_lost_events;
@@ -1399,6 +1400,14 @@ static void __cmd_lat(void)
1399 printf(" (due to lost events?)"); 1400 printf(" (due to lost events?)");
1400 printf("\n"); 1401 printf("\n");
1401 } 1402 }
1403 if (nr_context_switch_bugs && nr_timestamps) {
1404 printf(" INFO: %.3f%% context switch bugs (%ld out of %ld)",
1405 (double)nr_context_switch_bugs/(double)nr_timestamps*100.0,
1406 nr_context_switch_bugs, nr_timestamps);
1407 if (nr_lost_events)
1408 printf(" (due to lost events?)");
1409 printf("\n");
1410 }
1402 printf("\n"); 1411 printf("\n");
1403 1412
1404} 1413}
@@ -1425,10 +1434,16 @@ process_sched_wakeup_event(struct raw_event_sample *raw,
1425 trace_handler->wakeup_event(&wakeup_event, event, cpu, timestamp, thread); 1434 trace_handler->wakeup_event(&wakeup_event, event, cpu, timestamp, thread);
1426} 1435}
1427 1436
1437/*
1438 * Track the current task - that way we can know whether there's any
1439 * weird events, such as a task being switched away that is not current.
1440 */
1441static u32 curr_pid[MAX_CPUS] = { [0 ... MAX_CPUS-1] = -1 };
1442
1428static void 1443static void
1429process_sched_switch_event(struct raw_event_sample *raw, 1444process_sched_switch_event(struct raw_event_sample *raw,
1430 struct event *event, 1445 struct event *event,
1431 int cpu __used, 1446 int cpu,
1432 u64 timestamp __used, 1447 u64 timestamp __used,
1433 struct thread *thread __used) 1448 struct thread *thread __used)
1434{ 1449{
@@ -1444,6 +1459,16 @@ process_sched_switch_event(struct raw_event_sample *raw,
1444 FILL_FIELD(switch_event, next_pid, event, raw->data); 1459 FILL_FIELD(switch_event, next_pid, event, raw->data);
1445 FILL_FIELD(switch_event, next_prio, event, raw->data); 1460 FILL_FIELD(switch_event, next_prio, event, raw->data);
1446 1461
1462 if (curr_pid[cpu] != (u32)-1) {
1463 /*
1464 * Are we trying to switch away a PID that is
1465 * not current?
1466 */
1467 if (curr_pid[cpu] != switch_event.prev_pid)
1468 nr_context_switch_bugs++;
1469 }
1470 curr_pid[cpu] = switch_event.next_pid;
1471
1447 trace_handler->switch_event(&switch_event, event, cpu, timestamp, thread); 1472 trace_handler->switch_event(&switch_event, event, cpu, timestamp, thread);
1448} 1473}
1449 1474