Lines Matching refs:sched
146 int (*switch_event)(struct perf_sched *sched, struct evsel *evsel,
149 int (*runtime_event)(struct perf_sched *sched, struct evsel *evsel,
152 int (*wakeup_event)(struct perf_sched *sched, struct evsel *evsel,
156 int (*fork_event)(struct perf_sched *sched, union perf_event *event,
159 int (*migrate_task_event)(struct perf_sched *sched,
304 static void burn_nsecs(struct perf_sched *sched, u64 nsecs) in burn_nsecs() argument
310 } while (T1 + sched->run_measurement_overhead < T0 + nsecs); in burn_nsecs()
323 static void calibrate_run_measurement_overhead(struct perf_sched *sched) in calibrate_run_measurement_overhead() argument
330 burn_nsecs(sched, 0); in calibrate_run_measurement_overhead()
335 sched->run_measurement_overhead = min_delta; in calibrate_run_measurement_overhead()
340 static void calibrate_sleep_measurement_overhead(struct perf_sched *sched) in calibrate_sleep_measurement_overhead() argument
353 sched->sleep_measurement_overhead = min_delta; in calibrate_sleep_measurement_overhead()
386 static void add_sched_event_run(struct perf_sched *sched, struct task_desc *task, in add_sched_event_run() argument
396 sched->nr_run_events_optimized++; in add_sched_event_run()
406 sched->nr_run_events++; in add_sched_event_run()
409 static void add_sched_event_wakeup(struct perf_sched *sched, struct task_desc *task, in add_sched_event_wakeup() argument
420 sched->targetless_wakeups++; in add_sched_event_wakeup()
424 sched->multitarget_wakeups++; in add_sched_event_wakeup()
433 sched->nr_wakeup_events++; in add_sched_event_wakeup()
436 static void add_sched_event_sleep(struct perf_sched *sched, struct task_desc *task, in add_sched_event_sleep() argument
443 sched->nr_sleep_events++; in add_sched_event_sleep()
446 static struct task_desc *register_pid(struct perf_sched *sched, in register_pid() argument
452 if (sched->pid_to_task == NULL) { in register_pid()
455 BUG_ON((sched->pid_to_task = calloc(pid_max, sizeof(struct task_desc *))) == NULL); in register_pid()
458 BUG_ON((sched->pid_to_task = realloc(sched->pid_to_task, (pid + 1) * in register_pid()
461 sched->pid_to_task[pid_max++] = NULL; in register_pid()
464 task = sched->pid_to_task[pid]; in register_pid()
471 task->nr = sched->nr_tasks; in register_pid()
477 add_sched_event_sleep(sched, task, 0, 0); in register_pid()
479 sched->pid_to_task[pid] = task; in register_pid()
480 sched->nr_tasks++; in register_pid()
481 sched->tasks = realloc(sched->tasks, sched->nr_tasks * sizeof(struct task_desc *)); in register_pid()
482 BUG_ON(!sched->tasks); in register_pid()
483 sched->tasks[task->nr] = task; in register_pid()
486 printf("registered task #%ld, PID %ld (%s)\n", sched->nr_tasks, pid, comm); in register_pid()
492 static void print_task_traces(struct perf_sched *sched) in print_task_traces() argument
497 for (i = 0; i < sched->nr_tasks; i++) { in print_task_traces()
498 task = sched->tasks[i]; in print_task_traces()
504 static void add_cross_task_wakeups(struct perf_sched *sched) in add_cross_task_wakeups() argument
509 for (i = 0; i < sched->nr_tasks; i++) { in add_cross_task_wakeups()
510 task1 = sched->tasks[i]; in add_cross_task_wakeups()
512 if (j == sched->nr_tasks) in add_cross_task_wakeups()
514 task2 = sched->tasks[j]; in add_cross_task_wakeups()
515 add_sched_event_wakeup(sched, task1, 0, task2); in add_cross_task_wakeups()
519 static void perf_sched__process_event(struct perf_sched *sched, in perf_sched__process_event() argument
526 burn_nsecs(sched, atom->duration); in perf_sched__process_event()
560 static int self_open_counters(struct perf_sched *sched, unsigned long cur_task) in self_open_counters() argument
579 if (sched->force) { in self_open_counters()
581 limit.rlim_cur += sched->nr_tasks - cur_task; in self_open_counters()
615 struct perf_sched *sched; member
623 struct perf_sched *sched = parms->sched; in thread_func() local
638 ret = pthread_mutex_lock(&sched->start_work_mutex); in thread_func()
640 ret = pthread_mutex_unlock(&sched->start_work_mutex); in thread_func()
647 perf_sched__process_event(sched, this_task->atoms[i]); in thread_func()
655 ret = pthread_mutex_lock(&sched->work_done_wait_mutex); in thread_func()
657 ret = pthread_mutex_unlock(&sched->work_done_wait_mutex); in thread_func()
663 static void create_tasks(struct perf_sched *sched) in create_tasks() argument
675 err = pthread_mutex_lock(&sched->start_work_mutex); in create_tasks()
677 err = pthread_mutex_lock(&sched->work_done_wait_mutex); in create_tasks()
679 for (i = 0; i < sched->nr_tasks; i++) { in create_tasks()
682 parms->task = task = sched->tasks[i]; in create_tasks()
683 parms->sched = sched; in create_tasks()
684 parms->fd = self_open_counters(sched, i); in create_tasks()
694 static void wait_for_tasks(struct perf_sched *sched) in wait_for_tasks() argument
700 sched->start_time = get_nsecs(); in wait_for_tasks()
701 sched->cpu_usage = 0; in wait_for_tasks()
702 pthread_mutex_unlock(&sched->work_done_wait_mutex); in wait_for_tasks()
704 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
705 task = sched->tasks[i]; in wait_for_tasks()
710 ret = pthread_mutex_lock(&sched->work_done_wait_mutex); in wait_for_tasks()
715 pthread_mutex_unlock(&sched->start_work_mutex); in wait_for_tasks()
717 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
718 task = sched->tasks[i]; in wait_for_tasks()
722 sched->cpu_usage += task->cpu_usage; in wait_for_tasks()
727 if (!sched->runavg_cpu_usage) in wait_for_tasks()
728 sched->runavg_cpu_usage = sched->cpu_usage; in wait_for_tasks()
729 …sched->runavg_cpu_usage = (sched->runavg_cpu_usage * (sched->replay_repeat - 1) + sched->cpu_usage… in wait_for_tasks()
731 sched->parent_cpu_usage = cpu_usage_1 - cpu_usage_0; in wait_for_tasks()
732 if (!sched->runavg_parent_cpu_usage) in wait_for_tasks()
733 sched->runavg_parent_cpu_usage = sched->parent_cpu_usage; in wait_for_tasks()
734 sched->runavg_parent_cpu_usage = (sched->runavg_parent_cpu_usage * (sched->replay_repeat - 1) + in wait_for_tasks()
735 sched->parent_cpu_usage)/sched->replay_repeat; in wait_for_tasks()
737 ret = pthread_mutex_lock(&sched->start_work_mutex); in wait_for_tasks()
740 for (i = 0; i < sched->nr_tasks; i++) { in wait_for_tasks()
741 task = sched->tasks[i]; in wait_for_tasks()
747 static void run_one_test(struct perf_sched *sched) in run_one_test() argument
752 wait_for_tasks(sched); in run_one_test()
756 sched->sum_runtime += delta; in run_one_test()
757 sched->nr_runs++; in run_one_test()
759 avg_delta = sched->sum_runtime / sched->nr_runs; in run_one_test()
764 sched->sum_fluct += fluct; in run_one_test()
765 if (!sched->run_avg) in run_one_test()
766 sched->run_avg = delta; in run_one_test()
767 sched->run_avg = (sched->run_avg * (sched->replay_repeat - 1) + delta) / sched->replay_repeat; in run_one_test()
769 printf("#%-3ld: %0.3f, ", sched->nr_runs, (double)delta / NSEC_PER_MSEC); in run_one_test()
771 printf("ravg: %0.2f, ", (double)sched->run_avg / NSEC_PER_MSEC); in run_one_test()
774 (double)sched->cpu_usage / NSEC_PER_MSEC, (double)sched->runavg_cpu_usage / NSEC_PER_MSEC); in run_one_test()
782 (double)sched->parent_cpu_usage / NSEC_PER_MSEC, in run_one_test()
783 (double)sched->runavg_parent_cpu_usage / NSEC_PER_MSEC); in run_one_test()
788 if (sched->nr_sleep_corrections) in run_one_test()
789 printf(" (%ld sleep corrections)\n", sched->nr_sleep_corrections); in run_one_test()
790 sched->nr_sleep_corrections = 0; in run_one_test()
793 static void test_calibrations(struct perf_sched *sched) in test_calibrations() argument
798 burn_nsecs(sched, NSEC_PER_MSEC); in test_calibrations()
811 replay_wakeup_event(struct perf_sched *sched, in replay_wakeup_event() argument
825 waker = register_pid(sched, sample->tid, "<unknown>"); in replay_wakeup_event()
826 wakee = register_pid(sched, pid, comm); in replay_wakeup_event()
828 add_sched_event_wakeup(sched, waker, sample->time, wakee); in replay_wakeup_event()
832 static int replay_switch_event(struct perf_sched *sched, in replay_switch_event() argument
853 timestamp0 = sched->cpu_last_switched[cpu]; in replay_switch_event()
867 prev = register_pid(sched, prev_pid, prev_comm); in replay_switch_event()
868 next = register_pid(sched, next_pid, next_comm); in replay_switch_event()
870 sched->cpu_last_switched[cpu] = timestamp; in replay_switch_event()
872 add_sched_event_run(sched, prev, timestamp, delta); in replay_switch_event()
873 add_sched_event_sleep(sched, prev, timestamp, prev_state); in replay_switch_event()
878 static int replay_fork_event(struct perf_sched *sched, in replay_fork_event() argument
901 register_pid(sched, parent->tid, thread__comm_str(parent)); in replay_fork_event()
902 register_pid(sched, child->tid, thread__comm_str(child)); in replay_fork_event()
1017 static int thread_atoms_insert(struct perf_sched *sched, struct thread *thread) in thread_atoms_insert() argument
1027 __thread_latency_insert(&sched->atom_root, atoms, &sched->cmp_pid); in thread_atoms_insert()
1106 static int latency_switch_event(struct perf_sched *sched, in latency_switch_event() argument
1122 timestamp0 = sched->cpu_last_switched[cpu]; in latency_switch_event()
1123 sched->cpu_last_switched[cpu] = timestamp; in latency_switch_event()
1139 out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid); in latency_switch_event()
1141 if (thread_atoms_insert(sched, sched_out)) in latency_switch_event()
1143 out_events = thread_atoms_search(&sched->atom_root, sched_out, &sched->cmp_pid); in latency_switch_event()
1152 in_events = thread_atoms_search(&sched->atom_root, sched_in, &sched->cmp_pid); in latency_switch_event()
1154 if (thread_atoms_insert(sched, sched_in)) in latency_switch_event()
1156 in_events = thread_atoms_search(&sched->atom_root, sched_in, &sched->cmp_pid); in latency_switch_event()
1176 static int latency_runtime_event(struct perf_sched *sched, in latency_runtime_event() argument
1184 struct work_atoms *atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); in latency_runtime_event()
1193 if (thread_atoms_insert(sched, thread)) in latency_runtime_event()
1195 atoms = thread_atoms_search(&sched->atom_root, thread, &sched->cmp_pid); in latency_runtime_event()
1211 static int latency_wakeup_event(struct perf_sched *sched, in latency_wakeup_event() argument
1226 atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid); in latency_wakeup_event()
1228 if (thread_atoms_insert(sched, wakee)) in latency_wakeup_event()
1230 atoms = thread_atoms_search(&sched->atom_root, wakee, &sched->cmp_pid); in latency_wakeup_event()
1254 if (sched->profile_cpu == -1 && atom->state != THREAD_SLEEPING) in latency_wakeup_event()
1257 sched->nr_timestamps++; in latency_wakeup_event()
1259 sched->nr_unordered_timestamps++; in latency_wakeup_event()
1272 static int latency_migrate_task_event(struct perf_sched *sched, in latency_migrate_task_event() argument
1287 if (sched->profile_cpu == -1) in latency_migrate_task_event()
1293 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid); in latency_migrate_task_event()
1295 if (thread_atoms_insert(sched, migrant)) in latency_migrate_task_event()
1297 register_pid(sched, migrant->tid, thread__comm_str(migrant)); in latency_migrate_task_event()
1298 atoms = thread_atoms_search(&sched->atom_root, migrant, &sched->cmp_pid); in latency_migrate_task_event()
1312 sched->nr_timestamps++; in latency_migrate_task_event()
1315 sched->nr_unordered_timestamps++; in latency_migrate_task_event()
1322 static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_list) in output_lat_thread() argument
1337 sched->all_runtime += work_list->total_runtime; in output_lat_thread()
1338 sched->all_count += work_list->nb_atoms; in output_lat_thread()
1463 static void perf_sched__sort_lat(struct perf_sched *sched) in perf_sched__sort_lat() argument
1466 struct rb_root_cached *root = &sched->atom_root; in perf_sched__sort_lat()
1476 __thread_latency_insert(&sched->sorted_atom_root, data, &sched->sort_list); in perf_sched__sort_lat()
1478 if (root == &sched->atom_root) { in perf_sched__sort_lat()
1479 root = &sched->merged_atom_root; in perf_sched__sort_lat()
1489 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in process_sched_wakeup_event() local
1491 if (sched->tp_handler->wakeup_event) in process_sched_wakeup_event()
1492 return sched->tp_handler->wakeup_event(sched, evsel, sample, machine); in process_sched_wakeup_event()
1512 map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid, pid_t tid) in map__findnew_thread() argument
1519 if (!sched->map.color_pids || !thread || thread__priv(thread)) in map__findnew_thread()
1522 if (thread_map__has(sched->map.color_pids, tid)) in map__findnew_thread()
1529 static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, in map_switch_event() argument
1546 if (this_cpu > sched->max_cpu) in map_switch_event()
1547 sched->max_cpu = this_cpu; in map_switch_event()
1549 if (sched->map.comp) { in map_switch_event()
1550 cpus_nr = bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS); in map_switch_event()
1551 if (!test_and_set_bit(this_cpu, sched->map.comp_cpus_mask)) { in map_switch_event()
1552 sched->map.comp_cpus[cpus_nr++] = this_cpu; in map_switch_event()
1556 cpus_nr = sched->max_cpu; in map_switch_event()
1558 timestamp0 = sched->cpu_last_switched[this_cpu]; in map_switch_event()
1559 sched->cpu_last_switched[this_cpu] = timestamp; in map_switch_event()
1570 sched_in = map__findnew_thread(sched, machine, -1, next_pid); in map_switch_event()
1580 sched->curr_thread[this_cpu] = thread__get(sched_in); in map_switch_event()
1594 tr->shortname[0] = sched->next_shortname1; in map_switch_event()
1595 tr->shortname[1] = sched->next_shortname2; in map_switch_event()
1597 if (sched->next_shortname1 < 'Z') { in map_switch_event()
1598 sched->next_shortname1++; in map_switch_event()
1600 sched->next_shortname1 = 'A'; in map_switch_event()
1601 if (sched->next_shortname2 < '9') in map_switch_event()
1602 sched->next_shortname2++; in map_switch_event()
1604 sched->next_shortname2 = '0'; in map_switch_event()
1611 int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i; in map_switch_event()
1612 struct thread *curr_thread = sched->curr_thread[cpu]; in map_switch_event()
1620 if (sched->map.cpus && !cpu_map__has(sched->map.cpus, cpu)) in map_switch_event()
1623 if (sched->map.color_cpus && cpu_map__has(sched->map.color_cpus, cpu)) in map_switch_event()
1631 if (sched->curr_thread[cpu]) { in map_switch_event()
1632 curr_tr = thread__get_runtime(sched->curr_thread[cpu]); in map_switch_event()
1642 if (sched->map.cpus && !cpu_map__has(sched->map.cpus, this_cpu)) in map_switch_event()
1658 if (sched->map.comp && new_cpu) in map_switch_event()
1674 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in process_sched_switch_event() local
1679 if (sched->curr_pid[this_cpu] != (u32)-1) { in process_sched_switch_event()
1684 if (sched->curr_pid[this_cpu] != prev_pid) in process_sched_switch_event()
1685 sched->nr_context_switch_bugs++; in process_sched_switch_event()
1688 if (sched->tp_handler->switch_event) in process_sched_switch_event()
1689 err = sched->tp_handler->switch_event(sched, evsel, sample, machine); in process_sched_switch_event()
1691 sched->curr_pid[this_cpu] = next_pid; in process_sched_switch_event()
1700 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in process_sched_runtime_event() local
1702 if (sched->tp_handler->runtime_event) in process_sched_runtime_event()
1703 return sched->tp_handler->runtime_event(sched, evsel, sample, machine); in process_sched_runtime_event()
1713 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in perf_sched__process_fork_event() local
1719 if (sched->tp_handler->fork_event) in perf_sched__process_fork_event()
1720 return sched->tp_handler->fork_event(sched, event, machine); in perf_sched__process_fork_event()
1730 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in process_sched_migrate_task_event() local
1732 if (sched->tp_handler->migrate_task_event) in process_sched_migrate_task_event()
1733 return sched->tp_handler->migrate_task_event(sched, evsel, sample, machine); in process_sched_migrate_task_event()
1790 static int perf_sched__read_events(struct perf_sched *sched) in perf_sched__read_events() argument
1803 .force = sched->force, in perf_sched__read_events()
1807 session = perf_session__new(&data, false, &sched->tool); in perf_sched__read_events()
1825 sched->nr_events = session->evlist->stats.nr_events[0]; in perf_sched__read_events()
1826 sched->nr_lost_events = session->evlist->stats.total_lost; in perf_sched__read_events()
1827 sched->nr_lost_chunks = session->evlist->stats.nr_events[PERF_RECORD_LOST]; in perf_sched__read_events()
1930 static void timehist_header(struct perf_sched *sched) in timehist_header() argument
1932 u32 ncpus = sched->max_cpu + 1; in timehist_header()
1937 if (sched->show_cpu_visual) { in timehist_header()
1950 if (sched->show_state) in timehist_header()
1960 if (sched->show_cpu_visual) in timehist_header()
1966 if (sched->show_state) in timehist_header()
1976 if (sched->show_cpu_visual) in timehist_header()
1983 if (sched->show_state) in timehist_header()
2001 static void timehist_print_sample(struct perf_sched *sched, in timehist_print_sample() argument
2011 u32 max_cpus = sched->max_cpu + 1; in timehist_print_sample()
2022 if (sched->show_cpu_visual) { in timehist_print_sample()
2046 if (sched->show_state) in timehist_print_sample()
2049 if (sched->show_next) { in timehist_print_sample()
2054 if (sched->show_wakeups && !sched->show_next) in timehist_print_sample()
2060 if (sched->show_callchain) in timehist_print_sample()
2147 static void save_task_callchain(struct perf_sched *sched, in save_task_callchain() argument
2162 if (!sched->show_callchain || sample->callchain == NULL) in save_task_callchain()
2166 NULL, NULL, sched->max_stack + 2) != 0) { in save_task_callchain()
2290 static void save_idle_callchain(struct perf_sched *sched, in save_idle_callchain() argument
2294 if (!sched->show_callchain || sample->callchain == NULL) in save_idle_callchain()
2300 static struct thread *timehist_get_thread(struct perf_sched *sched, in timehist_get_thread() argument
2321 save_task_callchain(sched, sample, evsel, machine); in timehist_get_thread()
2322 if (sched->idle_hist) { in timehist_get_thread()
2340 save_idle_callchain(sched, itr, sample); in timehist_get_thread()
2347 static bool timehist_skip_sample(struct perf_sched *sched, in timehist_skip_sample() argument
2356 sched->skipped_samples++; in timehist_skip_sample()
2359 if (sched->idle_hist) { in timehist_skip_sample()
2370 static void timehist_print_wakeup_event(struct perf_sched *sched, in timehist_print_wakeup_event() argument
2384 if (timehist_skip_sample(sched, thread, evsel, sample) && in timehist_print_wakeup_event()
2385 timehist_skip_sample(sched, awakened, evsel, sample)) { in timehist_print_wakeup_event()
2391 if (sched->show_cpu_visual) in timehist_print_wakeup_event()
2392 printf(" %*s ", sched->max_cpu + 1, ""); in timehist_print_wakeup_event()
2419 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in timehist_sched_wakeup_event() local
2437 if (sched->show_wakeups && in timehist_sched_wakeup_event()
2438 !perf_time__skip_sample(&sched->ptime, sample->time)) in timehist_sched_wakeup_event()
2439 timehist_print_wakeup_event(sched, evsel, sample, machine, thread); in timehist_sched_wakeup_event()
2444 static void timehist_print_migration_event(struct perf_sched *sched, in timehist_print_migration_event() argument
2452 u32 max_cpus = sched->max_cpu + 1; in timehist_print_migration_event()
2455 if (sched->summary_only) in timehist_print_migration_event()
2458 max_cpus = sched->max_cpu + 1; in timehist_print_migration_event()
2466 if (timehist_skip_sample(sched, thread, evsel, sample) && in timehist_print_migration_event()
2467 timehist_skip_sample(sched, migrated, evsel, sample)) { in timehist_print_migration_event()
2474 if (sched->show_cpu_visual) { in timehist_print_migration_event()
2503 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in timehist_migrate_task_event() local
2520 timehist_print_migration_event(sched, evsel, sample, machine, thread); in timehist_migrate_task_event()
2531 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in timehist_sched_change_event() local
2532 struct perf_time_interval *ptime = &sched->ptime; in timehist_sched_change_event()
2547 thread = timehist_get_thread(sched, sample, machine, evsel); in timehist_sched_change_event()
2553 if (timehist_skip_sample(sched, thread, evsel, sample)) in timehist_sched_change_event()
2589 if (!sched->idle_hist || thread->tid == 0) { in timehist_sched_change_event()
2593 if (sched->idle_hist) { in timehist_sched_change_event()
2626 if (!sched->summary_only) in timehist_sched_change_event()
2627 timehist_print_sample(sched, evsel, sample, &al, thread, t, state); in timehist_sched_change_event()
2630 if (sched->hist_time.start == 0 && t >= ptime->start) in timehist_sched_change_event()
2631 sched->hist_time.start = t; in timehist_sched_change_event()
2633 sched->hist_time.end = t; in timehist_sched_change_event()
2717 struct perf_sched *sched; member
2737 if (stats->sched->show_state) in __show_thread_runtime()
2816 static void timehist_print_summary(struct perf_sched *sched, in timehist_print_summary() argument
2825 u64 hist_time = sched->hist_time.end - sched->hist_time.start; in timehist_print_summary()
2828 totals.sched = sched; in timehist_print_summary()
2830 if (sched->idle_hist) { in timehist_print_summary()
2834 } else if (sched->show_state) { in timehist_print_summary()
2845 sched->show_state ? "(msec)" : "%"); in timehist_print_summary()
2859 if (sched->skipped_samples && !sched->idle_hist) in timehist_print_summary()
2881 if (sched->idle_hist && sched->show_callchain) { in timehist_print_summary()
2921 printf(" (x %d)\n", sched->max_cpu); in timehist_print_summary()
2936 struct perf_sched *sched = container_of(tool, struct perf_sched, tool); in perf_timehist__process_sample() local
2940 if (this_cpu > sched->max_cpu) in perf_timehist__process_sample()
2941 sched->max_cpu = this_cpu; in perf_timehist__process_sample()
2952 static int timehist_check_attr(struct perf_sched *sched, in timehist_check_attr() argument
2965 if (sched->show_callchain && !evsel__has_callchain(evsel)) { in timehist_check_attr()
2967 sched->show_callchain = 0; in timehist_check_attr()
2975 static int perf_sched__timehist(struct perf_sched *sched) in perf_sched__timehist() argument
2989 .force = sched->force, in perf_sched__timehist()
2999 sched->tool.sample = perf_timehist__process_sample; in perf_sched__timehist()
3000 sched->tool.mmap = perf_event__process_mmap; in perf_sched__timehist()
3001 sched->tool.comm = perf_event__process_comm; in perf_sched__timehist()
3002 sched->tool.exit = perf_event__process_exit; in perf_sched__timehist()
3003 sched->tool.fork = perf_event__process_fork; in perf_sched__timehist()
3004 sched->tool.lost = process_lost; in perf_sched__timehist()
3005 sched->tool.attr = perf_event__process_attr; in perf_sched__timehist()
3006 sched->tool.tracing_data = perf_event__process_tracing_data; in perf_sched__timehist()
3007 sched->tool.build_id = perf_event__process_build_id; in perf_sched__timehist()
3009 sched->tool.ordered_events = true; in perf_sched__timehist()
3010 sched->tool.ordering_requires_timestamps = true; in perf_sched__timehist()
3012 symbol_conf.use_callchain = sched->show_callchain; in perf_sched__timehist()
3014 session = perf_session__new(&data, false, &sched->tool); in perf_sched__timehist()
3028 if (perf_time__parse_str(&sched->ptime, sched->time_str) != 0) { in perf_sched__timehist()
3033 if (timehist_check_attr(sched, evlist) != 0) in perf_sched__timehist()
3054 if (sched->show_migrations && in perf_sched__timehist()
3059 sched->max_cpu = session->header.env.nr_cpus_online; in perf_sched__timehist()
3060 if (sched->max_cpu == 0) in perf_sched__timehist()
3061 sched->max_cpu = 4; in perf_sched__timehist()
3062 if (init_idle_threads(sched->max_cpu)) in perf_sched__timehist()
3066 if (sched->summary_only) in perf_sched__timehist()
3067 sched->summary = sched->summary_only; in perf_sched__timehist()
3069 if (!sched->summary_only) in perf_sched__timehist()
3070 timehist_header(sched); in perf_sched__timehist()
3078 sched->nr_events = evlist->stats.nr_events[0]; in perf_sched__timehist()
3079 sched->nr_lost_events = evlist->stats.total_lost; in perf_sched__timehist()
3080 sched->nr_lost_chunks = evlist->stats.nr_events[PERF_RECORD_LOST]; in perf_sched__timehist()
3082 if (sched->summary) in perf_sched__timehist()
3083 timehist_print_summary(sched, session); in perf_sched__timehist()
3093 static void print_bad_events(struct perf_sched *sched) in print_bad_events() argument
3095 if (sched->nr_unordered_timestamps && sched->nr_timestamps) { in print_bad_events()
3097 (double)sched->nr_unordered_timestamps/(double)sched->nr_timestamps*100.0, in print_bad_events()
3098 sched->nr_unordered_timestamps, sched->nr_timestamps); in print_bad_events()
3100 if (sched->nr_lost_events && sched->nr_events) { in print_bad_events()
3102 (double)sched->nr_lost_events/(double)sched->nr_events * 100.0, in print_bad_events()
3103 sched->nr_lost_events, sched->nr_events, sched->nr_lost_chunks); in print_bad_events()
3105 if (sched->nr_context_switch_bugs && sched->nr_timestamps) { in print_bad_events()
3107 (double)sched->nr_context_switch_bugs/(double)sched->nr_timestamps*100.0, in print_bad_events()
3108 sched->nr_context_switch_bugs, sched->nr_timestamps); in print_bad_events()
3109 if (sched->nr_lost_events) in print_bad_events()
3156 static void perf_sched__merge_lat(struct perf_sched *sched) in perf_sched__merge_lat() argument
3161 if (sched->skip_merge) in perf_sched__merge_lat()
3164 while ((node = rb_first_cached(&sched->atom_root))) { in perf_sched__merge_lat()
3165 rb_erase_cached(node, &sched->atom_root); in perf_sched__merge_lat()
3167 __merge_work_atoms(&sched->merged_atom_root, data); in perf_sched__merge_lat()
3171 static int perf_sched__lat(struct perf_sched *sched) in perf_sched__lat() argument
3177 if (perf_sched__read_events(sched)) in perf_sched__lat()
3180 perf_sched__merge_lat(sched); in perf_sched__lat()
3181 perf_sched__sort_lat(sched); in perf_sched__lat()
3187 next = rb_first_cached(&sched->sorted_atom_root); in perf_sched__lat()
3193 output_lat_thread(sched, work_list); in perf_sched__lat()
3200 (double)sched->all_runtime / NSEC_PER_MSEC, sched->all_count); in perf_sched__lat()
3204 print_bad_events(sched); in perf_sched__lat()
3210 static int setup_map_cpus(struct perf_sched *sched) in setup_map_cpus() argument
3214 sched->max_cpu = sysconf(_SC_NPROCESSORS_CONF); in setup_map_cpus()
3216 if (sched->map.comp) { in setup_map_cpus()
3217 sched->map.comp_cpus = zalloc(sched->max_cpu * sizeof(int)); in setup_map_cpus()
3218 if (!sched->map.comp_cpus) in setup_map_cpus()
3222 if (!sched->map.cpus_str) in setup_map_cpus()
3225 map = perf_cpu_map__new(sched->map.cpus_str); in setup_map_cpus()
3227 pr_err("failed to get cpus map from %s\n", sched->map.cpus_str); in setup_map_cpus()
3231 sched->map.cpus = map; in setup_map_cpus()
3235 static int setup_color_pids(struct perf_sched *sched) in setup_color_pids() argument
3239 if (!sched->map.color_pids_str) in setup_color_pids()
3242 map = thread_map__new_by_tid_str(sched->map.color_pids_str); in setup_color_pids()
3244 pr_err("failed to get thread map from %s\n", sched->map.color_pids_str); in setup_color_pids()
3248 sched->map.color_pids = map; in setup_color_pids()
3252 static int setup_color_cpus(struct perf_sched *sched) in setup_color_cpus() argument
3256 if (!sched->map.color_cpus_str) in setup_color_cpus()
3259 map = perf_cpu_map__new(sched->map.color_cpus_str); in setup_color_cpus()
3261 pr_err("failed to get thread map from %s\n", sched->map.color_cpus_str); in setup_color_cpus()
3265 sched->map.color_cpus = map; in setup_color_cpus()
3269 static int perf_sched__map(struct perf_sched *sched) in perf_sched__map() argument
3271 if (setup_map_cpus(sched)) in perf_sched__map()
3274 if (setup_color_pids(sched)) in perf_sched__map()
3277 if (setup_color_cpus(sched)) in perf_sched__map()
3281 if (perf_sched__read_events(sched)) in perf_sched__map()
3283 print_bad_events(sched); in perf_sched__map()
3287 static int perf_sched__replay(struct perf_sched *sched) in perf_sched__replay() argument
3291 calibrate_run_measurement_overhead(sched); in perf_sched__replay()
3292 calibrate_sleep_measurement_overhead(sched); in perf_sched__replay()
3294 test_calibrations(sched); in perf_sched__replay()
3296 if (perf_sched__read_events(sched)) in perf_sched__replay()
3299 printf("nr_run_events: %ld\n", sched->nr_run_events); in perf_sched__replay()
3300 printf("nr_sleep_events: %ld\n", sched->nr_sleep_events); in perf_sched__replay()
3301 printf("nr_wakeup_events: %ld\n", sched->nr_wakeup_events); in perf_sched__replay()
3303 if (sched->targetless_wakeups) in perf_sched__replay()
3304 printf("target-less wakeups: %ld\n", sched->targetless_wakeups); in perf_sched__replay()
3305 if (sched->multitarget_wakeups) in perf_sched__replay()
3306 printf("multi-target wakeups: %ld\n", sched->multitarget_wakeups); in perf_sched__replay()
3307 if (sched->nr_run_events_optimized) in perf_sched__replay()
3309 sched->nr_run_events_optimized); in perf_sched__replay()
3311 print_task_traces(sched); in perf_sched__replay()
3312 add_cross_task_wakeups(sched); in perf_sched__replay()
3314 create_tasks(sched); in perf_sched__replay()
3316 for (i = 0; i < sched->replay_repeat; i++) in perf_sched__replay()
3317 run_one_test(sched); in perf_sched__replay()
3322 static void setup_sorting(struct perf_sched *sched, const struct option *options, in setup_sorting() argument
3325 char *tmp, *tok, *str = strdup(sched->sort_order); in setup_sorting()
3329 if (sort_dimension__add(tok, &sched->sort_list) < 0) { in setup_sorting()
3337 sort_dimension__add("pid", &sched->cmp_pid); in setup_sorting()
3417 struct perf_sched sched = { in cmd_sched() local
3426 .cmp_pid = LIST_HEAD_INIT(sched.cmp_pid), in cmd_sched()
3427 .sort_list = LIST_HEAD_INIT(sched.sort_list), in cmd_sched()
3446 OPT_BOOLEAN('f', "force", &sched.force, "don't complain, do it"), in cmd_sched()
3450 OPT_STRING('s', "sort", &sched.sort_order, "key[,key2...]", in cmd_sched()
3452 OPT_INTEGER('C', "CPU", &sched.profile_cpu, in cmd_sched()
3454 OPT_BOOLEAN('p', "pids", &sched.skip_merge, in cmd_sched()
3459 OPT_UINTEGER('r', "repeat", &sched.replay_repeat, in cmd_sched()
3464 OPT_BOOLEAN(0, "compact", &sched.map.comp, in cmd_sched()
3466 OPT_STRING(0, "color-pids", &sched.map.color_pids_str, "pids", in cmd_sched()
3468 OPT_STRING(0, "color-cpus", &sched.map.color_cpus_str, "cpus", in cmd_sched()
3470 OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus", in cmd_sched()
3479 OPT_BOOLEAN('g', "call-graph", &sched.show_callchain, in cmd_sched()
3481 OPT_UINTEGER(0, "max-stack", &sched.max_stack, in cmd_sched()
3485 OPT_BOOLEAN('s', "summary", &sched.summary_only, in cmd_sched()
3487 OPT_BOOLEAN('S', "with-summary", &sched.summary, in cmd_sched()
3489 OPT_BOOLEAN('w', "wakeups", &sched.show_wakeups, "Show wakeup events"), in cmd_sched()
3490 OPT_BOOLEAN('n', "next", &sched.show_next, "Show next task"), in cmd_sched()
3491 OPT_BOOLEAN('M', "migrations", &sched.show_migrations, "Show migration events"), in cmd_sched()
3492 OPT_BOOLEAN('V', "cpu-visual", &sched.show_cpu_visual, "Add CPU visual"), in cmd_sched()
3493 OPT_BOOLEAN('I', "idle-hist", &sched.idle_hist, "Show idle events only"), in cmd_sched()
3494 OPT_STRING(0, "time", &sched.time_str, "str", in cmd_sched()
3496 OPT_BOOLEAN(0, "state", &sched.show_state, "Show task state when sched-out"), in cmd_sched()
3544 for (i = 0; i < ARRAY_SIZE(sched.curr_pid); i++) in cmd_sched()
3545 sched.curr_pid[i] = -1; in cmd_sched()
3561 sched.tp_handler = &lat_ops; in cmd_sched()
3567 setup_sorting(&sched, latency_options, latency_usage); in cmd_sched()
3568 return perf_sched__lat(&sched); in cmd_sched()
3575 sched.tp_handler = &map_ops; in cmd_sched()
3576 setup_sorting(&sched, latency_options, latency_usage); in cmd_sched()
3577 return perf_sched__map(&sched); in cmd_sched()
3579 sched.tp_handler = &replay_ops; in cmd_sched()
3585 return perf_sched__replay(&sched); in cmd_sched()
3593 if ((sched.show_wakeups || sched.show_next) && in cmd_sched()
3594 sched.summary_only) { in cmd_sched()
3597 if (sched.show_wakeups) in cmd_sched()
3599 if (sched.show_next) in cmd_sched()
3604 return perf_sched__timehist(&sched); in cmd_sched()