Lines Matching refs:sched

130 	int (*switch_event)(struct perf_sched *sched, struct evsel *evsel,
133 int (*runtime_event)(struct perf_sched *sched, struct evsel *evsel,
136 int (*wakeup_event)(struct perf_sched *sched, struct evsel *evsel,
140 int (*fork_event)(struct perf_sched *sched, union perf_event *event,
143 int (*migrate_task_event)(struct perf_sched *sched,
298 static void burn_nsecs(struct perf_sched *sched, u64 nsecs) in burn_nsecs() argument
304 } while (T1 + sched->run_measurement_overhead < T0 + nsecs); in burn_nsecs()
317 static void calibrate_run_measurement_overhead(struct perf_sched *sched) in calibrate_run_measurement_overhead() argument
324 burn_nsecs(sched, 0); in calibrate_run_measurement_overhead()
329 sched->run_measurement_overhead = min_delta; in calibrate_run_measurement_overhead()
334 static void calibrate_sleep_measurement_overhead(struct perf_sched *sched) in calibrate_sleep_measurement_overhead() argument
347 sched->sleep_measurement_overhead = min_delta; in calibrate_sleep_measurement_overhead()
380 static void add_sched_event_run(struct perf_sched *sched, struct task_desc *task, in add_sched_event_run() argument
390 sched->nr_run_events_optimized++; in add_sched_event_run()
400 sched->nr_run_events++; in add_sched_event_run()
403 static void add_sched_event_wakeup(struct perf_sched *sched, struct task_desc *task, in add_sched_event_wakeup() argument
414 sched->targetless_wakeups++; in add_sched_event_wakeup()
418 sched->multitarget_wakeups++; in add_sched_event_wakeup()
427 sched->nr_wakeup_events++; in add_sched_event_wakeup()
430 static void add_sched_event_sleep(struct perf_sched *sched, struct task_desc *task, in add_sched_event_sleep() argument
437 sched->nr_sleep_events++; in add_sched_event_sleep()
440 static struct task_desc *register_pid(struct perf_sched *sched, in register_pid() argument
446 if (sched->pid_to_task == NULL) { in register_pid()
449 BUG_ON((sched->pid_to_task = calloc(pid_max, sizeof(struct task_desc *))) == NULL); in register_pid()
452 BUG_ON((sched->pid_to_task = realloc(sched->pid_to_task, (pid + 1) * in register_pid()
455 sched->pid_to_task[pid_max++] = NULL; in register_pid()
458 task = sched->pid_to_task[pid]; in register_pid()
465 task->nr = sched->nr_tasks; in register_pid()
471 add_sched_event_sleep(sched, task, 0, 0); in register_pid()
473 sched->pid_to_task[pid] = task; in register_pid()
474 sched->nr_tasks++; in register_pid()
475 sched->tasks = realloc(sched->tasks, sched->nr_tasks * sizeof(struct task_desc *)); in register_pid()
476 BUG_ON(!sched->tasks); in register_pid()
477 sched->tasks[task->nr] = task; in register_pid()
480 printf("registered task #%ld, PID %ld (%s)\n", sched->nr_tasks, pid, comm); in register_pid()
486 static void print_task_traces(struct perf_sched *sched) in print_task_traces() argument
491 for (i = 0; i < sched->nr_tasks; i++) { in print_task_traces()
492 task = sched->tasks[i]; in print_task_traces()
498 static void add_cross_task_wakeups(struct perf_sched *sched) in add_cross_task_wakeups() argument
503 for (i = 0; i < sched->nr_tasks; i++) { in add_cross_task_wakeups()
504 task1 = sched->tasks[i]; in add_cross_task_wakeups()
506 if (j == sched->nr_tasks) in add_cross_task_wakeups()
508 task2 = sched->tasks[j]; in add_cross_task_wakeups()
509 add_sched_event_wakeup(sched, task1, 0, task2); in add_cross_task_wakeups()
513 static void perf_sched__process_event(struct perf_sched *sched, in perf_sched__process_event() argument
520 burn_nsecs(sched, atom->duration); in perf_sched__process_event()
554 static int self_open_counters(struct perf_sched *sched, unsigned long cur_task) in self_open_counters() argument
573 if (sched->force) { in self_open_counters()
575 limit.rlim_cur += sched->nr_tasks - cur_task; in self_open_counters()
609 struct perf_sched *sched; member
617 struct perf_sched *sched = parms->sched; in thread_func() local
630 while (!sched->thread_funcs_exit) { in thread_func()
633 mutex_lock(&sched->start_work_mutex); in thread_func()
634 mutex_unlock(&sched->start_work_mutex); in thread_func()
640 perf_sched__process_event(sched, this_task->atoms[i]); in thread_func()
648 mutex_lock(&sched->work_done_wait_mutex); in thread_func()
649 mutex_unlock(&sched->work_done_wait_mutex); in thread_func()
654 static void create_tasks(struct perf_sched *sched) in create_tasks() argument
655 EXCLUSIVE_LOCK_FUNCTION(sched->start_work_mutex) in create_tasks()
656 EXCLUSIVE_LOCK_FUNCTION(sched->work_done_wait_mutex) in create_tasks()
668 mutex_lock(&sched->start_work_mutex); in create_tasks()
669 mutex_lock(&sched->work_done_wait_mutex); in create_tasks()
670 for (i = 0; i < sched->nr_tasks; i++) { in create_tasks()
673 parms->task = task = sched->tasks[i]; in create_tasks()
674 parms->sched = sched; in create_tasks()
675 parms->fd = self_open_counters(sched, i); in create_tasks()
685 static void destroy_tasks(struct perf_sched *sched) in destroy_tasks() argument
686 UNLOCK_FUNCTION(sched->start_work_mutex) in destroy_tasks()
687 UNLOCK_FUNCTION(sched->work_done_wait_mutex) in destroy_tasks()
693 mutex_unlock(&sched->start_work_mutex); in destroy_tasks()
694 mutex_unlock(&sched->work_done_wait_mutex); in destroy_tasks()
696 for (i = 0; i < sched->nr_tasks; i++) { in destroy_tasks()
697 task = sched->tasks[i]; in destroy_tasks()
706 static void wait_for_tasks(struct perf_sched *sched) in wait_for_tasks() argument
707 EXCLUSIVE_LOCKS_REQUIRED(sched->work_done_wait_mutex) in wait_for_tasks()
708 EXCLUSIVE_LOCKS_REQUIRED(sched->start_work_mutex) in wait_for_tasks()
714 sched->start_time = get_nsecs(); in wait_for_tasks()
715 sched->cpu_usage = 0; in wait_for_tasks()
716 mutex_unlock(&sched->work_done_wait_mutex); in wait_for_tasks()
718 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
719 task = sched->tasks[i]; in wait_for_tasks()
724 mutex_lock(&sched->work_done_wait_mutex); in wait_for_tasks()
728 mutex_unlock(&sched->start_work_mutex); in wait_for_tasks()
730 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
731 task = sched->tasks[i]; in wait_for_tasks()
735 sched->cpu_usage += task->cpu_usage; in wait_for_tasks()
740 if (!sched->runavg_cpu_usage) in wait_for_tasks()
741 sched->runavg_cpu_usage = sched->cpu_usage; in wait_for_tasks()
742sched->runavg_cpu_usage = (sched->runavg_cpu_usage * (sched->replay_repeat - 1) + sched->cpu_usage… in wait_for_tasks()
744 sched->parent_cpu_usage = cpu_usage_1 - cpu_usage_0; in wait_for_tasks()
745 if (!sched->runavg_parent_cpu_usage) in wait_for_tasks()
746 sched->runavg_parent_cpu_usage = sched->parent_cpu_usage; in wait_for_tasks()
747 sched->runavg_parent_cpu_usage = (sched->runavg_parent_cpu_usage * (sched->replay_repeat - 1) + in wait_for_tasks()
748 sched->parent_cpu_usage)/sched->replay_repeat; in wait_for_tasks()
750 mutex_lock(&sched->start_work_mutex); in wait_for_tasks()
752 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
753 task = sched->tasks[i]; in wait_for_tasks()
759 static void run_one_test(struct perf_sched *sched) in run_one_test() argument
760 EXCLUSIVE_LOCKS_REQUIRED(sched->work_done_wait_mutex) in run_one_test()
761 EXCLUSIVE_LOCKS_REQUIRED(sched->start_work_mutex) in run_one_test()
766 wait_for_tasks(sched); in run_one_test()
770 sched->sum_runtime += delta; in run_one_test()
771 sched->nr_runs++; in run_one_test()
773 avg_delta = sched->sum_runtime / sched->nr_runs; in run_one_test()
778 sched->sum_fluct += fluct; in run_one_test()
779 if (!sched->run_avg) in run_one_test()
780 sched->run_avg = delta; in run_one_test()
781 sched->run_avg = (sched->run_avg * (sched->replay_repeat - 1) + delta) / sched->replay_repeat; in run_one_test()
783 printf("#%-3ld: %0.3f, ", sched->nr_runs, (double)delta / NSEC_PER_MSEC); in run_one_test()
785 printf("ravg: %0.2f, ", (double)sched->run_avg / NSEC_PER_MSEC); in run_one_test()
788 (double)sched->cpu_usage / NSEC_PER_MSEC, (double)sched->runavg_cpu_usage / NSEC_PER_MSEC); in run_one_test()
796 (double)sched->parent_cpu_usage / NSEC_PER_MSEC, in run_one_test()
797 (double)sched->runavg_parent_cpu_usage / NSEC_PER_MSEC); in run_one_test()
802 if (sched->nr_sleep_corrections) in run_one_test()
803 printf(" (%ld sleep corrections)\n", sched->nr_sleep_corrections); in run_one_test()
804 sched->nr_sleep_corrections = 0; in run_one_test()
807 static void test_calibrations(struct perf_sched *sched) in test_calibrations() argument
812 burn_nsecs(sched, NSEC_PER_MSEC); in test_calibrations()
825 replay_wakeup_event(struct perf_sched *sched, in replay_wakeup_event() argument
839 waker = register_pid(sched, sample->tid, "<unknown>"); in replay_wakeup_event()
840 wakee = register_pid(sched, pid, comm); in replay_wakeup_event()
842 add_sched_event_wakeup(sched, waker, sample->time, wakee); in replay_wakeup_event()
846 static int replay_switch_event(struct perf_sched *sched, in replay_switch_event() argument
867 timestamp0 = sched->cpu_last_switched[cpu]; in replay_switch_event()
881 prev = register_pid(sched, prev_pid, prev_comm); in replay_switch_event()
882 next = register_pid(sched, next_pid, next_comm); in replay_switch_event()
884 sched->cpu_last_switched[cpu] = timestamp; in replay_switch_event()
886 add_sched_event_run(sched, prev, timestamp, delta); in replay_switch_event()
887 add_sched_event_sleep(sched, prev, timestamp, prev_state); in replay_switch_event()
892 static int replay_fork_event(struct perf_sched *sched, in replay_fork_event() argument
915 register_pid(sched, thread__tid(parent), thread__comm_str(parent)); in replay_fork_event()
916 register_pid(sched, thread__tid(child), thread__comm_str(child)); in replay_fork_event()
1037 static int thread_atoms_insert(struct perf_sched *sched, struct thread *thread) in thread_atoms_insert() argument
1047 __thread_latency_insert(&sched->atom_root, atoms, &sched->cmp_pid); in thread_atoms_insert()
1119 static int latency_switch_event(struct perf_sched *sched, in latency_switch_event() argument
1135 timestamp0 = sched->cpu_last_switched[cpu]; in latency_switch_event()
1136 sched->cpu_last_switched[cpu] = timestamp; in latency_switch_event()
1152 out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid); in latency_switch_event()
1154 if (thread_atoms_insert(sched, sched_out)) in latency_switch_event()
1156 out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid); in latency_switch_event()
1165 in_events = thread_atoms_search(&sched->atom_root, sched_in, &sched->cmp_pid); in latency_switch_event()
1167 if (thread_atoms_insert(sched, sched_in)) in latency_switch_event()
1169 in_events = thread_atoms_search(&sched->atom_root, sched_in, &sched->cmp_pid); in latency_switch_event()
1189 static int latency_runtime_event(struct perf_sched *sched, in latency_runtime_event() argument
1197 struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); in latency_runtime_event()
1206 if (thread_atoms_insert(sched, thread)) in latency_runtime_event()
1208 atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); in latency_runtime_event()
1224 static int latency_wakeup_event(struct perf_sched *sched, in latency_wakeup_event() argument
1239 atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid); in latency_wakeup_event()
1241 if (thread_atoms_insert(sched, wakee)) in latency_wakeup_event()
1243 atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid); in latency_wakeup_event()
1267 if (sched->profile_cpu == -1 && atom->state != THREAD_SLEEPING) in latency_wakeup_event()
1270 sched->nr_timestamps++; in latency_wakeup_event()
1272 sched->nr_unordered_timestamps++; in latency_wakeup_event()
1285 static int latency_migrate_task_event(struct perf_sched *sched, in latency_migrate_task_event() argument
1300 if (sched->profile_cpu == -1) in latency_migrate_task_event()
1306 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid); in latency_migrate_task_event()
1308 if (thread_atoms_insert(sched, migrant)) in latency_migrate_task_event()
1310 register_pid(sched, thread__tid(migrant), thread__comm_str(migrant)); in latency_migrate_task_event()
1311 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid); in latency_migrate_task_event()
1325 sched->nr_timestamps++; in latency_migrate_task_event()
1328 sched->nr_unordered_timestamps++; in latency_migrate_task_event()
1335 static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_list) in output_lat_thread() argument
1350 sched->all_runtime += work_list->total_runtime; in output_lat_thread()
1351 sched->all_count += work_list->nb_atoms; in output_lat_thread()
1483 static void perf_sched__sort_lat(struct perf_sched *sched) in perf_sched__sort_lat() argument
1486 struct rb_root_cached *root = &sched->atom_root; in perf_sched__sort_lat()
1496 __thread_latency_insert(&sched->sorted_atom_root, data, &sched->sort_list); in perf_sched__sort_lat()
1498 if (root == &sched->atom_root) { in perf_sched__sort_lat()
1499 root = &sched->merged_atom_root; in perf_sched__sort_lat()
1509 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in process_sched_wakeup_event() local
1511 if (sched->tp_handler->wakeup_event) in process_sched_wakeup_event()
1512 return sched->tp_handler->wakeup_event(sched, evsel, sample, machine); in process_sched_wakeup_event()
1540 map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid, pid_t tid) in map__findnew_thread() argument
1547 if (!sched->map.color_pids || !thread || thread__priv(thread)) in map__findnew_thread()
1550 if (thread_map__has(sched->map.color_pids, tid)) in map__findnew_thread()
1557 static bool sched_match_task(struct perf_sched *sched, const char *comm_str) in sched_match_task() argument
1559 bool fuzzy_match = sched->map.fuzzy; in sched_match_task()
1560 struct strlist *task_names = sched->map.task_names; in sched_match_task()
1573 static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, int cpus_nr, in print_sched_map() argument
1578 .cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i, in print_sched_map()
1580 struct thread *curr_thread = sched->curr_thread[cpu.cpu]; in print_sched_map()
1581 struct thread *curr_out_thread = sched->curr_out_thread[cpu.cpu]; in print_sched_map()
1591 if (sched->map.color_cpus && perf_cpu_map__has(sched->map.color_cpus, cpu)) in print_sched_map()
1599 thread_to_check = sched_out ? sched->curr_out_thread[cpu.cpu] : in print_sched_map()
1600 sched->curr_thread[cpu.cpu]; in print_sched_map()
1611 curr_tr = thread__get_runtime(sched->curr_thread[cpu.cpu]); in print_sched_map()
1623 static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, in map_switch_event() argument
1645 if (this_cpu.cpu > sched->max_cpu.cpu) in map_switch_event()
1646 sched->max_cpu = this_cpu; in map_switch_event()
1648 if (sched->map.comp) { in map_switch_event()
1649 cpus_nr = bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS); in map_switch_event()
1650 if (!__test_and_set_bit(this_cpu.cpu, sched->map.comp_cpus_mask)) { in map_switch_event()
1651 sched->map.comp_cpus[cpus_nr++] = this_cpu; in map_switch_event()
1655 cpus_nr = sched->max_cpu.cpu; in map_switch_event()
1657 timestamp0 = sched->cpu_last_switched[this_cpu.cpu]; in map_switch_event()
1658 sched->cpu_last_switched[this_cpu.cpu] = timestamp; in map_switch_event()
1669 sched_in = map__findnew_thread(sched, machine, -1, next_pid); in map_switch_event()
1670 sched_out = map__findnew_thread(sched, machine, -1, prev_pid); in map_switch_event()
1680 sched->curr_thread[this_cpu.cpu] = thread__get(sched_in); in map_switch_event()
1681 sched->curr_out_thread[this_cpu.cpu] = thread__get(sched_out); in map_switch_event()
1693 } else if (!sched->map.task_name || sched_match_task(sched, str)) { in map_switch_event()
1694 tr->shortname[0] = sched->next_shortname1; in map_switch_event()
1695 tr->shortname[1] = sched->next_shortname2; in map_switch_event()
1697 if (sched->next_shortname1 < 'Z') { in map_switch_event()
1698 sched->next_shortname1++; in map_switch_event()
1700 sched->next_shortname1 = 'A'; in map_switch_event()
1701 if (sched->next_shortname2 < '9') in map_switch_event()
1702 sched->next_shortname2++; in map_switch_event()
1704 sched->next_shortname2 = '0'; in map_switch_event()
1713 if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu)) in map_switch_event()
1722 if (sched->map.task_name && !sched_match_task(sched, str)) { in map_switch_event()
1723 if (!sched_match_task(sched, thread__comm_str(sched_out))) in map_switch_event()
1730 if (!(sched->map.task_name && !sched_match_task(sched, str))) in map_switch_event()
1736 print_sched_map(sched, this_cpu, cpus_nr, color, false); in map_switch_event()
1751 if (sched->map.comp && new_cpu) in map_switch_event()
1760 if (sched->map.task_name) { in map_switch_event()
1761 tr = thread__get_runtime(sched->curr_out_thread[this_cpu.cpu]); in map_switch_event()
1769 print_sched_map(sched, this_cpu, cpus_nr, color, true); in map_switch_event()
1777 if (sched->map.task_name) in map_switch_event()
1790 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in process_sched_switch_event() local
1795 if (sched->curr_pid[this_cpu] != (u32)-1) { in process_sched_switch_event()
1800 if (sched->curr_pid[this_cpu] != prev_pid) in process_sched_switch_event()
1801 sched->nr_context_switch_bugs++; in process_sched_switch_event()
1804 if (sched->tp_handler->switch_event) in process_sched_switch_event()
1805 err = sched->tp_handler->switch_event(sched, evsel, sample, machine); in process_sched_switch_event()
1807 sched->curr_pid[this_cpu] = next_pid; in process_sched_switch_event()
1816 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in process_sched_runtime_event() local
1818 if (sched->tp_handler->runtime_event) in process_sched_runtime_event()
1819 return sched->tp_handler->runtime_event(sched, evsel, sample, machine); in process_sched_runtime_event()
1829 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in perf_sched__process_fork_event() local
1835 if (sched->tp_handler->fork_event) in perf_sched__process_fork_event()
1836 return sched->tp_handler->fork_event(sched, event, machine); in perf_sched__process_fork_event()
1846 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in process_sched_migrate_task_event() local
1848 if (sched->tp_handler->migrate_task_event) in process_sched_migrate_task_event()
1849 return sched->tp_handler->migrate_task_event(sched, evsel, sample, machine); in process_sched_migrate_task_event()
1906 static int perf_sched__read_events(struct perf_sched *sched) in perf_sched__read_events() argument
1920 .force = sched->force, in perf_sched__read_events()
1924 session = perf_session__new(&data, &sched->tool); in perf_sched__read_events()
1946 sched->nr_events = session->evlist->stats.nr_events[0]; in perf_sched__read_events()
1947 sched->nr_lost_events = session->evlist->stats.total_lost; in perf_sched__read_events()
1948 sched->nr_lost_chunks = session->evlist->stats.nr_events[PERF_RECORD_LOST]; in perf_sched__read_events()
2069 static void timehist_header(struct perf_sched *sched) in timehist_header() argument
2071 u32 ncpus = sched->max_cpu.cpu + 1; in timehist_header()
2076 if (sched->show_cpu_visual) { in timehist_header()
2086 if (sched->show_prio) { in timehist_header()
2095 if (sched->show_state) in timehist_header()
2105 if (sched->show_cpu_visual) in timehist_header()
2108 if (sched->show_prio) { in timehist_header()
2117 if (sched->show_state) in timehist_header()
2127 if (sched->show_cpu_visual) in timehist_header()
2130 if (sched->show_prio) { in timehist_header()
2140 if (sched->show_state) in timehist_header()
2146 static void timehist_print_sample(struct perf_sched *sched, in timehist_print_sample() argument
2156 u32 max_cpus = sched->max_cpu.cpu + 1; in timehist_print_sample()
2167 if (sched->show_cpu_visual) { in timehist_print_sample()
2185 if (sched->show_prio) in timehist_print_sample()
2194 if (sched->show_state) in timehist_print_sample()
2197 if (sched->show_next) { in timehist_print_sample()
2202 if (sched->show_wakeups && !sched->show_next) in timehist_print_sample()
2208 if (sched->show_callchain) in timehist_print_sample()
2295 static void save_task_callchain(struct perf_sched *sched, in save_task_callchain() argument
2310 if (!sched->show_callchain || sample->callchain == NULL) in save_task_callchain()
2316 NULL, NULL, sched->max_stack + 2) != 0) { in save_task_callchain()
2441 static void save_idle_callchain(struct perf_sched *sched, in save_idle_callchain() argument
2447 if (!sched->show_callchain || sample->callchain == NULL) in save_idle_callchain()
2457 static struct thread *timehist_get_thread(struct perf_sched *sched, in timehist_get_thread() argument
2478 save_task_callchain(sched, sample, evsel, machine); in timehist_get_thread()
2479 if (sched->idle_hist) { in timehist_get_thread()
2497 save_idle_callchain(sched, itr, sample); in timehist_get_thread()
2504 static bool timehist_skip_sample(struct perf_sched *sched, in timehist_skip_sample() argument
2515 sched->skipped_samples++; in timehist_skip_sample()
2518 if (sched->prio_str) { in timehist_skip_sample()
2531 if (prio != -1 && !test_bit(prio, sched->prio_bitmap)) { in timehist_skip_sample()
2533 sched->skipped_samples++; in timehist_skip_sample()
2537 if (sched->idle_hist) { in timehist_skip_sample()
2548 static void timehist_print_wakeup_event(struct perf_sched *sched, in timehist_print_wakeup_event() argument
2562 if (timehist_skip_sample(sched, thread, evsel, sample) && in timehist_print_wakeup_event()
2563 timehist_skip_sample(sched, awakened, evsel, sample)) { in timehist_print_wakeup_event()
2569 if (sched->show_cpu_visual) in timehist_print_wakeup_event()
2570 printf(" %*s ", sched->max_cpu.cpu + 1, ""); in timehist_print_wakeup_event()
2597 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in timehist_sched_wakeup_event() local
2615 if (sched->show_wakeups && in timehist_sched_wakeup_event()
2616 !perf_time__skip_sample(&sched->ptime, sample->time)) in timehist_sched_wakeup_event()
2617 timehist_print_wakeup_event(sched, evsel, sample, machine, thread); in timehist_sched_wakeup_event()
2622 static void timehist_print_migration_event(struct perf_sched *sched, in timehist_print_migration_event() argument
2633 if (sched->summary_only) in timehist_print_migration_event()
2636 max_cpus = sched->max_cpu.cpu + 1; in timehist_print_migration_event()
2644 if (timehist_skip_sample(sched, thread, evsel, sample) && in timehist_print_migration_event()
2645 timehist_skip_sample(sched, migrated, evsel, sample)) { in timehist_print_migration_event()
2652 if (sched->show_cpu_visual) { in timehist_print_migration_event()
2681 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in timehist_migrate_task_event() local
2698 timehist_print_migration_event(sched, evsel, sample, machine, thread); in timehist_migrate_task_event()
2733 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in timehist_sched_change_event() local
2734 struct perf_time_interval *ptime = &sched->ptime; in timehist_sched_change_event()
2750 if (sched->show_prio || sched->prio_str) in timehist_sched_change_event()
2753 thread = timehist_get_thread(sched, sample, machine, evsel); in timehist_sched_change_event()
2759 if (timehist_skip_sample(sched, thread, evsel, sample)) in timehist_sched_change_event()
2798 if (!sched->idle_hist || thread__tid(thread) == 0) { in timehist_sched_change_event()
2802 if (sched->idle_hist) { in timehist_sched_change_event()
2832 if (!sched->summary_only) in timehist_sched_change_event()
2833 timehist_print_sample(sched, evsel, sample, &al, thread, t, state); in timehist_sched_change_event()
2837 if (sched->hist_time.start == 0 && t >= ptime->start) in timehist_sched_change_event()
2838 sched->hist_time.start = t; in timehist_sched_change_event()
2840 sched->hist_time.end = t; in timehist_sched_change_event()
2928 struct perf_sched *sched; member
2948 if (stats->sched->show_state) in show_thread_runtime()
3011 static void timehist_print_summary(struct perf_sched *sched, in timehist_print_summary() argument
3020 u64 hist_time = sched->hist_time.end - sched->hist_time.start; in timehist_print_summary()
3023 totals.sched = sched; in timehist_print_summary()
3025 if (sched->idle_hist) { in timehist_print_summary()
3029 } else if (sched->show_state) { in timehist_print_summary()
3040 sched->show_state ? "(msec)" : "%"); in timehist_print_summary()
3049 if (sched->skipped_samples && !sched->idle_hist) in timehist_print_summary()
3071 if (sched->idle_hist && sched->show_callchain) { in timehist_print_summary()
3111 printf(" (x %d)\n", sched->max_cpu.cpu); in timehist_print_summary()
3126 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in perf_timehist__process_sample() local
3132 if (this_cpu.cpu > sched->max_cpu.cpu) in perf_timehist__process_sample()
3133 sched->max_cpu = this_cpu; in perf_timehist__process_sample()
3144 static int timehist_check_attr(struct perf_sched *sched, in timehist_check_attr() argument
3158 if (sched->show_callchain && in timehist_check_attr()
3162 sched->show_callchain = 0; in timehist_check_attr()
3170 static int timehist_parse_prio_str(struct perf_sched *sched) in timehist_parse_prio_str() argument
3174 const char *str = sched->prio_str; in timehist_parse_prio_str()
3200 __set_bit(start_prio, sched->prio_bitmap); in timehist_parse_prio_str()
3211 static int perf_sched__timehist(struct perf_sched *sched) in perf_sched__timehist() argument
3225 .force = sched->force, in perf_sched__timehist()
3235 sched->tool.sample = perf_timehist__process_sample; in perf_sched__timehist()
3236 sched->tool.mmap = perf_event__process_mmap; in perf_sched__timehist()
3237 sched->tool.comm = perf_event__process_comm; in perf_sched__timehist()
3238 sched->tool.exit = perf_event__process_exit; in perf_sched__timehist()
3239 sched->tool.fork = perf_event__process_fork; in perf_sched__timehist()
3240 sched->tool.lost = process_lost; in perf_sched__timehist()
3241 sched->tool.attr = perf_event__process_attr; in perf_sched__timehist()
3242 sched->tool.tracing_data = perf_event__process_tracing_data; in perf_sched__timehist()
3243 sched->tool.build_id = perf_event__process_build_id; in perf_sched__timehist()
3245 sched->tool.ordering_requires_timestamps = true; in perf_sched__timehist()
3247 symbol_conf.use_callchain = sched->show_callchain; in perf_sched__timehist()
3249 session = perf_session__new(&data, &sched->tool); in perf_sched__timehist()
3263 if (perf_time__parse_str(&sched->ptime, sched->time_str) != 0) { in perf_sched__timehist()
3269 if (timehist_check_attr(sched, evlist) != 0) in perf_sched__timehist()
3272 if (timehist_parse_prio_str(sched) != 0) { in perf_sched__timehist()
3293 if (sched->show_migrations && in perf_sched__timehist()
3298 sched->max_cpu.cpu = session->header.env.nr_cpus_online; in perf_sched__timehist()
3299 if (sched->max_cpu.cpu == 0) in perf_sched__timehist()
3300 sched->max_cpu.cpu = 4; in perf_sched__timehist()
3301 if (init_idle_threads(sched->max_cpu.cpu)) in perf_sched__timehist()
3305 if (sched->summary_only) in perf_sched__timehist()
3306 sched->summary = sched->summary_only; in perf_sched__timehist()
3308 if (!sched->summary_only) in perf_sched__timehist()
3309 timehist_header(sched); in perf_sched__timehist()
3317 sched->nr_events = evlist->stats.nr_events[0]; in perf_sched__timehist()
3318 sched->nr_lost_events = evlist->stats.total_lost; in perf_sched__timehist()
3319 sched->nr_lost_chunks = evlist->stats.nr_events[PERF_RECORD_LOST]; in perf_sched__timehist()
3321 if (sched->summary) in perf_sched__timehist()
3322 timehist_print_summary(sched, session); in perf_sched__timehist()
3332 static void print_bad_events(struct perf_sched *sched) in print_bad_events() argument
3334 if (sched->nr_unordered_timestamps && sched->nr_timestamps) { in print_bad_events()
3336 (double)sched->nr_unordered_timestamps/(double)sched->nr_timestamps*100.0, in print_bad_events()
3337 sched->nr_unordered_timestamps, sched->nr_timestamps); in print_bad_events()
3339 if (sched->nr_lost_events && sched->nr_events) { in print_bad_events()
3341 (double)sched->nr_lost_events/(double)sched->nr_events * 100.0, in print_bad_events()
3342 sched->nr_lost_events, sched->nr_events, sched->nr_lost_chunks); in print_bad_events()
3344 if (sched->nr_context_switch_bugs && sched->nr_timestamps) { in print_bad_events()
3346 (double)sched->nr_context_switch_bugs/(double)sched->nr_timestamps*100.0, in print_bad_events()
3347 sched->nr_context_switch_bugs, sched->nr_timestamps); in print_bad_events()
3348 if (sched->nr_lost_events) in print_bad_events()
3395 static void perf_sched__merge_lat(struct perf_sched *sched) in perf_sched__merge_lat() argument
3400 if (sched->skip_merge) in perf_sched__merge_lat()
3403 while ((node = rb_first_cached(&sched->atom_root))) { in perf_sched__merge_lat()
3404 rb_erase_cached(node, &sched->atom_root); in perf_sched__merge_lat()
3406 __merge_work_atoms(&sched->merged_atom_root, data); in perf_sched__merge_lat()
3410 static int setup_cpus_switch_event(struct perf_sched *sched) in setup_cpus_switch_event() argument
3414 sched->cpu_last_switched = calloc(MAX_CPUS, sizeof(*(sched->cpu_last_switched))); in setup_cpus_switch_event()
3415 if (!sched->cpu_last_switched) in setup_cpus_switch_event()
3418 sched->curr_pid = malloc(MAX_CPUS * sizeof(*(sched->curr_pid))); in setup_cpus_switch_event()
3419 if (!sched->curr_pid) { in setup_cpus_switch_event()
3420 zfree(&sched->cpu_last_switched); in setup_cpus_switch_event()
3425 sched->curr_pid[i] = -1; in setup_cpus_switch_event()
3430 static void free_cpus_switch_event(struct perf_sched *sched) in free_cpus_switch_event() argument
3432 zfree(&sched->curr_pid); in free_cpus_switch_event()
3433 zfree(&sched->cpu_last_switched); in free_cpus_switch_event()
3436 static int perf_sched__lat(struct perf_sched *sched) in perf_sched__lat() argument
3443 if (setup_cpus_switch_event(sched)) in perf_sched__lat()
3446 if (perf_sched__read_events(sched)) in perf_sched__lat()
3449 perf_sched__merge_lat(sched); in perf_sched__lat()
3450 perf_sched__sort_lat(sched); in perf_sched__lat()
3456 next = rb_first_cached(&sched->sorted_atom_root); in perf_sched__lat()
3462 output_lat_thread(sched, work_list); in perf_sched__lat()
3469 (double)sched->all_runtime / NSEC_PER_MSEC, sched->all_count); in perf_sched__lat()
3473 print_bad_events(sched); in perf_sched__lat()
3479 free_cpus_switch_event(sched); in perf_sched__lat()
3483 static int setup_map_cpus(struct perf_sched *sched) in setup_map_cpus() argument
3485 sched->max_cpu.cpu = sysconf(_SC_NPROCESSORS_CONF); in setup_map_cpus()
3487 if (sched->map.comp) { in setup_map_cpus()
3488 sched->map.comp_cpus = zalloc(sched->max_cpu.cpu * sizeof(int)); in setup_map_cpus()
3489 if (!sched->map.comp_cpus) in setup_map_cpus()
3493 if (sched->map.cpus_str) { in setup_map_cpus()
3494 sched->map.cpus = perf_cpu_map__new(sched->map.cpus_str); in setup_map_cpus()
3495 if (!sched->map.cpus) { in setup_map_cpus()
3496 pr_err("failed to get cpus map from %s\n", sched->map.cpus_str); in setup_map_cpus()
3497 zfree(&sched->map.comp_cpus); in setup_map_cpus()
3505 static int setup_color_pids(struct perf_sched *sched) in setup_color_pids() argument
3509 if (!sched->map.color_pids_str) in setup_color_pids()
3512 map = thread_map__new_by_tid_str(sched->map.color_pids_str); in setup_color_pids()
3514 pr_err("failed to get thread map from %s\n", sched->map.color_pids_str); in setup_color_pids()
3518 sched->map.color_pids = map; in setup_color_pids()
3522 static int setup_color_cpus(struct perf_sched *sched) in setup_color_cpus() argument
3526 if (!sched->map.color_cpus_str) in setup_color_cpus()
3529 map = perf_cpu_map__new(sched->map.color_cpus_str); in setup_color_cpus()
3531 pr_err("failed to get thread map from %s\n", sched->map.color_cpus_str); in setup_color_cpus()
3535 sched->map.color_cpus = map; in setup_color_cpus()
3539 static int perf_sched__map(struct perf_sched *sched) in perf_sched__map() argument
3543 sched->curr_thread = calloc(MAX_CPUS, sizeof(*(sched->curr_thread))); in perf_sched__map()
3544 if (!sched->curr_thread) in perf_sched__map()
3547 sched->curr_out_thread = calloc(MAX_CPUS, sizeof(*(sched->curr_out_thread))); in perf_sched__map()
3548 if (!sched->curr_out_thread) in perf_sched__map()
3551 if (setup_cpus_switch_event(sched)) in perf_sched__map()
3554 if (setup_map_cpus(sched)) in perf_sched__map()
3557 if (setup_color_pids(sched)) in perf_sched__map()
3560 if (setup_color_cpus(sched)) in perf_sched__map()
3564 if (perf_sched__read_events(sched)) in perf_sched__map()
3568 print_bad_events(sched); in perf_sched__map()
3571 perf_cpu_map__put(sched->map.color_cpus); in perf_sched__map()
3574 perf_thread_map__put(sched->map.color_pids); in perf_sched__map()
3577 zfree(&sched->map.comp_cpus); in perf_sched__map()
3578 perf_cpu_map__put(sched->map.cpus); in perf_sched__map()
3581 free_cpus_switch_event(sched); in perf_sched__map()
3584 zfree(&sched->curr_thread); in perf_sched__map()
3588 static int perf_sched__replay(struct perf_sched *sched) in perf_sched__replay() argument
3593 mutex_init(&sched->start_work_mutex); in perf_sched__replay()
3594 mutex_init(&sched->work_done_wait_mutex); in perf_sched__replay()
3596 ret = setup_cpus_switch_event(sched); in perf_sched__replay()
3600 calibrate_run_measurement_overhead(sched); in perf_sched__replay()
3601 calibrate_sleep_measurement_overhead(sched); in perf_sched__replay()
3603 test_calibrations(sched); in perf_sched__replay()
3605 ret = perf_sched__read_events(sched); in perf_sched__replay()
3609 printf("nr_run_events: %ld\n", sched->nr_run_events); in perf_sched__replay()
3610 printf("nr_sleep_events: %ld\n", sched->nr_sleep_events); in perf_sched__replay()
3611 printf("nr_wakeup_events: %ld\n", sched->nr_wakeup_events); in perf_sched__replay()
3613 if (sched->targetless_wakeups) in perf_sched__replay()
3614 printf("target-less wakeups: %ld\n", sched->targetless_wakeups); in perf_sched__replay()
3615 if (sched->multitarget_wakeups) in perf_sched__replay()
3616 printf("multi-target wakeups: %ld\n", sched->multitarget_wakeups); in perf_sched__replay()
3617 if (sched->nr_run_events_optimized) in perf_sched__replay()
3619 sched->nr_run_events_optimized); in perf_sched__replay()
3621 print_task_traces(sched); in perf_sched__replay()
3622 add_cross_task_wakeups(sched); in perf_sched__replay()
3624 sched->thread_funcs_exit = false; in perf_sched__replay()
3625 create_tasks(sched); in perf_sched__replay()
3627 if (sched->replay_repeat == 0) in perf_sched__replay()
3628 sched->replay_repeat = UINT_MAX; in perf_sched__replay()
3630 for (i = 0; i < sched->replay_repeat; i++) in perf_sched__replay()
3631 run_one_test(sched); in perf_sched__replay()
3633 sched->thread_funcs_exit = true; in perf_sched__replay()
3634 destroy_tasks(sched); in perf_sched__replay()
3637 free_cpus_switch_event(sched); in perf_sched__replay()
3640 mutex_destroy(&sched->start_work_mutex); in perf_sched__replay()
3641 mutex_destroy(&sched->work_done_wait_mutex); in perf_sched__replay()
3645 static void setup_sorting(struct perf_sched *sched, const struct option *options, in setup_sorting() argument
3648 char *tmp, *tok, *str = strdup(sched->sort_order); in setup_sorting()
3652 if (sort_dimension__add(tok, &sched->sort_list) < 0) { in setup_sorting()
3660 sort_dimension__add("pid", &sched->cmp_pid); in setup_sorting()
3754 struct perf_sched sched = { in cmd_sched() local
3755 .cmp_pid = LIST_HEAD_INIT(sched.cmp_pid), in cmd_sched()
3756 .sort_list = LIST_HEAD_INIT(sched.sort_list), in cmd_sched()
3773 OPT_BOOLEAN('f', "force", &sched.force, "don't complain, do it"), in cmd_sched()
3777 OPT_STRING('s', "sort", &sched.sort_order, "key[,key2...]", in cmd_sched()
3779 OPT_INTEGER('C', "CPU", &sched.profile_cpu, in cmd_sched()
3781 OPT_BOOLEAN('p', "pids", &sched.skip_merge, in cmd_sched()
3786 OPT_UINTEGER('r', "repeat", &sched.replay_repeat, in cmd_sched()
3791 OPT_BOOLEAN(0, "compact", &sched.map.comp, in cmd_sched()
3793 OPT_STRING(0, "color-pids", &sched.map.color_pids_str, "pids", in cmd_sched()
3795 OPT_STRING(0, "color-cpus", &sched.map.color_cpus_str, "cpus", in cmd_sched()
3797 OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus", in cmd_sched()
3799 OPT_STRING(0, "task-name", &sched.map.task_name, "task", in cmd_sched()
3801 OPT_BOOLEAN(0, "fuzzy-name", &sched.map.fuzzy, in cmd_sched()
3810 OPT_BOOLEAN('g', "call-graph", &sched.show_callchain, in cmd_sched()
3812 OPT_UINTEGER(0, "max-stack", &sched.max_stack, in cmd_sched()
3816 OPT_BOOLEAN('s', "summary", &sched.summary_only, in cmd_sched()
3818 OPT_BOOLEAN('S', "with-summary", &sched.summary, in cmd_sched()
3820 OPT_BOOLEAN('w', "wakeups", &sched.show_wakeups, "Show wakeup events"), in cmd_sched()
3821 OPT_BOOLEAN('n', "next", &sched.show_next, "Show next task"), in cmd_sched()
3822 OPT_BOOLEAN('M', "migrations", &sched.show_migrations, "Show migration events"), in cmd_sched()
3823 OPT_BOOLEAN('V', "cpu-visual", &sched.show_cpu_visual, "Add CPU visual"), in cmd_sched()
3824 OPT_BOOLEAN('I', "idle-hist", &sched.idle_hist, "Show idle events only"), in cmd_sched()
3825 OPT_STRING(0, "time", &sched.time_str, "str", in cmd_sched()
3827 OPT_BOOLEAN(0, "state", &sched.show_state, "Show task state when sched-out"), in cmd_sched()
3833 OPT_BOOLEAN(0, "show-prio", &sched.show_prio, "Show task priority"), in cmd_sched()
3834 OPT_STRING(0, "prio", &sched.prio_str, "prio", in cmd_sched()
3878 perf_tool__init(&sched.tool, /*ordered_events=*/true); in cmd_sched()
3879 sched.tool.sample = perf_sched__process_tracepoint_sample; in cmd_sched()
3880 sched.tool.comm = perf_sched__process_comm; in cmd_sched()
3881 sched.tool.namespaces = perf_event__process_namespaces; in cmd_sched()
3882 sched.tool.lost = perf_event__process_lost; in cmd_sched()
3883 sched.tool.fork = perf_sched__process_fork_event; in cmd_sched()
3898 sched.tp_handler = &lat_ops; in cmd_sched()
3904 setup_sorting(&sched, latency_options, latency_usage); in cmd_sched()
3905 return perf_sched__lat(&sched); in cmd_sched()
3912 if (sched.map.task_name) { in cmd_sched()
3913 sched.map.task_names = strlist__new(sched.map.task_name, NULL); in cmd_sched()
3914 if (sched.map.task_names == NULL) { in cmd_sched()
3920 sched.tp_handler = &map_ops; in cmd_sched()
3921 setup_sorting(&sched, latency_options, latency_usage); in cmd_sched()
3922 return perf_sched__map(&sched); in cmd_sched()
3924 sched.tp_handler = &replay_ops; in cmd_sched()
3930 return perf_sched__replay(&sched); in cmd_sched()
3938 if ((sched.show_wakeups || sched.show_next) && in cmd_sched()
3939 sched.summary_only) { in cmd_sched()
3942 if (sched.show_wakeups) in cmd_sched()
3944 if (sched.show_next) in cmd_sched()
3952 return perf_sched__timehist(&sched); in cmd_sched()