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