• Home
  • Raw
  • Download

Lines Matching +full:min +full:- +full:sample +full:- +full:time +full:- +full:nsecs

1 // SPDX-License-Identifier: GPL-2.0
19 #include "util/time-utils.h"
21 #include <subcmd/parse-options.h>
22 #include "util/trace-event.h"
92 /* in tsk->exit_state */
96 /* in tsk->state again */
136 struct perf_sample *sample, struct machine *machine);
139 struct perf_sample *sample, struct machine *machine);
142 struct perf_sample *sample, struct machine *machine);
150 struct perf_sample *sample,
180 * Track the current task - that way we can know whether there's any
239 /* per thread run time data */
241 u64 last_time; /* time of previous sched in/out event */
242 u64 dt_run; /* run time */
243 u64 dt_sleep; /* time between CPU access by sleep (off cpu) */
244 u64 dt_iowait; /* time between CPU access by iowait (off cpu) */
245 u64 dt_preempt; /* time between CPU access by preempt (off cpu) */
246 u64 dt_delay; /* time between wakeup and sched-in */
247 u64 ready_to_run; /* time of wakeup */
264 /* per event run time data */
266 u64 *last_time; /* time this event was last seen per cpu */
270 /* per cpu idle time data */
293 static void burn_nsecs(struct perf_sched *sched, u64 nsecs) in burn_nsecs() argument
299 } while (T1 + sched->run_measurement_overhead < T0 + nsecs); in burn_nsecs()
302 static void sleep_nsecs(u64 nsecs) in sleep_nsecs() argument
306 ts.tv_nsec = nsecs % 999999999; in sleep_nsecs()
307 ts.tv_sec = nsecs / 999999999; in sleep_nsecs()
321 delta = T1-T0; in calibrate_run_measurement_overhead()
322 min_delta = min(min_delta, delta); in calibrate_run_measurement_overhead()
324 sched->run_measurement_overhead = min_delta; in calibrate_run_measurement_overhead()
326 printf("run measurement overhead: %" PRIu64 " nsecs\n", min_delta); in calibrate_run_measurement_overhead()
338 delta = T1-T0; in calibrate_sleep_measurement_overhead()
339 min_delta = min(min_delta, delta); in calibrate_sleep_measurement_overhead()
341 min_delta -= 10000; in calibrate_sleep_measurement_overhead()
342 sched->sleep_measurement_overhead = min_delta; in calibrate_sleep_measurement_overhead()
344 printf("sleep measurement overhead: %" PRIu64 " nsecs\n", min_delta); in calibrate_sleep_measurement_overhead()
351 unsigned long idx = task->nr_events; in get_new_event()
354 event->timestamp = timestamp; in get_new_event()
355 event->nr = idx; in get_new_event()
357 task->nr_events++; in get_new_event()
358 size = sizeof(struct sched_atom *) * task->nr_events; in get_new_event()
359 task->atoms = realloc(task->atoms, size); in get_new_event()
360 BUG_ON(!task->atoms); in get_new_event()
362 task->atoms[idx] = event; in get_new_event()
369 if (!task->nr_events) in last_event()
372 return task->atoms[task->nr_events - 1]; in last_event()
384 if (curr_event && curr_event->type == SCHED_EVENT_RUN) { in add_sched_event_run()
385 sched->nr_run_events_optimized++; in add_sched_event_run()
386 curr_event->duration += duration; in add_sched_event_run()
392 event->type = SCHED_EVENT_RUN; in add_sched_event_run()
393 event->duration = duration; in add_sched_event_run()
395 sched->nr_run_events++; in add_sched_event_run()
404 event->type = SCHED_EVENT_WAKEUP; in add_sched_event_wakeup()
405 event->wakee = wakee; in add_sched_event_wakeup()
408 if (!wakee_event || wakee_event->type != SCHED_EVENT_SLEEP) { in add_sched_event_wakeup()
409 sched->targetless_wakeups++; in add_sched_event_wakeup()
412 if (wakee_event->wait_sem) { in add_sched_event_wakeup()
413 sched->multitarget_wakeups++; in add_sched_event_wakeup()
417 wakee_event->wait_sem = zalloc(sizeof(*wakee_event->wait_sem)); in add_sched_event_wakeup()
418 sem_init(wakee_event->wait_sem, 0, 0); in add_sched_event_wakeup()
419 wakee_event->specific_wait = 1; in add_sched_event_wakeup()
420 event->wait_sem = wakee_event->wait_sem; in add_sched_event_wakeup()
422 sched->nr_wakeup_events++; in add_sched_event_wakeup()
430 event->type = SCHED_EVENT_SLEEP; in add_sched_event_sleep()
432 sched->nr_sleep_events++; in add_sched_event_sleep()
441 if (sched->pid_to_task == NULL) { in register_pid()
444 BUG_ON((sched->pid_to_task = calloc(pid_max, sizeof(struct task_desc *))) == NULL); in register_pid()
447 BUG_ON((sched->pid_to_task = realloc(sched->pid_to_task, (pid + 1) * in register_pid()
450 sched->pid_to_task[pid_max++] = NULL; in register_pid()
453 task = sched->pid_to_task[pid]; in register_pid()
459 task->pid = pid; in register_pid()
460 task->nr = sched->nr_tasks; in register_pid()
461 strcpy(task->comm, comm); in register_pid()
463 * every task starts in sleeping state - this gets ignored in register_pid()
468 sched->pid_to_task[pid] = task; in register_pid()
469 sched->nr_tasks++; in register_pid()
470 sched->tasks = realloc(sched->tasks, sched->nr_tasks * sizeof(struct task_desc *)); in register_pid()
471 BUG_ON(!sched->tasks); in register_pid()
472 sched->tasks[task->nr] = task; in register_pid()
475 printf("registered task #%ld, PID %ld (%s)\n", sched->nr_tasks, pid, comm); in register_pid()
486 for (i = 0; i < sched->nr_tasks; i++) { in print_task_traces()
487 task = sched->tasks[i]; in print_task_traces()
489 task->nr, task->comm, task->pid, task->nr_events); in print_task_traces()
498 for (i = 0; i < sched->nr_tasks; i++) { in add_cross_task_wakeups()
499 task1 = sched->tasks[i]; in add_cross_task_wakeups()
501 if (j == sched->nr_tasks) in add_cross_task_wakeups()
503 task2 = sched->tasks[j]; in add_cross_task_wakeups()
513 switch (atom->type) { in perf_sched__process_event()
515 burn_nsecs(sched, atom->duration); in perf_sched__process_event()
518 if (atom->wait_sem) in perf_sched__process_event()
519 ret = sem_wait(atom->wait_sem); in perf_sched__process_event()
523 if (atom->wait_sem) in perf_sched__process_event()
524 ret = sem_post(atom->wait_sem); in perf_sched__process_event()
563 fd = sys_perf_event_open(&attr, 0, -1, -1, in self_open_counters()
568 if (sched->force) { in self_open_counters()
569 BUG_ON(getrlimit(RLIMIT_NOFILE, &limit) == -1); in self_open_counters()
570 limit.rlim_cur += sched->nr_tasks - cur_task; in self_open_counters()
575 if (setrlimit(RLIMIT_NOFILE, &limit) == -1) { in self_open_counters()
581 strcpy(info, "Have a try with -f option\n"); in self_open_counters()
611 struct task_desc *this_task = parms->task; in thread_func()
612 struct perf_sched *sched = parms->sched; in thread_func()
616 int fd = parms->fd; in thread_func()
620 sprintf(comm2, ":%s", this_task->comm); in thread_func()
625 ret = sem_post(&this_task->ready_for_work); in thread_func()
627 ret = pthread_mutex_lock(&sched->start_work_mutex); in thread_func()
629 ret = pthread_mutex_unlock(&sched->start_work_mutex); in thread_func()
634 for (i = 0; i < this_task->nr_events; i++) { in thread_func()
635 this_task->curr_event = i; in thread_func()
636 perf_sched__process_event(sched, this_task->atoms[i]); in thread_func()
640 this_task->cpu_usage = cpu_usage_1 - cpu_usage_0; in thread_func()
641 ret = sem_post(&this_task->work_done_sem); in thread_func()
644 ret = pthread_mutex_lock(&sched->work_done_wait_mutex); in thread_func()
646 ret = pthread_mutex_unlock(&sched->work_done_wait_mutex); in thread_func()
664 err = pthread_mutex_lock(&sched->start_work_mutex); in create_tasks()
666 err = pthread_mutex_lock(&sched->work_done_wait_mutex); in create_tasks()
668 for (i = 0; i < sched->nr_tasks; i++) { in create_tasks()
671 parms->task = task = sched->tasks[i]; in create_tasks()
672 parms->sched = sched; in create_tasks()
673 parms->fd = self_open_counters(sched, i); in create_tasks()
674 sem_init(&task->sleep_sem, 0, 0); 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()
689 sched->start_time = get_nsecs(); in wait_for_tasks()
690 sched->cpu_usage = 0; in wait_for_tasks()
691 pthread_mutex_unlock(&sched->work_done_wait_mutex); in wait_for_tasks()
693 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
694 task = sched->tasks[i]; in wait_for_tasks()
695 ret = sem_wait(&task->ready_for_work); in wait_for_tasks()
697 sem_init(&task->ready_for_work, 0, 0); in wait_for_tasks()
699 ret = pthread_mutex_lock(&sched->work_done_wait_mutex); in wait_for_tasks()
704 pthread_mutex_unlock(&sched->start_work_mutex); in wait_for_tasks()
706 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
707 task = sched->tasks[i]; in wait_for_tasks()
708 ret = sem_wait(&task->work_done_sem); in wait_for_tasks()
710 sem_init(&task->work_done_sem, 0, 0); in wait_for_tasks()
711 sched->cpu_usage += task->cpu_usage; in wait_for_tasks()
712 task->cpu_usage = 0; in wait_for_tasks()
716 if (!sched->runavg_cpu_usage) in wait_for_tasks()
717 sched->runavg_cpu_usage = sched->cpu_usage; in wait_for_tasks()
718 …sched->runavg_cpu_usage = (sched->runavg_cpu_usage * (sched->replay_repeat - 1) + sched->cpu_usage… in wait_for_tasks()
720 sched->parent_cpu_usage = cpu_usage_1 - cpu_usage_0; in wait_for_tasks()
721 if (!sched->runavg_parent_cpu_usage) in wait_for_tasks()
722 sched->runavg_parent_cpu_usage = sched->parent_cpu_usage; in wait_for_tasks()
723 sched->runavg_parent_cpu_usage = (sched->runavg_parent_cpu_usage * (sched->replay_repeat - 1) + in wait_for_tasks()
724 sched->parent_cpu_usage)/sched->replay_repeat; in wait_for_tasks()
726 ret = pthread_mutex_lock(&sched->start_work_mutex); in wait_for_tasks()
729 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
730 task = sched->tasks[i]; in wait_for_tasks()
731 sem_init(&task->sleep_sem, 0, 0); in wait_for_tasks()
732 task->curr_event = 0; in wait_for_tasks()
744 delta = T1 - T0; in run_one_test()
745 sched->sum_runtime += delta; in run_one_test()
746 sched->nr_runs++; in run_one_test()
748 avg_delta = sched->sum_runtime / sched->nr_runs; in run_one_test()
750 fluct = avg_delta - delta; in run_one_test()
752 fluct = delta - avg_delta; in run_one_test()
753 sched->sum_fluct += fluct; in run_one_test()
754 if (!sched->run_avg) in run_one_test()
755 sched->run_avg = delta; in run_one_test()
756 sched->run_avg = (sched->run_avg * (sched->replay_repeat - 1) + delta) / sched->replay_repeat; in run_one_test()
758 printf("#%-3ld: %0.3f, ", sched->nr_runs, (double)delta / NSEC_PER_MSEC); in run_one_test()
760 printf("ravg: %0.2f, ", (double)sched->run_avg / NSEC_PER_MSEC); in run_one_test()
763 (double)sched->cpu_usage / NSEC_PER_MSEC, (double)sched->runavg_cpu_usage / NSEC_PER_MSEC); in run_one_test()
768 * accurate than the sched->sum_exec_runtime based statistics: in run_one_test()
771 (double)sched->parent_cpu_usage / NSEC_PER_MSEC, in run_one_test()
772 (double)sched->runavg_parent_cpu_usage / NSEC_PER_MSEC); in run_one_test()
777 if (sched->nr_sleep_corrections) in run_one_test()
778 printf(" (%ld sleep corrections)\n", sched->nr_sleep_corrections); in run_one_test()
779 sched->nr_sleep_corrections = 0; in run_one_test()
790 printf("the run test took %" PRIu64 " nsecs\n", T1 - T0); in test_calibrations()
796 printf("the sleep test took %" PRIu64 " nsecs\n", T1 - T0); in test_calibrations()
801 struct perf_evsel *evsel, struct perf_sample *sample, in replay_wakeup_event() argument
804 const char *comm = perf_evsel__strval(evsel, sample, "comm"); in replay_wakeup_event()
805 const u32 pid = perf_evsel__intval(evsel, sample, "pid"); in replay_wakeup_event()
811 printf(" ... pid %d woke up %s/%d\n", sample->tid, comm, pid); in replay_wakeup_event()
814 waker = register_pid(sched, sample->tid, "<unknown>"); in replay_wakeup_event()
817 add_sched_event_wakeup(sched, waker, sample->time, wakee); in replay_wakeup_event()
823 struct perf_sample *sample, in replay_switch_event() argument
826 const char *prev_comm = perf_evsel__strval(evsel, sample, "prev_comm"), in replay_switch_event()
827 *next_comm = perf_evsel__strval(evsel, sample, "next_comm"); in replay_switch_event()
828 const u32 prev_pid = perf_evsel__intval(evsel, sample, "prev_pid"), in replay_switch_event()
829 next_pid = perf_evsel__intval(evsel, sample, "next_pid"); in replay_switch_event()
830 const u64 prev_state = perf_evsel__intval(evsel, sample, "prev_state"); in replay_switch_event()
832 u64 timestamp0, timestamp = sample->time; in replay_switch_event()
833 int cpu = sample->cpu; in replay_switch_event()
842 timestamp0 = sched->cpu_last_switched[cpu]; in replay_switch_event()
844 delta = timestamp - timestamp0; in replay_switch_event()
850 return -1; in replay_switch_event()
853 pr_debug(" ... switch from %s/%d to %s/%d [ran %" PRIu64 " nsecs]\n", in replay_switch_event()
859 sched->cpu_last_switched[cpu] = timestamp; in replay_switch_event()
873 child = machine__findnew_thread(machine, event->fork.pid, in replay_fork_event()
874 event->fork.tid); in replay_fork_event()
875 parent = machine__findnew_thread(machine, event->fork.ppid, in replay_fork_event()
876 event->fork.ptid); in replay_fork_event()
886 printf("... parent: %s/%d\n", thread__comm_str(parent), parent->tid); in replay_fork_event()
887 printf("... child: %s/%d\n", thread__comm_str(child), child->tid); in replay_fork_event()
890 register_pid(sched, parent->tid, thread__comm_str(parent)); in replay_fork_event()
891 register_pid(sched, child->tid, thread__comm_str(child)); in replay_fork_event()
915 init_stats(&r->run_stats); in thread__init_runtime()
944 ret = sort->cmp(l, r); in thread_lat_cmp()
956 struct rb_node *node = root->rb_node; in thread_atoms_search()
967 node = node->rb_left; in thread_atoms_search()
969 node = node->rb_right; in thread_atoms_search()
971 BUG_ON(thread != atoms->thread); in thread_atoms_search()
982 struct rb_node **new = &(root->rb_node), *parent = NULL; in __thread_latency_insert()
994 new = &((*new)->rb_left); in __thread_latency_insert()
996 new = &((*new)->rb_right); in __thread_latency_insert()
999 rb_link_node(&data->node, parent, new); in __thread_latency_insert()
1000 rb_insert_color(&data->node, root); in __thread_latency_insert()
1008 return -1; in thread_atoms_insert()
1011 atoms->thread = thread__get(thread); in thread_atoms_insert()
1012 INIT_LIST_HEAD(&atoms->work_list); in thread_atoms_insert()
1013 __thread_latency_insert(&sched->atom_root, atoms, &sched->cmp_pid); in thread_atoms_insert()
1032 return -1; in add_sched_out_event()
1035 atom->sched_out_time = timestamp; in add_sched_out_event()
1038 atom->state = THREAD_WAIT_CPU; in add_sched_out_event()
1039 atom->wake_up_time = atom->sched_out_time; in add_sched_out_event()
1042 list_add_tail(&atom->list, &atoms->work_list); in add_sched_out_event()
1052 BUG_ON(list_empty(&atoms->work_list)); in add_runtime_event()
1054 atom = list_entry(atoms->work_list.prev, struct work_atom, list); in add_runtime_event()
1056 atom->runtime += delta; in add_runtime_event()
1057 atoms->total_runtime += delta; in add_runtime_event()
1066 if (list_empty(&atoms->work_list)) in add_sched_in_event()
1069 atom = list_entry(atoms->work_list.prev, struct work_atom, list); in add_sched_in_event()
1071 if (atom->state != THREAD_WAIT_CPU) in add_sched_in_event()
1074 if (timestamp < atom->wake_up_time) { in add_sched_in_event()
1075 atom->state = THREAD_IGNORE; in add_sched_in_event()
1079 atom->state = THREAD_SCHED_IN; in add_sched_in_event()
1080 atom->sched_in_time = timestamp; in add_sched_in_event()
1082 delta = atom->sched_in_time - atom->wake_up_time; in add_sched_in_event()
1083 atoms->total_lat += delta; in add_sched_in_event()
1084 if (delta > atoms->max_lat) { in add_sched_in_event()
1085 atoms->max_lat = delta; in add_sched_in_event()
1086 atoms->max_lat_at = timestamp; in add_sched_in_event()
1088 atoms->nb_atoms++; in add_sched_in_event()
1093 struct perf_sample *sample, in latency_switch_event() argument
1096 const u32 prev_pid = perf_evsel__intval(evsel, sample, "prev_pid"), in latency_switch_event()
1097 next_pid = perf_evsel__intval(evsel, sample, "next_pid"); in latency_switch_event()
1098 const u64 prev_state = perf_evsel__intval(evsel, sample, "prev_state"); in latency_switch_event()
1101 u64 timestamp0, timestamp = sample->time; in latency_switch_event()
1102 int cpu = sample->cpu, err = -1; in latency_switch_event()
1107 timestamp0 = sched->cpu_last_switched[cpu]; in latency_switch_event()
1108 sched->cpu_last_switched[cpu] = timestamp; in latency_switch_event()
1110 delta = timestamp - timestamp0; in latency_switch_event()
1116 return -1; in latency_switch_event()
1119 sched_out = machine__findnew_thread(machine, -1, prev_pid); in latency_switch_event()
1120 sched_in = machine__findnew_thread(machine, -1, next_pid); in latency_switch_event()
1124 out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid); in latency_switch_event()
1128 out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid); in latency_switch_event()
1130 pr_err("out-event: Internal tree error"); in latency_switch_event()
1135 return -1; in latency_switch_event()
1137 in_events = thread_atoms_search(&sched->atom_root, sched_in, &sched->cmp_pid); in latency_switch_event()
1141 in_events = thread_atoms_search(&sched->atom_root, sched_in, &sched->cmp_pid); in latency_switch_event()
1143 pr_err("in-event: Internal tree error"); in latency_switch_event()
1163 struct perf_sample *sample, in latency_runtime_event() argument
1166 const u32 pid = perf_evsel__intval(evsel, sample, "pid"); in latency_runtime_event()
1167 const u64 runtime = perf_evsel__intval(evsel, sample, "runtime"); in latency_runtime_event()
1168 struct thread *thread = machine__findnew_thread(machine, -1, pid); in latency_runtime_event()
1169 struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); in latency_runtime_event()
1170 u64 timestamp = sample->time; in latency_runtime_event()
1171 int cpu = sample->cpu, err = -1; in latency_runtime_event()
1174 return -1; in latency_runtime_event()
1180 atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); in latency_runtime_event()
1182 pr_err("in-event: Internal tree error"); in latency_runtime_event()
1198 struct perf_sample *sample, in latency_wakeup_event() argument
1201 const u32 pid = perf_evsel__intval(evsel, sample, "pid"); in latency_wakeup_event()
1205 u64 timestamp = sample->time; in latency_wakeup_event()
1206 int err = -1; in latency_wakeup_event()
1208 wakee = machine__findnew_thread(machine, -1, pid); in latency_wakeup_event()
1210 return -1; in latency_wakeup_event()
1211 atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid); in latency_wakeup_event()
1215 atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid); in latency_wakeup_event()
1217 pr_err("wakeup-event: Internal tree error"); in latency_wakeup_event()
1224 BUG_ON(list_empty(&atoms->work_list)); in latency_wakeup_event()
1226 atom = list_entry(atoms->work_list.prev, struct work_atom, list); in latency_wakeup_event()
1231 * on run queue and wakeup only change ->state to TASK_RUNNING, in latency_wakeup_event()
1232 * then we should not set the ->wake_up_time when wake up a in latency_wakeup_event()
1239 if (sched->profile_cpu == -1 && atom->state != THREAD_SLEEPING) in latency_wakeup_event()
1242 sched->nr_timestamps++; in latency_wakeup_event()
1243 if (atom->sched_out_time > timestamp) { in latency_wakeup_event()
1244 sched->nr_unordered_timestamps++; in latency_wakeup_event()
1248 atom->state = THREAD_WAIT_CPU; in latency_wakeup_event()
1249 atom->wake_up_time = timestamp; in latency_wakeup_event()
1259 struct perf_sample *sample, in latency_migrate_task_event() argument
1262 const u32 pid = perf_evsel__intval(evsel, sample, "pid"); in latency_migrate_task_event()
1263 u64 timestamp = sample->time; in latency_migrate_task_event()
1267 int err = -1; in latency_migrate_task_event()
1272 if (sched->profile_cpu == -1) in latency_migrate_task_event()
1275 migrant = machine__findnew_thread(machine, -1, pid); in latency_migrate_task_event()
1277 return -1; in latency_migrate_task_event()
1278 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid); in latency_migrate_task_event()
1282 register_pid(sched, migrant->tid, thread__comm_str(migrant)); in latency_migrate_task_event()
1283 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid); in latency_migrate_task_event()
1285 pr_err("migration-event: Internal tree error"); in latency_migrate_task_event()
1292 BUG_ON(list_empty(&atoms->work_list)); in latency_migrate_task_event()
1294 atom = list_entry(atoms->work_list.prev, struct work_atom, list); in latency_migrate_task_event()
1295 atom->sched_in_time = atom->sched_out_time = atom->wake_up_time = timestamp; in latency_migrate_task_event()
1297 sched->nr_timestamps++; in latency_migrate_task_event()
1299 if (atom->sched_out_time > timestamp) in latency_migrate_task_event()
1300 sched->nr_unordered_timestamps++; in latency_migrate_task_event()
1314 if (!work_list->nb_atoms) in output_lat_thread()
1319 if (!strcmp(thread__comm_str(work_list->thread), "swapper")) in output_lat_thread()
1322 sched->all_runtime += work_list->total_runtime; in output_lat_thread()
1323 sched->all_count += work_list->nb_atoms; in output_lat_thread()
1325 if (work_list->num_merged > 1) in output_lat_thread()
1326 ret = printf(" %s:(%d) ", thread__comm_str(work_list->thread), work_list->num_merged); in output_lat_thread()
1328 ret = printf(" %s:%d ", thread__comm_str(work_list->thread), work_list->thread->tid); in output_lat_thread()
1330 for (i = 0; i < 24 - ret; i++) in output_lat_thread()
1333 avg = work_list->total_lat / work_list->nb_atoms; in output_lat_thread()
1334 timestamp__scnprintf_usec(work_list->max_lat_at, max_lat_at, sizeof(max_lat_at)); in output_lat_thread()
1337 (double)work_list->total_runtime / NSEC_PER_MSEC, in output_lat_thread()
1338 work_list->nb_atoms, (double)avg / NSEC_PER_MSEC, in output_lat_thread()
1339 (double)work_list->max_lat / NSEC_PER_MSEC, in output_lat_thread()
1345 if (l->thread == r->thread) in pid_cmp()
1347 if (l->thread->tid < r->thread->tid) in pid_cmp()
1348 return -1; in pid_cmp()
1349 if (l->thread->tid > r->thread->tid) in pid_cmp()
1351 return (int)(l->thread - r->thread); in pid_cmp()
1358 if (!l->nb_atoms) in avg_cmp()
1359 return -1; in avg_cmp()
1361 if (!r->nb_atoms) in avg_cmp()
1364 avgl = l->total_lat / l->nb_atoms; in avg_cmp()
1365 avgr = r->total_lat / r->nb_atoms; in avg_cmp()
1368 return -1; in avg_cmp()
1377 if (l->max_lat < r->max_lat) in max_cmp()
1378 return -1; in max_cmp()
1379 if (l->max_lat > r->max_lat) in max_cmp()
1387 if (l->nb_atoms < r->nb_atoms) in switch_cmp()
1388 return -1; in switch_cmp()
1389 if (l->nb_atoms > r->nb_atoms) in switch_cmp()
1397 if (l->total_runtime < r->total_runtime) in runtime_cmp()
1398 return -1; in runtime_cmp()
1399 if (l->total_runtime > r->total_runtime) in runtime_cmp()
1437 if (!strcmp(available_sorts[i]->name, tok)) { in sort_dimension__add()
1438 list_add_tail(&available_sorts[i]->list, list); in sort_dimension__add()
1444 return -1; in sort_dimension__add()
1450 struct rb_root *root = &sched->atom_root; in perf_sched__sort_lat()
1460 __thread_latency_insert(&sched->sorted_atom_root, data, &sched->sort_list); in perf_sched__sort_lat()
1462 if (root == &sched->atom_root) { in perf_sched__sort_lat()
1463 root = &sched->merged_atom_root; in perf_sched__sort_lat()
1470 struct perf_sample *sample, in process_sched_wakeup_event() argument
1475 if (sched->tp_handler->wakeup_event) in process_sched_wakeup_event()
1476 return sched->tp_handler->wakeup_event(sched, evsel, sample, machine); in process_sched_wakeup_event()
1503 if (!sched->map.color_pids || !thread || thread__priv(thread)) in map__findnew_thread()
1506 if (thread_map__has(sched->map.color_pids, tid)) in map__findnew_thread()
1514 struct perf_sample *sample, struct machine *machine) in map_switch_event() argument
1516 const u32 next_pid = perf_evsel__intval(evsel, sample, "next_pid"); in map_switch_event()
1520 u64 timestamp0, timestamp = sample->time; in map_switch_event()
1522 int i, this_cpu = sample->cpu; in map_switch_event()
1530 if (this_cpu > sched->max_cpu) in map_switch_event()
1531 sched->max_cpu = this_cpu; in map_switch_event()
1533 if (sched->map.comp) { in map_switch_event()
1534 cpus_nr = bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS); in map_switch_event()
1535 if (!test_and_set_bit(this_cpu, sched->map.comp_cpus_mask)) { in map_switch_event()
1536 sched->map.comp_cpus[cpus_nr++] = this_cpu; in map_switch_event()
1540 cpus_nr = sched->max_cpu; in map_switch_event()
1542 timestamp0 = sched->cpu_last_switched[this_cpu]; in map_switch_event()
1543 sched->cpu_last_switched[this_cpu] = timestamp; in map_switch_event()
1545 delta = timestamp - timestamp0; in map_switch_event()
1551 return -1; in map_switch_event()
1554 sched_in = map__findnew_thread(sched, machine, -1, next_pid); in map_switch_event()
1556 return -1; in map_switch_event()
1561 return -1; in map_switch_event()
1564 sched->curr_thread[this_cpu] = thread__get(sched_in); in map_switch_event()
1569 if (!tr->shortname[0]) { in map_switch_event()
1572 * Don't allocate a letter-number for swapper:0 in map_switch_event()
1575 tr->shortname[0] = '.'; in map_switch_event()
1576 tr->shortname[1] = ' '; in map_switch_event()
1578 tr->shortname[0] = sched->next_shortname1; in map_switch_event()
1579 tr->shortname[1] = sched->next_shortname2; in map_switch_event()
1581 if (sched->next_shortname1 < 'Z') { in map_switch_event()
1582 sched->next_shortname1++; in map_switch_event()
1584 sched->next_shortname1 = 'A'; in map_switch_event()
1585 if (sched->next_shortname2 < '9') in map_switch_event()
1586 sched->next_shortname2++; in map_switch_event()
1588 sched->next_shortname2 = '0'; in map_switch_event()
1595 int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i; in map_switch_event()
1596 struct thread *curr_thread = sched->curr_thread[cpu]; in map_switch_event()
1604 if (sched->map.cpus && !cpu_map__has(sched->map.cpus, cpu)) in map_switch_event()
1607 if (sched->map.color_cpus && cpu_map__has(sched->map.color_cpus, cpu)) in map_switch_event()
1615 if (sched->curr_thread[cpu]) { in map_switch_event()
1616 curr_tr = thread__get_runtime(sched->curr_thread[cpu]); in map_switch_event()
1619 return -1; in map_switch_event()
1621 color_fprintf(stdout, pid_color, "%2s ", curr_tr->shortname); in map_switch_event()
1626 if (sched->map.cpus && !cpu_map__has(sched->map.cpus, this_cpu)) in map_switch_event()
1631 if (new_shortname || tr->comm_changed || (verbose > 0 && sched_in->tid)) { in map_switch_event()
1638 tr->shortname, thread__comm_str(sched_in), sched_in->tid); in map_switch_event()
1639 tr->comm_changed = false; in map_switch_event()
1642 if (sched->map.comp && new_cpu) in map_switch_event()
1655 struct perf_sample *sample, in process_sched_switch_event() argument
1659 int this_cpu = sample->cpu, err = 0; in process_sched_switch_event()
1660 u32 prev_pid = perf_evsel__intval(evsel, sample, "prev_pid"), in process_sched_switch_event()
1661 next_pid = perf_evsel__intval(evsel, sample, "next_pid"); in process_sched_switch_event()
1663 if (sched->curr_pid[this_cpu] != (u32)-1) { in process_sched_switch_event()
1668 if (sched->curr_pid[this_cpu] != prev_pid) in process_sched_switch_event()
1669 sched->nr_context_switch_bugs++; in process_sched_switch_event()
1672 if (sched->tp_handler->switch_event) in process_sched_switch_event()
1673 err = sched->tp_handler->switch_event(sched, evsel, sample, machine); in process_sched_switch_event()
1675 sched->curr_pid[this_cpu] = next_pid; in process_sched_switch_event()
1681 struct perf_sample *sample, in process_sched_runtime_event() argument
1686 if (sched->tp_handler->runtime_event) in process_sched_runtime_event()
1687 return sched->tp_handler->runtime_event(sched, evsel, sample, machine); in process_sched_runtime_event()
1694 struct perf_sample *sample, in perf_sched__process_fork_event() argument
1700 perf_event__process_fork(tool, event, sample, machine); in perf_sched__process_fork_event()
1703 if (sched->tp_handler->fork_event) in perf_sched__process_fork_event()
1704 return sched->tp_handler->fork_event(sched, event, machine); in perf_sched__process_fork_event()
1711 struct perf_sample *sample, in process_sched_migrate_task_event() argument
1716 if (sched->tp_handler->migrate_task_event) in process_sched_migrate_task_event()
1717 return sched->tp_handler->migrate_task_event(sched, evsel, sample, machine); in process_sched_migrate_task_event()
1724 struct perf_sample *sample,
1729 struct perf_sample *sample, in perf_sched__process_tracepoint_sample() argument
1735 if (evsel->handler != NULL) { in perf_sched__process_tracepoint_sample()
1736 tracepoint_handler f = evsel->handler; in perf_sched__process_tracepoint_sample()
1737 err = f(tool, evsel, sample, machine); in perf_sched__process_tracepoint_sample()
1745 struct perf_sample *sample, in perf_sched__process_comm() argument
1752 err = perf_event__process_comm(tool, event, sample, machine); in perf_sched__process_comm()
1756 thread = machine__find_thread(machine, sample->pid, sample->tid); in perf_sched__process_comm()
1759 return -1; in perf_sched__process_comm()
1765 return -1; in perf_sched__process_comm()
1768 tr->comm_changed = true; in perf_sched__process_comm()
1789 .force = sched->force, in perf_sched__read_events()
1791 int rc = -1; in perf_sched__read_events()
1793 session = perf_session__new(&data, false, &sched->tool); in perf_sched__read_events()
1796 return -1; in perf_sched__read_events()
1799 symbol__init(&session->header.env); in perf_sched__read_events()
1804 if (perf_session__has_traces(session, "record -R")) { in perf_sched__read_events()
1811 sched->nr_events = session->evlist->stats.nr_events[0]; in perf_sched__read_events()
1812 sched->nr_lost_events = session->evlist->stats.total_lost; in perf_sched__read_events()
1813 sched->nr_lost_chunks = session->evlist->stats.nr_events[PERF_RECORD_LOST]; in perf_sched__read_events()
1825 static inline void print_sched_time(unsigned long long nsecs, int width) in print_sched_time() argument
1830 msecs = nsecs / NSEC_PER_MSEC; in print_sched_time()
1831 nsecs -= msecs * NSEC_PER_MSEC; in print_sched_time()
1832 usecs = nsecs / NSEC_PER_USEC; in print_sched_time()
1838 * first time it is used.
1842 struct evsel_runtime *r = evsel->priv; in perf_evsel__get_runtime()
1846 evsel->priv = r; in perf_evsel__get_runtime()
1853 * save last time event was seen per cpu
1863 if ((cpu >= r->ncpu) || (r->last_time == NULL)) { in perf_evsel__save_time()
1865 void *p = r->last_time; in perf_evsel__save_time()
1867 p = realloc(r->last_time, n * sizeof(u64)); in perf_evsel__save_time()
1871 r->last_time = p; in perf_evsel__save_time()
1872 for (i = r->ncpu; i < n; ++i) in perf_evsel__save_time()
1873 r->last_time[i] = (u64) 0; in perf_evsel__save_time()
1875 r->ncpu = n; in perf_evsel__save_time()
1878 r->last_time[cpu] = timestamp; in perf_evsel__save_time()
1881 /* returns last time this event was seen on the given cpu */
1886 if ((r == NULL) || (r->last_time == NULL) || (cpu >= r->ncpu)) in perf_evsel__get_time()
1889 return r->last_time[cpu]; in perf_evsel__get_time()
1898 pid_t tid = thread->tid; in timehist_get_commstr()
1899 pid_t pid = thread->pid_; in timehist_get_commstr()
1919 u32 ncpus = sched->max_cpu + 1; in timehist_header()
1922 printf("%15s %6s ", "time", "cpu"); in timehist_header()
1924 if (sched->show_cpu_visual) { in timehist_header()
1934 printf(" %-*s %9s %9s %9s", comm_width, in timehist_header()
1935 "task name", "wait time", "sch delay", "run time"); in timehist_header()
1937 if (sched->show_state) in timehist_header()
1945 printf("%15s %-6s ", "", ""); in timehist_header()
1947 if (sched->show_cpu_visual) in timehist_header()
1950 printf(" %-*s %9s %9s %9s", comm_width, in timehist_header()
1953 if (sched->show_state) in timehist_header()
1963 if (sched->show_cpu_visual) in timehist_header()
1970 if (sched->show_state) in timehist_header()
1982 if (thread->tid == 0) in task_state_char()
1985 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; in task_state_char()
1990 struct perf_sample *sample, in timehist_print_sample() argument
1996 const char *next_comm = perf_evsel__strval(evsel, sample, "next_comm"); in timehist_print_sample()
1997 const u32 next_pid = perf_evsel__intval(evsel, sample, "next_pid"); in timehist_print_sample()
1998 u32 max_cpus = sched->max_cpu + 1; in timehist_print_sample()
2004 printf("%15s [%04d] ", tstr, sample->cpu); in timehist_print_sample()
2006 if (sched->show_cpu_visual) { in timehist_print_sample()
2013 if (i == sample->cpu) in timehist_print_sample()
2014 c = (thread->tid == 0) ? 'i' : 's'; in timehist_print_sample()
2022 printf(" %-*s ", comm_width, timehist_get_commstr(thread)); in timehist_print_sample()
2024 wait_time = tr->dt_sleep + tr->dt_iowait + tr->dt_preempt; in timehist_print_sample()
2027 print_sched_time(tr->dt_delay, 6); in timehist_print_sample()
2028 print_sched_time(tr->dt_run, 6); in timehist_print_sample()
2030 if (sched->show_state) in timehist_print_sample()
2033 if (sched->show_next) { in timehist_print_sample()
2035 printf(" %-*s", comm_width, nstr); in timehist_print_sample()
2038 if (sched->show_wakeups && !sched->show_next) in timehist_print_sample()
2039 printf(" %-*s", comm_width, ""); in timehist_print_sample()
2041 if (thread->tid == 0) in timehist_print_sample()
2044 if (sched->show_callchain) in timehist_print_sample()
2047 sample__fprintf_sym(sample, al, 0, in timehist_print_sample()
2058 * Explanation of delta-time stats:
2060 * t = time of current schedule out event
2061 * tprev = time of previous sched out event
2062 * also time of schedule-in event for current task
2063 * last_time = time of last sched change event for current task
2064 * (i.e, time process was last scheduled out)
2065 * ready_to_run = time of wakeup for current task
2067 * -----|------------|------------|------------|------
2069 * time to run
2071 * |-------- dt_wait --------|
2072 * |- dt_delay -|-- dt_run --|
2074 * dt_run = run time of current task
2075 * dt_wait = time between last schedule out event for task and tprev
2076 * represents time spent off the cpu
2077 * dt_delay = time between wakeup and schedule-in of task
2083 r->dt_delay = 0; in timehist_update_runtime_stats()
2084 r->dt_sleep = 0; in timehist_update_runtime_stats()
2085 r->dt_iowait = 0; in timehist_update_runtime_stats()
2086 r->dt_preempt = 0; in timehist_update_runtime_stats()
2087 r->dt_run = 0; in timehist_update_runtime_stats()
2090 r->dt_run = t - tprev; in timehist_update_runtime_stats()
2091 if (r->ready_to_run) { in timehist_update_runtime_stats()
2092 if (r->ready_to_run > tprev) in timehist_update_runtime_stats()
2093 pr_debug("time travel: wakeup time for task > previous sched_switch event\n"); in timehist_update_runtime_stats()
2095 r->dt_delay = tprev - r->ready_to_run; in timehist_update_runtime_stats()
2098 if (r->last_time > tprev) in timehist_update_runtime_stats()
2099 pr_debug("time travel: last sched out time for task > previous sched_switch event\n"); in timehist_update_runtime_stats()
2100 else if (r->last_time) { in timehist_update_runtime_stats()
2101 u64 dt_wait = tprev - r->last_time; in timehist_update_runtime_stats()
2103 if (r->last_state == TASK_RUNNING) in timehist_update_runtime_stats()
2104 r->dt_preempt = dt_wait; in timehist_update_runtime_stats()
2105 else if (r->last_state == TASK_UNINTERRUPTIBLE) in timehist_update_runtime_stats()
2106 r->dt_iowait = dt_wait; in timehist_update_runtime_stats()
2108 r->dt_sleep = dt_wait; in timehist_update_runtime_stats()
2112 update_stats(&r->run_stats, r->dt_run); in timehist_update_runtime_stats()
2114 r->total_run_time += r->dt_run; in timehist_update_runtime_stats()
2115 r->total_delay_time += r->dt_delay; in timehist_update_runtime_stats()
2116 r->total_sleep_time += r->dt_sleep; in timehist_update_runtime_stats()
2117 r->total_iowait_time += r->dt_iowait; in timehist_update_runtime_stats()
2118 r->total_preempt_time += r->dt_preempt; in timehist_update_runtime_stats()
2121 static bool is_idle_sample(struct perf_sample *sample, in is_idle_sample() argument
2126 return perf_evsel__intval(evsel, sample, "prev_pid") == 0; in is_idle_sample()
2128 return sample->pid == 0; in is_idle_sample()
2132 struct perf_sample *sample, in save_task_callchain() argument
2139 /* want main thread for process - has maps */ in save_task_callchain()
2140 thread = machine__findnew_thread(machine, sample->pid, sample->pid); in save_task_callchain()
2142 pr_debug("Failed to get thread for pid %d.\n", sample->pid); in save_task_callchain()
2146 if (!sched->show_callchain || sample->callchain == NULL) in save_task_callchain()
2149 if (thread__resolve_callchain(thread, cursor, evsel, sample, in save_task_callchain()
2150 NULL, NULL, sched->max_stack + 2) != 0) { in save_task_callchain()
2167 sym = node->sym; in save_task_callchain()
2169 if (!strcmp(sym->name, "schedule") || in save_task_callchain()
2170 !strcmp(sym->name, "__schedule") || in save_task_callchain()
2171 !strcmp(sym->name, "preempt_schedule")) in save_task_callchain()
2172 sym->ignore = 1; in save_task_callchain()
2187 return -ENOMEM; in init_idle_thread()
2189 init_stats(&itr->tr.run_stats); in init_idle_thread()
2190 callchain_init(&itr->callchain); in init_idle_thread()
2191 callchain_cursor_reset(&itr->cursor); in init_idle_thread()
2207 return -ENOMEM; in init_idle_threads()
2215 return -ENOMEM; in init_idle_threads()
2276 struct perf_sample *sample) in save_idle_callchain() argument
2278 if (!sched->show_callchain || sample->callchain == NULL) in save_idle_callchain()
2281 callchain_cursor__copy(&itr->cursor, &callchain_cursor); in save_idle_callchain()
2285 struct perf_sample *sample, in timehist_get_thread() argument
2291 if (is_idle_sample(sample, evsel)) { in timehist_get_thread()
2292 thread = get_idle_thread(sample->cpu); in timehist_get_thread()
2294 pr_err("Failed to get idle thread for cpu %d.\n", sample->cpu); in timehist_get_thread()
2297 /* there were samples with tid 0 but non-zero pid */ in timehist_get_thread()
2298 thread = machine__findnew_thread(machine, sample->pid, in timehist_get_thread()
2299 sample->tid ?: sample->pid); in timehist_get_thread()
2301 pr_debug("Failed to get thread for tid %d. skipping sample.\n", in timehist_get_thread()
2302 sample->tid); in timehist_get_thread()
2305 save_task_callchain(sched, sample, evsel, machine); in timehist_get_thread()
2306 if (sched->idle_hist) { in timehist_get_thread()
2310 idle = get_idle_thread(sample->cpu); in timehist_get_thread()
2312 pr_err("Failed to get idle thread for cpu %d.\n", sample->cpu); in timehist_get_thread()
2320 itr->last_thread = thread; in timehist_get_thread()
2323 if (perf_evsel__intval(evsel, sample, "next_pid") == 0) in timehist_get_thread()
2324 save_idle_callchain(sched, itr, sample); in timehist_get_thread()
2334 struct perf_sample *sample) in timehist_skip_sample() argument
2340 sched->skipped_samples++; in timehist_skip_sample()
2343 if (sched->idle_hist) { in timehist_skip_sample()
2346 else if (perf_evsel__intval(evsel, sample, "prev_pid") != 0 && in timehist_skip_sample()
2347 perf_evsel__intval(evsel, sample, "next_pid") != 0) in timehist_skip_sample()
2356 struct perf_sample *sample, in timehist_print_wakeup_event() argument
2363 thread = machine__findnew_thread(machine, sample->pid, sample->tid); in timehist_print_wakeup_event()
2368 if (timehist_skip_sample(sched, thread, evsel, sample) && in timehist_print_wakeup_event()
2369 timehist_skip_sample(sched, awakened, evsel, sample)) { in timehist_print_wakeup_event()
2373 timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr)); in timehist_print_wakeup_event()
2374 printf("%15s [%04d] ", tstr, sample->cpu); in timehist_print_wakeup_event()
2375 if (sched->show_cpu_visual) in timehist_print_wakeup_event()
2376 printf(" %*s ", sched->max_cpu + 1, ""); in timehist_print_wakeup_event()
2378 printf(" %-*s ", comm_width, timehist_get_commstr(thread)); in timehist_print_wakeup_event()
2391 struct perf_sample *sample, in timehist_sched_wakeup_event() argument
2397 /* want pid of awakened task not pid in sample */ in timehist_sched_wakeup_event()
2398 const u32 pid = perf_evsel__intval(evsel, sample, "pid"); in timehist_sched_wakeup_event()
2402 return -1; in timehist_sched_wakeup_event()
2406 return -1; in timehist_sched_wakeup_event()
2408 if (tr->ready_to_run == 0) in timehist_sched_wakeup_event()
2409 tr->ready_to_run = sample->time; in timehist_sched_wakeup_event()
2412 if (sched->show_wakeups && in timehist_sched_wakeup_event()
2413 !perf_time__skip_sample(&sched->ptime, sample->time)) in timehist_sched_wakeup_event()
2414 timehist_print_wakeup_event(sched, evsel, sample, machine, thread); in timehist_sched_wakeup_event()
2421 struct perf_sample *sample, in timehist_print_migration_event() argument
2427 u32 max_cpus = sched->max_cpu + 1; in timehist_print_migration_event()
2430 if (sched->summary_only) in timehist_print_migration_event()
2433 max_cpus = sched->max_cpu + 1; in timehist_print_migration_event()
2434 ocpu = perf_evsel__intval(evsel, sample, "orig_cpu"); in timehist_print_migration_event()
2435 dcpu = perf_evsel__intval(evsel, sample, "dest_cpu"); in timehist_print_migration_event()
2437 thread = machine__findnew_thread(machine, sample->pid, sample->tid); in timehist_print_migration_event()
2441 if (timehist_skip_sample(sched, thread, evsel, sample) && in timehist_print_migration_event()
2442 timehist_skip_sample(sched, migrated, evsel, sample)) { in timehist_print_migration_event()
2446 timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr)); in timehist_print_migration_event()
2447 printf("%15s [%04d] ", tstr, sample->cpu); in timehist_print_migration_event()
2449 if (sched->show_cpu_visual) { in timehist_print_migration_event()
2455 c = (i == sample->cpu) ? 'm' : ' '; in timehist_print_migration_event()
2461 printf(" %-*s ", comm_width, timehist_get_commstr(thread)); in timehist_print_migration_event()
2475 struct perf_sample *sample, in timehist_migrate_task_event() argument
2481 /* want pid of migrated task not pid in sample */ in timehist_migrate_task_event()
2482 const u32 pid = perf_evsel__intval(evsel, sample, "pid"); in timehist_migrate_task_event()
2486 return -1; in timehist_migrate_task_event()
2490 return -1; in timehist_migrate_task_event()
2492 tr->migrations++; in timehist_migrate_task_event()
2495 timehist_print_migration_event(sched, evsel, sample, machine, thread); in timehist_migrate_task_event()
2503 struct perf_sample *sample, in timehist_sched_change_event() argument
2507 struct perf_time_interval *ptime = &sched->ptime; in timehist_sched_change_event()
2511 u64 tprev, t = sample->time; in timehist_sched_change_event()
2513 int state = perf_evsel__intval(evsel, sample, "prev_state"); in timehist_sched_change_event()
2516 if (machine__resolve(machine, &al, sample) < 0) { in timehist_sched_change_event()
2518 event->header.type); in timehist_sched_change_event()
2519 rc = -1; in timehist_sched_change_event()
2523 thread = timehist_get_thread(sched, sample, machine, evsel); in timehist_sched_change_event()
2525 rc = -1; in timehist_sched_change_event()
2529 if (timehist_skip_sample(sched, thread, evsel, sample)) in timehist_sched_change_event()
2534 rc = -1; in timehist_sched_change_event()
2538 tprev = perf_evsel__get_time(evsel, sample->cpu); in timehist_sched_change_event()
2541 * If start time given: in timehist_sched_change_event()
2542 * - sample time is under window user cares about - skip sample in timehist_sched_change_event()
2543 * - tprev is under window user cares about - reset to start of window in timehist_sched_change_event()
2545 if (ptime->start && ptime->start > t) in timehist_sched_change_event()
2548 if (tprev && ptime->start > tprev) in timehist_sched_change_event()
2549 tprev = ptime->start; in timehist_sched_change_event()
2552 * If end time given: in timehist_sched_change_event()
2553 * - previous sched event is out of window - we are done in timehist_sched_change_event()
2554 * - sample time is beyond window user cares about - reset it in timehist_sched_change_event()
2555 * to close out stats for time window interest in timehist_sched_change_event()
2557 if (ptime->end) { in timehist_sched_change_event()
2558 if (tprev > ptime->end) in timehist_sched_change_event()
2561 if (t > ptime->end) in timehist_sched_change_event()
2562 t = ptime->end; in timehist_sched_change_event()
2565 if (!sched->idle_hist || thread->tid == 0) { in timehist_sched_change_event()
2568 if (sched->idle_hist) { in timehist_sched_change_event()
2572 BUG_ON(thread->tid != 0); in timehist_sched_change_event()
2574 if (itr->last_thread == NULL) in timehist_sched_change_event()
2577 /* add current idle time as last thread's runtime */ in timehist_sched_change_event()
2578 last_tr = thread__get_runtime(itr->last_thread); in timehist_sched_change_event()
2584 * remove delta time of last thread as it's not updated in timehist_sched_change_event()
2586 * time. we only care total run time and run stat. in timehist_sched_change_event()
2588 last_tr->dt_run = 0; in timehist_sched_change_event()
2589 last_tr->dt_delay = 0; in timehist_sched_change_event()
2590 last_tr->dt_sleep = 0; in timehist_sched_change_event()
2591 last_tr->dt_iowait = 0; in timehist_sched_change_event()
2592 last_tr->dt_preempt = 0; in timehist_sched_change_event()
2594 if (itr->cursor.nr) in timehist_sched_change_event()
2595 callchain_append(&itr->callchain, &itr->cursor, t - tprev); in timehist_sched_change_event()
2597 itr->last_thread = NULL; in timehist_sched_change_event()
2601 if (!sched->summary_only) in timehist_sched_change_event()
2602 timehist_print_sample(sched, evsel, sample, &al, thread, t, state); in timehist_sched_change_event()
2605 if (sched->hist_time.start == 0 && t >= ptime->start) in timehist_sched_change_event()
2606 sched->hist_time.start = t; in timehist_sched_change_event()
2607 if (ptime->end == 0 || t <= ptime->end) in timehist_sched_change_event()
2608 sched->hist_time.end = t; in timehist_sched_change_event()
2611 /* time of this sched_switch event becomes last time task seen */ in timehist_sched_change_event()
2612 tr->last_time = sample->time; in timehist_sched_change_event()
2614 /* last state is used to determine where to account wait time */ in timehist_sched_change_event()
2615 tr->last_state = state; in timehist_sched_change_event()
2617 /* sched out event for task so reset ready to run time */ in timehist_sched_change_event()
2618 tr->ready_to_run = 0; in timehist_sched_change_event()
2621 perf_evsel__save_time(evsel, sample->time, sample->cpu); in timehist_sched_change_event()
2629 struct perf_sample *sample, in timehist_sched_switch_event() argument
2632 return timehist_sched_change_event(tool, event, evsel, sample, machine); in timehist_sched_switch_event()
2637 struct perf_sample *sample, in process_lost() argument
2642 timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr)); in process_lost()
2644 printf("lost %" PRIu64 " events on cpu %d\n", event->lost.lost, sample->cpu); in process_lost()
2653 double mean = avg_stats(&r->run_stats); in print_thread_runtime()
2657 comm_width, timehist_get_commstr(t), t->ppid, in print_thread_runtime()
2658 (u64) r->run_stats.n); in print_thread_runtime()
2660 print_sched_time(r->total_run_time, 8); in print_thread_runtime()
2661 stddev = rel_stddev_stats(stddev_stats(&r->run_stats), mean); in print_thread_runtime()
2662 print_sched_time(r->run_stats.min, 6); in print_thread_runtime()
2666 print_sched_time(r->run_stats.max, 6); in print_thread_runtime()
2669 printf(" %5" PRIu64, r->migrations); in print_thread_runtime()
2677 comm_width, timehist_get_commstr(t), t->ppid, in print_thread_waittime()
2678 (u64) r->run_stats.n); in print_thread_waittime()
2680 print_sched_time(r->total_run_time, 8); in print_thread_waittime()
2681 print_sched_time(r->total_sleep_time, 6); in print_thread_waittime()
2683 print_sched_time(r->total_iowait_time, 6); in print_thread_waittime()
2685 print_sched_time(r->total_preempt_time, 6); in print_thread_waittime()
2687 print_sched_time(r->total_delay_time, 6); in print_thread_waittime()
2707 if (r && r->run_stats.n) { in __show_thread_runtime()
2708 stats->task_count++; in __show_thread_runtime()
2709 stats->sched_count += r->run_stats.n; in __show_thread_runtime()
2710 stats->total_run_time += r->total_run_time; in __show_thread_runtime()
2712 if (stats->sched->show_state) in __show_thread_runtime()
2723 if (t->dead) in show_thread_runtime()
2731 if (!t->dead) in show_deadthread_runtime()
2739 const char *sep = " <- "; in callchain__fprintf_folded()
2748 ret = callchain__fprintf_folded(fp, node->parent); in callchain__fprintf_folded()
2751 list_for_each_entry(chain, &node->val, list) { in callchain__fprintf_folded()
2752 if (chain->ip >= PERF_CONTEXT_MAX) in callchain__fprintf_folded()
2754 if (chain->ms.sym && chain->ms.sym->ignore) in callchain__fprintf_folded()
2772 printf(" %16s %8s %s\n", "Idle time (msec)", "Count", "Callchains"); in timehist_print_idlehist_callchain()
2781 print_sched_time(chain->hit, 12); in timehist_print_idlehist_callchain()
2783 ret += fprintf(fp, " %8d ", chain->count); in timehist_print_idlehist_callchain()
2794 struct machine *m = &session->machines.host; in timehist_print_summary()
2800 u64 hist_time = sched->hist_time.end - sched->hist_time.start; in timehist_print_summary()
2805 if (sched->idle_hist) { in timehist_print_summary()
2806 printf("\nIdle-time summary\n"); in timehist_print_summary()
2807 printf("%*s parent sched-out ", comm_width, "comm"); in timehist_print_summary()
2808 printf(" idle-time min-idle avg-idle max-idle stddev migrations\n"); in timehist_print_summary()
2809 } else if (sched->show_state) { in timehist_print_summary()
2810 printf("\nWait-time summary\n"); in timehist_print_summary()
2811 printf("%*s parent sched-in ", comm_width, "comm"); in timehist_print_summary()
2812 printf(" run-time sleep iowait preempt delay\n"); in timehist_print_summary()
2815 printf("%*s parent sched-in ", comm_width, "comm"); in timehist_print_summary()
2816 printf(" run-time min-run avg-run max-run stddev migrations\n"); in timehist_print_summary()
2820 sched->show_state ? "(msec)" : "%"); in timehist_print_summary()
2834 if (sched->skipped_samples && !sched->idle_hist) in timehist_print_summary()
2844 if (r && r->run_stats.n) { in timehist_print_summary()
2845 totals.sched_count += r->run_stats.n; in timehist_print_summary()
2847 print_sched_time(r->total_run_time, 6); in timehist_print_summary()
2848 printf(" msec (%6.2f%%)\n", 100.0 * r->total_run_time / hist_time); in timehist_print_summary()
2850 printf(" CPU %2d idle entire time window\n", i); in timehist_print_summary()
2853 if (sched->idle_hist && sched->show_callchain) { in timehist_print_summary()
2871 callchain_param.sort(&itr->sorted_root, &itr->callchain, in timehist_print_summary()
2875 print_sched_time(itr->tr.total_run_time, 6); in timehist_print_summary()
2877 timehist_print_idlehist_callchain(&itr->sorted_root); in timehist_print_summary()
2887 printf(" Total run time (msec): "); in timehist_print_summary()
2891 printf(" Total scheduling time (msec): "); in timehist_print_summary()
2893 printf(" (x %d)\n", sched->max_cpu); in timehist_print_summary()
2899 struct perf_sample *sample,
2904 struct perf_sample *sample, in perf_timehist__process_sample() argument
2910 int this_cpu = sample->cpu; in perf_timehist__process_sample()
2912 if (this_cpu > sched->max_cpu) in perf_timehist__process_sample()
2913 sched->max_cpu = this_cpu; in perf_timehist__process_sample()
2915 if (evsel->handler != NULL) { in perf_timehist__process_sample()
2916 sched_handler f = evsel->handler; in perf_timehist__process_sample()
2918 err = f(tool, event, evsel, sample, machine); in perf_timehist__process_sample()
2930 list_for_each_entry(evsel, &evlist->entries, node) { in timehist_check_attr()
2934 return -1; in timehist_check_attr()
2937 if (sched->show_callchain && !evsel__has_callchain(evsel)) { in timehist_check_attr()
2939 sched->show_callchain = 0; in timehist_check_attr()
2962 .force = sched->force, in perf_sched__timehist()
2967 int err = -1; in perf_sched__timehist()
2972 sched->tool.sample = perf_timehist__process_sample; in perf_sched__timehist()
2973 sched->tool.mmap = perf_event__process_mmap; in perf_sched__timehist()
2974 sched->tool.comm = perf_event__process_comm; in perf_sched__timehist()
2975 sched->tool.exit = perf_event__process_exit; in perf_sched__timehist()
2976 sched->tool.fork = perf_event__process_fork; in perf_sched__timehist()
2977 sched->tool.lost = process_lost; in perf_sched__timehist()
2978 sched->tool.attr = perf_event__process_attr; in perf_sched__timehist()
2979 sched->tool.tracing_data = perf_event__process_tracing_data; in perf_sched__timehist()
2980 sched->tool.build_id = perf_event__process_build_id; in perf_sched__timehist()
2982 sched->tool.ordered_events = true; in perf_sched__timehist()
2983 sched->tool.ordering_requires_timestamps = true; in perf_sched__timehist()
2985 symbol_conf.use_callchain = sched->show_callchain; in perf_sched__timehist()
2987 session = perf_session__new(&data, false, &sched->tool); in perf_sched__timehist()
2989 return -ENOMEM; in perf_sched__timehist()
2991 evlist = session->evlist; in perf_sched__timehist()
2993 symbol__init(&session->header.env); in perf_sched__timehist()
2995 if (perf_time__parse_str(&sched->ptime, sched->time_str) != 0) { in perf_sched__timehist()
2996 pr_err("Invalid time string\n"); in perf_sched__timehist()
2997 return -EINVAL; in perf_sched__timehist()
3005 /* setup per-evsel handlers */ in perf_sched__timehist()
3010 if (!perf_evlist__find_tracepoint_by_name(session->evlist, in perf_sched__timehist()
3016 if (sched->show_migrations && in perf_sched__timehist()
3020 /* pre-allocate struct for per-CPU idle stats */ in perf_sched__timehist()
3021 sched->max_cpu = session->header.env.nr_cpus_online; in perf_sched__timehist()
3022 if (sched->max_cpu == 0) in perf_sched__timehist()
3023 sched->max_cpu = 4; in perf_sched__timehist()
3024 if (init_idle_threads(sched->max_cpu)) in perf_sched__timehist()
3028 if (sched->summary_only) in perf_sched__timehist()
3029 sched->summary = sched->summary_only; in perf_sched__timehist()
3031 if (!sched->summary_only) in perf_sched__timehist()
3040 sched->nr_events = evlist->stats.nr_events[0]; in perf_sched__timehist()
3041 sched->nr_lost_events = evlist->stats.total_lost; in perf_sched__timehist()
3042 sched->nr_lost_chunks = evlist->stats.nr_events[PERF_RECORD_LOST]; in perf_sched__timehist()
3044 if (sched->summary) in perf_sched__timehist()
3057 if (sched->nr_unordered_timestamps && sched->nr_timestamps) { in print_bad_events()
3059 (double)sched->nr_unordered_timestamps/(double)sched->nr_timestamps*100.0, in print_bad_events()
3060 sched->nr_unordered_timestamps, sched->nr_timestamps); in print_bad_events()
3062 if (sched->nr_lost_events && sched->nr_events) { in print_bad_events()
3064 (double)sched->nr_lost_events/(double)sched->nr_events * 100.0, in print_bad_events()
3065 sched->nr_lost_events, sched->nr_events, sched->nr_lost_chunks); in print_bad_events()
3067 if (sched->nr_context_switch_bugs && sched->nr_timestamps) { in print_bad_events()
3069 (double)sched->nr_context_switch_bugs/(double)sched->nr_timestamps*100.0, in print_bad_events()
3070 sched->nr_context_switch_bugs, sched->nr_timestamps); in print_bad_events()
3071 if (sched->nr_lost_events) in print_bad_events()
3079 struct rb_node **new = &(root->rb_node), *parent = NULL; in __merge_work_atoms()
3081 const char *comm = thread__comm_str(data->thread), *this_comm; in __merge_work_atoms()
3089 this_comm = thread__comm_str(this->thread); in __merge_work_atoms()
3092 new = &((*new)->rb_left); in __merge_work_atoms()
3094 new = &((*new)->rb_right); in __merge_work_atoms()
3096 this->num_merged++; in __merge_work_atoms()
3097 this->total_runtime += data->total_runtime; in __merge_work_atoms()
3098 this->nb_atoms += data->nb_atoms; in __merge_work_atoms()
3099 this->total_lat += data->total_lat; in __merge_work_atoms()
3100 list_splice(&data->work_list, &this->work_list); in __merge_work_atoms()
3101 if (this->max_lat < data->max_lat) { in __merge_work_atoms()
3102 this->max_lat = data->max_lat; in __merge_work_atoms()
3103 this->max_lat_at = data->max_lat_at; in __merge_work_atoms()
3110 data->num_merged++; in __merge_work_atoms()
3111 rb_link_node(&data->node, parent, new); in __merge_work_atoms()
3112 rb_insert_color(&data->node, root); in __merge_work_atoms()
3120 if (sched->skip_merge) in perf_sched__merge_lat()
3123 while ((node = rb_first(&sched->atom_root))) { in perf_sched__merge_lat()
3124 rb_erase(node, &sched->atom_root); in perf_sched__merge_lat()
3126 __merge_work_atoms(&sched->merged_atom_root, data); in perf_sched__merge_lat()
3137 return -1; in perf_sched__lat()
3142 …printf("\n ---------------------------------------------------------------------------------------… in perf_sched__lat()
3144 …printf(" -----------------------------------------------------------------------------------------… in perf_sched__lat()
3146 next = rb_first(&sched->sorted_atom_root); in perf_sched__lat()
3154 thread__zput(work_list->thread); in perf_sched__lat()
3157 …printf(" -----------------------------------------------------------------------------------------… in perf_sched__lat()
3159 (double)sched->all_runtime / NSEC_PER_MSEC, sched->all_count); in perf_sched__lat()
3161 printf(" ---------------------------------------------------\n"); in perf_sched__lat()
3173 sched->max_cpu = sysconf(_SC_NPROCESSORS_CONF); in setup_map_cpus()
3175 if (sched->map.comp) { in setup_map_cpus()
3176 sched->map.comp_cpus = zalloc(sched->max_cpu * sizeof(int)); in setup_map_cpus()
3177 if (!sched->map.comp_cpus) in setup_map_cpus()
3178 return -1; in setup_map_cpus()
3181 if (!sched->map.cpus_str) in setup_map_cpus()
3184 map = cpu_map__new(sched->map.cpus_str); in setup_map_cpus()
3186 pr_err("failed to get cpus map from %s\n", sched->map.cpus_str); in setup_map_cpus()
3187 return -1; in setup_map_cpus()
3190 sched->map.cpus = map; in setup_map_cpus()
3198 if (!sched->map.color_pids_str) in setup_color_pids()
3201 map = thread_map__new_by_tid_str(sched->map.color_pids_str); in setup_color_pids()
3203 pr_err("failed to get thread map from %s\n", sched->map.color_pids_str); in setup_color_pids()
3204 return -1; in setup_color_pids()
3207 sched->map.color_pids = map; in setup_color_pids()
3215 if (!sched->map.color_cpus_str) in setup_color_cpus()
3218 map = cpu_map__new(sched->map.color_cpus_str); in setup_color_cpus()
3220 pr_err("failed to get thread map from %s\n", sched->map.color_cpus_str); in setup_color_cpus()
3221 return -1; in setup_color_cpus()
3224 sched->map.color_cpus = map; in setup_color_cpus()
3231 return -1; in perf_sched__map()
3234 return -1; in perf_sched__map()
3237 return -1; in perf_sched__map()
3241 return -1; in perf_sched__map()
3256 return -1; in perf_sched__replay()
3258 printf("nr_run_events: %ld\n", sched->nr_run_events); in perf_sched__replay()
3259 printf("nr_sleep_events: %ld\n", sched->nr_sleep_events); in perf_sched__replay()
3260 printf("nr_wakeup_events: %ld\n", sched->nr_wakeup_events); in perf_sched__replay()
3262 if (sched->targetless_wakeups) in perf_sched__replay()
3263 printf("target-less wakeups: %ld\n", sched->targetless_wakeups); in perf_sched__replay()
3264 if (sched->multitarget_wakeups) in perf_sched__replay()
3265 printf("multi-target wakeups: %ld\n", sched->multitarget_wakeups); in perf_sched__replay()
3266 if (sched->nr_run_events_optimized) in perf_sched__replay()
3268 sched->nr_run_events_optimized); in perf_sched__replay()
3274 printf("------------------------------------------------------------\n"); in perf_sched__replay()
3275 for (i = 0; i < sched->replay_repeat; i++) in perf_sched__replay()
3284 char *tmp, *tok, *str = strdup(sched->sort_order); in setup_sorting()
3288 if (sort_dimension__add(tok, &sched->sort_list) < 0) { in setup_sorting()
3290 "Unknown --sort key: `%s'", tok); in setup_sorting()
3296 sort_dimension__add("pid", &sched->cmp_pid); in setup_sorting()
3305 "-a", in __cmd_record()
3306 "-R", in __cmd_record()
3307 "-m", "1024", in __cmd_record()
3308 "-c", "1", in __cmd_record()
3309 "-e", "sched:sched_switch", in __cmd_record()
3310 "-e", "sched:sched_stat_wait", in __cmd_record()
3311 "-e", "sched:sched_stat_sleep", in __cmd_record()
3312 "-e", "sched:sched_stat_iowait", in __cmd_record()
3313 "-e", "sched:sched_stat_runtime", in __cmd_record()
3314 "-e", "sched:sched_process_fork", in __cmd_record()
3315 "-e", "sched:sched_wakeup", in __cmd_record()
3316 "-e", "sched:sched_wakeup_new", in __cmd_record()
3317 "-e", "sched:sched_migrate_task", in __cmd_record()
3320 rec_argc = ARRAY_SIZE(record_args) + argc - 1; in __cmd_record()
3324 return -ENOMEM; in __cmd_record()
3342 .sample = perf_sched__process_tracepoint_sample, in cmd_sched()
3355 .profile_cpu = -1, in cmd_sched()
3367 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, in cmd_sched()
3383 "repeat the workload replay N times (-1: infinite)"), in cmd_sched()
3389 OPT_STRING(0, "color-pids", &sched.map.color_pids_str, "pids", in cmd_sched()
3391 OPT_STRING(0, "color-cpus", &sched.map.color_cpus_str, "cpus", in cmd_sched()
3402 OPT_BOOLEAN('g', "call-graph", &sched.show_callchain, in cmd_sched()
3404 OPT_UINTEGER(0, "max-stack", &sched.max_stack, in cmd_sched()
3410 OPT_BOOLEAN('S', "with-summary", &sched.summary, in cmd_sched()
3415 OPT_BOOLEAN('V', "cpu-visual", &sched.show_cpu_visual, "Add CPU visual"), in cmd_sched()
3416 OPT_BOOLEAN('I', "idle-hist", &sched.idle_hist, "Show idle events only"), in cmd_sched()
3417 OPT_STRING(0, "time", &sched.time_str, "str", in cmd_sched()
3418 "Time span for analysis (start,stop)"), in cmd_sched()
3419 OPT_BOOLEAN(0, "state", &sched.show_state, "Show task state when sched-out"), in cmd_sched()
3467 sched.curr_pid[i] = -1; in cmd_sched()
3517 pr_err(" Error: -s and -[n|w] are mutually exclusive.\n"); in cmd_sched()
3523 return -EINVAL; in cmd_sched()