Lines Matching +full:exit +full:- +full:latency +full:- +full:us
1 // SPDX-License-Identifier: GPL-2.0
78 * timerlat_free_top - free runtime data
83 free(data->cpu_data); in timerlat_free_top()
88 * timerlat_alloc_histogram - alloc runtime data
99 data->nr_cpus = nr_cpus; in timerlat_alloc_top()
102 data->cpu_data = calloc(1, sizeof(*data->cpu_data) * nr_cpus); in timerlat_alloc_top()
103 if (!data->cpu_data) in timerlat_alloc_top()
108 data->cpu_data[cpu].min_irq = ~0; in timerlat_alloc_top()
109 data->cpu_data[cpu].min_thread = ~0; in timerlat_alloc_top()
110 data->cpu_data[cpu].min_user = ~0; in timerlat_alloc_top()
121 * timerlat_hist_update - record a new timerlat occurent on cpu, updating data
126 unsigned long long latency) in timerlat_top_update() argument
128 struct timerlat_top_data *data = tool->data; in timerlat_top_update()
129 struct timerlat_top_cpu *cpu_data = &data->cpu_data[cpu]; in timerlat_top_update()
132 cpu_data->irq_count++; in timerlat_top_update()
133 cpu_data->cur_irq = latency; in timerlat_top_update()
134 update_min(&cpu_data->min_irq, &latency); in timerlat_top_update()
135 update_sum(&cpu_data->sum_irq, &latency); in timerlat_top_update()
136 update_max(&cpu_data->max_irq, &latency); in timerlat_top_update()
138 cpu_data->thread_count++; in timerlat_top_update()
139 cpu_data->cur_thread = latency; in timerlat_top_update()
140 update_min(&cpu_data->min_thread, &latency); in timerlat_top_update()
141 update_sum(&cpu_data->sum_thread, &latency); in timerlat_top_update()
142 update_max(&cpu_data->max_thread, &latency); in timerlat_top_update()
144 cpu_data->user_count++; in timerlat_top_update()
145 cpu_data->cur_user = latency; in timerlat_top_update()
146 update_min(&cpu_data->min_user, &latency); in timerlat_top_update()
147 update_sum(&cpu_data->sum_user, &latency); in timerlat_top_update()
148 update_max(&cpu_data->max_user, &latency); in timerlat_top_update()
153 * timerlat_top_handler - this is the handler for timerlat tracer events
161 unsigned long long latency, thread; in timerlat_top_handler() local
163 int cpu = record->cpu; in timerlat_top_handler()
166 params = top->params; in timerlat_top_handler()
168 if (!params->aa_only) { in timerlat_top_handler()
170 tep_get_field_val(s, event, "timer_latency", record, &latency, 1); in timerlat_top_handler()
172 timerlat_top_update(top, cpu, thread, latency); in timerlat_top_handler()
179 * timerlat_top_header - print the header of the tool output
183 struct timerlat_top_params *params = top->params; in timerlat_top_header()
184 struct trace_seq *s = top->trace.seq; in timerlat_top_header()
187 get_duration(top->start_time, duration, sizeof(duration)); in timerlat_top_header()
190 …trace_seq_printf(s, " Timer Latency … in timerlat_top_header()
191 if (params->user_top) in timerlat_top_header()
196 …trace_seq_printf(s, "%-6s | IRQ Timer Latency (%s) | Thread Timer Latenc… in timerlat_top_header()
197 params->output_divisor == 1 ? "ns" : "us", in timerlat_top_header()
198 params->output_divisor == 1 ? "ns" : "us"); in timerlat_top_header()
200 if (params->user_top) { in timerlat_top_header()
201 trace_seq_printf(s, " | Ret user Timer Latency (%s)", in timerlat_top_header()
202 params->output_divisor == 1 ? "ns" : "us"); in timerlat_top_header()
208 if (params->user_top) in timerlat_top_header()
214 static const char *no_value = " -";
217 * timerlat_top_print - prints the output of a given CPU
222 struct timerlat_top_params *params = top->params; in timerlat_top_print()
223 struct timerlat_top_data *data = top->data; in timerlat_top_print()
224 struct timerlat_top_cpu *cpu_data = &data->cpu_data[cpu]; in timerlat_top_print()
225 int divisor = params->output_divisor; in timerlat_top_print()
226 struct trace_seq *s = top->trace.seq; in timerlat_top_print()
234 if (!cpu_data->irq_count && !cpu_data->thread_count) in timerlat_top_print()
240 trace_seq_printf(s, "%3d #%-9llu |", cpu, cpu_data->irq_count); in timerlat_top_print()
242 if (!cpu_data->irq_count) { in timerlat_top_print()
245 trace_seq_printf(s, "%9llu ", cpu_data->cur_irq / params->output_divisor); in timerlat_top_print()
246 trace_seq_printf(s, "%9llu ", cpu_data->min_irq / params->output_divisor); in timerlat_top_print()
247 trace_seq_printf(s, "%9llu ", (cpu_data->sum_irq / cpu_data->irq_count) / divisor); in timerlat_top_print()
248 trace_seq_printf(s, "%9llu |", cpu_data->max_irq / divisor); in timerlat_top_print()
251 if (!cpu_data->thread_count) { in timerlat_top_print()
254 trace_seq_printf(s, "%9llu ", cpu_data->cur_thread / divisor); in timerlat_top_print()
255 trace_seq_printf(s, "%9llu ", cpu_data->min_thread / divisor); in timerlat_top_print()
257 (cpu_data->sum_thread / cpu_data->thread_count) / divisor); in timerlat_top_print()
258 trace_seq_printf(s, "%9llu", cpu_data->max_thread / divisor); in timerlat_top_print()
261 if (!params->user_top) { in timerlat_top_print()
268 if (!cpu_data->user_count) { in timerlat_top_print()
271 trace_seq_printf(s, "%9llu ", cpu_data->cur_user / divisor); in timerlat_top_print()
272 trace_seq_printf(s, "%9llu ", cpu_data->min_user / divisor); in timerlat_top_print()
274 (cpu_data->sum_user / cpu_data->user_count) / divisor); in timerlat_top_print()
275 trace_seq_printf(s, "%9llu\n", cpu_data->max_user / divisor); in timerlat_top_print()
280 * clear_terminal - clears the output terminal
289 * timerlat_print_stats - print data for all cpus
294 struct trace_instance *trace = &top->trace; in timerlat_print_stats()
295 static int nr_cpus = -1; in timerlat_print_stats()
298 if (params->aa_only) in timerlat_print_stats()
301 if (nr_cpus == -1) in timerlat_print_stats()
304 if (!params->quiet) in timerlat_print_stats()
305 clear_terminal(trace->seq); in timerlat_print_stats()
310 if (params->cpus && !CPU_ISSET(i, ¶ms->monitored_cpus)) in timerlat_print_stats()
315 trace_seq_do_printf(trace->seq); in timerlat_print_stats()
316 trace_seq_reset(trace->seq); in timerlat_print_stats()
320 * timerlat_top_usage - prints timerlat top usage message
328 …" usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \… in timerlat_top_usage()
329 …" [[-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-… in timerlat_top_usage()
330 " [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]] [-u]", in timerlat_top_usage()
332 " -h/--help: print this menu", in timerlat_top_usage()
333 " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", in timerlat_top_usage()
334 …" --aa-only us: stop if <us> latency is hit, only printing the auto analysis (reduces CPU usa… in timerlat_top_usage()
335 " -p/--period us: timerlat period in us", in timerlat_top_usage()
336 " -i/--irq us: stop trace if the irq latency is higher than the argument in us", in timerlat_top_usage()
337 " -T/--thread us: stop trace if the thread latency is higher than the argument in us", in timerlat_top_usage()
338 …" -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument… in timerlat_top_usage()
339 " -c/--cpus cpus: run the tracer only on the given cpus", in timerlat_top_usage()
340 " -H/--house-keeping cpus: run rtla control threads only on the given cpus", in timerlat_top_usage()
341 …" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be … in timerlat_top_usage()
342 " -d/--duration time[s|m|h|d]: duration of the session", in timerlat_top_usage()
343 " -D/--debug: print debug info", in timerlat_top_usage()
344 …" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !-… in timerlat_top_usage()
345 " -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]", in timerlat_top_usage()
346 …" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed", in timerlat_top_usage()
347 " --filter <command>: enable a trace event filter to the previous -e event", in timerlat_top_usage()
348 " --trigger <command>: enable a trace event trigger to the previous -e event", in timerlat_top_usage()
349 " -n/--nano: display data in nanoseconds", in timerlat_top_usage()
350 " --no-aa: disable auto-analysis, reducing rtla timerlat cpu usage", in timerlat_top_usage()
351 " -q/--quiet print only a summary at the end", in timerlat_top_usage()
352 " --dma-latency us: set /dev/cpu_dma_latency latency <us> to reduce exit from idle latency", in timerlat_top_usage()
353 " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", in timerlat_top_usage()
354 " o:prio - use SCHED_OTHER with prio", in timerlat_top_usage()
355 " r:prio - use SCHED_RR with prio", in timerlat_top_usage()
356 " f:prio - use SCHED_FIFO with prio", in timerlat_top_usage()
357 " d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period", in timerlat_top_usage()
359 " -u/--user-threads: use rtla user-space threads instead of in-kernel timerlat threads", in timerlat_top_usage()
366 fprintf(stderr, "rtla timerlat top: a per-cpu summary of the timer latency (version %s)\n", in timerlat_top_usage()
373 exit(EXIT_FAILURE); in timerlat_top_usage()
375 exit(EXIT_SUCCESS); in timerlat_top_usage()
379 * timerlat_top_parse_args - allocs, parse and fill the cmd line parameters
392 exit(1); in timerlat_top_parse_args()
395 params->dma_latency = -1; in timerlat_top_parse_args()
398 params->output_divisor = 1000; in timerlat_top_parse_args()
409 {"house-keeping", required_argument, 0, 'H'}, in timerlat_top_parse_args()
418 {"user-threads", no_argument, 0, 'u'}, in timerlat_top_parse_args()
421 {"dma-latency", required_argument, 0, '2'}, in timerlat_top_parse_args()
422 {"no-aa", no_argument, 0, '3'}, in timerlat_top_parse_args()
423 {"dump-tasks", no_argument, 0, '4'}, in timerlat_top_parse_args()
424 {"aa-only", required_argument, 0, '5'}, in timerlat_top_parse_args()
435 if (c == -1) in timerlat_top_parse_args()
443 params->stop_total_us = auto_thresh; in timerlat_top_parse_args()
444 params->stop_us = auto_thresh; in timerlat_top_parse_args()
447 params->print_stack = auto_thresh; in timerlat_top_parse_args()
450 params->trace_output = "timerlat_trace.txt"; in timerlat_top_parse_args()
453 /* it is here because it is similar to -a */ in timerlat_top_parse_args()
457 params->stop_total_us = auto_thresh; in timerlat_top_parse_args()
458 params->stop_us = auto_thresh; in timerlat_top_parse_args()
461 params->print_stack = auto_thresh; in timerlat_top_parse_args()
464 params->aa_only = 1; in timerlat_top_parse_args()
467 retval = parse_cpu_set(optarg, ¶ms->monitored_cpus); in timerlat_top_parse_args()
469 timerlat_top_usage("\nInvalid -c cpu list\n"); in timerlat_top_parse_args()
470 params->cpus = optarg; in timerlat_top_parse_args()
473 params->cgroup = 1; in timerlat_top_parse_args()
476 params->cgroup_name = NULL; in timerlat_top_parse_args()
479 params->cgroup_name = ++optarg; in timerlat_top_parse_args()
486 params->duration = parse_seconds_duration(optarg); in timerlat_top_parse_args()
487 if (!params->duration) in timerlat_top_parse_args()
488 timerlat_top_usage("Invalid -d duration\n"); in timerlat_top_parse_args()
494 exit(EXIT_FAILURE); in timerlat_top_parse_args()
497 if (params->events) in timerlat_top_parse_args()
498 tevent->next = params->events; in timerlat_top_parse_args()
499 params->events = tevent; in timerlat_top_parse_args()
506 params->hk_cpus = 1; in timerlat_top_parse_args()
507 retval = parse_cpu_set(optarg, ¶ms->hk_cpu_set); in timerlat_top_parse_args()
510 exit(EXIT_FAILURE); in timerlat_top_parse_args()
514 params->stop_us = get_llong_from_str(optarg); in timerlat_top_parse_args()
517 params->output_divisor = 1; in timerlat_top_parse_args()
520 params->timerlat_period_us = get_llong_from_str(optarg); in timerlat_top_parse_args()
521 if (params->timerlat_period_us > 1000000) in timerlat_top_parse_args()
525 retval = parse_prio(optarg, ¶ms->sched_param); in timerlat_top_parse_args()
526 if (retval == -1) in timerlat_top_parse_args()
527 timerlat_top_usage("Invalid -P priority"); in timerlat_top_parse_args()
528 params->set_sched = 1; in timerlat_top_parse_args()
531 params->quiet = 1; in timerlat_top_parse_args()
534 params->print_stack = get_llong_from_str(optarg); in timerlat_top_parse_args()
537 params->stop_total_us = get_llong_from_str(optarg); in timerlat_top_parse_args()
542 params->trace_output = &optarg[1]; in timerlat_top_parse_args()
544 params->trace_output = "timerlat_trace.txt"; in timerlat_top_parse_args()
548 params->user_top = true; in timerlat_top_parse_args()
551 if (params->events) { in timerlat_top_parse_args()
552 retval = trace_event_add_trigger(params->events, optarg); in timerlat_top_parse_args()
555 exit(EXIT_FAILURE); in timerlat_top_parse_args()
558 timerlat_top_usage("--trigger requires a previous -e\n"); in timerlat_top_parse_args()
562 if (params->events) { in timerlat_top_parse_args()
563 retval = trace_event_add_filter(params->events, optarg); in timerlat_top_parse_args()
566 exit(EXIT_FAILURE); in timerlat_top_parse_args()
569 timerlat_top_usage("--filter requires a previous -e\n"); in timerlat_top_parse_args()
572 case '2': /* dma-latency */ in timerlat_top_parse_args()
573 params->dma_latency = get_llong_from_str(optarg); in timerlat_top_parse_args()
574 if (params->dma_latency < 0 || params->dma_latency > 10000) { in timerlat_top_parse_args()
575 err_msg("--dma-latency needs to be >= 0 and < 10000"); in timerlat_top_parse_args()
576 exit(EXIT_FAILURE); in timerlat_top_parse_args()
579 case '3': /* no-aa */ in timerlat_top_parse_args()
580 params->no_aa = 1; in timerlat_top_parse_args()
583 params->dump_tasks = 1; in timerlat_top_parse_args()
592 exit(EXIT_FAILURE); in timerlat_top_parse_args()
598 if (!params->stop_us && !params->stop_total_us) in timerlat_top_parse_args()
599 params->no_aa = 1; in timerlat_top_parse_args()
601 if (params->no_aa && params->aa_only) in timerlat_top_parse_args()
602 timerlat_top_usage("--no-aa and --aa-only are mutually exclusive!"); in timerlat_top_parse_args()
608 * timerlat_top_apply_config - apply the top configs to the initialized tool
616 if (!params->sleep_time) in timerlat_top_apply_config()
617 params->sleep_time = 1; in timerlat_top_apply_config()
619 if (params->cpus) { in timerlat_top_apply_config()
620 retval = osnoise_set_cpus(top->context, params->cpus); in timerlat_top_apply_config()
627 CPU_SET(i, ¶ms->monitored_cpus); in timerlat_top_apply_config()
630 if (params->stop_us) { in timerlat_top_apply_config()
631 retval = osnoise_set_stop_us(top->context, params->stop_us); in timerlat_top_apply_config()
633 err_msg("Failed to set stop us\n"); in timerlat_top_apply_config()
638 if (params->stop_total_us) { in timerlat_top_apply_config()
639 retval = osnoise_set_stop_total_us(top->context, params->stop_total_us); in timerlat_top_apply_config()
641 err_msg("Failed to set stop total us\n"); in timerlat_top_apply_config()
647 if (params->timerlat_period_us) { in timerlat_top_apply_config()
648 retval = osnoise_set_timerlat_period_us(top->context, params->timerlat_period_us); in timerlat_top_apply_config()
656 if (params->print_stack) { in timerlat_top_apply_config()
657 retval = osnoise_set_print_stack(top->context, params->print_stack); in timerlat_top_apply_config()
664 if (params->hk_cpus) { in timerlat_top_apply_config()
665 retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set), in timerlat_top_apply_config()
666 ¶ms->hk_cpu_set); in timerlat_top_apply_config()
667 if (retval == -1) { in timerlat_top_apply_config()
671 } else if (params->cpus) { in timerlat_top_apply_config()
673 * Even if the user do not set a house-keeping CPU, try to in timerlat_top_apply_config()
679 auto_house_keeping(¶ms->monitored_cpus); in timerlat_top_apply_config()
682 if (params->user_top) { in timerlat_top_apply_config()
683 retval = osnoise_set_workload(top->context, 0); in timerlat_top_apply_config()
693 return -1; in timerlat_top_apply_config()
697 * timerlat_init_top - initialize a timerlat top tool with parameters
711 top->data = timerlat_alloc_top(nr_cpus); in timerlat_init_top()
712 if (!top->data) in timerlat_init_top()
715 top->params = params; in timerlat_init_top()
717 tep_register_event_handler(top->trace.tep, -1, "ftrace", "timerlat", in timerlat_init_top()
734 * timerlat_top_set_signals - handles the signal to stop the tool
740 if (params->duration) { in timerlat_top_set_signals()
742 alarm(params->duration); in timerlat_top_set_signals()
754 int dma_latency_fd = -1; in timerlat_top_main()
762 exit(1); in timerlat_top_main()
776 trace = &top->trace; in timerlat_top_main()
784 if (params->set_sched) { in timerlat_top_main()
785 retval = set_comm_sched_attr("timerlat/", ¶ms->sched_param); in timerlat_top_main()
792 if (params->cgroup && !params->user_top) { in timerlat_top_main()
793 retval = set_comm_cgroup("timerlat/", params->cgroup_name); in timerlat_top_main()
800 if (params->dma_latency >= 0) { in timerlat_top_main()
801 dma_latency_fd = set_cpu_dma_latency(params->dma_latency); in timerlat_top_main()
808 if (params->trace_output) { in timerlat_top_main()
815 if (params->events) { in timerlat_top_main()
816 retval = trace_events_enable(&record->trace, params->events); in timerlat_top_main()
822 if (!params->no_aa) { in timerlat_top_main()
823 if (params->aa_only) { in timerlat_top_main()
833 retval = timerlat_aa_init(aa, params->dump_tasks); in timerlat_top_main()
839 /* if it is re-using the main instance, there is no need to start it */ in timerlat_top_main()
841 retval = enable_timerlat(&aa->trace); in timerlat_top_main()
856 if (params->trace_output) in timerlat_top_main()
857 trace_instance_start(&record->trace); in timerlat_top_main()
858 if (!params->no_aa && aa != top) in timerlat_top_main()
859 trace_instance_start(&aa->trace); in timerlat_top_main()
862 top->start_time = time(NULL); in timerlat_top_main()
865 if (params->user_top) { in timerlat_top_main()
871 params_u.set = ¶ms->monitored_cpus; in timerlat_top_main()
872 if (params->set_sched) in timerlat_top_main()
873 params_u.sched_param = ¶ms->sched_param; in timerlat_top_main()
877 params_u.cgroup_name = params->cgroup_name; in timerlat_top_main()
881 err_msg("Error creating timerlat user-space threads\n"); in timerlat_top_main()
885 sleep(params->sleep_time); in timerlat_top_main()
887 if (params->aa_only && !trace_is_off(&top->trace, &record->trace)) in timerlat_top_main()
890 retval = tracefs_iterate_raw_events(trace->tep, in timerlat_top_main()
891 trace->inst, in timerlat_top_main()
901 if (!params->quiet) in timerlat_top_main()
904 if (trace_is_off(&top->trace, &record->trace)) in timerlat_top_main()
907 /* is there still any user-threads ? */ in timerlat_top_main()
908 if (params->user_top) { in timerlat_top_main()
916 if (params->user_top && !params_u.stopped_running) { in timerlat_top_main()
925 if (trace_is_off(&top->trace, &record->trace)) { in timerlat_top_main()
928 if (!params->no_aa) in timerlat_top_main()
929 timerlat_auto_analysis(params->stop_us, params->stop_total_us); in timerlat_top_main()
931 if (params->trace_output) { in timerlat_top_main()
932 printf(" Saving trace to %s\n", params->trace_output); in timerlat_top_main()
933 save_trace_to_file(record->trace.inst, params->trace_output); in timerlat_top_main()
935 } else if (params->aa_only) { in timerlat_top_main()
937 * If the trace did not stop with --aa-only, at least print the in timerlat_top_main()
938 * max known latency. in timerlat_top_main()
940 max_lat = tracefs_instance_file_read(trace->inst, "tracing_max_latency", NULL); in timerlat_top_main()
942 printf(" Max latency was %s\n", max_lat); in timerlat_top_main()
951 trace_events_destroy(&record->trace, params->events); in timerlat_top_main()
952 params->events = NULL; in timerlat_top_main()
954 timerlat_free_top(top->data); in timerlat_top_main()
961 exit(return_value); in timerlat_top_main()