diff options
Diffstat (limited to 'tools/perf/builtin-sched.c')
-rw-r--r-- | tools/perf/builtin-sched.c | 100 |
1 files changed, 46 insertions, 54 deletions
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 55f3b5dcc731..dcfe8873c9a1 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -193,7 +193,7 @@ static void calibrate_run_measurement_overhead(void) | |||
193 | } | 193 | } |
194 | run_measurement_overhead = min_delta; | 194 | run_measurement_overhead = min_delta; |
195 | 195 | ||
196 | printf("run measurement overhead: %Ld nsecs\n", min_delta); | 196 | printf("run measurement overhead: %" PRIu64 " nsecs\n", min_delta); |
197 | } | 197 | } |
198 | 198 | ||
199 | static void calibrate_sleep_measurement_overhead(void) | 199 | static void calibrate_sleep_measurement_overhead(void) |
@@ -211,7 +211,7 @@ static void calibrate_sleep_measurement_overhead(void) | |||
211 | min_delta -= 10000; | 211 | min_delta -= 10000; |
212 | sleep_measurement_overhead = min_delta; | 212 | sleep_measurement_overhead = min_delta; |
213 | 213 | ||
214 | printf("sleep measurement overhead: %Ld nsecs\n", min_delta); | 214 | printf("sleep measurement overhead: %" PRIu64 " nsecs\n", min_delta); |
215 | } | 215 | } |
216 | 216 | ||
217 | static struct sched_atom * | 217 | static struct sched_atom * |
@@ -369,11 +369,6 @@ static void | |||
369 | process_sched_event(struct task_desc *this_task __used, struct sched_atom *atom) | 369 | process_sched_event(struct task_desc *this_task __used, struct sched_atom *atom) |
370 | { | 370 | { |
371 | int ret = 0; | 371 | int ret = 0; |
372 | u64 now; | ||
373 | long long delta; | ||
374 | |||
375 | now = get_nsecs(); | ||
376 | delta = start_time + atom->timestamp - now; | ||
377 | 372 | ||
378 | switch (atom->type) { | 373 | switch (atom->type) { |
379 | case SCHED_EVENT_RUN: | 374 | case SCHED_EVENT_RUN: |
@@ -489,7 +484,8 @@ static void create_tasks(void) | |||
489 | 484 | ||
490 | err = pthread_attr_init(&attr); | 485 | err = pthread_attr_init(&attr); |
491 | BUG_ON(err); | 486 | BUG_ON(err); |
492 | err = pthread_attr_setstacksize(&attr, (size_t)(16*1024)); | 487 | err = pthread_attr_setstacksize(&attr, |
488 | (size_t) max(16 * 1024, PTHREAD_STACK_MIN)); | ||
493 | BUG_ON(err); | 489 | BUG_ON(err); |
494 | err = pthread_mutex_lock(&start_work_mutex); | 490 | err = pthread_mutex_lock(&start_work_mutex); |
495 | BUG_ON(err); | 491 | BUG_ON(err); |
@@ -561,7 +557,7 @@ static void wait_for_tasks(void) | |||
561 | 557 | ||
562 | static void run_one_test(void) | 558 | static void run_one_test(void) |
563 | { | 559 | { |
564 | u64 T0, T1, delta, avg_delta, fluct, std_dev; | 560 | u64 T0, T1, delta, avg_delta, fluct; |
565 | 561 | ||
566 | T0 = get_nsecs(); | 562 | T0 = get_nsecs(); |
567 | wait_for_tasks(); | 563 | wait_for_tasks(); |
@@ -577,7 +573,6 @@ static void run_one_test(void) | |||
577 | else | 573 | else |
578 | fluct = delta - avg_delta; | 574 | fluct = delta - avg_delta; |
579 | sum_fluct += fluct; | 575 | sum_fluct += fluct; |
580 | std_dev = sum_fluct / nr_runs / sqrt(nr_runs); | ||
581 | if (!run_avg) | 576 | if (!run_avg) |
582 | run_avg = delta; | 577 | run_avg = delta; |
583 | run_avg = (run_avg*9 + delta)/10; | 578 | run_avg = (run_avg*9 + delta)/10; |
@@ -616,13 +611,13 @@ static void test_calibrations(void) | |||
616 | burn_nsecs(1e6); | 611 | burn_nsecs(1e6); |
617 | T1 = get_nsecs(); | 612 | T1 = get_nsecs(); |
618 | 613 | ||
619 | printf("the run test took %Ld nsecs\n", T1-T0); | 614 | printf("the run test took %" PRIu64 " nsecs\n", T1 - T0); |
620 | 615 | ||
621 | T0 = get_nsecs(); | 616 | T0 = get_nsecs(); |
622 | sleep_nsecs(1e6); | 617 | sleep_nsecs(1e6); |
623 | T1 = get_nsecs(); | 618 | T1 = get_nsecs(); |
624 | 619 | ||
625 | printf("the sleep test took %Ld nsecs\n", T1-T0); | 620 | printf("the sleep test took %" PRIu64 " nsecs\n", T1 - T0); |
626 | } | 621 | } |
627 | 622 | ||
628 | #define FILL_FIELD(ptr, field, event, data) \ | 623 | #define FILL_FIELD(ptr, field, event, data) \ |
@@ -798,7 +793,7 @@ replay_switch_event(struct trace_switch_event *switch_event, | |||
798 | u64 timestamp, | 793 | u64 timestamp, |
799 | struct thread *thread __used) | 794 | struct thread *thread __used) |
800 | { | 795 | { |
801 | struct task_desc *prev, *next; | 796 | struct task_desc *prev, __used *next; |
802 | u64 timestamp0; | 797 | u64 timestamp0; |
803 | s64 delta; | 798 | s64 delta; |
804 | 799 | ||
@@ -815,10 +810,10 @@ replay_switch_event(struct trace_switch_event *switch_event, | |||
815 | delta = 0; | 810 | delta = 0; |
816 | 811 | ||
817 | if (delta < 0) | 812 | if (delta < 0) |
818 | die("hm, delta: %Ld < 0 ?\n", delta); | 813 | die("hm, delta: %" PRIu64 " < 0 ?\n", delta); |
819 | 814 | ||
820 | if (verbose) { | 815 | if (verbose) { |
821 | printf(" ... switch from %s/%d to %s/%d [ran %Ld nsecs]\n", | 816 | printf(" ... switch from %s/%d to %s/%d [ran %" PRIu64 " nsecs]\n", |
822 | switch_event->prev_comm, switch_event->prev_pid, | 817 | switch_event->prev_comm, switch_event->prev_pid, |
823 | switch_event->next_comm, switch_event->next_pid, | 818 | switch_event->next_comm, switch_event->next_pid, |
824 | delta); | 819 | delta); |
@@ -1047,7 +1042,7 @@ latency_switch_event(struct trace_switch_event *switch_event, | |||
1047 | delta = 0; | 1042 | delta = 0; |
1048 | 1043 | ||
1049 | if (delta < 0) | 1044 | if (delta < 0) |
1050 | die("hm, delta: %Ld < 0 ?\n", delta); | 1045 | die("hm, delta: %" PRIu64 " < 0 ?\n", delta); |
1051 | 1046 | ||
1052 | 1047 | ||
1053 | sched_out = perf_session__findnew(session, switch_event->prev_pid); | 1048 | sched_out = perf_session__findnew(session, switch_event->prev_pid); |
@@ -1220,7 +1215,7 @@ static void output_lat_thread(struct work_atoms *work_list) | |||
1220 | 1215 | ||
1221 | avg = work_list->total_lat / work_list->nb_atoms; | 1216 | avg = work_list->total_lat / work_list->nb_atoms; |
1222 | 1217 | ||
1223 | printf("|%11.3f ms |%9llu | avg:%9.3f ms | max:%9.3f ms | max at: %9.6f s\n", | 1218 | printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max at: %9.6f s\n", |
1224 | (double)work_list->total_runtime / 1e6, | 1219 | (double)work_list->total_runtime / 1e6, |
1225 | work_list->nb_atoms, (double)avg / 1e6, | 1220 | work_list->nb_atoms, (double)avg / 1e6, |
1226 | (double)work_list->max_lat / 1e6, | 1221 | (double)work_list->max_lat / 1e6, |
@@ -1403,7 +1398,7 @@ map_switch_event(struct trace_switch_event *switch_event, | |||
1403 | u64 timestamp, | 1398 | u64 timestamp, |
1404 | struct thread *thread __used) | 1399 | struct thread *thread __used) |
1405 | { | 1400 | { |
1406 | struct thread *sched_out, *sched_in; | 1401 | struct thread *sched_out __used, *sched_in; |
1407 | int new_shortname; | 1402 | int new_shortname; |
1408 | u64 timestamp0; | 1403 | u64 timestamp0; |
1409 | s64 delta; | 1404 | s64 delta; |
@@ -1422,7 +1417,7 @@ map_switch_event(struct trace_switch_event *switch_event, | |||
1422 | delta = 0; | 1417 | delta = 0; |
1423 | 1418 | ||
1424 | if (delta < 0) | 1419 | if (delta < 0) |
1425 | die("hm, delta: %Ld < 0 ?\n", delta); | 1420 | die("hm, delta: %" PRIu64 " < 0 ?\n", delta); |
1426 | 1421 | ||
1427 | 1422 | ||
1428 | sched_out = perf_session__findnew(session, switch_event->prev_pid); | 1423 | sched_out = perf_session__findnew(session, switch_event->prev_pid); |
@@ -1579,9 +1574,9 @@ process_sched_migrate_task_event(void *data, struct perf_session *session, | |||
1579 | event, cpu, timestamp, thread); | 1574 | event, cpu, timestamp, thread); |
1580 | } | 1575 | } |
1581 | 1576 | ||
1582 | static void | 1577 | static void process_raw_event(union perf_event *raw_event __used, |
1583 | process_raw_event(event_t *raw_event __used, struct perf_session *session, | 1578 | struct perf_session *session, void *data, int cpu, |
1584 | void *data, int cpu, u64 timestamp, struct thread *thread) | 1579 | u64 timestamp, struct thread *thread) |
1585 | { | 1580 | { |
1586 | struct event *event; | 1581 | struct event *event; |
1587 | int type; | 1582 | int type; |
@@ -1606,25 +1601,17 @@ process_raw_event(event_t *raw_event __used, struct perf_session *session, | |||
1606 | process_sched_migrate_task_event(data, session, event, cpu, timestamp, thread); | 1601 | process_sched_migrate_task_event(data, session, event, cpu, timestamp, thread); |
1607 | } | 1602 | } |
1608 | 1603 | ||
1609 | static int process_sample_event(event_t *event, struct perf_session *session) | 1604 | static int process_sample_event(union perf_event *event, |
1605 | struct perf_sample *sample, | ||
1606 | struct perf_evsel *evsel __used, | ||
1607 | struct perf_session *session) | ||
1610 | { | 1608 | { |
1611 | struct sample_data data; | ||
1612 | struct thread *thread; | 1609 | struct thread *thread; |
1613 | 1610 | ||
1614 | if (!(session->sample_type & PERF_SAMPLE_RAW)) | 1611 | if (!(session->sample_type & PERF_SAMPLE_RAW)) |
1615 | return 0; | 1612 | return 0; |
1616 | 1613 | ||
1617 | memset(&data, 0, sizeof(data)); | 1614 | thread = perf_session__findnew(session, sample->pid); |
1618 | data.time = -1; | ||
1619 | data.cpu = -1; | ||
1620 | data.period = -1; | ||
1621 | |||
1622 | event__parse_sample(event, session->sample_type, &data); | ||
1623 | |||
1624 | dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc, | ||
1625 | data.pid, data.tid, data.ip, data.period); | ||
1626 | |||
1627 | thread = perf_session__findnew(session, data.pid); | ||
1628 | if (thread == NULL) { | 1615 | if (thread == NULL) { |
1629 | pr_debug("problem processing %d event, skipping it.\n", | 1616 | pr_debug("problem processing %d event, skipping it.\n", |
1630 | event->header.type); | 1617 | event->header.type); |
@@ -1633,26 +1620,28 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
1633 | 1620 | ||
1634 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); | 1621 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
1635 | 1622 | ||
1636 | if (profile_cpu != -1 && profile_cpu != (int)data.cpu) | 1623 | if (profile_cpu != -1 && profile_cpu != (int)sample->cpu) |
1637 | return 0; | 1624 | return 0; |
1638 | 1625 | ||
1639 | process_raw_event(event, session, data.raw_data, data.cpu, data.time, thread); | 1626 | process_raw_event(event, session, sample->raw_data, sample->cpu, |
1627 | sample->time, thread); | ||
1640 | 1628 | ||
1641 | return 0; | 1629 | return 0; |
1642 | } | 1630 | } |
1643 | 1631 | ||
1644 | static struct perf_event_ops event_ops = { | 1632 | static struct perf_event_ops event_ops = { |
1645 | .sample = process_sample_event, | 1633 | .sample = process_sample_event, |
1646 | .comm = event__process_comm, | 1634 | .comm = perf_event__process_comm, |
1647 | .lost = event__process_lost, | 1635 | .lost = perf_event__process_lost, |
1648 | .fork = event__process_task, | 1636 | .fork = perf_event__process_task, |
1649 | .ordered_samples = true, | 1637 | .ordered_samples = true, |
1650 | }; | 1638 | }; |
1651 | 1639 | ||
1652 | static int read_events(void) | 1640 | static int read_events(void) |
1653 | { | 1641 | { |
1654 | int err = -EINVAL; | 1642 | int err = -EINVAL; |
1655 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false); | 1643 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, |
1644 | 0, false, &event_ops); | ||
1656 | if (session == NULL) | 1645 | if (session == NULL) |
1657 | return -ENOMEM; | 1646 | return -ENOMEM; |
1658 | 1647 | ||
@@ -1720,7 +1709,7 @@ static void __cmd_lat(void) | |||
1720 | } | 1709 | } |
1721 | 1710 | ||
1722 | printf(" -----------------------------------------------------------------------------------------\n"); | 1711 | printf(" -----------------------------------------------------------------------------------------\n"); |
1723 | printf(" TOTAL: |%11.3f ms |%9Ld |\n", | 1712 | printf(" TOTAL: |%11.3f ms |%9" PRIu64 " |\n", |
1724 | (double)all_runtime/1e6, all_count); | 1713 | (double)all_runtime/1e6, all_count); |
1725 | 1714 | ||
1726 | printf(" ---------------------------------------------------\n"); | 1715 | printf(" ---------------------------------------------------\n"); |
@@ -1850,15 +1839,15 @@ static const char *record_args[] = { | |||
1850 | "-f", | 1839 | "-f", |
1851 | "-m", "1024", | 1840 | "-m", "1024", |
1852 | "-c", "1", | 1841 | "-c", "1", |
1853 | "-e", "sched:sched_switch:r", | 1842 | "-e", "sched:sched_switch", |
1854 | "-e", "sched:sched_stat_wait:r", | 1843 | "-e", "sched:sched_stat_wait", |
1855 | "-e", "sched:sched_stat_sleep:r", | 1844 | "-e", "sched:sched_stat_sleep", |
1856 | "-e", "sched:sched_stat_iowait:r", | 1845 | "-e", "sched:sched_stat_iowait", |
1857 | "-e", "sched:sched_stat_runtime:r", | 1846 | "-e", "sched:sched_stat_runtime", |
1858 | "-e", "sched:sched_process_exit:r", | 1847 | "-e", "sched:sched_process_exit", |
1859 | "-e", "sched:sched_process_fork:r", | 1848 | "-e", "sched:sched_process_fork", |
1860 | "-e", "sched:sched_wakeup:r", | 1849 | "-e", "sched:sched_wakeup", |
1861 | "-e", "sched:sched_migrate_task:r", | 1850 | "-e", "sched:sched_migrate_task", |
1862 | }; | 1851 | }; |
1863 | 1852 | ||
1864 | static int __cmd_record(int argc, const char **argv) | 1853 | static int __cmd_record(int argc, const char **argv) |
@@ -1869,6 +1858,9 @@ static int __cmd_record(int argc, const char **argv) | |||
1869 | rec_argc = ARRAY_SIZE(record_args) + argc - 1; | 1858 | rec_argc = ARRAY_SIZE(record_args) + argc - 1; |
1870 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); | 1859 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
1871 | 1860 | ||
1861 | if (rec_argv == NULL) | ||
1862 | return -ENOMEM; | ||
1863 | |||
1872 | for (i = 0; i < ARRAY_SIZE(record_args); i++) | 1864 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
1873 | rec_argv[i] = strdup(record_args[i]); | 1865 | rec_argv[i] = strdup(record_args[i]); |
1874 | 1866 | ||
@@ -1888,10 +1880,10 @@ int cmd_sched(int argc, const char **argv, const char *prefix __used) | |||
1888 | usage_with_options(sched_usage, sched_options); | 1880 | usage_with_options(sched_usage, sched_options); |
1889 | 1881 | ||
1890 | /* | 1882 | /* |
1891 | * Aliased to 'perf trace' for now: | 1883 | * Aliased to 'perf script' for now: |
1892 | */ | 1884 | */ |
1893 | if (!strcmp(argv[0], "trace")) | 1885 | if (!strcmp(argv[0], "script")) |
1894 | return cmd_trace(argc, argv, prefix); | 1886 | return cmd_script(argc, argv, prefix); |
1895 | 1887 | ||
1896 | symbol__init(); | 1888 | symbol__init(); |
1897 | if (!strncmp(argv[0], "rec", 3)) { | 1889 | if (!strncmp(argv[0], "rec", 3)) { |