Lines Matching refs:sched

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