Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1 | #include "builtin.h" |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 2 | #include "perf.h" |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 3 | |
| 4 | #include "util/util.h" |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 5 | #include "util/evlist.h" |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 6 | #include "util/cache.h" |
Arnaldo Carvalho de Melo | e3f4260 | 2011-11-16 17:02:54 -0200 | [diff] [blame] | 7 | #include "util/evsel.h" |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 8 | #include "util/symbol.h" |
| 9 | #include "util/thread.h" |
| 10 | #include "util/header.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 11 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 12 | #include "util/tool.h" |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 13 | |
| 14 | #include "util/parse-options.h" |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 15 | #include "util/trace-event.h" |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 16 | |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 17 | #include "util/debug.h" |
| 18 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 19 | #include <sys/prctl.h> |
Markus Trippelsdorf | 7b78f13 | 2012-04-04 10:45:27 +0200 | [diff] [blame] | 20 | #include <sys/resource.h> |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 21 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 22 | #include <semaphore.h> |
| 23 | #include <pthread.h> |
| 24 | #include <math.h> |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 25 | |
Robert Richter | efad141 | 2011-12-07 10:02:54 +0100 | [diff] [blame] | 26 | static const char *input_name; |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 27 | |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 28 | static char default_sort_order[] = "avg, max, switch, runtime"; |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 29 | static const char *sort_order = default_sort_order; |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 30 | |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 31 | static int profile_cpu = -1; |
| 32 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 33 | #define PR_SET_NAME 15 /* Set process name */ |
| 34 | #define MAX_CPUS 4096 |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 35 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 36 | static u64 run_measurement_overhead; |
| 37 | static u64 sleep_measurement_overhead; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 38 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 39 | #define COMM_LEN 20 |
| 40 | #define SYM_LEN 129 |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 41 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 42 | #define MAX_PID 65536 |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 43 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 44 | static unsigned long nr_tasks; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 45 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 46 | struct perf_sched { |
| 47 | struct perf_tool tool; |
| 48 | struct perf_session *session; |
| 49 | }; |
| 50 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 51 | struct sched_atom; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 52 | |
| 53 | struct task_desc { |
| 54 | unsigned long nr; |
| 55 | unsigned long pid; |
| 56 | char comm[COMM_LEN]; |
| 57 | |
| 58 | unsigned long nr_events; |
| 59 | unsigned long curr_event; |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 60 | struct sched_atom **atoms; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 61 | |
| 62 | pthread_t thread; |
| 63 | sem_t sleep_sem; |
| 64 | |
| 65 | sem_t ready_for_work; |
| 66 | sem_t work_done_sem; |
| 67 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 68 | u64 cpu_usage; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | enum sched_event_type { |
| 72 | SCHED_EVENT_RUN, |
| 73 | SCHED_EVENT_SLEEP, |
| 74 | SCHED_EVENT_WAKEUP, |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 75 | SCHED_EVENT_MIGRATION, |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 78 | struct sched_atom { |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 79 | enum sched_event_type type; |
Arnaldo Carvalho de Melo | eed05fe | 2010-04-05 12:53:45 -0300 | [diff] [blame] | 80 | int specific_wait; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 81 | u64 timestamp; |
| 82 | u64 duration; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 83 | unsigned long nr; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 84 | sem_t *wait_sem; |
| 85 | struct task_desc *wakee; |
| 86 | }; |
| 87 | |
| 88 | static struct task_desc *pid_to_task[MAX_PID]; |
| 89 | |
| 90 | static struct task_desc **tasks; |
| 91 | |
| 92 | static pthread_mutex_t start_work_mutex = PTHREAD_MUTEX_INITIALIZER; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 93 | static u64 start_time; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 94 | |
| 95 | static pthread_mutex_t work_done_wait_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 96 | |
| 97 | static unsigned long nr_run_events; |
| 98 | static unsigned long nr_sleep_events; |
| 99 | static unsigned long nr_wakeup_events; |
| 100 | |
| 101 | static unsigned long nr_sleep_corrections; |
| 102 | static unsigned long nr_run_events_optimized; |
| 103 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 104 | static unsigned long targetless_wakeups; |
| 105 | static unsigned long multitarget_wakeups; |
| 106 | |
| 107 | static u64 cpu_usage; |
| 108 | static u64 runavg_cpu_usage; |
| 109 | static u64 parent_cpu_usage; |
| 110 | static u64 runavg_parent_cpu_usage; |
| 111 | |
| 112 | static unsigned long nr_runs; |
| 113 | static u64 sum_runtime; |
| 114 | static u64 sum_fluct; |
| 115 | static u64 run_avg; |
| 116 | |
Arnaldo Carvalho de Melo | 1967936 | 2010-05-17 15:39:16 -0300 | [diff] [blame] | 117 | static unsigned int replay_repeat = 10; |
Ingo Molnar | ea57c4f | 2009-09-13 18:15:54 +0200 | [diff] [blame] | 118 | static unsigned long nr_timestamps; |
Ingo Molnar | dc02bf7 | 2009-09-16 13:45:00 +0200 | [diff] [blame] | 119 | static unsigned long nr_unordered_timestamps; |
| 120 | static unsigned long nr_state_machine_bugs; |
Ingo Molnar | c8a3775 | 2009-09-16 14:07:00 +0200 | [diff] [blame] | 121 | static unsigned long nr_context_switch_bugs; |
Ingo Molnar | dc02bf7 | 2009-09-16 13:45:00 +0200 | [diff] [blame] | 122 | static unsigned long nr_events; |
| 123 | static unsigned long nr_lost_chunks; |
| 124 | static unsigned long nr_lost_events; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 125 | |
| 126 | #define TASK_STATE_TO_CHAR_STR "RSDTtZX" |
| 127 | |
| 128 | enum thread_state { |
| 129 | THREAD_SLEEPING = 0, |
| 130 | THREAD_WAIT_CPU, |
| 131 | THREAD_SCHED_IN, |
| 132 | THREAD_IGNORE |
| 133 | }; |
| 134 | |
| 135 | struct work_atom { |
| 136 | struct list_head list; |
| 137 | enum thread_state state; |
Frederic Weisbecker | aa1ab9d | 2009-09-14 03:01:12 +0200 | [diff] [blame] | 138 | u64 sched_out_time; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 139 | u64 wake_up_time; |
| 140 | u64 sched_in_time; |
| 141 | u64 runtime; |
| 142 | }; |
| 143 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 144 | struct work_atoms { |
| 145 | struct list_head work_list; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 146 | struct thread *thread; |
| 147 | struct rb_node node; |
| 148 | u64 max_lat; |
Frederic Weisbecker | 3786310a | 2009-12-09 21:40:08 +0100 | [diff] [blame] | 149 | u64 max_lat_at; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 150 | u64 total_lat; |
| 151 | u64 nb_atoms; |
| 152 | u64 total_runtime; |
| 153 | }; |
| 154 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 155 | typedef int (*sort_fn_t)(struct work_atoms *, struct work_atoms *); |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 156 | |
| 157 | static struct rb_root atom_root, sorted_atom_root; |
| 158 | |
| 159 | static u64 all_runtime; |
| 160 | static u64 all_count; |
| 161 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 162 | |
| 163 | static u64 get_nsecs(void) |
| 164 | { |
| 165 | struct timespec ts; |
| 166 | |
| 167 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 168 | |
| 169 | return ts.tv_sec * 1000000000ULL + ts.tv_nsec; |
| 170 | } |
| 171 | |
| 172 | static void burn_nsecs(u64 nsecs) |
| 173 | { |
| 174 | u64 T0 = get_nsecs(), T1; |
| 175 | |
| 176 | do { |
| 177 | T1 = get_nsecs(); |
| 178 | } while (T1 + run_measurement_overhead < T0 + nsecs); |
| 179 | } |
| 180 | |
| 181 | static void sleep_nsecs(u64 nsecs) |
| 182 | { |
| 183 | struct timespec ts; |
| 184 | |
| 185 | ts.tv_nsec = nsecs % 999999999; |
| 186 | ts.tv_sec = nsecs / 999999999; |
| 187 | |
| 188 | nanosleep(&ts, NULL); |
| 189 | } |
| 190 | |
| 191 | static void calibrate_run_measurement_overhead(void) |
| 192 | { |
| 193 | u64 T0, T1, delta, min_delta = 1000000000ULL; |
| 194 | int i; |
| 195 | |
| 196 | for (i = 0; i < 10; i++) { |
| 197 | T0 = get_nsecs(); |
| 198 | burn_nsecs(0); |
| 199 | T1 = get_nsecs(); |
| 200 | delta = T1-T0; |
| 201 | min_delta = min(min_delta, delta); |
| 202 | } |
| 203 | run_measurement_overhead = min_delta; |
| 204 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 205 | printf("run measurement overhead: %" PRIu64 " nsecs\n", min_delta); |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static void calibrate_sleep_measurement_overhead(void) |
| 209 | { |
| 210 | u64 T0, T1, delta, min_delta = 1000000000ULL; |
| 211 | int i; |
| 212 | |
| 213 | for (i = 0; i < 10; i++) { |
| 214 | T0 = get_nsecs(); |
| 215 | sleep_nsecs(10000); |
| 216 | T1 = get_nsecs(); |
| 217 | delta = T1-T0; |
| 218 | min_delta = min(min_delta, delta); |
| 219 | } |
| 220 | min_delta -= 10000; |
| 221 | sleep_measurement_overhead = min_delta; |
| 222 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 223 | printf("sleep measurement overhead: %" PRIu64 " nsecs\n", min_delta); |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 224 | } |
| 225 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 226 | static struct sched_atom * |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 227 | get_new_event(struct task_desc *task, u64 timestamp) |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 228 | { |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 229 | struct sched_atom *event = zalloc(sizeof(*event)); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 230 | unsigned long idx = task->nr_events; |
| 231 | size_t size; |
| 232 | |
| 233 | event->timestamp = timestamp; |
| 234 | event->nr = idx; |
| 235 | |
| 236 | task->nr_events++; |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 237 | size = sizeof(struct sched_atom *) * task->nr_events; |
| 238 | task->atoms = realloc(task->atoms, size); |
| 239 | BUG_ON(!task->atoms); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 240 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 241 | task->atoms[idx] = event; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 242 | |
| 243 | return event; |
| 244 | } |
| 245 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 246 | static struct sched_atom *last_event(struct task_desc *task) |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 247 | { |
| 248 | if (!task->nr_events) |
| 249 | return NULL; |
| 250 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 251 | return task->atoms[task->nr_events - 1]; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static void |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 255 | add_sched_event_run(struct task_desc *task, u64 timestamp, u64 duration) |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 256 | { |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 257 | struct sched_atom *event, *curr_event = last_event(task); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 258 | |
| 259 | /* |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 260 | * optimize an existing RUN event by merging this one |
| 261 | * to it: |
| 262 | */ |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 263 | if (curr_event && curr_event->type == SCHED_EVENT_RUN) { |
| 264 | nr_run_events_optimized++; |
| 265 | curr_event->duration += duration; |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | event = get_new_event(task, timestamp); |
| 270 | |
| 271 | event->type = SCHED_EVENT_RUN; |
| 272 | event->duration = duration; |
| 273 | |
| 274 | nr_run_events++; |
| 275 | } |
| 276 | |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 277 | static void |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 278 | add_sched_event_wakeup(struct task_desc *task, u64 timestamp, |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 279 | struct task_desc *wakee) |
| 280 | { |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 281 | struct sched_atom *event, *wakee_event; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 282 | |
| 283 | event = get_new_event(task, timestamp); |
| 284 | event->type = SCHED_EVENT_WAKEUP; |
| 285 | event->wakee = wakee; |
| 286 | |
| 287 | wakee_event = last_event(wakee); |
| 288 | if (!wakee_event || wakee_event->type != SCHED_EVENT_SLEEP) { |
| 289 | targetless_wakeups++; |
| 290 | return; |
| 291 | } |
| 292 | if (wakee_event->wait_sem) { |
| 293 | multitarget_wakeups++; |
| 294 | return; |
| 295 | } |
| 296 | |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 297 | wakee_event->wait_sem = zalloc(sizeof(*wakee_event->wait_sem)); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 298 | sem_init(wakee_event->wait_sem, 0, 0); |
| 299 | wakee_event->specific_wait = 1; |
| 300 | event->wait_sem = wakee_event->wait_sem; |
| 301 | |
| 302 | nr_wakeup_events++; |
| 303 | } |
| 304 | |
| 305 | static void |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 306 | add_sched_event_sleep(struct task_desc *task, u64 timestamp, |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 307 | u64 task_state __used) |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 308 | { |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 309 | struct sched_atom *event = get_new_event(task, timestamp); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 310 | |
| 311 | event->type = SCHED_EVENT_SLEEP; |
| 312 | |
| 313 | nr_sleep_events++; |
| 314 | } |
| 315 | |
| 316 | static struct task_desc *register_pid(unsigned long pid, const char *comm) |
| 317 | { |
| 318 | struct task_desc *task; |
| 319 | |
| 320 | BUG_ON(pid >= MAX_PID); |
| 321 | |
| 322 | task = pid_to_task[pid]; |
| 323 | |
| 324 | if (task) |
| 325 | return task; |
| 326 | |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 327 | task = zalloc(sizeof(*task)); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 328 | task->pid = pid; |
| 329 | task->nr = nr_tasks; |
| 330 | strcpy(task->comm, comm); |
| 331 | /* |
| 332 | * every task starts in sleeping state - this gets ignored |
| 333 | * if there's no wakeup pointing to this sleep state: |
| 334 | */ |
| 335 | add_sched_event_sleep(task, 0, 0); |
| 336 | |
| 337 | pid_to_task[pid] = task; |
| 338 | nr_tasks++; |
| 339 | tasks = realloc(tasks, nr_tasks*sizeof(struct task_task *)); |
| 340 | BUG_ON(!tasks); |
| 341 | tasks[task->nr] = task; |
| 342 | |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 343 | if (verbose) |
| 344 | printf("registered task #%ld, PID %ld (%s)\n", nr_tasks, pid, comm); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 345 | |
| 346 | return task; |
| 347 | } |
| 348 | |
| 349 | |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 350 | static void print_task_traces(void) |
| 351 | { |
| 352 | struct task_desc *task; |
| 353 | unsigned long i; |
| 354 | |
| 355 | for (i = 0; i < nr_tasks; i++) { |
| 356 | task = tasks[i]; |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 357 | printf("task %6ld (%20s:%10ld), nr_events: %ld\n", |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 358 | task->nr, task->comm, task->pid, task->nr_events); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | static void add_cross_task_wakeups(void) |
| 363 | { |
| 364 | struct task_desc *task1, *task2; |
| 365 | unsigned long i, j; |
| 366 | |
| 367 | for (i = 0; i < nr_tasks; i++) { |
| 368 | task1 = tasks[i]; |
| 369 | j = i + 1; |
| 370 | if (j == nr_tasks) |
| 371 | j = 0; |
| 372 | task2 = tasks[j]; |
| 373 | add_sched_event_wakeup(task1, 0, task2); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | static void |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 378 | process_sched_event(struct task_desc *this_task __used, struct sched_atom *atom) |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 379 | { |
| 380 | int ret = 0; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 381 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 382 | switch (atom->type) { |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 383 | case SCHED_EVENT_RUN: |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 384 | burn_nsecs(atom->duration); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 385 | break; |
| 386 | case SCHED_EVENT_SLEEP: |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 387 | if (atom->wait_sem) |
| 388 | ret = sem_wait(atom->wait_sem); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 389 | BUG_ON(ret); |
| 390 | break; |
| 391 | case SCHED_EVENT_WAKEUP: |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 392 | if (atom->wait_sem) |
| 393 | ret = sem_post(atom->wait_sem); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 394 | BUG_ON(ret); |
| 395 | break; |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 396 | case SCHED_EVENT_MIGRATION: |
| 397 | break; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 398 | default: |
| 399 | BUG_ON(1); |
| 400 | } |
| 401 | } |
| 402 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 403 | static u64 get_cpu_usage_nsec_parent(void) |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 404 | { |
| 405 | struct rusage ru; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 406 | u64 sum; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 407 | int err; |
| 408 | |
| 409 | err = getrusage(RUSAGE_SELF, &ru); |
| 410 | BUG_ON(err); |
| 411 | |
| 412 | sum = ru.ru_utime.tv_sec*1e9 + ru.ru_utime.tv_usec*1e3; |
| 413 | sum += ru.ru_stime.tv_sec*1e9 + ru.ru_stime.tv_usec*1e3; |
| 414 | |
| 415 | return sum; |
| 416 | } |
| 417 | |
Xiao Guangrong | c0c9e72 | 2009-12-09 17:51:30 +0800 | [diff] [blame] | 418 | static int self_open_counters(void) |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 419 | { |
Xiao Guangrong | c0c9e72 | 2009-12-09 17:51:30 +0800 | [diff] [blame] | 420 | struct perf_event_attr attr; |
| 421 | int fd; |
| 422 | |
| 423 | memset(&attr, 0, sizeof(attr)); |
| 424 | |
| 425 | attr.type = PERF_TYPE_SOFTWARE; |
| 426 | attr.config = PERF_COUNT_SW_TASK_CLOCK; |
| 427 | |
| 428 | fd = sys_perf_event_open(&attr, 0, -1, -1, 0); |
| 429 | |
| 430 | if (fd < 0) |
| 431 | die("Error: sys_perf_event_open() syscall returned" |
| 432 | "with %d (%s)\n", fd, strerror(errno)); |
| 433 | return fd; |
| 434 | } |
| 435 | |
| 436 | static u64 get_cpu_usage_nsec_self(int fd) |
| 437 | { |
| 438 | u64 runtime; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 439 | int ret; |
| 440 | |
Xiao Guangrong | c0c9e72 | 2009-12-09 17:51:30 +0800 | [diff] [blame] | 441 | ret = read(fd, &runtime, sizeof(runtime)); |
| 442 | BUG_ON(ret != sizeof(runtime)); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 443 | |
Xiao Guangrong | c0c9e72 | 2009-12-09 17:51:30 +0800 | [diff] [blame] | 444 | return runtime; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static void *thread_func(void *ctx) |
| 448 | { |
| 449 | struct task_desc *this_task = ctx; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 450 | u64 cpu_usage_0, cpu_usage_1; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 451 | unsigned long i, ret; |
| 452 | char comm2[22]; |
Xiao Guangrong | c0c9e72 | 2009-12-09 17:51:30 +0800 | [diff] [blame] | 453 | int fd; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 454 | |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 455 | sprintf(comm2, ":%s", this_task->comm); |
| 456 | prctl(PR_SET_NAME, comm2); |
Xiao Guangrong | c0c9e72 | 2009-12-09 17:51:30 +0800 | [diff] [blame] | 457 | fd = self_open_counters(); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 458 | |
| 459 | again: |
| 460 | ret = sem_post(&this_task->ready_for_work); |
| 461 | BUG_ON(ret); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 462 | ret = pthread_mutex_lock(&start_work_mutex); |
| 463 | BUG_ON(ret); |
| 464 | ret = pthread_mutex_unlock(&start_work_mutex); |
| 465 | BUG_ON(ret); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 466 | |
Xiao Guangrong | c0c9e72 | 2009-12-09 17:51:30 +0800 | [diff] [blame] | 467 | cpu_usage_0 = get_cpu_usage_nsec_self(fd); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 468 | |
| 469 | for (i = 0; i < this_task->nr_events; i++) { |
| 470 | this_task->curr_event = i; |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 471 | process_sched_event(this_task, this_task->atoms[i]); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 472 | } |
| 473 | |
Xiao Guangrong | c0c9e72 | 2009-12-09 17:51:30 +0800 | [diff] [blame] | 474 | cpu_usage_1 = get_cpu_usage_nsec_self(fd); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 475 | this_task->cpu_usage = cpu_usage_1 - cpu_usage_0; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 476 | ret = sem_post(&this_task->work_done_sem); |
| 477 | BUG_ON(ret); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 478 | |
| 479 | ret = pthread_mutex_lock(&work_done_wait_mutex); |
| 480 | BUG_ON(ret); |
| 481 | ret = pthread_mutex_unlock(&work_done_wait_mutex); |
| 482 | BUG_ON(ret); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 483 | |
| 484 | goto again; |
| 485 | } |
| 486 | |
| 487 | static void create_tasks(void) |
| 488 | { |
| 489 | struct task_desc *task; |
| 490 | pthread_attr_t attr; |
| 491 | unsigned long i; |
| 492 | int err; |
| 493 | |
| 494 | err = pthread_attr_init(&attr); |
| 495 | BUG_ON(err); |
Jiri Pirko | 12f7e03 | 2011-01-10 14:14:23 -0200 | [diff] [blame] | 496 | err = pthread_attr_setstacksize(&attr, |
| 497 | (size_t) max(16 * 1024, PTHREAD_STACK_MIN)); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 498 | BUG_ON(err); |
| 499 | err = pthread_mutex_lock(&start_work_mutex); |
| 500 | BUG_ON(err); |
| 501 | err = pthread_mutex_lock(&work_done_wait_mutex); |
| 502 | BUG_ON(err); |
| 503 | for (i = 0; i < nr_tasks; i++) { |
| 504 | task = tasks[i]; |
| 505 | sem_init(&task->sleep_sem, 0, 0); |
| 506 | sem_init(&task->ready_for_work, 0, 0); |
| 507 | sem_init(&task->work_done_sem, 0, 0); |
| 508 | task->curr_event = 0; |
| 509 | err = pthread_create(&task->thread, &attr, thread_func, task); |
| 510 | BUG_ON(err); |
| 511 | } |
| 512 | } |
| 513 | |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 514 | static void wait_for_tasks(void) |
| 515 | { |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 516 | u64 cpu_usage_0, cpu_usage_1; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 517 | struct task_desc *task; |
| 518 | unsigned long i, ret; |
| 519 | |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 520 | start_time = get_nsecs(); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 521 | cpu_usage = 0; |
| 522 | pthread_mutex_unlock(&work_done_wait_mutex); |
| 523 | |
| 524 | for (i = 0; i < nr_tasks; i++) { |
| 525 | task = tasks[i]; |
| 526 | ret = sem_wait(&task->ready_for_work); |
| 527 | BUG_ON(ret); |
| 528 | sem_init(&task->ready_for_work, 0, 0); |
| 529 | } |
| 530 | ret = pthread_mutex_lock(&work_done_wait_mutex); |
| 531 | BUG_ON(ret); |
| 532 | |
| 533 | cpu_usage_0 = get_cpu_usage_nsec_parent(); |
| 534 | |
| 535 | pthread_mutex_unlock(&start_work_mutex); |
| 536 | |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 537 | for (i = 0; i < nr_tasks; i++) { |
| 538 | task = tasks[i]; |
| 539 | ret = sem_wait(&task->work_done_sem); |
| 540 | BUG_ON(ret); |
| 541 | sem_init(&task->work_done_sem, 0, 0); |
| 542 | cpu_usage += task->cpu_usage; |
| 543 | task->cpu_usage = 0; |
| 544 | } |
| 545 | |
| 546 | cpu_usage_1 = get_cpu_usage_nsec_parent(); |
| 547 | if (!runavg_cpu_usage) |
| 548 | runavg_cpu_usage = cpu_usage; |
| 549 | runavg_cpu_usage = (runavg_cpu_usage*9 + cpu_usage)/10; |
| 550 | |
| 551 | parent_cpu_usage = cpu_usage_1 - cpu_usage_0; |
| 552 | if (!runavg_parent_cpu_usage) |
| 553 | runavg_parent_cpu_usage = parent_cpu_usage; |
| 554 | runavg_parent_cpu_usage = (runavg_parent_cpu_usage*9 + |
| 555 | parent_cpu_usage)/10; |
| 556 | |
| 557 | ret = pthread_mutex_lock(&start_work_mutex); |
| 558 | BUG_ON(ret); |
| 559 | |
| 560 | for (i = 0; i < nr_tasks; i++) { |
| 561 | task = tasks[i]; |
| 562 | sem_init(&task->sleep_sem, 0, 0); |
| 563 | task->curr_event = 0; |
| 564 | } |
| 565 | } |
| 566 | |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 567 | static void run_one_test(void) |
| 568 | { |
Kyle McMartin | fb7d0b3 | 2011-01-24 11:13:04 -0500 | [diff] [blame] | 569 | u64 T0, T1, delta, avg_delta, fluct; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 570 | |
| 571 | T0 = get_nsecs(); |
| 572 | wait_for_tasks(); |
| 573 | T1 = get_nsecs(); |
| 574 | |
| 575 | delta = T1 - T0; |
| 576 | sum_runtime += delta; |
| 577 | nr_runs++; |
| 578 | |
| 579 | avg_delta = sum_runtime / nr_runs; |
| 580 | if (delta < avg_delta) |
| 581 | fluct = avg_delta - delta; |
| 582 | else |
| 583 | fluct = delta - avg_delta; |
| 584 | sum_fluct += fluct; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 585 | if (!run_avg) |
| 586 | run_avg = delta; |
| 587 | run_avg = (run_avg*9 + delta)/10; |
| 588 | |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 589 | printf("#%-3ld: %0.3f, ", |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 590 | nr_runs, (double)delta/1000000.0); |
| 591 | |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 592 | printf("ravg: %0.2f, ", |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 593 | (double)run_avg/1e6); |
| 594 | |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 595 | printf("cpu: %0.2f / %0.2f", |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 596 | (double)cpu_usage/1e6, (double)runavg_cpu_usage/1e6); |
| 597 | |
| 598 | #if 0 |
| 599 | /* |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 600 | * rusage statistics done by the parent, these are less |
| 601 | * accurate than the sum_exec_runtime based statistics: |
| 602 | */ |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 603 | printf(" [%0.2f / %0.2f]", |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 604 | (double)parent_cpu_usage/1e6, |
| 605 | (double)runavg_parent_cpu_usage/1e6); |
| 606 | #endif |
| 607 | |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 608 | printf("\n"); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 609 | |
| 610 | if (nr_sleep_corrections) |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 611 | printf(" (%ld sleep corrections)\n", nr_sleep_corrections); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 612 | nr_sleep_corrections = 0; |
| 613 | } |
| 614 | |
| 615 | static void test_calibrations(void) |
| 616 | { |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 617 | u64 T0, T1; |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 618 | |
| 619 | T0 = get_nsecs(); |
| 620 | burn_nsecs(1e6); |
| 621 | T1 = get_nsecs(); |
| 622 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 623 | printf("the run test took %" PRIu64 " nsecs\n", T1 - T0); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 624 | |
| 625 | T0 = get_nsecs(); |
| 626 | sleep_nsecs(1e6); |
| 627 | T1 = get_nsecs(); |
| 628 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 629 | printf("the sleep test took %" PRIu64 " nsecs\n", T1 - T0); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 630 | } |
| 631 | |
Frederic Weisbecker | 4653881 | 2009-09-12 02:43:45 +0200 | [diff] [blame] | 632 | #define FILL_FIELD(ptr, field, event, data) \ |
| 633 | ptr.field = (typeof(ptr.field)) raw_field_value(event, #field, data) |
| 634 | |
| 635 | #define FILL_ARRAY(ptr, array, event, data) \ |
| 636 | do { \ |
| 637 | void *__array = raw_field_ptr(event, #array, data); \ |
| 638 | memcpy(ptr.array, __array, sizeof(ptr.array)); \ |
| 639 | } while(0) |
| 640 | |
| 641 | #define FILL_COMMON_FIELDS(ptr, event, data) \ |
| 642 | do { \ |
| 643 | FILL_FIELD(ptr, common_type, event, data); \ |
| 644 | FILL_FIELD(ptr, common_flags, event, data); \ |
| 645 | FILL_FIELD(ptr, common_preempt_count, event, data); \ |
| 646 | FILL_FIELD(ptr, common_pid, event, data); \ |
| 647 | FILL_FIELD(ptr, common_tgid, event, data); \ |
| 648 | } while (0) |
| 649 | |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 650 | |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 651 | |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 652 | struct trace_switch_event { |
| 653 | u32 size; |
| 654 | |
| 655 | u16 common_type; |
| 656 | u8 common_flags; |
| 657 | u8 common_preempt_count; |
| 658 | u32 common_pid; |
| 659 | u32 common_tgid; |
| 660 | |
| 661 | char prev_comm[16]; |
| 662 | u32 prev_pid; |
| 663 | u32 prev_prio; |
| 664 | u64 prev_state; |
| 665 | char next_comm[16]; |
| 666 | u32 next_pid; |
| 667 | u32 next_prio; |
| 668 | }; |
| 669 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 670 | struct trace_runtime_event { |
| 671 | u32 size; |
| 672 | |
| 673 | u16 common_type; |
| 674 | u8 common_flags; |
| 675 | u8 common_preempt_count; |
| 676 | u32 common_pid; |
| 677 | u32 common_tgid; |
| 678 | |
| 679 | char comm[16]; |
| 680 | u32 pid; |
| 681 | u64 runtime; |
| 682 | u64 vruntime; |
| 683 | }; |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 684 | |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 685 | struct trace_wakeup_event { |
| 686 | u32 size; |
| 687 | |
| 688 | u16 common_type; |
| 689 | u8 common_flags; |
| 690 | u8 common_preempt_count; |
| 691 | u32 common_pid; |
| 692 | u32 common_tgid; |
| 693 | |
| 694 | char comm[16]; |
| 695 | u32 pid; |
| 696 | |
| 697 | u32 prio; |
| 698 | u32 success; |
| 699 | u32 cpu; |
| 700 | }; |
| 701 | |
| 702 | struct trace_fork_event { |
| 703 | u32 size; |
| 704 | |
| 705 | u16 common_type; |
| 706 | u8 common_flags; |
| 707 | u8 common_preempt_count; |
| 708 | u32 common_pid; |
| 709 | u32 common_tgid; |
| 710 | |
| 711 | char parent_comm[16]; |
| 712 | u32 parent_pid; |
| 713 | char child_comm[16]; |
| 714 | u32 child_pid; |
| 715 | }; |
| 716 | |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 717 | struct trace_migrate_task_event { |
| 718 | u32 size; |
| 719 | |
| 720 | u16 common_type; |
| 721 | u8 common_flags; |
| 722 | u8 common_preempt_count; |
| 723 | u32 common_pid; |
| 724 | u32 common_tgid; |
| 725 | |
| 726 | char comm[16]; |
| 727 | u32 pid; |
| 728 | |
| 729 | u32 prio; |
| 730 | u32 cpu; |
| 731 | }; |
| 732 | |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 733 | struct trace_sched_handler { |
| 734 | void (*switch_event)(struct trace_switch_event *, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 735 | struct machine *, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 736 | struct event_format *, |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 737 | int cpu, |
| 738 | u64 timestamp, |
| 739 | struct thread *thread); |
| 740 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 741 | void (*runtime_event)(struct trace_runtime_event *, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 742 | struct machine *, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 743 | struct event_format *, |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 744 | int cpu, |
| 745 | u64 timestamp, |
| 746 | struct thread *thread); |
| 747 | |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 748 | void (*wakeup_event)(struct trace_wakeup_event *, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 749 | struct machine *, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 750 | struct event_format *, |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 751 | int cpu, |
| 752 | u64 timestamp, |
| 753 | struct thread *thread); |
| 754 | |
| 755 | void (*fork_event)(struct trace_fork_event *, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 756 | struct event_format *, |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 757 | int cpu, |
| 758 | u64 timestamp, |
| 759 | struct thread *thread); |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 760 | |
| 761 | void (*migrate_task_event)(struct trace_migrate_task_event *, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 762 | struct machine *machine, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 763 | struct event_format *, |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 764 | int cpu, |
| 765 | u64 timestamp, |
| 766 | struct thread *thread); |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 767 | }; |
| 768 | |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 769 | |
| 770 | static void |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 771 | replay_wakeup_event(struct trace_wakeup_event *wakeup_event, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 772 | struct machine *machine __used, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 773 | struct event_format *event, |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 774 | int cpu __used, |
| 775 | u64 timestamp __used, |
| 776 | struct thread *thread __used) |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 777 | { |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 778 | struct task_desc *waker, *wakee; |
| 779 | |
| 780 | if (verbose) { |
| 781 | printf("sched_wakeup event %p\n", event); |
| 782 | |
| 783 | printf(" ... pid %d woke up %s/%d\n", |
| 784 | wakeup_event->common_pid, |
| 785 | wakeup_event->comm, |
| 786 | wakeup_event->pid); |
| 787 | } |
| 788 | |
| 789 | waker = register_pid(wakeup_event->common_pid, "<unknown>"); |
| 790 | wakee = register_pid(wakeup_event->pid, wakeup_event->comm); |
| 791 | |
| 792 | add_sched_event_wakeup(waker, timestamp, wakee); |
| 793 | } |
| 794 | |
Ingo Molnar | d115338 | 2009-09-14 18:22:53 +0200 | [diff] [blame] | 795 | static u64 cpu_last_switched[MAX_CPUS]; |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 796 | |
| 797 | static void |
| 798 | replay_switch_event(struct trace_switch_event *switch_event, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 799 | struct machine *machine __used, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 800 | struct event_format *event, |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 801 | int cpu, |
| 802 | u64 timestamp, |
| 803 | struct thread *thread __used) |
| 804 | { |
Kyle McMartin | fb7d0b3 | 2011-01-24 11:13:04 -0500 | [diff] [blame] | 805 | struct task_desc *prev, __used *next; |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 806 | u64 timestamp0; |
| 807 | s64 delta; |
| 808 | |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 809 | if (verbose) |
| 810 | printf("sched_switch event %p\n", event); |
| 811 | |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 812 | if (cpu >= MAX_CPUS || cpu < 0) |
| 813 | return; |
| 814 | |
| 815 | timestamp0 = cpu_last_switched[cpu]; |
| 816 | if (timestamp0) |
| 817 | delta = timestamp - timestamp0; |
| 818 | else |
| 819 | delta = 0; |
| 820 | |
| 821 | if (delta < 0) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 822 | die("hm, delta: %" PRIu64 " < 0 ?\n", delta); |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 823 | |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 824 | if (verbose) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 825 | printf(" ... switch from %s/%d to %s/%d [ran %" PRIu64 " nsecs]\n", |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 826 | switch_event->prev_comm, switch_event->prev_pid, |
| 827 | switch_event->next_comm, switch_event->next_pid, |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 828 | delta); |
| 829 | } |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 830 | |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 831 | prev = register_pid(switch_event->prev_pid, switch_event->prev_comm); |
| 832 | next = register_pid(switch_event->next_pid, switch_event->next_comm); |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 833 | |
| 834 | cpu_last_switched[cpu] = timestamp; |
| 835 | |
| 836 | add_sched_event_run(prev, timestamp, delta); |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 837 | add_sched_event_sleep(prev, timestamp, switch_event->prev_state); |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 838 | } |
| 839 | |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 840 | |
| 841 | static void |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 842 | replay_fork_event(struct trace_fork_event *fork_event, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 843 | struct event_format *event, |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 844 | int cpu __used, |
| 845 | u64 timestamp __used, |
| 846 | struct thread *thread __used) |
| 847 | { |
| 848 | if (verbose) { |
| 849 | printf("sched_fork event %p\n", event); |
| 850 | printf("... parent: %s/%d\n", fork_event->parent_comm, fork_event->parent_pid); |
| 851 | printf("... child: %s/%d\n", fork_event->child_comm, fork_event->child_pid); |
| 852 | } |
| 853 | register_pid(fork_event->parent_pid, fork_event->parent_comm); |
| 854 | register_pid(fork_event->child_pid, fork_event->child_comm); |
| 855 | } |
| 856 | |
| 857 | static struct trace_sched_handler replay_ops = { |
Ingo Molnar | ea92ed5 | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 858 | .wakeup_event = replay_wakeup_event, |
| 859 | .switch_event = replay_switch_event, |
| 860 | .fork_event = replay_fork_event, |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 861 | }; |
| 862 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 863 | struct sort_dimension { |
| 864 | const char *name; |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 865 | sort_fn_t cmp; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 866 | struct list_head list; |
| 867 | }; |
| 868 | |
| 869 | static LIST_HEAD(cmp_pid); |
| 870 | |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 871 | static int |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 872 | thread_lat_cmp(struct list_head *list, struct work_atoms *l, struct work_atoms *r) |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 873 | { |
| 874 | struct sort_dimension *sort; |
| 875 | int ret = 0; |
| 876 | |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 877 | BUG_ON(list_empty(list)); |
| 878 | |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 879 | list_for_each_entry(sort, list, list) { |
| 880 | ret = sort->cmp(l, r); |
| 881 | if (ret) |
| 882 | return ret; |
| 883 | } |
| 884 | |
| 885 | return ret; |
| 886 | } |
| 887 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 888 | static struct work_atoms * |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 889 | thread_atoms_search(struct rb_root *root, struct thread *thread, |
| 890 | struct list_head *sort_list) |
| 891 | { |
| 892 | struct rb_node *node = root->rb_node; |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 893 | struct work_atoms key = { .thread = thread }; |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 894 | |
| 895 | while (node) { |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 896 | struct work_atoms *atoms; |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 897 | int cmp; |
| 898 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 899 | atoms = container_of(node, struct work_atoms, node); |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 900 | |
| 901 | cmp = thread_lat_cmp(sort_list, &key, atoms); |
| 902 | if (cmp > 0) |
| 903 | node = node->rb_left; |
| 904 | else if (cmp < 0) |
| 905 | node = node->rb_right; |
| 906 | else { |
| 907 | BUG_ON(thread != atoms->thread); |
| 908 | return atoms; |
| 909 | } |
| 910 | } |
| 911 | return NULL; |
| 912 | } |
| 913 | |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 914 | static void |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 915 | __thread_latency_insert(struct rb_root *root, struct work_atoms *data, |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 916 | struct list_head *sort_list) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 917 | { |
| 918 | struct rb_node **new = &(root->rb_node), *parent = NULL; |
| 919 | |
| 920 | while (*new) { |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 921 | struct work_atoms *this; |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 922 | int cmp; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 923 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 924 | this = container_of(*new, struct work_atoms, node); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 925 | parent = *new; |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 926 | |
| 927 | cmp = thread_lat_cmp(sort_list, data, this); |
| 928 | |
| 929 | if (cmp > 0) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 930 | new = &((*new)->rb_left); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 931 | else |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 932 | new = &((*new)->rb_right); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | rb_link_node(&data->node, parent, new); |
| 936 | rb_insert_color(&data->node, root); |
| 937 | } |
| 938 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 939 | static void thread_atoms_insert(struct thread *thread) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 940 | { |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 941 | struct work_atoms *atoms = zalloc(sizeof(*atoms)); |
Frederic Weisbecker | 1756220 | 2009-09-12 23:11:32 +0200 | [diff] [blame] | 942 | if (!atoms) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 943 | die("No memory"); |
| 944 | |
Frederic Weisbecker | 1756220 | 2009-09-12 23:11:32 +0200 | [diff] [blame] | 945 | atoms->thread = thread; |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 946 | INIT_LIST_HEAD(&atoms->work_list); |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 947 | __thread_latency_insert(&atom_root, atoms, &cmp_pid); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | static void |
| 951 | latency_fork_event(struct trace_fork_event *fork_event __used, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 952 | struct event_format *event __used, |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 953 | int cpu __used, |
| 954 | u64 timestamp __used, |
| 955 | struct thread *thread __used) |
| 956 | { |
| 957 | /* should insert the newcomer */ |
| 958 | } |
| 959 | |
Ingo Molnar | ea92ed5 | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 960 | __used |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 961 | static char sched_out_state(struct trace_switch_event *switch_event) |
| 962 | { |
| 963 | const char *str = TASK_STATE_TO_CHAR_STR; |
| 964 | |
| 965 | return str[switch_event->prev_state]; |
| 966 | } |
| 967 | |
| 968 | static void |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 969 | add_sched_out_event(struct work_atoms *atoms, |
| 970 | char run_state, |
| 971 | u64 timestamp) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 972 | { |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 973 | struct work_atom *atom = zalloc(sizeof(*atom)); |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 974 | if (!atom) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 975 | die("Non memory"); |
| 976 | |
Frederic Weisbecker | aa1ab9d | 2009-09-14 03:01:12 +0200 | [diff] [blame] | 977 | atom->sched_out_time = timestamp; |
| 978 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 979 | if (run_state == 'R') { |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 980 | atom->state = THREAD_WAIT_CPU; |
Frederic Weisbecker | aa1ab9d | 2009-09-14 03:01:12 +0200 | [diff] [blame] | 981 | atom->wake_up_time = atom->sched_out_time; |
Frederic Weisbecker | c6ced61 | 2009-09-13 00:46:19 +0200 | [diff] [blame] | 982 | } |
| 983 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 984 | list_add_tail(&atom->list, &atoms->work_list); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | static void |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 988 | add_runtime_event(struct work_atoms *atoms, u64 delta, u64 timestamp __used) |
| 989 | { |
| 990 | struct work_atom *atom; |
| 991 | |
| 992 | BUG_ON(list_empty(&atoms->work_list)); |
| 993 | |
| 994 | atom = list_entry(atoms->work_list.prev, struct work_atom, list); |
| 995 | |
| 996 | atom->runtime += delta; |
| 997 | atoms->total_runtime += delta; |
| 998 | } |
| 999 | |
| 1000 | static void |
| 1001 | add_sched_in_event(struct work_atoms *atoms, u64 timestamp) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1002 | { |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1003 | struct work_atom *atom; |
Frederic Weisbecker | 6668567 | 2009-09-13 01:56:25 +0200 | [diff] [blame] | 1004 | u64 delta; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1005 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1006 | if (list_empty(&atoms->work_list)) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1007 | return; |
| 1008 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1009 | atom = list_entry(atoms->work_list.prev, struct work_atom, list); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1010 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1011 | if (atom->state != THREAD_WAIT_CPU) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1012 | return; |
| 1013 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1014 | if (timestamp < atom->wake_up_time) { |
| 1015 | atom->state = THREAD_IGNORE; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1016 | return; |
| 1017 | } |
| 1018 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1019 | atom->state = THREAD_SCHED_IN; |
| 1020 | atom->sched_in_time = timestamp; |
Frederic Weisbecker | 6668567 | 2009-09-13 01:56:25 +0200 | [diff] [blame] | 1021 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1022 | delta = atom->sched_in_time - atom->wake_up_time; |
Frederic Weisbecker | 6668567 | 2009-09-13 01:56:25 +0200 | [diff] [blame] | 1023 | atoms->total_lat += delta; |
Frederic Weisbecker | 3786310a | 2009-12-09 21:40:08 +0100 | [diff] [blame] | 1024 | if (delta > atoms->max_lat) { |
Frederic Weisbecker | 6668567 | 2009-09-13 01:56:25 +0200 | [diff] [blame] | 1025 | atoms->max_lat = delta; |
Frederic Weisbecker | 3786310a | 2009-12-09 21:40:08 +0100 | [diff] [blame] | 1026 | atoms->max_lat_at = timestamp; |
| 1027 | } |
Frederic Weisbecker | 6668567 | 2009-09-13 01:56:25 +0200 | [diff] [blame] | 1028 | atoms->nb_atoms++; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1029 | } |
| 1030 | |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1031 | static void |
| 1032 | latency_switch_event(struct trace_switch_event *switch_event, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1033 | struct machine *machine, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1034 | struct event_format *event __used, |
Ingo Molnar | ea92ed5 | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 1035 | int cpu, |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1036 | u64 timestamp, |
| 1037 | struct thread *thread __used) |
| 1038 | { |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1039 | struct work_atoms *out_events, *in_events; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1040 | struct thread *sched_out, *sched_in; |
Ingo Molnar | ea92ed5 | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 1041 | u64 timestamp0; |
| 1042 | s64 delta; |
| 1043 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1044 | BUG_ON(cpu >= MAX_CPUS || cpu < 0); |
Ingo Molnar | ea92ed5 | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 1045 | |
| 1046 | timestamp0 = cpu_last_switched[cpu]; |
| 1047 | cpu_last_switched[cpu] = timestamp; |
| 1048 | if (timestamp0) |
| 1049 | delta = timestamp - timestamp0; |
| 1050 | else |
| 1051 | delta = 0; |
| 1052 | |
| 1053 | if (delta < 0) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1054 | die("hm, delta: %" PRIu64 " < 0 ?\n", delta); |
Ingo Molnar | ea92ed5 | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 1055 | |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1056 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1057 | sched_out = machine__findnew_thread(machine, switch_event->prev_pid); |
| 1058 | sched_in = machine__findnew_thread(machine, switch_event->next_pid); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1059 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1060 | out_events = thread_atoms_search(&atom_root, sched_out, &cmp_pid); |
| 1061 | if (!out_events) { |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1062 | thread_atoms_insert(sched_out); |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1063 | out_events = thread_atoms_search(&atom_root, sched_out, &cmp_pid); |
| 1064 | if (!out_events) |
| 1065 | die("out-event: Internal tree error"); |
| 1066 | } |
| 1067 | add_sched_out_event(out_events, sched_out_state(switch_event), timestamp); |
| 1068 | |
| 1069 | in_events = thread_atoms_search(&atom_root, sched_in, &cmp_pid); |
| 1070 | if (!in_events) { |
| 1071 | thread_atoms_insert(sched_in); |
| 1072 | in_events = thread_atoms_search(&atom_root, sched_in, &cmp_pid); |
| 1073 | if (!in_events) |
| 1074 | die("in-event: Internal tree error"); |
| 1075 | /* |
| 1076 | * Take came in we have not heard about yet, |
| 1077 | * add in an initial atom in runnable state: |
| 1078 | */ |
| 1079 | add_sched_out_event(in_events, 'R', timestamp); |
| 1080 | } |
| 1081 | add_sched_in_event(in_events, timestamp); |
| 1082 | } |
| 1083 | |
| 1084 | static void |
| 1085 | latency_runtime_event(struct trace_runtime_event *runtime_event, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1086 | struct machine *machine, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1087 | struct event_format *event __used, |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1088 | int cpu, |
| 1089 | u64 timestamp, |
| 1090 | struct thread *this_thread __used) |
| 1091 | { |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1092 | struct thread *thread = machine__findnew_thread(machine, runtime_event->pid); |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame] | 1093 | struct work_atoms *atoms = thread_atoms_search(&atom_root, thread, &cmp_pid); |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1094 | |
| 1095 | BUG_ON(cpu >= MAX_CPUS || cpu < 0); |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1096 | if (!atoms) { |
| 1097 | thread_atoms_insert(thread); |
| 1098 | atoms = thread_atoms_search(&atom_root, thread, &cmp_pid); |
| 1099 | if (!atoms) |
| 1100 | die("in-event: Internal tree error"); |
| 1101 | add_sched_out_event(atoms, 'R', timestamp); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1102 | } |
| 1103 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1104 | add_runtime_event(atoms, runtime_event->runtime, timestamp); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | static void |
| 1108 | latency_wakeup_event(struct trace_wakeup_event *wakeup_event, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1109 | struct machine *machine, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1110 | struct event_format *__event __used, |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1111 | int cpu __used, |
| 1112 | u64 timestamp, |
| 1113 | struct thread *thread __used) |
| 1114 | { |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1115 | struct work_atoms *atoms; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1116 | struct work_atom *atom; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1117 | struct thread *wakee; |
| 1118 | |
| 1119 | /* Note for later, it may be interesting to observe the failing cases */ |
| 1120 | if (!wakeup_event->success) |
| 1121 | return; |
| 1122 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1123 | wakee = machine__findnew_thread(machine, wakeup_event->pid); |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1124 | atoms = thread_atoms_search(&atom_root, wakee, &cmp_pid); |
Frederic Weisbecker | 1756220 | 2009-09-12 23:11:32 +0200 | [diff] [blame] | 1125 | if (!atoms) { |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1126 | thread_atoms_insert(wakee); |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1127 | atoms = thread_atoms_search(&atom_root, wakee, &cmp_pid); |
| 1128 | if (!atoms) |
| 1129 | die("wakeup-event: Internal tree error"); |
| 1130 | add_sched_out_event(atoms, 'S', timestamp); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1131 | } |
| 1132 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1133 | BUG_ON(list_empty(&atoms->work_list)); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1134 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1135 | atom = list_entry(atoms->work_list.prev, struct work_atom, list); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1136 | |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1137 | /* |
| 1138 | * You WILL be missing events if you've recorded only |
| 1139 | * one CPU, or are only looking at only one, so don't |
| 1140 | * make useless noise. |
| 1141 | */ |
| 1142 | if (profile_cpu == -1 && atom->state != THREAD_SLEEPING) |
Ingo Molnar | dc02bf7 | 2009-09-16 13:45:00 +0200 | [diff] [blame] | 1143 | nr_state_machine_bugs++; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1144 | |
Ingo Molnar | ea57c4f | 2009-09-13 18:15:54 +0200 | [diff] [blame] | 1145 | nr_timestamps++; |
| 1146 | if (atom->sched_out_time > timestamp) { |
Ingo Molnar | dc02bf7 | 2009-09-16 13:45:00 +0200 | [diff] [blame] | 1147 | nr_unordered_timestamps++; |
Frederic Weisbecker | aa1ab9d | 2009-09-14 03:01:12 +0200 | [diff] [blame] | 1148 | return; |
Ingo Molnar | ea57c4f | 2009-09-13 18:15:54 +0200 | [diff] [blame] | 1149 | } |
Frederic Weisbecker | aa1ab9d | 2009-09-14 03:01:12 +0200 | [diff] [blame] | 1150 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1151 | atom->state = THREAD_WAIT_CPU; |
| 1152 | atom->wake_up_time = timestamp; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1153 | } |
| 1154 | |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1155 | static void |
| 1156 | latency_migrate_task_event(struct trace_migrate_task_event *migrate_task_event, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1157 | struct machine *machine, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1158 | struct event_format *__event __used, |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1159 | int cpu __used, |
| 1160 | u64 timestamp, |
| 1161 | struct thread *thread __used) |
| 1162 | { |
| 1163 | struct work_atoms *atoms; |
| 1164 | struct work_atom *atom; |
| 1165 | struct thread *migrant; |
| 1166 | |
| 1167 | /* |
| 1168 | * Only need to worry about migration when profiling one CPU. |
| 1169 | */ |
| 1170 | if (profile_cpu == -1) |
| 1171 | return; |
| 1172 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1173 | migrant = machine__findnew_thread(machine, migrate_task_event->pid); |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1174 | atoms = thread_atoms_search(&atom_root, migrant, &cmp_pid); |
| 1175 | if (!atoms) { |
| 1176 | thread_atoms_insert(migrant); |
| 1177 | register_pid(migrant->pid, migrant->comm); |
| 1178 | atoms = thread_atoms_search(&atom_root, migrant, &cmp_pid); |
| 1179 | if (!atoms) |
| 1180 | die("migration-event: Internal tree error"); |
| 1181 | add_sched_out_event(atoms, 'R', timestamp); |
| 1182 | } |
| 1183 | |
| 1184 | BUG_ON(list_empty(&atoms->work_list)); |
| 1185 | |
| 1186 | atom = list_entry(atoms->work_list.prev, struct work_atom, list); |
| 1187 | atom->sched_in_time = atom->sched_out_time = atom->wake_up_time = timestamp; |
| 1188 | |
| 1189 | nr_timestamps++; |
| 1190 | |
| 1191 | if (atom->sched_out_time > timestamp) |
| 1192 | nr_unordered_timestamps++; |
| 1193 | } |
| 1194 | |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1195 | static struct trace_sched_handler lat_ops = { |
Ingo Molnar | ea92ed5 | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 1196 | .wakeup_event = latency_wakeup_event, |
| 1197 | .switch_event = latency_switch_event, |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1198 | .runtime_event = latency_runtime_event, |
Ingo Molnar | ea92ed5 | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 1199 | .fork_event = latency_fork_event, |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1200 | .migrate_task_event = latency_migrate_task_event, |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1201 | }; |
| 1202 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1203 | static void output_lat_thread(struct work_atoms *work_list) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1204 | { |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1205 | int i; |
| 1206 | int ret; |
Frederic Weisbecker | 6668567 | 2009-09-13 01:56:25 +0200 | [diff] [blame] | 1207 | u64 avg; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1208 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1209 | if (!work_list->nb_atoms) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1210 | return; |
Ingo Molnar | ea57c4f | 2009-09-13 18:15:54 +0200 | [diff] [blame] | 1211 | /* |
| 1212 | * Ignore idle threads: |
| 1213 | */ |
Ingo Molnar | 80ed098 | 2009-09-16 14:12:36 +0200 | [diff] [blame] | 1214 | if (!strcmp(work_list->thread->comm, "swapper")) |
Ingo Molnar | ea57c4f | 2009-09-13 18:15:54 +0200 | [diff] [blame] | 1215 | return; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1216 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1217 | all_runtime += work_list->total_runtime; |
| 1218 | all_count += work_list->nb_atoms; |
Frederic Weisbecker | 6668567 | 2009-09-13 01:56:25 +0200 | [diff] [blame] | 1219 | |
Ingo Molnar | 80ed098 | 2009-09-16 14:12:36 +0200 | [diff] [blame] | 1220 | ret = printf(" %s:%d ", work_list->thread->comm, work_list->thread->pid); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1221 | |
mingo | 08f69e6 | 2009-09-14 18:30:44 +0200 | [diff] [blame] | 1222 | for (i = 0; i < 24 - ret; i++) |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1223 | printf(" "); |
| 1224 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1225 | avg = work_list->total_lat / work_list->nb_atoms; |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1226 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1227 | printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max at: %9.6f s\n", |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1228 | (double)work_list->total_runtime / 1e6, |
| 1229 | work_list->nb_atoms, (double)avg / 1e6, |
Frederic Weisbecker | 3786310a | 2009-12-09 21:40:08 +0100 | [diff] [blame] | 1230 | (double)work_list->max_lat / 1e6, |
| 1231 | (double)work_list->max_lat_at / 1e9); |
Frederic Weisbecker | cdce9d7 | 2009-09-12 08:06:14 +0200 | [diff] [blame] | 1232 | } |
| 1233 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1234 | static int pid_cmp(struct work_atoms *l, struct work_atoms *r) |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1235 | { |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1236 | if (l->thread->pid < r->thread->pid) |
| 1237 | return -1; |
| 1238 | if (l->thread->pid > r->thread->pid) |
| 1239 | return 1; |
| 1240 | |
| 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | static struct sort_dimension pid_sort_dimension = { |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1245 | .name = "pid", |
| 1246 | .cmp = pid_cmp, |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1247 | }; |
| 1248 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1249 | static int avg_cmp(struct work_atoms *l, struct work_atoms *r) |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1250 | { |
| 1251 | u64 avgl, avgr; |
| 1252 | |
| 1253 | if (!l->nb_atoms) |
| 1254 | return -1; |
| 1255 | |
| 1256 | if (!r->nb_atoms) |
| 1257 | return 1; |
| 1258 | |
| 1259 | avgl = l->total_lat / l->nb_atoms; |
| 1260 | avgr = r->total_lat / r->nb_atoms; |
| 1261 | |
| 1262 | if (avgl < avgr) |
| 1263 | return -1; |
| 1264 | if (avgl > avgr) |
| 1265 | return 1; |
| 1266 | |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
| 1270 | static struct sort_dimension avg_sort_dimension = { |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1271 | .name = "avg", |
| 1272 | .cmp = avg_cmp, |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1273 | }; |
| 1274 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1275 | static int max_cmp(struct work_atoms *l, struct work_atoms *r) |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1276 | { |
| 1277 | if (l->max_lat < r->max_lat) |
| 1278 | return -1; |
| 1279 | if (l->max_lat > r->max_lat) |
| 1280 | return 1; |
| 1281 | |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | static struct sort_dimension max_sort_dimension = { |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1286 | .name = "max", |
| 1287 | .cmp = max_cmp, |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1288 | }; |
| 1289 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1290 | static int switch_cmp(struct work_atoms *l, struct work_atoms *r) |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1291 | { |
| 1292 | if (l->nb_atoms < r->nb_atoms) |
| 1293 | return -1; |
| 1294 | if (l->nb_atoms > r->nb_atoms) |
| 1295 | return 1; |
| 1296 | |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | static struct sort_dimension switch_sort_dimension = { |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1301 | .name = "switch", |
| 1302 | .cmp = switch_cmp, |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1303 | }; |
| 1304 | |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1305 | static int runtime_cmp(struct work_atoms *l, struct work_atoms *r) |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1306 | { |
| 1307 | if (l->total_runtime < r->total_runtime) |
| 1308 | return -1; |
| 1309 | if (l->total_runtime > r->total_runtime) |
| 1310 | return 1; |
| 1311 | |
| 1312 | return 0; |
| 1313 | } |
| 1314 | |
| 1315 | static struct sort_dimension runtime_sort_dimension = { |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1316 | .name = "runtime", |
| 1317 | .cmp = runtime_cmp, |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1318 | }; |
| 1319 | |
| 1320 | static struct sort_dimension *available_sorts[] = { |
| 1321 | &pid_sort_dimension, |
| 1322 | &avg_sort_dimension, |
| 1323 | &max_sort_dimension, |
| 1324 | &switch_sort_dimension, |
| 1325 | &runtime_sort_dimension, |
| 1326 | }; |
| 1327 | |
| 1328 | #define NB_AVAILABLE_SORTS (int)(sizeof(available_sorts) / sizeof(struct sort_dimension *)) |
| 1329 | |
| 1330 | static LIST_HEAD(sort_list); |
| 1331 | |
Randy Dunlap | cbef79a | 2009-10-05 13:17:29 -0700 | [diff] [blame] | 1332 | static int sort_dimension__add(const char *tok, struct list_head *list) |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1333 | { |
| 1334 | int i; |
| 1335 | |
| 1336 | for (i = 0; i < NB_AVAILABLE_SORTS; i++) { |
| 1337 | if (!strcmp(available_sorts[i]->name, tok)) { |
| 1338 | list_add_tail(&available_sorts[i]->list, list); |
| 1339 | |
| 1340 | return 0; |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | return -1; |
| 1345 | } |
| 1346 | |
| 1347 | static void setup_sorting(void); |
| 1348 | |
| 1349 | static void sort_lat(void) |
| 1350 | { |
| 1351 | struct rb_node *node; |
| 1352 | |
| 1353 | for (;;) { |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1354 | struct work_atoms *data; |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1355 | node = rb_first(&atom_root); |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1356 | if (!node) |
| 1357 | break; |
| 1358 | |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1359 | rb_erase(node, &atom_root); |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1360 | data = rb_entry(node, struct work_atoms, node); |
Ingo Molnar | b1ffe8f | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1361 | __thread_latency_insert(&sorted_atom_root, data, &sort_list); |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1362 | } |
| 1363 | } |
| 1364 | |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1365 | static struct trace_sched_handler *trace_handler; |
| 1366 | |
| 1367 | static void |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1368 | process_sched_wakeup_event(struct perf_tool *tool __used, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1369 | struct event_format *event, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1370 | struct perf_sample *sample, |
| 1371 | struct machine *machine, |
| 1372 | struct thread *thread) |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1373 | { |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1374 | void *data = sample->raw_data; |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1375 | struct trace_wakeup_event wakeup_event; |
| 1376 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 1377 | FILL_COMMON_FIELDS(wakeup_event, event, data); |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1378 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 1379 | FILL_ARRAY(wakeup_event, comm, event, data); |
| 1380 | FILL_FIELD(wakeup_event, pid, event, data); |
| 1381 | FILL_FIELD(wakeup_event, prio, event, data); |
| 1382 | FILL_FIELD(wakeup_event, success, event, data); |
| 1383 | FILL_FIELD(wakeup_event, cpu, event, data); |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1384 | |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1385 | if (trace_handler->wakeup_event) |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1386 | trace_handler->wakeup_event(&wakeup_event, machine, event, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1387 | sample->cpu, sample->time, thread); |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1388 | } |
| 1389 | |
Ingo Molnar | c8a3775 | 2009-09-16 14:07:00 +0200 | [diff] [blame] | 1390 | /* |
| 1391 | * Track the current task - that way we can know whether there's any |
| 1392 | * weird events, such as a task being switched away that is not current. |
| 1393 | */ |
Ingo Molnar | 40749d0 | 2009-09-17 18:24:55 +0200 | [diff] [blame] | 1394 | static int max_cpu; |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1395 | |
Ingo Molnar | c8a3775 | 2009-09-16 14:07:00 +0200 | [diff] [blame] | 1396 | static u32 curr_pid[MAX_CPUS] = { [0 ... MAX_CPUS-1] = -1 }; |
| 1397 | |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1398 | static struct thread *curr_thread[MAX_CPUS]; |
| 1399 | |
| 1400 | static char next_shortname1 = 'A'; |
| 1401 | static char next_shortname2 = '0'; |
| 1402 | |
| 1403 | static void |
| 1404 | map_switch_event(struct trace_switch_event *switch_event, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1405 | struct machine *machine, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1406 | struct event_format *event __used, |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1407 | int this_cpu, |
| 1408 | u64 timestamp, |
| 1409 | struct thread *thread __used) |
| 1410 | { |
Kyle McMartin | fb7d0b3 | 2011-01-24 11:13:04 -0500 | [diff] [blame] | 1411 | struct thread *sched_out __used, *sched_in; |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1412 | int new_shortname; |
| 1413 | u64 timestamp0; |
| 1414 | s64 delta; |
| 1415 | int cpu; |
| 1416 | |
| 1417 | BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0); |
| 1418 | |
| 1419 | if (this_cpu > max_cpu) |
| 1420 | max_cpu = this_cpu; |
| 1421 | |
| 1422 | timestamp0 = cpu_last_switched[this_cpu]; |
| 1423 | cpu_last_switched[this_cpu] = timestamp; |
| 1424 | if (timestamp0) |
| 1425 | delta = timestamp - timestamp0; |
| 1426 | else |
| 1427 | delta = 0; |
| 1428 | |
| 1429 | if (delta < 0) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1430 | die("hm, delta: %" PRIu64 " < 0 ?\n", delta); |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1431 | |
| 1432 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1433 | sched_out = machine__findnew_thread(machine, switch_event->prev_pid); |
| 1434 | sched_in = machine__findnew_thread(machine, switch_event->next_pid); |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1435 | |
| 1436 | curr_thread[this_cpu] = sched_in; |
| 1437 | |
| 1438 | printf(" "); |
| 1439 | |
| 1440 | new_shortname = 0; |
| 1441 | if (!sched_in->shortname[0]) { |
| 1442 | sched_in->shortname[0] = next_shortname1; |
| 1443 | sched_in->shortname[1] = next_shortname2; |
| 1444 | |
| 1445 | if (next_shortname1 < 'Z') { |
| 1446 | next_shortname1++; |
| 1447 | } else { |
| 1448 | next_shortname1='A'; |
| 1449 | if (next_shortname2 < '9') { |
| 1450 | next_shortname2++; |
| 1451 | } else { |
| 1452 | next_shortname2='0'; |
| 1453 | } |
| 1454 | } |
| 1455 | new_shortname = 1; |
| 1456 | } |
| 1457 | |
| 1458 | for (cpu = 0; cpu <= max_cpu; cpu++) { |
| 1459 | if (cpu != this_cpu) |
| 1460 | printf(" "); |
| 1461 | else |
| 1462 | printf("*"); |
| 1463 | |
| 1464 | if (curr_thread[cpu]) { |
| 1465 | if (curr_thread[cpu]->pid) |
| 1466 | printf("%2s ", curr_thread[cpu]->shortname); |
| 1467 | else |
| 1468 | printf(". "); |
| 1469 | } else |
| 1470 | printf(" "); |
| 1471 | } |
| 1472 | |
| 1473 | printf(" %12.6f secs ", (double)timestamp/1e9); |
| 1474 | if (new_shortname) { |
| 1475 | printf("%s => %s:%d\n", |
| 1476 | sched_in->shortname, sched_in->comm, sched_in->pid); |
| 1477 | } else { |
| 1478 | printf("\n"); |
| 1479 | } |
| 1480 | } |
| 1481 | |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1482 | static void |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1483 | process_sched_switch_event(struct perf_tool *tool __used, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1484 | struct event_format *event, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1485 | struct perf_sample *sample, |
| 1486 | struct machine *machine, |
| 1487 | struct thread *thread) |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1488 | { |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1489 | int this_cpu = sample->cpu; |
| 1490 | void *data = sample->raw_data; |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1491 | struct trace_switch_event switch_event; |
| 1492 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 1493 | FILL_COMMON_FIELDS(switch_event, event, data); |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1494 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 1495 | FILL_ARRAY(switch_event, prev_comm, event, data); |
| 1496 | FILL_FIELD(switch_event, prev_pid, event, data); |
| 1497 | FILL_FIELD(switch_event, prev_prio, event, data); |
| 1498 | FILL_FIELD(switch_event, prev_state, event, data); |
| 1499 | FILL_ARRAY(switch_event, next_comm, event, data); |
| 1500 | FILL_FIELD(switch_event, next_pid, event, data); |
| 1501 | FILL_FIELD(switch_event, next_prio, event, data); |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1502 | |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1503 | if (curr_pid[this_cpu] != (u32)-1) { |
Ingo Molnar | c8a3775 | 2009-09-16 14:07:00 +0200 | [diff] [blame] | 1504 | /* |
| 1505 | * Are we trying to switch away a PID that is |
| 1506 | * not current? |
| 1507 | */ |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1508 | if (curr_pid[this_cpu] != switch_event.prev_pid) |
Ingo Molnar | c8a3775 | 2009-09-16 14:07:00 +0200 | [diff] [blame] | 1509 | nr_context_switch_bugs++; |
| 1510 | } |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1511 | if (trace_handler->switch_event) |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1512 | trace_handler->switch_event(&switch_event, machine, event, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1513 | this_cpu, sample->time, thread); |
Ingo Molnar | c8a3775 | 2009-09-16 14:07:00 +0200 | [diff] [blame] | 1514 | |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1515 | curr_pid[this_cpu] = switch_event.next_pid; |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | static void |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1519 | process_sched_runtime_event(struct perf_tool *tool __used, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1520 | struct event_format *event, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1521 | struct perf_sample *sample, |
| 1522 | struct machine *machine, |
| 1523 | struct thread *thread) |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1524 | { |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1525 | void *data = sample->raw_data; |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1526 | struct trace_runtime_event runtime_event; |
| 1527 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 1528 | FILL_ARRAY(runtime_event, comm, event, data); |
| 1529 | FILL_FIELD(runtime_event, pid, event, data); |
| 1530 | FILL_FIELD(runtime_event, runtime, event, data); |
| 1531 | FILL_FIELD(runtime_event, vruntime, event, data); |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1532 | |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1533 | if (trace_handler->runtime_event) |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1534 | trace_handler->runtime_event(&runtime_event, machine, event, |
| 1535 | sample->cpu, sample->time, thread); |
mingo | 39aeb52 | 2009-09-14 20:04:48 +0200 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | static void |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1539 | process_sched_fork_event(struct perf_tool *tool __used, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1540 | struct event_format *event, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1541 | struct perf_sample *sample, |
| 1542 | struct machine *machine __used, |
| 1543 | struct thread *thread) |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1544 | { |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1545 | void *data = sample->raw_data; |
Frederic Weisbecker | 4653881 | 2009-09-12 02:43:45 +0200 | [diff] [blame] | 1546 | struct trace_fork_event fork_event; |
| 1547 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 1548 | FILL_COMMON_FIELDS(fork_event, event, data); |
Frederic Weisbecker | 4653881 | 2009-09-12 02:43:45 +0200 | [diff] [blame] | 1549 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 1550 | FILL_ARRAY(fork_event, parent_comm, event, data); |
| 1551 | FILL_FIELD(fork_event, parent_pid, event, data); |
| 1552 | FILL_ARRAY(fork_event, child_comm, event, data); |
| 1553 | FILL_FIELD(fork_event, child_pid, event, data); |
Frederic Weisbecker | 4653881 | 2009-09-12 02:43:45 +0200 | [diff] [blame] | 1554 | |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1555 | if (trace_handler->fork_event) |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 1556 | trace_handler->fork_event(&fork_event, event, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1557 | sample->cpu, sample->time, thread); |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1558 | } |
| 1559 | |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1560 | static void |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1561 | process_sched_exit_event(struct perf_tool *tool __used, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1562 | struct event_format *event, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1563 | struct perf_sample *sample __used, |
| 1564 | struct machine *machine __used, |
Frederic Weisbecker | 419ab0d | 2009-09-12 03:59:01 +0200 | [diff] [blame] | 1565 | struct thread *thread __used) |
Ingo Molnar | fbf9482 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1566 | { |
Ingo Molnar | ad236fd | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1567 | if (verbose) |
| 1568 | printf("sched_exit event %p\n", event); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static void |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1572 | process_sched_migrate_task_event(struct perf_tool *tool __used, |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1573 | struct event_format *event, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1574 | struct perf_sample *sample, |
| 1575 | struct machine *machine, |
| 1576 | struct thread *thread) |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1577 | { |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1578 | void *data = sample->raw_data; |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1579 | struct trace_migrate_task_event migrate_task_event; |
| 1580 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 1581 | FILL_COMMON_FIELDS(migrate_task_event, event, data); |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1582 | |
Xiao Guangrong | f48f669 | 2009-12-07 13:04:04 +0800 | [diff] [blame] | 1583 | FILL_ARRAY(migrate_task_event, comm, event, data); |
| 1584 | FILL_FIELD(migrate_task_event, pid, event, data); |
| 1585 | FILL_FIELD(migrate_task_event, prio, event, data); |
| 1586 | FILL_FIELD(migrate_task_event, cpu, event, data); |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1587 | |
| 1588 | if (trace_handler->migrate_task_event) |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 1589 | trace_handler->migrate_task_event(&migrate_task_event, machine, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1590 | event, sample->cpu, |
| 1591 | sample->time, thread); |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1592 | } |
| 1593 | |
Steven Rostedt | aaf045f | 2012-04-06 00:47:56 +0200 | [diff] [blame] | 1594 | typedef void (*tracepoint_handler)(struct perf_tool *tool, struct event_format *event, |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1595 | struct perf_sample *sample, |
| 1596 | struct machine *machine, |
| 1597 | struct thread *thread); |
| 1598 | |
| 1599 | static int perf_sched__process_tracepoint_sample(struct perf_tool *tool, |
| 1600 | union perf_event *event __used, |
| 1601 | struct perf_sample *sample, |
| 1602 | struct perf_evsel *evsel, |
| 1603 | struct machine *machine) |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1604 | { |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 1605 | struct perf_sched *sched = container_of(tool, struct perf_sched, tool); |
| 1606 | struct pevent *pevent = sched->session->pevent; |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1607 | struct thread *thread = machine__findnew_thread(machine, sample->pid); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1608 | |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1609 | if (thread == NULL) { |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1610 | pr_debug("problem processing %s event, skipping it.\n", |
Arnaldo Carvalho de Melo | 22c8b84 | 2012-06-12 13:55:13 -0300 | [diff] [blame] | 1611 | perf_evsel__name(evsel)); |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1612 | return -1; |
| 1613 | } |
| 1614 | |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1615 | evsel->hists.stats.total_period += sample->period; |
| 1616 | hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); |
Julia Lawall | f39cdf2 | 2009-10-17 08:43:17 +0200 | [diff] [blame] | 1617 | |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1618 | if (evsel->handler.func != NULL) { |
| 1619 | tracepoint_handler f = evsel->handler.func; |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1620 | |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1621 | if (evsel->handler.data == NULL) |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 1622 | evsel->handler.data = pevent_find_event(pevent, |
| 1623 | evsel->attr.config); |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1624 | |
| 1625 | f(tool, evsel->handler.data, sample, machine, thread); |
| 1626 | } |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1627 | |
| 1628 | return 0; |
| 1629 | } |
| 1630 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 1631 | static struct perf_sched perf_sched = { |
| 1632 | .tool = { |
| 1633 | .sample = perf_sched__process_tracepoint_sample, |
| 1634 | .comm = perf_event__process_comm, |
| 1635 | .lost = perf_event__process_lost, |
| 1636 | .fork = perf_event__process_task, |
| 1637 | .ordered_samples = true, |
| 1638 | }, |
Frederic Weisbecker | 016e92f | 2009-10-07 12:47:31 +0200 | [diff] [blame] | 1639 | }; |
| 1640 | |
Jiri Olsa | 4c09baf | 2011-08-08 23:03:34 +0200 | [diff] [blame] | 1641 | static void read_events(bool destroy, struct perf_session **psession) |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1642 | { |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1643 | int err = -EINVAL; |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1644 | const struct perf_evsel_str_handler handlers[] = { |
| 1645 | { "sched:sched_switch", process_sched_switch_event, }, |
| 1646 | { "sched:sched_stat_runtime", process_sched_runtime_event, }, |
| 1647 | { "sched:sched_wakeup", process_sched_wakeup_event, }, |
| 1648 | { "sched:sched_wakeup_new", process_sched_wakeup_event, }, |
| 1649 | { "sched:sched_process_fork", process_sched_fork_event, }, |
| 1650 | { "sched:sched_process_exit", process_sched_exit_event, }, |
| 1651 | { "sched:sched_migrate_task", process_sched_migrate_task_event, }, |
| 1652 | }; |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 1653 | struct perf_session *session; |
| 1654 | |
| 1655 | session = perf_session__new(input_name, O_RDONLY, 0, false, |
| 1656 | &perf_sched.tool); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 1657 | if (session == NULL) |
Jiri Olsa | 4c09baf | 2011-08-08 23:03:34 +0200 | [diff] [blame] | 1658 | die("No Memory"); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 1659 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 1660 | perf_sched.session = session; |
| 1661 | |
| 1662 | err = perf_session__set_tracepoints_handlers(session, handlers); |
Arnaldo Carvalho de Melo | ee29be6 | 2011-11-28 17:57:40 -0200 | [diff] [blame] | 1663 | assert(err == 0); |
| 1664 | |
Arnaldo Carvalho de Melo | cee75ac | 2010-05-14 13:16:55 -0300 | [diff] [blame] | 1665 | if (perf_session__has_traces(session, "record -R")) { |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 1666 | err = perf_session__process_events(session, &perf_sched.tool); |
Jiri Olsa | 4c09baf | 2011-08-08 23:03:34 +0200 | [diff] [blame] | 1667 | if (err) |
| 1668 | die("Failed to process events, error %d", err); |
| 1669 | |
Arnaldo Carvalho de Melo | cee75ac | 2010-05-14 13:16:55 -0300 | [diff] [blame] | 1670 | nr_events = session->hists.stats.nr_events[0]; |
| 1671 | nr_lost_events = session->hists.stats.total_lost; |
| 1672 | nr_lost_chunks = session->hists.stats.nr_events[PERF_RECORD_LOST]; |
| 1673 | } |
Arnaldo Carvalho de Melo | d549c769 | 2009-12-27 21:37:02 -0200 | [diff] [blame] | 1674 | |
Jiri Olsa | 4c09baf | 2011-08-08 23:03:34 +0200 | [diff] [blame] | 1675 | if (destroy) |
| 1676 | perf_session__delete(session); |
| 1677 | |
| 1678 | if (psession) |
| 1679 | *psession = session; |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1680 | } |
| 1681 | |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1682 | static void print_bad_events(void) |
| 1683 | { |
| 1684 | if (nr_unordered_timestamps && nr_timestamps) { |
| 1685 | printf(" INFO: %.3f%% unordered timestamps (%ld out of %ld)\n", |
| 1686 | (double)nr_unordered_timestamps/(double)nr_timestamps*100.0, |
| 1687 | nr_unordered_timestamps, nr_timestamps); |
| 1688 | } |
| 1689 | if (nr_lost_events && nr_events) { |
| 1690 | printf(" INFO: %.3f%% lost events (%ld out of %ld, in %ld chunks)\n", |
| 1691 | (double)nr_lost_events/(double)nr_events*100.0, |
| 1692 | nr_lost_events, nr_events, nr_lost_chunks); |
| 1693 | } |
| 1694 | if (nr_state_machine_bugs && nr_timestamps) { |
| 1695 | printf(" INFO: %.3f%% state machine bugs (%ld out of %ld)", |
| 1696 | (double)nr_state_machine_bugs/(double)nr_timestamps*100.0, |
| 1697 | nr_state_machine_bugs, nr_timestamps); |
| 1698 | if (nr_lost_events) |
| 1699 | printf(" (due to lost events?)"); |
| 1700 | printf("\n"); |
| 1701 | } |
| 1702 | if (nr_context_switch_bugs && nr_timestamps) { |
| 1703 | printf(" INFO: %.3f%% context switch bugs (%ld out of %ld)", |
| 1704 | (double)nr_context_switch_bugs/(double)nr_timestamps*100.0, |
| 1705 | nr_context_switch_bugs, nr_timestamps); |
| 1706 | if (nr_lost_events) |
| 1707 | printf(" (due to lost events?)"); |
| 1708 | printf("\n"); |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | static void __cmd_lat(void) |
| 1713 | { |
| 1714 | struct rb_node *next; |
Jiri Olsa | 4c09baf | 2011-08-08 23:03:34 +0200 | [diff] [blame] | 1715 | struct perf_session *session; |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1716 | |
| 1717 | setup_pager(); |
Jiri Olsa | 4c09baf | 2011-08-08 23:03:34 +0200 | [diff] [blame] | 1718 | read_events(false, &session); |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1719 | sort_lat(); |
| 1720 | |
Frederic Weisbecker | 3786310a | 2009-12-09 21:40:08 +0100 | [diff] [blame] | 1721 | printf("\n ---------------------------------------------------------------------------------------------------------------\n"); |
| 1722 | printf(" Task | Runtime ms | Switches | Average delay ms | Maximum delay ms | Maximum delay at |\n"); |
| 1723 | printf(" ---------------------------------------------------------------------------------------------------------------\n"); |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1724 | |
| 1725 | next = rb_first(&sorted_atom_root); |
| 1726 | |
| 1727 | while (next) { |
| 1728 | struct work_atoms *work_list; |
| 1729 | |
| 1730 | work_list = rb_entry(next, struct work_atoms, node); |
| 1731 | output_lat_thread(work_list); |
| 1732 | next = rb_next(next); |
| 1733 | } |
| 1734 | |
| 1735 | printf(" -----------------------------------------------------------------------------------------\n"); |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 1736 | printf(" TOTAL: |%11.3f ms |%9" PRIu64 " |\n", |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1737 | (double)all_runtime/1e6, all_count); |
| 1738 | |
| 1739 | printf(" ---------------------------------------------------\n"); |
| 1740 | |
| 1741 | print_bad_events(); |
| 1742 | printf("\n"); |
| 1743 | |
Jiri Olsa | 4c09baf | 2011-08-08 23:03:34 +0200 | [diff] [blame] | 1744 | perf_session__delete(session); |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | static struct trace_sched_handler map_ops = { |
| 1748 | .wakeup_event = NULL, |
| 1749 | .switch_event = map_switch_event, |
| 1750 | .runtime_event = NULL, |
| 1751 | .fork_event = NULL, |
| 1752 | }; |
| 1753 | |
| 1754 | static void __cmd_map(void) |
| 1755 | { |
Ingo Molnar | 40749d0 | 2009-09-17 18:24:55 +0200 | [diff] [blame] | 1756 | max_cpu = sysconf(_SC_NPROCESSORS_CONF); |
| 1757 | |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1758 | setup_pager(); |
Jiri Olsa | 4c09baf | 2011-08-08 23:03:34 +0200 | [diff] [blame] | 1759 | read_events(true, NULL); |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1760 | print_bad_events(); |
| 1761 | } |
| 1762 | |
| 1763 | static void __cmd_replay(void) |
| 1764 | { |
| 1765 | unsigned long i; |
| 1766 | |
| 1767 | calibrate_run_measurement_overhead(); |
| 1768 | calibrate_sleep_measurement_overhead(); |
| 1769 | |
| 1770 | test_calibrations(); |
| 1771 | |
Jiri Olsa | 4c09baf | 2011-08-08 23:03:34 +0200 | [diff] [blame] | 1772 | read_events(true, NULL); |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1773 | |
| 1774 | printf("nr_run_events: %ld\n", nr_run_events); |
| 1775 | printf("nr_sleep_events: %ld\n", nr_sleep_events); |
| 1776 | printf("nr_wakeup_events: %ld\n", nr_wakeup_events); |
| 1777 | |
| 1778 | if (targetless_wakeups) |
| 1779 | printf("target-less wakeups: %ld\n", targetless_wakeups); |
| 1780 | if (multitarget_wakeups) |
| 1781 | printf("multi-target wakeups: %ld\n", multitarget_wakeups); |
| 1782 | if (nr_run_events_optimized) |
| 1783 | printf("run atoms optimized: %ld\n", |
| 1784 | nr_run_events_optimized); |
| 1785 | |
| 1786 | print_task_traces(); |
| 1787 | add_cross_task_wakeups(); |
| 1788 | |
| 1789 | create_tasks(); |
| 1790 | printf("------------------------------------------------------------\n"); |
| 1791 | for (i = 0; i < replay_repeat; i++) |
| 1792 | run_one_test(); |
| 1793 | } |
| 1794 | |
| 1795 | |
Ingo Molnar | 46f392c | 2009-09-12 10:08:34 +0200 | [diff] [blame] | 1796 | static const char * const sched_usage[] = { |
Jiri Olsa | 580cabe | 2011-08-09 14:46:51 +0200 | [diff] [blame] | 1797 | "perf sched [<options>] {record|latency|map|replay|script}", |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1798 | NULL |
| 1799 | }; |
| 1800 | |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1801 | static const struct option sched_options[] = { |
Mike Galbraith | 4b77a72 | 2009-09-18 08:22:24 +0200 | [diff] [blame] | 1802 | OPT_STRING('i', "input", &input_name, "file", |
| 1803 | "input file name"), |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 1804 | OPT_INCR('v', "verbose", &verbose, |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1805 | "be more verbose (show symbol address, etc)"), |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1806 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 1807 | "dump raw trace in ASCII"), |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1808 | OPT_END() |
| 1809 | }; |
| 1810 | |
| 1811 | static const char * const latency_usage[] = { |
| 1812 | "perf sched latency [<options>]", |
| 1813 | NULL |
| 1814 | }; |
| 1815 | |
| 1816 | static const struct option latency_options[] = { |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1817 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", |
| 1818 | "sort by key(s): runtime, switch, avg, max"), |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 1819 | OPT_INCR('v', "verbose", &verbose, |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1820 | "be more verbose (show symbol address, etc)"), |
Mike Galbraith | 55ffb7a | 2009-10-10 14:46:04 +0200 | [diff] [blame] | 1821 | OPT_INTEGER('C', "CPU", &profile_cpu, |
| 1822 | "CPU to profile on"), |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1823 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 1824 | "dump raw trace in ASCII"), |
| 1825 | OPT_END() |
| 1826 | }; |
| 1827 | |
| 1828 | static const char * const replay_usage[] = { |
| 1829 | "perf sched replay [<options>]", |
| 1830 | NULL |
| 1831 | }; |
| 1832 | |
| 1833 | static const struct option replay_options[] = { |
Arnaldo Carvalho de Melo | 1967936 | 2010-05-17 15:39:16 -0300 | [diff] [blame] | 1834 | OPT_UINTEGER('r', "repeat", &replay_repeat, |
| 1835 | "repeat the workload replay N times (-1: infinite)"), |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 1836 | OPT_INCR('v', "verbose", &verbose, |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1837 | "be more verbose (show symbol address, etc)"), |
| 1838 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 1839 | "dump raw trace in ASCII"), |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1840 | OPT_END() |
| 1841 | }; |
| 1842 | |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1843 | static void setup_sorting(void) |
| 1844 | { |
| 1845 | char *tmp, *tok, *str = strdup(sort_order); |
| 1846 | |
| 1847 | for (tok = strtok_r(str, ", ", &tmp); |
| 1848 | tok; tok = strtok_r(NULL, ", ", &tmp)) { |
| 1849 | if (sort_dimension__add(tok, &sort_list) < 0) { |
| 1850 | error("Unknown --sort key: `%s'", tok); |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1851 | usage_with_options(latency_usage, latency_options); |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | free(str); |
| 1856 | |
Randy Dunlap | cbef79a | 2009-10-05 13:17:29 -0700 | [diff] [blame] | 1857 | sort_dimension__add("pid", &cmp_pid); |
Frederic Weisbecker | daa1d7a | 2009-09-13 03:36:29 +0200 | [diff] [blame] | 1858 | } |
| 1859 | |
Ingo Molnar | 1fc35b2 | 2009-09-13 09:44:29 +0200 | [diff] [blame] | 1860 | static const char *record_args[] = { |
| 1861 | "record", |
| 1862 | "-a", |
| 1863 | "-R", |
Ingo Molnar | ea57c4f | 2009-09-13 18:15:54 +0200 | [diff] [blame] | 1864 | "-f", |
Ingo Molnar | dc02bf7 | 2009-09-16 13:45:00 +0200 | [diff] [blame] | 1865 | "-m", "1024", |
Ingo Molnar | 1fc35b2 | 2009-09-13 09:44:29 +0200 | [diff] [blame] | 1866 | "-c", "1", |
Stephane Eranian | 9710118 | 2011-01-12 10:29:05 +0100 | [diff] [blame] | 1867 | "-e", "sched:sched_switch", |
| 1868 | "-e", "sched:sched_stat_wait", |
| 1869 | "-e", "sched:sched_stat_sleep", |
| 1870 | "-e", "sched:sched_stat_iowait", |
| 1871 | "-e", "sched:sched_stat_runtime", |
| 1872 | "-e", "sched:sched_process_exit", |
| 1873 | "-e", "sched:sched_process_fork", |
| 1874 | "-e", "sched:sched_wakeup", |
| 1875 | "-e", "sched:sched_migrate_task", |
Ingo Molnar | 1fc35b2 | 2009-09-13 09:44:29 +0200 | [diff] [blame] | 1876 | }; |
| 1877 | |
| 1878 | static int __cmd_record(int argc, const char **argv) |
| 1879 | { |
| 1880 | unsigned int rec_argc, i, j; |
| 1881 | const char **rec_argv; |
| 1882 | |
| 1883 | rec_argc = ARRAY_SIZE(record_args) + argc - 1; |
| 1884 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 1885 | |
Arnaldo Carvalho de Melo | e462dc5 | 2011-01-10 10:48:47 -0200 | [diff] [blame] | 1886 | if (rec_argv == NULL) |
Chris Samuel | ce47dc5 | 2010-11-13 13:35:06 +1100 | [diff] [blame] | 1887 | return -ENOMEM; |
| 1888 | |
Ingo Molnar | 1fc35b2 | 2009-09-13 09:44:29 +0200 | [diff] [blame] | 1889 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
| 1890 | rec_argv[i] = strdup(record_args[i]); |
| 1891 | |
| 1892 | for (j = 1; j < (unsigned int)argc; j++, i++) |
| 1893 | rec_argv[i] = argv[j]; |
| 1894 | |
| 1895 | BUG_ON(i != rec_argc); |
| 1896 | |
| 1897 | return cmd_record(i, rec_argv, NULL); |
| 1898 | } |
| 1899 | |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1900 | int cmd_sched(int argc, const char **argv, const char *prefix __used) |
| 1901 | { |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1902 | argc = parse_options(argc, argv, sched_options, sched_usage, |
| 1903 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 1904 | if (!argc) |
| 1905 | usage_with_options(sched_usage, sched_options); |
| 1906 | |
Xiao Guangrong | c0777c5 | 2009-12-07 12:04:49 +0800 | [diff] [blame] | 1907 | /* |
Ingo Molnar | 133dc4c | 2010-11-16 18:45:39 +0100 | [diff] [blame] | 1908 | * Aliased to 'perf script' for now: |
Xiao Guangrong | c0777c5 | 2009-12-07 12:04:49 +0800 | [diff] [blame] | 1909 | */ |
Ingo Molnar | 133dc4c | 2010-11-16 18:45:39 +0100 | [diff] [blame] | 1910 | if (!strcmp(argv[0], "script")) |
| 1911 | return cmd_script(argc, argv, prefix); |
Xiao Guangrong | c0777c5 | 2009-12-07 12:04:49 +0800 | [diff] [blame] | 1912 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 1913 | symbol__init(); |
Ingo Molnar | 1fc35b2 | 2009-09-13 09:44:29 +0200 | [diff] [blame] | 1914 | if (!strncmp(argv[0], "rec", 3)) { |
| 1915 | return __cmd_record(argc, argv); |
| 1916 | } else if (!strncmp(argv[0], "lat", 3)) { |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1917 | trace_handler = &lat_ops; |
| 1918 | if (argc > 1) { |
| 1919 | argc = parse_options(argc, argv, latency_options, latency_usage, 0); |
| 1920 | if (argc) |
| 1921 | usage_with_options(latency_usage, latency_options); |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1922 | } |
Ingo Molnar | b5fae12 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1923 | setup_sorting(); |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1924 | __cmd_lat(); |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 1925 | } else if (!strcmp(argv[0], "map")) { |
| 1926 | trace_handler = &map_ops; |
| 1927 | setup_sorting(); |
| 1928 | __cmd_map(); |
Ingo Molnar | f2858d8 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1929 | } else if (!strncmp(argv[0], "rep", 3)) { |
| 1930 | trace_handler = &replay_ops; |
| 1931 | if (argc) { |
| 1932 | argc = parse_options(argc, argv, replay_options, replay_usage, 0); |
| 1933 | if (argc) |
| 1934 | usage_with_options(replay_usage, replay_options); |
| 1935 | } |
| 1936 | __cmd_replay(); |
| 1937 | } else { |
| 1938 | usage_with_options(sched_usage, sched_options); |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1939 | } |
| 1940 | |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1941 | return 0; |
Ingo Molnar | 0a02ad9 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 1942 | } |