Lines Matching +full:min +full:- +full:sample +full:- +full:time +full:- +full:nsecs
1 // SPDX-License-Identifier: GPL-2.0
4 #include "perf-sys.h"
22 #include "util/time-utils.h"
25 #include <subcmd/parse-options.h>
26 #include "util/trace-event.h"
129 struct perf_sample *sample, struct machine *machine);
132 struct perf_sample *sample, struct machine *machine);
135 struct perf_sample *sample, struct machine *machine);
143 struct perf_sample *sample,
176 * Track the current task - that way we can know whether there's any
241 /* per thread run time data */
243 u64 last_time; /* time of previous sched in/out event */
244 u64 dt_run; /* run time */
245 u64 dt_sleep; /* time between CPU access by sleep (off cpu) */
246 u64 dt_iowait; /* time between CPU access by iowait (off cpu) */
247 u64 dt_preempt; /* time between CPU access by preempt (off cpu) */
248 u64 dt_delay; /* time between wakeup and sched-in */
249 u64 dt_pre_mig; /* time between migration and wakeup */
250 u64 ready_to_run; /* time of wakeup */
251 u64 migrated; /* time when a thread is migrated */
271 /* per event run time data */
273 u64 *last_time; /* time this event was last seen per cpu */
277 /* per cpu idle time data */
300 static void burn_nsecs(struct perf_sched *sched, u64 nsecs) in burn_nsecs() argument
306 } while (T1 + sched->run_measurement_overhead < T0 + nsecs); in burn_nsecs()
309 static void sleep_nsecs(u64 nsecs) in sleep_nsecs() argument
313 ts.tv_nsec = nsecs % 999999999; in sleep_nsecs()
314 ts.tv_sec = nsecs / 999999999; in sleep_nsecs()
328 delta = T1-T0; in calibrate_run_measurement_overhead()
329 min_delta = min(min_delta, delta); in calibrate_run_measurement_overhead()
331 sched->run_measurement_overhead = min_delta; in calibrate_run_measurement_overhead()
333 printf("run measurement overhead: %" PRIu64 " nsecs\n", min_delta); in calibrate_run_measurement_overhead()
345 delta = T1-T0; in calibrate_sleep_measurement_overhead()
346 min_delta = min(min_delta, delta); in calibrate_sleep_measurement_overhead()
348 min_delta -= 10000; in calibrate_sleep_measurement_overhead()
349 sched->sleep_measurement_overhead = min_delta; in calibrate_sleep_measurement_overhead()
351 printf("sleep measurement overhead: %" PRIu64 " nsecs\n", min_delta); in calibrate_sleep_measurement_overhead()
358 unsigned long idx = task->nr_events; in get_new_event()
361 event->timestamp = timestamp; in get_new_event()
362 event->nr = idx; in get_new_event()
364 task->nr_events++; in get_new_event()
365 size = sizeof(struct sched_atom *) * task->nr_events; in get_new_event()
366 task->atoms = realloc(task->atoms, size); in get_new_event()
367 BUG_ON(!task->atoms); in get_new_event()
369 task->atoms[idx] = event; in get_new_event()
376 if (!task->nr_events) in last_event()
379 return task->atoms[task->nr_events - 1]; in last_event()
391 if (curr_event && curr_event->type == SCHED_EVENT_RUN) { in add_sched_event_run()
392 sched->nr_run_events_optimized++; in add_sched_event_run()
393 curr_event->duration += duration; in add_sched_event_run()
399 event->type = SCHED_EVENT_RUN; in add_sched_event_run()
400 event->duration = duration; in add_sched_event_run()
402 sched->nr_run_events++; in add_sched_event_run()
411 event->type = SCHED_EVENT_WAKEUP; in add_sched_event_wakeup()
412 event->wakee = wakee; in add_sched_event_wakeup()
415 if (!wakee_event || wakee_event->type != SCHED_EVENT_SLEEP) { in add_sched_event_wakeup()
416 sched->targetless_wakeups++; in add_sched_event_wakeup()
419 if (wakee_event->wait_sem) { in add_sched_event_wakeup()
420 sched->multitarget_wakeups++; in add_sched_event_wakeup()
424 wakee_event->wait_sem = zalloc(sizeof(*wakee_event->wait_sem)); in add_sched_event_wakeup()
425 sem_init(wakee_event->wait_sem, 0, 0); in add_sched_event_wakeup()
426 event->wait_sem = wakee_event->wait_sem; in add_sched_event_wakeup()
428 sched->nr_wakeup_events++; in add_sched_event_wakeup()
436 event->type = SCHED_EVENT_SLEEP; in add_sched_event_sleep()
438 sched->nr_sleep_events++; in add_sched_event_sleep()
447 if (sched->pid_to_task == NULL) { in register_pid()
450 BUG_ON((sched->pid_to_task = calloc(pid_max, sizeof(struct task_desc *))) == NULL); in register_pid()
453 BUG_ON((sched->pid_to_task = realloc(sched->pid_to_task, (pid + 1) * in register_pid()
456 sched->pid_to_task[pid_max++] = NULL; in register_pid()
459 task = sched->pid_to_task[pid]; in register_pid()
465 task->pid = pid; in register_pid()
466 task->nr = sched->nr_tasks; in register_pid()
467 strcpy(task->comm, comm); in register_pid()
469 * every task starts in sleeping state - this gets ignored in register_pid()
474 sched->pid_to_task[pid] = task; in register_pid()
475 sched->nr_tasks++; in register_pid()
476 sched->tasks = realloc(sched->tasks, sched->nr_tasks * sizeof(struct task_desc *)); in register_pid()
477 BUG_ON(!sched->tasks); in register_pid()
478 sched->tasks[task->nr] = task; in register_pid()
481 printf("registered task #%ld, PID %ld (%s)\n", sched->nr_tasks, pid, comm); in register_pid()
492 for (i = 0; i < sched->nr_tasks; i++) { in print_task_traces()
493 task = sched->tasks[i]; in print_task_traces()
495 task->nr, task->comm, task->pid, task->nr_events); in print_task_traces()
504 for (i = 0; i < sched->nr_tasks; i++) { in add_cross_task_wakeups()
505 task1 = sched->tasks[i]; in add_cross_task_wakeups()
507 if (j == sched->nr_tasks) in add_cross_task_wakeups()
509 task2 = sched->tasks[j]; in add_cross_task_wakeups()
519 switch (atom->type) { in perf_sched__process_event()
521 burn_nsecs(sched, atom->duration); in perf_sched__process_event()
524 if (atom->wait_sem) in perf_sched__process_event()
525 ret = sem_wait(atom->wait_sem); in perf_sched__process_event()
529 if (atom->wait_sem) in perf_sched__process_event()
530 ret = sem_post(atom->wait_sem); in perf_sched__process_event()
567 fd = sys_perf_event_open(&attr, 0, -1, -1, in self_open_counters()
572 if (sched->force) { in self_open_counters()
573 BUG_ON(getrlimit(RLIMIT_NOFILE, &limit) == -1); in self_open_counters()
574 limit.rlim_cur += sched->nr_tasks - cur_task; in self_open_counters()
579 if (setrlimit(RLIMIT_NOFILE, &limit) == -1) { in self_open_counters()
585 strcpy(info, "Have a try with -f option\n"); in self_open_counters()
615 struct task_desc *this_task = parms->task; in thread_func()
616 struct perf_sched *sched = parms->sched; in thread_func()
620 int fd = parms->fd; in thread_func()
624 sprintf(comm2, ":%s", this_task->comm); in thread_func()
629 while (!sched->thread_funcs_exit) { in thread_func()
630 ret = sem_post(&this_task->ready_for_work); in thread_func()
632 mutex_lock(&sched->start_work_mutex); in thread_func()
633 mutex_unlock(&sched->start_work_mutex); in thread_func()
637 for (i = 0; i < this_task->nr_events; i++) { in thread_func()
638 this_task->curr_event = i; in thread_func()
639 perf_sched__process_event(sched, this_task->atoms[i]); in thread_func()
643 this_task->cpu_usage = cpu_usage_1 - cpu_usage_0; in thread_func()
644 ret = sem_post(&this_task->work_done_sem); in thread_func()
647 mutex_lock(&sched->work_done_wait_mutex); in thread_func()
648 mutex_unlock(&sched->work_done_wait_mutex); in thread_func()
654 EXCLUSIVE_LOCK_FUNCTION(sched->start_work_mutex) in create_tasks()
655 EXCLUSIVE_LOCK_FUNCTION(sched->work_done_wait_mutex) in create_tasks()
667 mutex_lock(&sched->start_work_mutex); in create_tasks()
668 mutex_lock(&sched->work_done_wait_mutex); in create_tasks()
669 for (i = 0; i < sched->nr_tasks; i++) { in create_tasks()
672 parms->task = task = sched->tasks[i]; in create_tasks()
673 parms->sched = sched; in create_tasks()
674 parms->fd = self_open_counters(sched, i); in create_tasks()
675 sem_init(&task->ready_for_work, 0, 0); in create_tasks()
676 sem_init(&task->work_done_sem, 0, 0); in create_tasks()
677 task->curr_event = 0; in create_tasks()
678 err = pthread_create(&task->thread, &attr, thread_func, parms); in create_tasks()
684 UNLOCK_FUNCTION(sched->start_work_mutex) in destroy_tasks()
685 UNLOCK_FUNCTION(sched->work_done_wait_mutex) in destroy_tasks()
691 mutex_unlock(&sched->start_work_mutex); in destroy_tasks()
692 mutex_unlock(&sched->work_done_wait_mutex); in destroy_tasks()
694 for (i = 0; i < sched->nr_tasks; i++) { in destroy_tasks()
695 task = sched->tasks[i]; in destroy_tasks()
696 err = pthread_join(task->thread, NULL); in destroy_tasks()
698 sem_destroy(&task->ready_for_work); in destroy_tasks()
699 sem_destroy(&task->work_done_sem); in destroy_tasks()
704 EXCLUSIVE_LOCKS_REQUIRED(sched->work_done_wait_mutex) in wait_for_tasks()
705 EXCLUSIVE_LOCKS_REQUIRED(sched->start_work_mutex) in wait_for_tasks()
711 sched->start_time = get_nsecs(); in wait_for_tasks()
712 sched->cpu_usage = 0; in wait_for_tasks()
713 mutex_unlock(&sched->work_done_wait_mutex); in wait_for_tasks()
715 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
716 task = sched->tasks[i]; in wait_for_tasks()
717 ret = sem_wait(&task->ready_for_work); in wait_for_tasks()
719 sem_init(&task->ready_for_work, 0, 0); in wait_for_tasks()
721 mutex_lock(&sched->work_done_wait_mutex); in wait_for_tasks()
725 mutex_unlock(&sched->start_work_mutex); in wait_for_tasks()
727 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
728 task = sched->tasks[i]; in wait_for_tasks()
729 ret = sem_wait(&task->work_done_sem); in wait_for_tasks()
731 sem_init(&task->work_done_sem, 0, 0); in wait_for_tasks()
732 sched->cpu_usage += task->cpu_usage; in wait_for_tasks()
733 task->cpu_usage = 0; in wait_for_tasks()
737 if (!sched->runavg_cpu_usage) in wait_for_tasks()
738 sched->runavg_cpu_usage = sched->cpu_usage; in wait_for_tasks()
739 …sched->runavg_cpu_usage = (sched->runavg_cpu_usage * (sched->replay_repeat - 1) + sched->cpu_usage… in wait_for_tasks()
741 sched->parent_cpu_usage = cpu_usage_1 - cpu_usage_0; in wait_for_tasks()
742 if (!sched->runavg_parent_cpu_usage) in wait_for_tasks()
743 sched->runavg_parent_cpu_usage = sched->parent_cpu_usage; in wait_for_tasks()
744 sched->runavg_parent_cpu_usage = (sched->runavg_parent_cpu_usage * (sched->replay_repeat - 1) + in wait_for_tasks()
745 sched->parent_cpu_usage)/sched->replay_repeat; in wait_for_tasks()
747 mutex_lock(&sched->start_work_mutex); in wait_for_tasks()
749 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
750 task = sched->tasks[i]; in wait_for_tasks()
751 task->curr_event = 0; in wait_for_tasks()
756 EXCLUSIVE_LOCKS_REQUIRED(sched->work_done_wait_mutex) in run_one_test()
757 EXCLUSIVE_LOCKS_REQUIRED(sched->start_work_mutex) in run_one_test()
765 delta = T1 - T0; in run_one_test()
766 sched->sum_runtime += delta; in run_one_test()
767 sched->nr_runs++; in run_one_test()
769 avg_delta = sched->sum_runtime / sched->nr_runs; in run_one_test()
771 fluct = avg_delta - delta; in run_one_test()
773 fluct = delta - avg_delta; in run_one_test()
774 sched->sum_fluct += fluct; in run_one_test()
775 if (!sched->run_avg) in run_one_test()
776 sched->run_avg = delta; in run_one_test()
777 sched->run_avg = (sched->run_avg * (sched->replay_repeat - 1) + delta) / sched->replay_repeat; in run_one_test()
779 printf("#%-3ld: %0.3f, ", sched->nr_runs, (double)delta / NSEC_PER_MSEC); in run_one_test()
781 printf("ravg: %0.2f, ", (double)sched->run_avg / NSEC_PER_MSEC); in run_one_test()
784 (double)sched->cpu_usage / NSEC_PER_MSEC, (double)sched->runavg_cpu_usage / NSEC_PER_MSEC); in run_one_test()
789 * accurate than the sched->sum_exec_runtime based statistics: in run_one_test()
792 (double)sched->parent_cpu_usage / NSEC_PER_MSEC, in run_one_test()
793 (double)sched->runavg_parent_cpu_usage / NSEC_PER_MSEC); in run_one_test()
798 if (sched->nr_sleep_corrections) in run_one_test()
799 printf(" (%ld sleep corrections)\n", sched->nr_sleep_corrections); in run_one_test()
800 sched->nr_sleep_corrections = 0; in run_one_test()
811 printf("the run test took %" PRIu64 " nsecs\n", T1 - T0); in test_calibrations()
817 printf("the sleep test took %" PRIu64 " nsecs\n", T1 - T0); in test_calibrations()
822 struct evsel *evsel, struct perf_sample *sample, in replay_wakeup_event() argument
825 const char *comm = evsel__strval(evsel, sample, "comm"); in replay_wakeup_event()
826 const u32 pid = evsel__intval(evsel, sample, "pid"); in replay_wakeup_event()
832 printf(" ... pid %d woke up %s/%d\n", sample->tid, comm, pid); in replay_wakeup_event()
835 waker = register_pid(sched, sample->tid, "<unknown>"); in replay_wakeup_event()
838 add_sched_event_wakeup(sched, waker, sample->time, wakee); in replay_wakeup_event()
844 struct perf_sample *sample, in replay_switch_event() argument
847 const char *prev_comm = evsel__strval(evsel, sample, "prev_comm"), in replay_switch_event()
848 *next_comm = evsel__strval(evsel, sample, "next_comm"); in replay_switch_event()
849 const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), in replay_switch_event()
850 next_pid = evsel__intval(evsel, sample, "next_pid"); in replay_switch_event()
852 u64 timestamp0, timestamp = sample->time; in replay_switch_event()
853 int cpu = sample->cpu; in replay_switch_event()
862 timestamp0 = sched->cpu_last_switched[cpu]; in replay_switch_event()
864 delta = timestamp - timestamp0; in replay_switch_event()
870 return -1; in replay_switch_event()
873 pr_debug(" ... switch from %s/%d to %s/%d [ran %" PRIu64 " nsecs]\n", in replay_switch_event()
879 sched->cpu_last_switched[cpu] = timestamp; in replay_switch_event()
893 child = machine__findnew_thread(machine, event->fork.pid, in replay_fork_event()
894 event->fork.tid); in replay_fork_event()
895 parent = machine__findnew_thread(machine, event->fork.ppid, in replay_fork_event()
896 event->fork.ptid); in replay_fork_event()
926 r->prio = -1; in init_prio()
940 init_stats(&r->run_stats); in thread__init_runtime()
970 ret = sort->cmp(l, r); in thread_lat_cmp()
982 struct rb_node *node = root->rb_root.rb_node; in thread_atoms_search()
993 node = node->rb_left; in thread_atoms_search()
995 node = node->rb_right; in thread_atoms_search()
997 BUG_ON(thread != atoms->thread); in thread_atoms_search()
1008 struct rb_node **new = &(root->rb_root.rb_node), *parent = NULL; in __thread_latency_insert()
1021 new = &((*new)->rb_left); in __thread_latency_insert()
1023 new = &((*new)->rb_right); in __thread_latency_insert()
1028 rb_link_node(&data->node, parent, new); in __thread_latency_insert()
1029 rb_insert_color_cached(&data->node, root, leftmost); in __thread_latency_insert()
1037 return -1; in thread_atoms_insert()
1040 atoms->thread = thread__get(thread); in thread_atoms_insert()
1041 INIT_LIST_HEAD(&atoms->work_list); in thread_atoms_insert()
1042 __thread_latency_insert(&sched->atom_root, atoms, &sched->cmp_pid); in thread_atoms_insert()
1054 return -1; in add_sched_out_event()
1057 atom->sched_out_time = timestamp; in add_sched_out_event()
1060 atom->state = THREAD_WAIT_CPU; in add_sched_out_event()
1061 atom->wake_up_time = atom->sched_out_time; in add_sched_out_event()
1064 list_add_tail(&atom->list, &atoms->work_list); in add_sched_out_event()
1074 BUG_ON(list_empty(&atoms->work_list)); in add_runtime_event()
1076 atom = list_entry(atoms->work_list.prev, struct work_atom, list); in add_runtime_event()
1078 atom->runtime += delta; in add_runtime_event()
1079 atoms->total_runtime += delta; in add_runtime_event()
1088 if (list_empty(&atoms->work_list)) in add_sched_in_event()
1091 atom = list_entry(atoms->work_list.prev, struct work_atom, list); in add_sched_in_event()
1093 if (atom->state != THREAD_WAIT_CPU) in add_sched_in_event()
1096 if (timestamp < atom->wake_up_time) { in add_sched_in_event()
1097 atom->state = THREAD_IGNORE; in add_sched_in_event()
1101 atom->state = THREAD_SCHED_IN; in add_sched_in_event()
1102 atom->sched_in_time = timestamp; in add_sched_in_event()
1104 delta = atom->sched_in_time - atom->wake_up_time; in add_sched_in_event()
1105 atoms->total_lat += delta; in add_sched_in_event()
1106 if (delta > atoms->max_lat) { in add_sched_in_event()
1107 atoms->max_lat = delta; in add_sched_in_event()
1108 atoms->max_lat_start = atom->wake_up_time; in add_sched_in_event()
1109 atoms->max_lat_end = timestamp; in add_sched_in_event()
1111 atoms->nb_atoms++; in add_sched_in_event()
1116 struct perf_sample *sample, in latency_switch_event() argument
1119 const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), in latency_switch_event()
1120 next_pid = evsel__intval(evsel, sample, "next_pid"); in latency_switch_event()
1121 const char prev_state = evsel__taskstate(evsel, sample, "prev_state"); in latency_switch_event()
1124 u64 timestamp0, timestamp = sample->time; in latency_switch_event()
1125 int cpu = sample->cpu, err = -1; in latency_switch_event()
1130 timestamp0 = sched->cpu_last_switched[cpu]; in latency_switch_event()
1131 sched->cpu_last_switched[cpu] = timestamp; in latency_switch_event()
1133 delta = timestamp - timestamp0; in latency_switch_event()
1139 return -1; in latency_switch_event()
1142 sched_out = machine__findnew_thread(machine, -1, prev_pid); in latency_switch_event()
1143 sched_in = machine__findnew_thread(machine, -1, next_pid); in latency_switch_event()
1147 out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid); in latency_switch_event()
1151 out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid); in latency_switch_event()
1153 pr_err("out-event: Internal tree error"); in latency_switch_event()
1158 return -1; in latency_switch_event()
1160 in_events = thread_atoms_search(&sched->atom_root, sched_in, &sched->cmp_pid); in latency_switch_event()
1164 in_events = thread_atoms_search(&sched->atom_root, sched_in, &sched->cmp_pid); in latency_switch_event()
1166 pr_err("in-event: Internal tree error"); in latency_switch_event()
1186 struct perf_sample *sample, in latency_runtime_event() argument
1189 const u32 pid = evsel__intval(evsel, sample, "pid"); in latency_runtime_event()
1190 const u64 runtime = evsel__intval(evsel, sample, "runtime"); in latency_runtime_event()
1191 struct thread *thread = machine__findnew_thread(machine, -1, pid); in latency_runtime_event()
1192 struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); in latency_runtime_event()
1193 u64 timestamp = sample->time; in latency_runtime_event()
1194 int cpu = sample->cpu, err = -1; in latency_runtime_event()
1197 return -1; in latency_runtime_event()
1203 atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); in latency_runtime_event()
1205 pr_err("in-event: Internal tree error"); in latency_runtime_event()
1221 struct perf_sample *sample, in latency_wakeup_event() argument
1224 const u32 pid = evsel__intval(evsel, sample, "pid"); in latency_wakeup_event()
1228 u64 timestamp = sample->time; in latency_wakeup_event()
1229 int err = -1; in latency_wakeup_event()
1231 wakee = machine__findnew_thread(machine, -1, pid); in latency_wakeup_event()
1233 return -1; in latency_wakeup_event()
1234 atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid); in latency_wakeup_event()
1238 atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid); in latency_wakeup_event()
1240 pr_err("wakeup-event: Internal tree error"); in latency_wakeup_event()
1247 BUG_ON(list_empty(&atoms->work_list)); in latency_wakeup_event()
1249 atom = list_entry(atoms->work_list.prev, struct work_atom, list); in latency_wakeup_event()
1254 * on run queue and wakeup only change ->state to TASK_RUNNING, in latency_wakeup_event()
1255 * then we should not set the ->wake_up_time when wake up a in latency_wakeup_event()
1262 if (sched->profile_cpu == -1 && atom->state != THREAD_SLEEPING) in latency_wakeup_event()
1265 sched->nr_timestamps++; in latency_wakeup_event()
1266 if (atom->sched_out_time > timestamp) { in latency_wakeup_event()
1267 sched->nr_unordered_timestamps++; in latency_wakeup_event()
1271 atom->state = THREAD_WAIT_CPU; in latency_wakeup_event()
1272 atom->wake_up_time = timestamp; in latency_wakeup_event()
1282 struct perf_sample *sample, in latency_migrate_task_event() argument
1285 const u32 pid = evsel__intval(evsel, sample, "pid"); in latency_migrate_task_event()
1286 u64 timestamp = sample->time; in latency_migrate_task_event()
1290 int err = -1; in latency_migrate_task_event()
1295 if (sched->profile_cpu == -1) in latency_migrate_task_event()
1298 migrant = machine__findnew_thread(machine, -1, pid); in latency_migrate_task_event()
1300 return -1; in latency_migrate_task_event()
1301 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid); in latency_migrate_task_event()
1306 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid); in latency_migrate_task_event()
1308 pr_err("migration-event: Internal tree error"); in latency_migrate_task_event()
1315 BUG_ON(list_empty(&atoms->work_list)); in latency_migrate_task_event()
1317 atom = list_entry(atoms->work_list.prev, struct work_atom, list); in latency_migrate_task_event()
1318 atom->sched_in_time = atom->sched_out_time = atom->wake_up_time = timestamp; in latency_migrate_task_event()
1320 sched->nr_timestamps++; in latency_migrate_task_event()
1322 if (atom->sched_out_time > timestamp) in latency_migrate_task_event()
1323 sched->nr_unordered_timestamps++; in latency_migrate_task_event()
1337 if (!work_list->nb_atoms) in output_lat_thread()
1342 if (!strcmp(thread__comm_str(work_list->thread), "swapper")) in output_lat_thread()
1345 sched->all_runtime += work_list->total_runtime; in output_lat_thread()
1346 sched->all_count += work_list->nb_atoms; in output_lat_thread()
1348 if (work_list->num_merged > 1) { in output_lat_thread()
1349 ret = printf(" %s:(%d) ", thread__comm_str(work_list->thread), in output_lat_thread()
1350 work_list->num_merged); in output_lat_thread()
1352 ret = printf(" %s:%d ", thread__comm_str(work_list->thread), in output_lat_thread()
1353 thread__tid(work_list->thread)); in output_lat_thread()
1356 for (i = 0; i < 24 - ret; i++) in output_lat_thread()
1359 avg = work_list->total_lat / work_list->nb_atoms; in output_lat_thread()
1360 timestamp__scnprintf_usec(work_list->max_lat_start, max_lat_start, sizeof(max_lat_start)); in output_lat_thread()
1361 timestamp__scnprintf_usec(work_list->max_lat_end, max_lat_end, sizeof(max_lat_end)); in output_lat_thread()
1364 (double)work_list->total_runtime / NSEC_PER_MSEC, in output_lat_thread()
1365 work_list->nb_atoms, (double)avg / NSEC_PER_MSEC, in output_lat_thread()
1366 (double)work_list->max_lat / NSEC_PER_MSEC, in output_lat_thread()
1374 if (RC_CHK_EQUAL(l->thread, r->thread)) in pid_cmp()
1376 l_tid = thread__tid(l->thread); in pid_cmp()
1377 r_tid = thread__tid(r->thread); in pid_cmp()
1379 return -1; in pid_cmp()
1382 return (int)(RC_CHK_ACCESS(l->thread) - RC_CHK_ACCESS(r->thread)); in pid_cmp()
1389 if (!l->nb_atoms) in avg_cmp()
1390 return -1; in avg_cmp()
1392 if (!r->nb_atoms) in avg_cmp()
1395 avgl = l->total_lat / l->nb_atoms; in avg_cmp()
1396 avgr = r->total_lat / r->nb_atoms; in avg_cmp()
1399 return -1; in avg_cmp()
1408 if (l->max_lat < r->max_lat) in max_cmp()
1409 return -1; in max_cmp()
1410 if (l->max_lat > r->max_lat) in max_cmp()
1418 if (l->nb_atoms < r->nb_atoms) in switch_cmp()
1419 return -1; in switch_cmp()
1420 if (l->nb_atoms > r->nb_atoms) in switch_cmp()
1428 if (l->total_runtime < r->total_runtime) in runtime_cmp()
1429 return -1; in runtime_cmp()
1430 if (l->total_runtime > r->total_runtime) in runtime_cmp()
1468 if (!strcmp(available_sorts[i]->name, tok)) { in sort_dimension__add()
1469 list_add_tail(&available_sorts[i]->list, list); in sort_dimension__add()
1475 return -1; in sort_dimension__add()
1481 struct rb_root_cached *root = &sched->atom_root; in perf_sched__sort_lat()
1491 __thread_latency_insert(&sched->sorted_atom_root, data, &sched->sort_list); in perf_sched__sort_lat()
1493 if (root == &sched->atom_root) { in perf_sched__sort_lat()
1494 root = &sched->merged_atom_root; in perf_sched__sort_lat()
1501 struct perf_sample *sample, in process_sched_wakeup_event() argument
1506 if (sched->tp_handler->wakeup_event) in process_sched_wakeup_event()
1507 return sched->tp_handler->wakeup_event(sched, evsel, sample, machine); in process_sched_wakeup_event()
1514 struct perf_sample *sample __maybe_unused, in process_sched_wakeup_ignore()
1542 if (!sched->map.color_pids || !thread || thread__priv(thread)) in map__findnew_thread()
1545 if (thread_map__has(sched->map.color_pids, tid)) in map__findnew_thread()
1554 bool fuzzy_match = sched->map.fuzzy; in sched_match_task()
1555 struct strlist *task_names = sched->map.task_names; in sched_match_task()
1559 bool match_found = fuzzy_match ? !!strstr(comm_str, node->s) : in sched_match_task()
1560 !strcmp(comm_str, node->s); in sched_match_task()
1573 .cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i, in print_sched_map()
1575 struct thread *curr_thread = sched->curr_thread[cpu.cpu]; in print_sched_map()
1576 struct thread *curr_out_thread = sched->curr_out_thread[cpu.cpu]; in print_sched_map()
1586 if (sched->map.color_cpus && perf_cpu_map__has(sched->map.color_cpus, cpu)) in print_sched_map()
1594 thread_to_check = sched_out ? sched->curr_out_thread[cpu.cpu] : in print_sched_map()
1595 sched->curr_thread[cpu.cpu]; in print_sched_map()
1604 color_fprintf(stdout, color, "- "); in print_sched_map()
1606 curr_tr = thread__get_runtime(sched->curr_thread[cpu.cpu]); in print_sched_map()
1609 curr_tr->shortname); in print_sched_map()
1612 color_fprintf(stdout, pid_color, "%2s ", curr_tr->shortname); in print_sched_map()
1619 struct perf_sample *sample, struct machine *machine) in map_switch_event() argument
1621 const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); in map_switch_event()
1622 const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"); in map_switch_event()
1626 u64 timestamp0, timestamp = sample->time; in map_switch_event()
1629 .cpu = sample->cpu, in map_switch_event()
1640 if (this_cpu.cpu > sched->max_cpu.cpu) in map_switch_event()
1641 sched->max_cpu = this_cpu; in map_switch_event()
1643 if (sched->map.comp) { in map_switch_event()
1644 cpus_nr = bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS); in map_switch_event()
1645 if (!__test_and_set_bit(this_cpu.cpu, sched->map.comp_cpus_mask)) { in map_switch_event()
1646 sched->map.comp_cpus[cpus_nr++] = this_cpu; in map_switch_event()
1650 cpus_nr = sched->max_cpu.cpu; in map_switch_event()
1652 timestamp0 = sched->cpu_last_switched[this_cpu.cpu]; in map_switch_event()
1653 sched->cpu_last_switched[this_cpu.cpu] = timestamp; in map_switch_event()
1655 delta = timestamp - timestamp0; in map_switch_event()
1661 return -1; in map_switch_event()
1664 sched_in = map__findnew_thread(sched, machine, -1, next_pid); in map_switch_event()
1665 sched_out = map__findnew_thread(sched, machine, -1, prev_pid); in map_switch_event()
1667 return -1; in map_switch_event()
1672 return -1; in map_switch_event()
1675 sched->curr_thread[this_cpu.cpu] = thread__get(sched_in); in map_switch_event()
1676 sched->curr_out_thread[this_cpu.cpu] = thread__get(sched_out); in map_switch_event()
1680 if (!tr->shortname[0]) { in map_switch_event()
1683 * Don't allocate a letter-number for swapper:0 in map_switch_event()
1686 tr->shortname[0] = '.'; in map_switch_event()
1687 tr->shortname[1] = ' '; in map_switch_event()
1688 } else if (!sched->map.task_name || sched_match_task(sched, str)) { in map_switch_event()
1689 tr->shortname[0] = sched->next_shortname1; in map_switch_event()
1690 tr->shortname[1] = sched->next_shortname2; in map_switch_event()
1692 if (sched->next_shortname1 < 'Z') { in map_switch_event()
1693 sched->next_shortname1++; in map_switch_event()
1695 sched->next_shortname1 = 'A'; in map_switch_event()
1696 if (sched->next_shortname2 < '9') in map_switch_event()
1697 sched->next_shortname2++; in map_switch_event()
1699 sched->next_shortname2 = '0'; in map_switch_event()
1702 tr->shortname[0] = '-'; in map_switch_event()
1703 tr->shortname[1] = ' '; in map_switch_event()
1708 if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu)) in map_switch_event()
1714 * Check which of sched_in and sched_out matches the passed --task-name in map_switch_event()
1717 if (sched->map.task_name && !sched_match_task(sched, str)) { in map_switch_event()
1725 if (!(sched->map.task_name && !sched_match_task(sched, str))) in map_switch_event()
1735 if (new_shortname || tr->comm_changed || (verbose > 0 && thread__tid(sched_in))) { in map_switch_event()
1742 tr->shortname, thread__comm_str(sched_in), thread__tid(sched_in)); in map_switch_event()
1743 tr->comm_changed = false; in map_switch_event()
1746 if (sched->map.comp && new_cpu) in map_switch_event()
1755 if (sched->map.task_name) { in map_switch_event()
1756 tr = thread__get_runtime(sched->curr_out_thread[this_cpu.cpu]); in map_switch_event()
1757 if (strcmp(tr->shortname, "") == 0) in map_switch_event()
1772 if (sched->map.task_name) in map_switch_event()
1782 struct perf_sample *sample, in process_sched_switch_event() argument
1786 int this_cpu = sample->cpu, err = 0; in process_sched_switch_event()
1787 u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), in process_sched_switch_event()
1788 next_pid = evsel__intval(evsel, sample, "next_pid"); in process_sched_switch_event()
1790 if (sched->curr_pid[this_cpu] != (u32)-1) { in process_sched_switch_event()
1795 if (sched->curr_pid[this_cpu] != prev_pid) in process_sched_switch_event()
1796 sched->nr_context_switch_bugs++; in process_sched_switch_event()
1799 if (sched->tp_handler->switch_event) in process_sched_switch_event()
1800 err = sched->tp_handler->switch_event(sched, evsel, sample, machine); in process_sched_switch_event()
1802 sched->curr_pid[this_cpu] = next_pid; in process_sched_switch_event()
1808 struct perf_sample *sample, in process_sched_runtime_event() argument
1813 if (sched->tp_handler->runtime_event) in process_sched_runtime_event()
1814 return sched->tp_handler->runtime_event(sched, evsel, sample, machine); in process_sched_runtime_event()
1821 struct perf_sample *sample, in perf_sched__process_fork_event() argument
1827 perf_event__process_fork(tool, event, sample, machine); in perf_sched__process_fork_event()
1830 if (sched->tp_handler->fork_event) in perf_sched__process_fork_event()
1831 return sched->tp_handler->fork_event(sched, event, machine); in perf_sched__process_fork_event()
1838 struct perf_sample *sample, in process_sched_migrate_task_event() argument
1843 if (sched->tp_handler->migrate_task_event) in process_sched_migrate_task_event()
1844 return sched->tp_handler->migrate_task_event(sched, evsel, sample, machine); in process_sched_migrate_task_event()
1851 struct perf_sample *sample,
1856 struct perf_sample *sample, in perf_sched__process_tracepoint_sample() argument
1862 if (evsel->handler != NULL) { in perf_sched__process_tracepoint_sample()
1863 tracepoint_handler f = evsel->handler; in perf_sched__process_tracepoint_sample()
1864 err = f(tool, evsel, sample, machine); in perf_sched__process_tracepoint_sample()
1872 struct perf_sample *sample, in perf_sched__process_comm() argument
1879 err = perf_event__process_comm(tool, event, sample, machine); in perf_sched__process_comm()
1883 thread = machine__find_thread(machine, sample->pid, sample->tid); in perf_sched__process_comm()
1886 return -1; in perf_sched__process_comm()
1892 return -1; in perf_sched__process_comm()
1895 tr->comm_changed = true; in perf_sched__process_comm()
1915 .force = sched->force, in perf_sched__read_events()
1917 int rc = -1; in perf_sched__read_events()
1919 session = perf_session__new(&data, &sched->tool); in perf_sched__read_events()
1925 symbol__init(&session->header.env); in perf_sched__read_events()
1928 if (evlist__find_tracepoint_by_name(session->evlist, "sched:sched_waking")) in perf_sched__read_events()
1934 if (perf_session__has_traces(session, "record -R")) { in perf_sched__read_events()
1941 sched->nr_events = session->evlist->stats.nr_events[0]; in perf_sched__read_events()
1942 sched->nr_lost_events = session->evlist->stats.total_lost; in perf_sched__read_events()
1943 sched->nr_lost_chunks = session->evlist->stats.nr_events[PERF_RECORD_LOST]; in perf_sched__read_events()
1955 static inline void print_sched_time(unsigned long long nsecs, int width) in print_sched_time() argument
1960 msecs = nsecs / NSEC_PER_MSEC; in print_sched_time()
1961 nsecs -= msecs * NSEC_PER_MSEC; in print_sched_time()
1962 usecs = nsecs / NSEC_PER_USEC; in print_sched_time()
1968 * first time it is used.
1972 struct evsel_runtime *r = evsel->priv; in evsel__get_runtime()
1976 evsel->priv = r; in evsel__get_runtime()
1983 * save last time event was seen per cpu
1992 if ((cpu >= r->ncpu) || (r->last_time == NULL)) { in evsel__save_time()
1994 void *p = r->last_time; in evsel__save_time()
1996 p = realloc(r->last_time, n * sizeof(u64)); in evsel__save_time()
2000 r->last_time = p; in evsel__save_time()
2001 for (i = r->ncpu; i < n; ++i) in evsel__save_time()
2002 r->last_time[i] = (u64) 0; in evsel__save_time()
2004 r->ncpu = n; in evsel__save_time()
2007 r->last_time[cpu] = timestamp; in evsel__save_time()
2010 /* returns last time this event was seen on the given cpu */
2015 if ((r == NULL) || (r->last_time == NULL) || (cpu >= r->ncpu)) in evsel__get_time()
2018 return r->last_time[cpu]; in evsel__get_time()
2046 /* prio field format: xxx or xxx->yyy */
2050 struct perf_sample *sample) in timehist_get_priostr() argument
2053 int prev_prio = (int)evsel__intval(evsel, sample, "prev_prio"); in timehist_get_priostr()
2056 if (tr->prio != prev_prio && tr->prio != -1) in timehist_get_priostr()
2057 scnprintf(prio_str, sizeof(prio_str), "%d->%d", tr->prio, prev_prio); in timehist_get_priostr()
2066 u32 ncpus = sched->max_cpu.cpu + 1; in timehist_header()
2069 printf("%15s %6s ", "time", "cpu"); in timehist_header()
2071 if (sched->show_cpu_visual) { in timehist_header()
2081 printf(" %-*s", comm_width, "task name"); in timehist_header()
2083 if (sched->show_prio) in timehist_header()
2084 printf(" %-*s", MAX_PRIO_STR_LEN, "prio"); in timehist_header()
2086 printf(" %9s %9s %9s", "wait time", "sch delay", "run time"); in timehist_header()
2088 if (sched->pre_migrations) in timehist_header()
2089 printf(" %9s", "pre-mig time"); in timehist_header()
2091 if (sched->show_state) in timehist_header()
2099 printf("%15s %-6s ", "", ""); in timehist_header()
2101 if (sched->show_cpu_visual) in timehist_header()
2104 printf(" %-*s", comm_width, "[tid/pid]"); in timehist_header()
2106 if (sched->show_prio) in timehist_header()
2107 printf(" %-*s", MAX_PRIO_STR_LEN, ""); in timehist_header()
2111 if (sched->pre_migrations) in timehist_header()
2121 if (sched->show_cpu_visual) in timehist_header()
2126 if (sched->show_prio) in timehist_header()
2131 if (sched->pre_migrations) in timehist_header()
2134 if (sched->show_state) in timehist_header()
2142 struct perf_sample *sample, in timehist_print_sample() argument
2148 const char *next_comm = evsel__strval(evsel, sample, "next_comm"); in timehist_print_sample()
2149 const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); in timehist_print_sample()
2150 u32 max_cpus = sched->max_cpu.cpu + 1; in timehist_print_sample()
2155 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) in timehist_print_sample()
2159 printf("%15s [%04d] ", tstr, sample->cpu); in timehist_print_sample()
2161 if (sched->show_cpu_visual) { in timehist_print_sample()
2168 if (i == sample->cpu) in timehist_print_sample()
2177 printf(" %-*s ", comm_width, timehist_get_commstr(thread)); in timehist_print_sample()
2179 if (sched->show_prio) in timehist_print_sample()
2180 printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(evsel, thread, sample)); in timehist_print_sample()
2182 wait_time = tr->dt_sleep + tr->dt_iowait + tr->dt_preempt; in timehist_print_sample()
2185 print_sched_time(tr->dt_delay, 6); in timehist_print_sample()
2186 print_sched_time(tr->dt_run, 6); in timehist_print_sample()
2187 if (sched->pre_migrations) in timehist_print_sample()
2188 print_sched_time(tr->dt_pre_mig, 6); in timehist_print_sample()
2190 if (sched->show_state) in timehist_print_sample()
2193 if (sched->show_next) { in timehist_print_sample()
2195 printf(" %-*s", comm_width, nstr); in timehist_print_sample()
2198 if (sched->show_wakeups && !sched->show_next) in timehist_print_sample()
2199 printf(" %-*s", comm_width, ""); in timehist_print_sample()
2204 if (sched->show_callchain) in timehist_print_sample()
2207 sample__fprintf_sym(sample, al, 0, in timehist_print_sample()
2218 * Explanation of delta-time stats:
2220 * t = time of current schedule out event
2221 * tprev = time of previous sched out event
2222 * also time of schedule-in event for current task
2223 * last_time = time of last sched change event for current task
2224 * (i.e, time process was last scheduled out)
2225 * ready_to_run = time of wakeup for current task
2226 * migrated = time of task migration to another CPU
2228 * -----|-------------|-------------|-------------|-------------|-----
2230 * time to run
2232 * |---------------- dt_wait ----------------|
2233 * |--------- dt_delay ---------|-- dt_run --|
2234 * |- dt_pre_mig -|
2236 * dt_run = run time of current task
2237 * dt_wait = time between last schedule out event for task and tprev
2238 * represents time spent off the cpu
2239 * dt_delay = time between wakeup and schedule-in of task
2240 * dt_pre_mig = time between wakeup and migration to another CPU
2246 r->dt_delay = 0; in timehist_update_runtime_stats()
2247 r->dt_sleep = 0; in timehist_update_runtime_stats()
2248 r->dt_iowait = 0; in timehist_update_runtime_stats()
2249 r->dt_preempt = 0; in timehist_update_runtime_stats()
2250 r->dt_run = 0; in timehist_update_runtime_stats()
2251 r->dt_pre_mig = 0; in timehist_update_runtime_stats()
2254 r->dt_run = t - tprev; in timehist_update_runtime_stats()
2255 if (r->ready_to_run) { in timehist_update_runtime_stats()
2256 if (r->ready_to_run > tprev) in timehist_update_runtime_stats()
2257 pr_debug("time travel: wakeup time for task > previous sched_switch event\n"); in timehist_update_runtime_stats()
2259 r->dt_delay = tprev - r->ready_to_run; in timehist_update_runtime_stats()
2261 if ((r->migrated > r->ready_to_run) && (r->migrated < tprev)) in timehist_update_runtime_stats()
2262 r->dt_pre_mig = r->migrated - r->ready_to_run; in timehist_update_runtime_stats()
2265 if (r->last_time > tprev) in timehist_update_runtime_stats()
2266 pr_debug("time travel: last sched out time for task > previous sched_switch event\n"); in timehist_update_runtime_stats()
2267 else if (r->last_time) { in timehist_update_runtime_stats()
2268 u64 dt_wait = tprev - r->last_time; in timehist_update_runtime_stats()
2270 if (r->last_state == 'R') in timehist_update_runtime_stats()
2271 r->dt_preempt = dt_wait; in timehist_update_runtime_stats()
2272 else if (r->last_state == 'D') in timehist_update_runtime_stats()
2273 r->dt_iowait = dt_wait; in timehist_update_runtime_stats()
2275 r->dt_sleep = dt_wait; in timehist_update_runtime_stats()
2279 update_stats(&r->run_stats, r->dt_run); in timehist_update_runtime_stats()
2281 r->total_run_time += r->dt_run; in timehist_update_runtime_stats()
2282 r->total_delay_time += r->dt_delay; in timehist_update_runtime_stats()
2283 r->total_sleep_time += r->dt_sleep; in timehist_update_runtime_stats()
2284 r->total_iowait_time += r->dt_iowait; in timehist_update_runtime_stats()
2285 r->total_preempt_time += r->dt_preempt; in timehist_update_runtime_stats()
2286 r->total_pre_mig_time += r->dt_pre_mig; in timehist_update_runtime_stats()
2289 static bool is_idle_sample(struct perf_sample *sample, in is_idle_sample() argument
2294 return evsel__intval(evsel, sample, "prev_pid") == 0; in is_idle_sample()
2296 return sample->pid == 0; in is_idle_sample()
2300 struct perf_sample *sample, in save_task_callchain() argument
2307 /* want main thread for process - has maps */ in save_task_callchain()
2308 thread = machine__findnew_thread(machine, sample->pid, sample->pid); in save_task_callchain()
2310 pr_debug("Failed to get thread for pid %d.\n", sample->pid); in save_task_callchain()
2314 if (!sched->show_callchain || sample->callchain == NULL) in save_task_callchain()
2319 if (thread__resolve_callchain(thread, cursor, evsel, sample, in save_task_callchain()
2320 NULL, NULL, sched->max_stack + 2) != 0) { in save_task_callchain()
2337 sym = node->ms.sym; in save_task_callchain()
2339 if (!strcmp(sym->name, "schedule") || in save_task_callchain()
2340 !strcmp(sym->name, "__schedule") || in save_task_callchain()
2341 !strcmp(sym->name, "preempt_schedule")) in save_task_callchain()
2342 sym->ignore = 1; in save_task_callchain()
2357 return -ENOMEM; in init_idle_thread()
2359 init_prio(&itr->tr); in init_idle_thread()
2360 init_stats(&itr->tr.run_stats); in init_idle_thread()
2361 callchain_init(&itr->callchain); in init_idle_thread()
2362 callchain_cursor_reset(&itr->cursor); in init_idle_thread()
2378 return -ENOMEM; in init_idle_threads()
2386 return -ENOMEM; in init_idle_threads()
2447 struct perf_sample *sample) in save_idle_callchain() argument
2451 if (!sched->show_callchain || sample->callchain == NULL) in save_idle_callchain()
2458 callchain_cursor__copy(&itr->cursor, cursor); in save_idle_callchain()
2462 struct perf_sample *sample, in timehist_get_thread() argument
2468 if (is_idle_sample(sample, evsel)) { in timehist_get_thread()
2469 thread = get_idle_thread(sample->cpu); in timehist_get_thread()
2471 pr_err("Failed to get idle thread for cpu %d.\n", sample->cpu); in timehist_get_thread()
2474 /* there were samples with tid 0 but non-zero pid */ in timehist_get_thread()
2475 thread = machine__findnew_thread(machine, sample->pid, in timehist_get_thread()
2476 sample->tid ?: sample->pid); in timehist_get_thread()
2478 pr_debug("Failed to get thread for tid %d. skipping sample.\n", in timehist_get_thread()
2479 sample->tid); in timehist_get_thread()
2482 save_task_callchain(sched, sample, evsel, machine); in timehist_get_thread()
2483 if (sched->idle_hist) { in timehist_get_thread()
2487 idle = get_idle_thread(sample->cpu); in timehist_get_thread()
2489 pr_err("Failed to get idle thread for cpu %d.\n", sample->cpu); in timehist_get_thread()
2497 itr->last_thread = thread; in timehist_get_thread()
2500 if (evsel__intval(evsel, sample, "next_pid") == 0) in timehist_get_thread()
2501 save_idle_callchain(sched, itr, sample); in timehist_get_thread()
2511 struct perf_sample *sample) in timehist_skip_sample() argument
2514 int prio = -1; in timehist_skip_sample()
2519 sched->skipped_samples++; in timehist_skip_sample()
2522 if (sched->prio_str) { in timehist_skip_sample()
2530 if (tr && tr->prio != -1) in timehist_skip_sample()
2531 prio = tr->prio; in timehist_skip_sample()
2533 prio = evsel__intval(evsel, sample, "prev_prio"); in timehist_skip_sample()
2535 if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) { in timehist_skip_sample()
2537 sched->skipped_samples++; in timehist_skip_sample()
2541 if (sched->idle_hist) { in timehist_skip_sample()
2544 else if (evsel__intval(evsel, sample, "prev_pid") != 0 && in timehist_skip_sample()
2545 evsel__intval(evsel, sample, "next_pid") != 0) in timehist_skip_sample()
2554 struct perf_sample *sample, in timehist_print_wakeup_event() argument
2561 thread = machine__findnew_thread(machine, sample->pid, sample->tid); in timehist_print_wakeup_event()
2566 if (timehist_skip_sample(sched, thread, evsel, sample) && in timehist_print_wakeup_event()
2567 timehist_skip_sample(sched, awakened, evsel, sample)) { in timehist_print_wakeup_event()
2571 timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr)); in timehist_print_wakeup_event()
2572 printf("%15s [%04d] ", tstr, sample->cpu); in timehist_print_wakeup_event()
2573 if (sched->show_cpu_visual) in timehist_print_wakeup_event()
2574 printf(" %*s ", sched->max_cpu.cpu + 1, ""); in timehist_print_wakeup_event()
2576 printf(" %-*s ", comm_width, timehist_get_commstr(thread)); in timehist_print_wakeup_event()
2589 struct perf_sample *sample __maybe_unused, in timehist_sched_wakeup_ignore()
2598 struct perf_sample *sample, in timehist_sched_wakeup_event() argument
2604 /* want pid of awakened task not pid in sample */ in timehist_sched_wakeup_event()
2605 const u32 pid = evsel__intval(evsel, sample, "pid"); in timehist_sched_wakeup_event()
2609 return -1; in timehist_sched_wakeup_event()
2613 return -1; in timehist_sched_wakeup_event()
2615 if (tr->ready_to_run == 0) in timehist_sched_wakeup_event()
2616 tr->ready_to_run = sample->time; in timehist_sched_wakeup_event()
2619 if (sched->show_wakeups && in timehist_sched_wakeup_event()
2620 !perf_time__skip_sample(&sched->ptime, sample->time)) in timehist_sched_wakeup_event()
2621 timehist_print_wakeup_event(sched, evsel, sample, machine, thread); in timehist_sched_wakeup_event()
2628 struct perf_sample *sample, in timehist_print_migration_event() argument
2637 if (sched->summary_only) in timehist_print_migration_event()
2640 max_cpus = sched->max_cpu.cpu + 1; in timehist_print_migration_event()
2641 ocpu = evsel__intval(evsel, sample, "orig_cpu"); in timehist_print_migration_event()
2642 dcpu = evsel__intval(evsel, sample, "dest_cpu"); in timehist_print_migration_event()
2644 thread = machine__findnew_thread(machine, sample->pid, sample->tid); in timehist_print_migration_event()
2648 if (timehist_skip_sample(sched, thread, evsel, sample) && in timehist_print_migration_event()
2649 timehist_skip_sample(sched, migrated, evsel, sample)) { in timehist_print_migration_event()
2653 timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr)); in timehist_print_migration_event()
2654 printf("%15s [%04d] ", tstr, sample->cpu); in timehist_print_migration_event()
2656 if (sched->show_cpu_visual) { in timehist_print_migration_event()
2662 c = (i == sample->cpu) ? 'm' : ' '; in timehist_print_migration_event()
2668 printf(" %-*s ", comm_width, timehist_get_commstr(thread)); in timehist_print_migration_event()
2682 struct perf_sample *sample, in timehist_migrate_task_event() argument
2688 /* want pid of migrated task not pid in sample */ in timehist_migrate_task_event()
2689 const u32 pid = evsel__intval(evsel, sample, "pid"); in timehist_migrate_task_event()
2693 return -1; in timehist_migrate_task_event()
2697 return -1; in timehist_migrate_task_event()
2699 tr->migrations++; in timehist_migrate_task_event()
2700 tr->migrated = sample->time; in timehist_migrate_task_event()
2703 if (sched->show_migrations) { in timehist_migrate_task_event()
2704 timehist_print_migration_event(sched, evsel, sample, in timehist_migrate_task_event()
2712 struct perf_sample *sample, in timehist_update_task_prio() argument
2717 const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); in timehist_update_task_prio()
2718 const u32 next_prio = evsel__intval(evsel, sample, "next_prio"); in timehist_update_task_prio()
2721 thread = get_idle_thread(sample->cpu); in timehist_update_task_prio()
2723 thread = machine__findnew_thread(machine, -1, next_pid); in timehist_update_task_prio()
2732 tr->prio = next_prio; in timehist_update_task_prio()
2738 struct perf_sample *sample, in timehist_sched_change_event() argument
2742 struct perf_time_interval *ptime = &sched->ptime; in timehist_sched_change_event()
2746 u64 tprev, t = sample->time; in timehist_sched_change_event()
2748 const char state = evsel__taskstate(evsel, sample, "prev_state"); in timehist_sched_change_event()
2751 if (machine__resolve(machine, &al, sample) < 0) { in timehist_sched_change_event()
2753 event->header.type); in timehist_sched_change_event()
2754 rc = -1; in timehist_sched_change_event()
2758 if (sched->show_prio || sched->prio_str) in timehist_sched_change_event()
2759 timehist_update_task_prio(evsel, sample, machine); in timehist_sched_change_event()
2761 thread = timehist_get_thread(sched, sample, machine, evsel); in timehist_sched_change_event()
2763 rc = -1; in timehist_sched_change_event()
2767 if (timehist_skip_sample(sched, thread, evsel, sample)) in timehist_sched_change_event()
2772 rc = -1; in timehist_sched_change_event()
2776 tprev = evsel__get_time(evsel, sample->cpu); in timehist_sched_change_event()
2779 * If start time given: in timehist_sched_change_event()
2780 * - sample time is under window user cares about - skip sample in timehist_sched_change_event()
2781 * - tprev is under window user cares about - reset to start of window in timehist_sched_change_event()
2783 if (ptime->start && ptime->start > t) in timehist_sched_change_event()
2786 if (tprev && ptime->start > tprev) in timehist_sched_change_event()
2787 tprev = ptime->start; in timehist_sched_change_event()
2790 * If end time given: in timehist_sched_change_event()
2791 * - previous sched event is out of window - we are done in timehist_sched_change_event()
2792 * - sample time is beyond window user cares about - reset it in timehist_sched_change_event()
2793 * to close out stats for time window interest in timehist_sched_change_event()
2794 * - If tprev is 0, that is, sched_in event for current task is in timehist_sched_change_event()
2796 * within time window interest - ignore it in timehist_sched_change_event()
2798 if (ptime->end) { in timehist_sched_change_event()
2799 if (!tprev || tprev > ptime->end) in timehist_sched_change_event()
2802 if (t > ptime->end) in timehist_sched_change_event()
2803 t = ptime->end; in timehist_sched_change_event()
2806 if (!sched->idle_hist || thread__tid(thread) == 0) { in timehist_sched_change_event()
2807 if (!cpu_list || test_bit(sample->cpu, cpu_bitmap)) in timehist_sched_change_event()
2810 if (sched->idle_hist) { in timehist_sched_change_event()
2814 if (itr->last_thread == NULL) in timehist_sched_change_event()
2817 /* add current idle time as last thread's runtime */ in timehist_sched_change_event()
2818 last_tr = thread__get_runtime(itr->last_thread); in timehist_sched_change_event()
2824 * remove delta time of last thread as it's not updated in timehist_sched_change_event()
2826 * time. we only care total run time and run stat. in timehist_sched_change_event()
2828 last_tr->dt_run = 0; in timehist_sched_change_event()
2829 last_tr->dt_delay = 0; in timehist_sched_change_event()
2830 last_tr->dt_sleep = 0; in timehist_sched_change_event()
2831 last_tr->dt_iowait = 0; in timehist_sched_change_event()
2832 last_tr->dt_preempt = 0; in timehist_sched_change_event()
2834 if (itr->cursor.nr) in timehist_sched_change_event()
2835 callchain_append(&itr->callchain, &itr->cursor, t - tprev); in timehist_sched_change_event()
2837 itr->last_thread = NULL; in timehist_sched_change_event()
2840 if (!sched->summary_only) in timehist_sched_change_event()
2841 timehist_print_sample(sched, evsel, sample, &al, thread, t, state); in timehist_sched_change_event()
2845 if (sched->hist_time.start == 0 && t >= ptime->start) in timehist_sched_change_event()
2846 sched->hist_time.start = t; in timehist_sched_change_event()
2847 if (ptime->end == 0 || t <= ptime->end) in timehist_sched_change_event()
2848 sched->hist_time.end = t; in timehist_sched_change_event()
2851 /* time of this sched_switch event becomes last time task seen */ in timehist_sched_change_event()
2852 tr->last_time = sample->time; in timehist_sched_change_event()
2854 /* last state is used to determine where to account wait time */ in timehist_sched_change_event()
2855 tr->last_state = state; in timehist_sched_change_event()
2857 /* sched out event for task so reset ready to run time and migrated time */ in timehist_sched_change_event()
2859 tr->ready_to_run = t; in timehist_sched_change_event()
2861 tr->ready_to_run = 0; in timehist_sched_change_event()
2863 tr->migrated = 0; in timehist_sched_change_event()
2866 evsel__save_time(evsel, sample->time, sample->cpu); in timehist_sched_change_event()
2875 struct perf_sample *sample, in timehist_sched_switch_event() argument
2878 return timehist_sched_change_event(tool, event, evsel, sample, machine); in timehist_sched_switch_event()
2883 struct perf_sample *sample, in process_lost() argument
2888 timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr)); in process_lost()
2890 printf("lost %" PRI_lu64 " events on cpu %d\n", event->lost.lost, sample->cpu); in process_lost()
2899 double mean = avg_stats(&r->run_stats); in print_thread_runtime()
2904 (u64) r->run_stats.n); in print_thread_runtime()
2906 print_sched_time(r->total_run_time, 8); in print_thread_runtime()
2907 stddev = rel_stddev_stats(stddev_stats(&r->run_stats), mean); in print_thread_runtime()
2908 print_sched_time(r->run_stats.min, 6); in print_thread_runtime()
2912 print_sched_time(r->run_stats.max, 6); in print_thread_runtime()
2915 printf(" %5" PRIu64, r->migrations); in print_thread_runtime()
2924 (u64) r->run_stats.n); in print_thread_waittime()
2926 print_sched_time(r->total_run_time, 8); in print_thread_waittime()
2927 print_sched_time(r->total_sleep_time, 6); in print_thread_waittime()
2929 print_sched_time(r->total_iowait_time, 6); in print_thread_waittime()
2931 print_sched_time(r->total_preempt_time, 6); in print_thread_waittime()
2933 print_sched_time(r->total_delay_time, 6); in print_thread_waittime()
2953 if (r && r->run_stats.n) { in show_thread_runtime()
2954 stats->task_count++; in show_thread_runtime()
2955 stats->sched_count += r->run_stats.n; in show_thread_runtime()
2956 stats->total_run_time += r->total_run_time; in show_thread_runtime()
2958 if (stats->sched->show_state) in show_thread_runtime()
2969 const char *sep = " <- "; in callchain__fprintf_folded()
2978 ret = callchain__fprintf_folded(fp, node->parent); in callchain__fprintf_folded()
2981 list_for_each_entry(chain, &node->val, list) { in callchain__fprintf_folded()
2982 if (chain->ip >= PERF_CONTEXT_MAX) in callchain__fprintf_folded()
2984 if (chain->ms.sym && chain->ms.sym->ignore) in callchain__fprintf_folded()
3002 printf(" %16s %8s %s\n", "Idle time (msec)", "Count", "Callchains"); in timehist_print_idlehist_callchain()
3011 print_sched_time(chain->hit, 12); in timehist_print_idlehist_callchain()
3013 ret += fprintf(fp, " %8d ", chain->count); in timehist_print_idlehist_callchain()
3024 struct machine *m = &session->machines.host; in timehist_print_summary()
3030 u64 hist_time = sched->hist_time.end - sched->hist_time.start; in timehist_print_summary()
3035 if (sched->idle_hist) { in timehist_print_summary()
3036 printf("\nIdle-time summary\n"); in timehist_print_summary()
3037 printf("%*s parent sched-out ", comm_width, "comm"); in timehist_print_summary()
3038 printf(" idle-time min-idle avg-idle max-idle stddev migrations\n"); in timehist_print_summary()
3039 } else if (sched->show_state) { in timehist_print_summary()
3040 printf("\nWait-time summary\n"); in timehist_print_summary()
3041 printf("%*s parent sched-in ", comm_width, "comm"); in timehist_print_summary()
3042 printf(" run-time sleep iowait preempt delay\n"); in timehist_print_summary()
3045 printf("%*s parent sched-in ", comm_width, "comm"); in timehist_print_summary()
3046 printf(" run-time min-run avg-run max-run stddev migrations\n"); in timehist_print_summary()
3050 sched->show_state ? "(msec)" : "%"); in timehist_print_summary()
3059 if (sched->skipped_samples && !sched->idle_hist) in timehist_print_summary()
3072 if (r && r->run_stats.n) { in timehist_print_summary()
3073 totals.sched_count += r->run_stats.n; in timehist_print_summary()
3075 print_sched_time(r->total_run_time, 6); in timehist_print_summary()
3076 printf(" msec (%6.2f%%)\n", 100.0 * r->total_run_time / hist_time); in timehist_print_summary()
3078 printf(" CPU %2d idle entire time window\n", i); in timehist_print_summary()
3081 if (sched->idle_hist && sched->show_callchain) { in timehist_print_summary()
3099 callchain_param.sort(&itr->sorted_root.rb_root, &itr->callchain, in timehist_print_summary()
3103 print_sched_time(itr->tr.total_run_time, 6); in timehist_print_summary()
3105 timehist_print_idlehist_callchain(&itr->sorted_root); in timehist_print_summary()
3115 printf(" Total run time (msec): "); in timehist_print_summary()
3119 printf(" Total scheduling time (msec): "); in timehist_print_summary()
3121 printf(" (x %d)\n", sched->max_cpu.cpu); in timehist_print_summary()
3127 struct perf_sample *sample,
3132 struct perf_sample *sample, in perf_timehist__process_sample() argument
3139 .cpu = sample->cpu, in perf_timehist__process_sample()
3142 if (this_cpu.cpu > sched->max_cpu.cpu) in perf_timehist__process_sample()
3143 sched->max_cpu = this_cpu; in perf_timehist__process_sample()
3145 if (evsel->handler != NULL) { in perf_timehist__process_sample()
3146 sched_handler f = evsel->handler; in perf_timehist__process_sample()
3148 err = f(tool, event, evsel, sample, machine); in perf_timehist__process_sample()
3160 list_for_each_entry(evsel, &evlist->core.entries, core.node) { in timehist_check_attr()
3164 return -1; in timehist_check_attr()
3168 if (sched->show_callchain && in timehist_check_attr()
3172 sched->show_callchain = 0; in timehist_check_attr()
3184 const char *str = sched->prio_str; in timehist_parse_prio_str()
3192 if (start_prio >= MAX_PRIO || (*p != '\0' && *p != ',' && *p != '-')) in timehist_parse_prio_str()
3193 return -1; in timehist_parse_prio_str()
3195 if (*p == '-') { in timehist_parse_prio_str()
3201 return -1; in timehist_parse_prio_str()
3204 return -1; in timehist_parse_prio_str()
3210 __set_bit(start_prio, sched->prio_bitmap); in timehist_parse_prio_str()
3235 .force = sched->force, in perf_sched__timehist()
3240 int err = -1; in perf_sched__timehist()
3245 sched->tool.sample = perf_timehist__process_sample; in perf_sched__timehist()
3246 sched->tool.mmap = perf_event__process_mmap; in perf_sched__timehist()
3247 sched->tool.comm = perf_event__process_comm; in perf_sched__timehist()
3248 sched->tool.exit = perf_event__process_exit; in perf_sched__timehist()
3249 sched->tool.fork = perf_event__process_fork; in perf_sched__timehist()
3250 sched->tool.lost = process_lost; in perf_sched__timehist()
3251 sched->tool.attr = perf_event__process_attr; in perf_sched__timehist()
3252 sched->tool.tracing_data = perf_event__process_tracing_data; in perf_sched__timehist()
3253 sched->tool.build_id = perf_event__process_build_id; in perf_sched__timehist()
3255 sched->tool.ordering_requires_timestamps = true; in perf_sched__timehist()
3257 symbol_conf.use_callchain = sched->show_callchain; in perf_sched__timehist()
3259 session = perf_session__new(&data, &sched->tool); in perf_sched__timehist()
3269 evlist = session->evlist; in perf_sched__timehist()
3271 symbol__init(&session->header.env); in perf_sched__timehist()
3273 if (perf_time__parse_str(&sched->ptime, sched->time_str) != 0) { in perf_sched__timehist()
3274 pr_err("Invalid time string\n"); in perf_sched__timehist()
3275 err = -EINVAL; in perf_sched__timehist()
3290 if (evlist__find_tracepoint_by_name(session->evlist, "sched:sched_waking")) in perf_sched__timehist()
3293 /* setup per-evsel handlers */ in perf_sched__timehist()
3298 if (!evlist__find_tracepoint_by_name(session->evlist, "sched:sched_switch")) { in perf_sched__timehist()
3303 if ((sched->show_migrations || sched->pre_migrations) && in perf_sched__timehist()
3307 /* pre-allocate struct for per-CPU idle stats */ in perf_sched__timehist()
3308 sched->max_cpu.cpu = session->header.env.nr_cpus_online; in perf_sched__timehist()
3309 if (sched->max_cpu.cpu == 0) in perf_sched__timehist()
3310 sched->max_cpu.cpu = 4; in perf_sched__timehist()
3311 if (init_idle_threads(sched->max_cpu.cpu)) in perf_sched__timehist()
3315 if (sched->summary_only) in perf_sched__timehist()
3316 sched->summary = sched->summary_only; in perf_sched__timehist()
3318 if (!sched->summary_only) in perf_sched__timehist()
3327 sched->nr_events = evlist->stats.nr_events[0]; in perf_sched__timehist()
3328 sched->nr_lost_events = evlist->stats.total_lost; in perf_sched__timehist()
3329 sched->nr_lost_chunks = evlist->stats.nr_events[PERF_RECORD_LOST]; in perf_sched__timehist()
3331 if (sched->summary) in perf_sched__timehist()
3344 if (sched->nr_unordered_timestamps && sched->nr_timestamps) { in print_bad_events()
3346 (double)sched->nr_unordered_timestamps/(double)sched->nr_timestamps*100.0, in print_bad_events()
3347 sched->nr_unordered_timestamps, sched->nr_timestamps); in print_bad_events()
3349 if (sched->nr_lost_events && sched->nr_events) { in print_bad_events()
3351 (double)sched->nr_lost_events/(double)sched->nr_events * 100.0, in print_bad_events()
3352 sched->nr_lost_events, sched->nr_events, sched->nr_lost_chunks); in print_bad_events()
3354 if (sched->nr_context_switch_bugs && sched->nr_timestamps) { in print_bad_events()
3356 (double)sched->nr_context_switch_bugs/(double)sched->nr_timestamps*100.0, in print_bad_events()
3357 sched->nr_context_switch_bugs, sched->nr_timestamps); in print_bad_events()
3358 if (sched->nr_lost_events) in print_bad_events()
3366 struct rb_node **new = &(root->rb_root.rb_node), *parent = NULL; in __merge_work_atoms()
3368 const char *comm = thread__comm_str(data->thread), *this_comm; in __merge_work_atoms()
3377 this_comm = thread__comm_str(this->thread); in __merge_work_atoms()
3380 new = &((*new)->rb_left); in __merge_work_atoms()
3382 new = &((*new)->rb_right); in __merge_work_atoms()
3385 this->num_merged++; in __merge_work_atoms()
3386 this->total_runtime += data->total_runtime; in __merge_work_atoms()
3387 this->nb_atoms += data->nb_atoms; in __merge_work_atoms()
3388 this->total_lat += data->total_lat; in __merge_work_atoms()
3389 list_splice(&data->work_list, &this->work_list); in __merge_work_atoms()
3390 if (this->max_lat < data->max_lat) { in __merge_work_atoms()
3391 this->max_lat = data->max_lat; in __merge_work_atoms()
3392 this->max_lat_start = data->max_lat_start; in __merge_work_atoms()
3393 this->max_lat_end = data->max_lat_end; in __merge_work_atoms()
3400 data->num_merged++; in __merge_work_atoms()
3401 rb_link_node(&data->node, parent, new); in __merge_work_atoms()
3402 rb_insert_color_cached(&data->node, root, leftmost); in __merge_work_atoms()
3410 if (sched->skip_merge) in perf_sched__merge_lat()
3413 while ((node = rb_first_cached(&sched->atom_root))) { in perf_sched__merge_lat()
3414 rb_erase_cached(node, &sched->atom_root); in perf_sched__merge_lat()
3416 __merge_work_atoms(&sched->merged_atom_root, data); in perf_sched__merge_lat()
3424 sched->cpu_last_switched = calloc(MAX_CPUS, sizeof(*(sched->cpu_last_switched))); in setup_cpus_switch_event()
3425 if (!sched->cpu_last_switched) in setup_cpus_switch_event()
3426 return -1; in setup_cpus_switch_event()
3428 sched->curr_pid = malloc(MAX_CPUS * sizeof(*(sched->curr_pid))); in setup_cpus_switch_event()
3429 if (!sched->curr_pid) { in setup_cpus_switch_event()
3430 zfree(&sched->cpu_last_switched); in setup_cpus_switch_event()
3431 return -1; in setup_cpus_switch_event()
3435 sched->curr_pid[i] = -1; in setup_cpus_switch_event()
3442 zfree(&sched->curr_pid); in free_cpus_switch_event()
3443 zfree(&sched->cpu_last_switched); in free_cpus_switch_event()
3448 int rc = -1; in perf_sched__lat()
3462 …tf("\n -------------------------------------------------------------------------------------------… in perf_sched__lat()
3464 …intf(" -------------------------------------------------------------------------------------------… in perf_sched__lat()
3466 next = rb_first_cached(&sched->sorted_atom_root); in perf_sched__lat()
3474 thread__zput(work_list->thread); in perf_sched__lat()
3477 …printf(" -----------------------------------------------------------------------------------------… in perf_sched__lat()
3479 (double)sched->all_runtime / NSEC_PER_MSEC, sched->all_count); in perf_sched__lat()
3481 printf(" ---------------------------------------------------\n"); in perf_sched__lat()
3495 sched->max_cpu.cpu = sysconf(_SC_NPROCESSORS_CONF); in setup_map_cpus()
3497 if (sched->map.comp) { in setup_map_cpus()
3498 sched->map.comp_cpus = zalloc(sched->max_cpu.cpu * sizeof(int)); in setup_map_cpus()
3499 if (!sched->map.comp_cpus) in setup_map_cpus()
3500 return -1; in setup_map_cpus()
3503 if (sched->map.cpus_str) { in setup_map_cpus()
3504 sched->map.cpus = perf_cpu_map__new(sched->map.cpus_str); in setup_map_cpus()
3505 if (!sched->map.cpus) { in setup_map_cpus()
3506 pr_err("failed to get cpus map from %s\n", sched->map.cpus_str); in setup_map_cpus()
3507 zfree(&sched->map.comp_cpus); in setup_map_cpus()
3508 return -1; in setup_map_cpus()
3519 if (!sched->map.color_pids_str) in setup_color_pids()
3522 map = thread_map__new_by_tid_str(sched->map.color_pids_str); in setup_color_pids()
3524 pr_err("failed to get thread map from %s\n", sched->map.color_pids_str); in setup_color_pids()
3525 return -1; in setup_color_pids()
3528 sched->map.color_pids = map; in setup_color_pids()
3536 if (!sched->map.color_cpus_str) in setup_color_cpus()
3539 map = perf_cpu_map__new(sched->map.color_cpus_str); in setup_color_cpus()
3541 pr_err("failed to get thread map from %s\n", sched->map.color_cpus_str); in setup_color_cpus()
3542 return -1; in setup_color_cpus()
3545 sched->map.color_cpus = map; in setup_color_cpus()
3551 int rc = -1; in perf_sched__map()
3553 sched->curr_thread = calloc(MAX_CPUS, sizeof(*(sched->curr_thread))); in perf_sched__map()
3554 if (!sched->curr_thread) in perf_sched__map()
3557 sched->curr_out_thread = calloc(MAX_CPUS, sizeof(*(sched->curr_out_thread))); in perf_sched__map()
3558 if (!sched->curr_out_thread) in perf_sched__map()
3581 perf_cpu_map__put(sched->map.color_cpus); in perf_sched__map()
3584 perf_thread_map__put(sched->map.color_pids); in perf_sched__map()
3587 zfree(&sched->map.comp_cpus); in perf_sched__map()
3588 perf_cpu_map__put(sched->map.cpus); in perf_sched__map()
3594 zfree(&sched->curr_thread); in perf_sched__map()
3603 mutex_init(&sched->start_work_mutex); in perf_sched__replay()
3604 mutex_init(&sched->work_done_wait_mutex); in perf_sched__replay()
3619 printf("nr_run_events: %ld\n", sched->nr_run_events); in perf_sched__replay()
3620 printf("nr_sleep_events: %ld\n", sched->nr_sleep_events); in perf_sched__replay()
3621 printf("nr_wakeup_events: %ld\n", sched->nr_wakeup_events); in perf_sched__replay()
3623 if (sched->targetless_wakeups) in perf_sched__replay()
3624 printf("target-less wakeups: %ld\n", sched->targetless_wakeups); in perf_sched__replay()
3625 if (sched->multitarget_wakeups) in perf_sched__replay()
3626 printf("multi-target wakeups: %ld\n", sched->multitarget_wakeups); in perf_sched__replay()
3627 if (sched->nr_run_events_optimized) in perf_sched__replay()
3629 sched->nr_run_events_optimized); in perf_sched__replay()
3634 sched->thread_funcs_exit = false; in perf_sched__replay()
3636 printf("------------------------------------------------------------\n"); in perf_sched__replay()
3637 if (sched->replay_repeat == 0) in perf_sched__replay()
3638 sched->replay_repeat = UINT_MAX; in perf_sched__replay()
3640 for (i = 0; i < sched->replay_repeat; i++) in perf_sched__replay()
3643 sched->thread_funcs_exit = true; in perf_sched__replay()
3650 mutex_destroy(&sched->start_work_mutex); in perf_sched__replay()
3651 mutex_destroy(&sched->work_done_wait_mutex); in perf_sched__replay()
3658 char *tmp, *tok, *str = strdup(sched->sort_order); in setup_sorting()
3662 if (sort_dimension__add(tok, &sched->sort_list) < 0) { in setup_sorting()
3664 "Unknown --sort key: `%s'", tok); in setup_sorting()
3670 sort_dimension__add("pid", &sched->cmp_pid); in setup_sorting()
3690 "-a", in __cmd_record()
3691 "-R", in __cmd_record()
3692 "-m", "1024", in __cmd_record()
3693 "-c", "1", in __cmd_record()
3694 "-e", "sched:sched_switch", in __cmd_record()
3695 "-e", "sched:sched_stat_runtime", in __cmd_record()
3696 "-e", "sched:sched_process_fork", in __cmd_record()
3697 "-e", "sched:sched_wakeup_new", in __cmd_record()
3698 "-e", "sched:sched_migrate_task", in __cmd_record()
3708 "-e", "sched:sched_stat_wait", in __cmd_record()
3709 "-e", "sched:sched_stat_sleep", in __cmd_record()
3710 "-e", "sched:sched_stat_iowait", in __cmd_record()
3719 * +2 for either "-e", "sched:sched_wakeup" or in __cmd_record()
3720 * "-e", "sched:sched_waking" in __cmd_record()
3722 rec_argc = ARRAY_SIZE(record_args) + 2 + schedstat_argc + argc - 1; in __cmd_record()
3725 return -ENOMEM; in __cmd_record()
3729 return -ENOMEM; in __cmd_record()
3735 rec_argv[i++] = strdup("-e"); in __cmd_record()
3769 .profile_cpu = -1, in cmd_sched()
3781 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, in cmd_sched()
3803 OPT_STRING(0, "color-pids", &sched.map.color_pids_str, "pids", in cmd_sched()
3805 OPT_STRING(0, "color-cpus", &sched.map.color_cpus_str, "cpus", in cmd_sched()
3809 OPT_STRING(0, "task-name", &sched.map.task_name, "task", in cmd_sched()
3811 OPT_BOOLEAN(0, "fuzzy-name", &sched.map.fuzzy, in cmd_sched()
3820 OPT_BOOLEAN('g', "call-graph", &sched.show_callchain, in cmd_sched()
3822 OPT_UINTEGER(0, "max-stack", &sched.max_stack, in cmd_sched()
3828 OPT_BOOLEAN('S', "with-summary", &sched.summary, in cmd_sched()
3833 OPT_BOOLEAN('V', "cpu-visual", &sched.show_cpu_visual, "Add CPU visual"), in cmd_sched()
3834 OPT_BOOLEAN('I', "idle-hist", &sched.idle_hist, "Show idle events only"), in cmd_sched()
3835 OPT_STRING(0, "time", &sched.time_str, "str", in cmd_sched()
3836 "Time span for analysis (start,stop)"), in cmd_sched()
3837 OPT_BOOLEAN(0, "state", &sched.show_state, "Show task state when sched-out"), in cmd_sched()
3843 OPT_BOOLEAN(0, "show-prio", &sched.show_prio, "Show task priority"), in cmd_sched()
3846 OPT_BOOLEAN('P', "pre-migrations", &sched.pre_migrations, "Show pre-migration wait time"), in cmd_sched()
3890 sched.tool.sample = perf_sched__process_tracepoint_sample; in cmd_sched()
3927 return -1; in cmd_sched()
3951 pr_err(" Error: -s and -[n|w] are mutually exclusive.\n"); in cmd_sched()
3957 return -EINVAL; in cmd_sched()