Lines Matching +full:set +full:- +full:top

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()
101 /* one set of histograms per CPU */ 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()
106 /* set the min to max */ 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
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
162 struct osnoise_tool *top; in timerlat_top_handler() local
163 int cpu = record->cpu; in timerlat_top_handler()
165 top = container_of(trace, struct osnoise_tool, trace); in timerlat_top_handler()
166 params = top->params; in timerlat_top_handler()
168 if (!params->aa_only) { 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
181 static void timerlat_top_header(struct osnoise_tool *top) in timerlat_top_header() argument
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()
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()
202 params->output_divisor == 1 ? "ns" : "us"); in timerlat_top_header()
208 if (params->user_top) in timerlat_top_header()
215 * timerlat_top_print - prints the output of a given CPU
217 static void timerlat_top_print(struct osnoise_tool *top, int cpu) in timerlat_top_print() argument
220 struct timerlat_top_params *params = top->params; in timerlat_top_print()
221 struct timerlat_top_data *data = top->data; in timerlat_top_print()
222 struct timerlat_top_cpu *cpu_data = &data->cpu_data[cpu]; in timerlat_top_print()
223 int divisor = params->output_divisor; in timerlat_top_print()
224 struct trace_seq *s = top->trace.seq; in timerlat_top_print()
232 if (!cpu_data->irq_count && !cpu_data->thread_count) in timerlat_top_print()
238 trace_seq_printf(s, "%3d #%-9d |", cpu, cpu_data->irq_count); in timerlat_top_print()
240 if (!cpu_data->irq_count) { in timerlat_top_print()
241 trace_seq_printf(s, " - "); in timerlat_top_print()
242 trace_seq_printf(s, " - "); in timerlat_top_print()
243 trace_seq_printf(s, " - "); in timerlat_top_print()
244 trace_seq_printf(s, " - |"); in timerlat_top_print()
246 trace_seq_printf(s, "%9llu ", cpu_data->cur_irq / params->output_divisor); in timerlat_top_print()
247 trace_seq_printf(s, "%9llu ", cpu_data->min_irq / params->output_divisor); in timerlat_top_print()
248 trace_seq_printf(s, "%9llu ", (cpu_data->sum_irq / cpu_data->irq_count) / divisor); in timerlat_top_print()
249 trace_seq_printf(s, "%9llu |", cpu_data->max_irq / divisor); in timerlat_top_print()
252 if (!cpu_data->thread_count) { in timerlat_top_print()
253 trace_seq_printf(s, " - "); in timerlat_top_print()
254 trace_seq_printf(s, " - "); in timerlat_top_print()
255 trace_seq_printf(s, " - "); in timerlat_top_print()
256 trace_seq_printf(s, " -\n"); in timerlat_top_print()
258 trace_seq_printf(s, "%9llu ", cpu_data->cur_thread / divisor); in timerlat_top_print()
259 trace_seq_printf(s, "%9llu ", cpu_data->min_thread / divisor); in timerlat_top_print()
261 (cpu_data->sum_thread / cpu_data->thread_count) / divisor); in timerlat_top_print()
262 trace_seq_printf(s, "%9llu", cpu_data->max_thread / divisor); in timerlat_top_print()
265 if (!params->user_top) { in timerlat_top_print()
272 if (!cpu_data->user_count) { in timerlat_top_print()
273 trace_seq_printf(s, " - "); in timerlat_top_print()
274 trace_seq_printf(s, " - "); in timerlat_top_print()
275 trace_seq_printf(s, " - "); in timerlat_top_print()
276 trace_seq_printf(s, " -\n"); in timerlat_top_print()
278 trace_seq_printf(s, "%9llu ", cpu_data->cur_user / divisor); in timerlat_top_print()
279 trace_seq_printf(s, "%9llu ", cpu_data->min_user / divisor); in timerlat_top_print()
281 (cpu_data->sum_user / cpu_data->user_count) / divisor); in timerlat_top_print()
282 trace_seq_printf(s, "%9llu\n", cpu_data->max_user / divisor); in timerlat_top_print()
287 * clear_terminal - clears the output terminal
296 * timerlat_print_stats - print data for all cpus
299 timerlat_print_stats(struct timerlat_top_params *params, struct osnoise_tool *top) in timerlat_print_stats() argument
301 struct trace_instance *trace = &top->trace; in timerlat_print_stats()
302 static int nr_cpus = -1; in timerlat_print_stats()
305 if (params->aa_only) in timerlat_print_stats()
308 if (nr_cpus == -1) in timerlat_print_stats()
311 if (!params->quiet) in timerlat_print_stats()
312 clear_terminal(trace->seq); in timerlat_print_stats()
314 timerlat_top_header(top); in timerlat_print_stats()
317 if (params->cpus && !CPU_ISSET(i, &params->monitored_cpus)) in timerlat_print_stats()
319 timerlat_top_print(top, i); in timerlat_print_stats()
322 trace_seq_do_printf(trace->seq); in timerlat_print_stats()
323 trace_seq_reset(trace->seq); in timerlat_print_stats()
327 * timerlat_top_usage - prints timerlat top usage message
335 …" usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \… in timerlat_top_usage()
336 …" [[-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu- in timerlat_top_usage()
337 " [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]] [-u]", in timerlat_top_usage()
339 " -h/--help: print this menu", in timerlat_top_usage()
340 " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", in timerlat_top_usage()
341 …" --aa-only us: stop if <us> latency is hit, only printing the auto analysis (reduces CPU usa… in timerlat_top_usage()
342 " -p/--period us: timerlat period in us", in timerlat_top_usage()
343 " -i/--irq us: stop trace if the irq latency is higher than the argument in us", in timerlat_top_usage()
344 " -T/--thread us: stop trace if the thread latency is higher than the argument in us", in timerlat_top_usage()
345 …" -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument… in timerlat_top_usage()
346 " -c/--cpus cpus: run the tracer only on the given cpus", in timerlat_top_usage()
347 " -H/--house-keeping cpus: run rtla control threads only on the given cpus", in timerlat_top_usage()
348 …" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be … in timerlat_top_usage()
349 " -d/--duration time[m|h|d]: duration of the session in seconds", in timerlat_top_usage()
350 " -D/--debug: print debug info", in timerlat_top_usage()
351 …" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !-… in timerlat_top_usage()
352 " -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]", in timerlat_top_usage()
353 …" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed", in timerlat_top_usage()
354 " --filter <command>: enable a trace event filter to the previous -e event", in timerlat_top_usage()
355 " --trigger <command>: enable a trace event trigger to the previous -e event", in timerlat_top_usage()
356 " -n/--nano: display data in nanoseconds", in timerlat_top_usage()
357 " --no-aa: disable auto-analysis, reducing rtla timerlat cpu usage", in timerlat_top_usage()
358 " -q/--quiet print only a summary at the end", in timerlat_top_usage()
359 " --dma-latency us: set /dev/cpu_dma_latency latency <us> to reduce exit from idle latency", in timerlat_top_usage()
360 " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", in timerlat_top_usage()
361 " o:prio - use SCHED_OTHER with prio", in timerlat_top_usage()
362 " r:prio - use SCHED_RR with prio", in timerlat_top_usage()
363 " f:prio - use SCHED_FIFO with prio", in timerlat_top_usage()
364 " d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period", in timerlat_top_usage()
366 " -u/--user-threads: use rtla user-space threads instead of in-kernel timerlat threads", in timerlat_top_usage()
373 fprintf(stderr, "rtla timerlat top: a per-cpu summary of the timer latency (version %s)\n", in timerlat_top_usage()
382 * timerlat_top_parse_args - allocs, parse and fill the cmd line parameters
398 params->dma_latency = -1; in timerlat_top_parse_args()
401 params->output_divisor = 1000; in timerlat_top_parse_args()
412 {"house-keeping", required_argument, 0, 'H'}, in timerlat_top_parse_args()
421 {"user-threads", no_argument, 0, 'u'}, in timerlat_top_parse_args()
424 {"dma-latency", required_argument, 0, '2'}, in timerlat_top_parse_args()
425 {"no-aa", no_argument, 0, '3'}, in timerlat_top_parse_args()
426 {"dump-tasks", no_argument, 0, '4'}, in timerlat_top_parse_args()
427 {"aa-only", required_argument, 0, '5'}, in timerlat_top_parse_args()
438 if (c == -1) in timerlat_top_parse_args()
445 /* set thread stop to auto_thresh */ in timerlat_top_parse_args()
446 params->stop_total_us = auto_thresh; in timerlat_top_parse_args()
447 params->stop_us = auto_thresh; in timerlat_top_parse_args()
450 params->print_stack = auto_thresh; in timerlat_top_parse_args()
452 /* set trace */ in timerlat_top_parse_args()
453 params->trace_output = "timerlat_trace.txt"; in timerlat_top_parse_args()
456 /* it is here because it is similar to -a */ in timerlat_top_parse_args()
459 /* set thread stop to auto_thresh */ in timerlat_top_parse_args()
460 params->stop_total_us = auto_thresh; in timerlat_top_parse_args()
461 params->stop_us = auto_thresh; in timerlat_top_parse_args()
464 params->print_stack = auto_thresh; in timerlat_top_parse_args()
466 /* set aa_only to avoid parsing the trace */ in timerlat_top_parse_args()
467 params->aa_only = 1; in timerlat_top_parse_args()
470 retval = parse_cpu_set(optarg, &params->monitored_cpus); in timerlat_top_parse_args()
472 timerlat_top_usage("\nInvalid -c cpu list\n"); in timerlat_top_parse_args()
473 params->cpus = optarg; in timerlat_top_parse_args()
476 params->cgroup = 1; in timerlat_top_parse_args()
479 params->cgroup_name = NULL; in timerlat_top_parse_args()
482 params->cgroup_name = ++optarg; in timerlat_top_parse_args()
489 params->duration = parse_seconds_duration(optarg); in timerlat_top_parse_args()
490 if (!params->duration) in timerlat_top_parse_args()
491 timerlat_top_usage("Invalid -D duration\n"); in timerlat_top_parse_args()
500 if (params->events) in timerlat_top_parse_args()
501 tevent->next = params->events; in timerlat_top_parse_args()
502 params->events = tevent; in timerlat_top_parse_args()
509 params->hk_cpus = 1; in timerlat_top_parse_args()
510 retval = parse_cpu_set(optarg, &params->hk_cpu_set); in timerlat_top_parse_args()
517 params->stop_us = get_llong_from_str(optarg); in timerlat_top_parse_args()
520 params->output_divisor = 1; in timerlat_top_parse_args()
523 params->timerlat_period_us = get_llong_from_str(optarg); in timerlat_top_parse_args()
524 if (params->timerlat_period_us > 1000000) in timerlat_top_parse_args()
528 retval = parse_prio(optarg, &params->sched_param); in timerlat_top_parse_args()
529 if (retval == -1) in timerlat_top_parse_args()
530 timerlat_top_usage("Invalid -P priority"); in timerlat_top_parse_args()
531 params->set_sched = 1; in timerlat_top_parse_args()
534 params->quiet = 1; in timerlat_top_parse_args()
537 params->print_stack = get_llong_from_str(optarg); in timerlat_top_parse_args()
540 params->stop_total_us = get_llong_from_str(optarg); in timerlat_top_parse_args()
545 params->trace_output = &optarg[1]; in timerlat_top_parse_args()
547 params->trace_output = "timerlat_trace.txt"; in timerlat_top_parse_args()
551 params->user_top = true; in timerlat_top_parse_args()
554 if (params->events) { in timerlat_top_parse_args()
555 retval = trace_event_add_trigger(params->events, optarg); in timerlat_top_parse_args()
561 timerlat_top_usage("--trigger requires a previous -e\n"); in timerlat_top_parse_args()
565 if (params->events) { in timerlat_top_parse_args()
566 retval = trace_event_add_filter(params->events, optarg); in timerlat_top_parse_args()
572 timerlat_top_usage("--filter requires a previous -e\n"); in timerlat_top_parse_args()
575 case '2': /* dma-latency */ in timerlat_top_parse_args()
576 params->dma_latency = get_llong_from_str(optarg); in timerlat_top_parse_args()
577 if (params->dma_latency < 0 || params->dma_latency > 10000) { in timerlat_top_parse_args()
578 err_msg("--dma-latency needs to be >= 0 and < 10000"); in timerlat_top_parse_args()
582 case '3': /* no-aa */ in timerlat_top_parse_args()
583 params->no_aa = 1; in timerlat_top_parse_args()
586 params->dump_tasks = 1; in timerlat_top_parse_args()
601 if (!params->stop_us && !params->stop_total_us) in timerlat_top_parse_args()
602 params->no_aa = 1; in timerlat_top_parse_args()
604 if (params->no_aa && params->aa_only) in timerlat_top_parse_args()
605 timerlat_top_usage("--no-aa and --aa-only are mutually exclusive!"); in timerlat_top_parse_args()
611 * timerlat_top_apply_config - apply the top configs to the initialized tool
614 timerlat_top_apply_config(struct osnoise_tool *top, struct timerlat_top_params *params) in timerlat_top_apply_config() argument
619 if (!params->sleep_time) in timerlat_top_apply_config()
620 params->sleep_time = 1; in timerlat_top_apply_config()
622 if (params->cpus) { in timerlat_top_apply_config()
623 retval = osnoise_set_cpus(top->context, params->cpus); in timerlat_top_apply_config()
630 CPU_SET(i, &params->monitored_cpus); in timerlat_top_apply_config()
633 if (params->stop_us) { in timerlat_top_apply_config()
634 retval = osnoise_set_stop_us(top->context, params->stop_us); in timerlat_top_apply_config()
636 err_msg("Failed to set stop us\n"); in timerlat_top_apply_config()
641 if (params->stop_total_us) { in timerlat_top_apply_config()
642 retval = osnoise_set_stop_total_us(top->context, params->stop_total_us); in timerlat_top_apply_config()
644 err_msg("Failed to set stop total us\n"); in timerlat_top_apply_config()
650 if (params->timerlat_period_us) { in timerlat_top_apply_config()
651 retval = osnoise_set_timerlat_period_us(top->context, params->timerlat_period_us); in timerlat_top_apply_config()
653 err_msg("Failed to set timerlat period\n"); in timerlat_top_apply_config()
659 if (params->print_stack) { in timerlat_top_apply_config()
660 retval = osnoise_set_print_stack(top->context, params->print_stack); in timerlat_top_apply_config()
662 err_msg("Failed to set print stack\n"); in timerlat_top_apply_config()
667 if (params->hk_cpus) { in timerlat_top_apply_config()
668 retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set), in timerlat_top_apply_config()
669 &params->hk_cpu_set); in timerlat_top_apply_config()
670 if (retval == -1) { in timerlat_top_apply_config()
671 err_msg("Failed to set rtla to the house keeping CPUs\n"); in timerlat_top_apply_config()
674 } else if (params->cpus) { in timerlat_top_apply_config()
676 * Even if the user do not set a house-keeping CPU, try to in timerlat_top_apply_config()
677 * move rtla to a CPU set different to the one where the user in timerlat_top_apply_config()
678 * set the workload to run. in timerlat_top_apply_config()
682 auto_house_keeping(&params->monitored_cpus); in timerlat_top_apply_config()
685 if (params->user_top) { in timerlat_top_apply_config()
686 retval = osnoise_set_workload(top->context, 0); in timerlat_top_apply_config()
688 err_msg("Failed to set OSNOISE_WORKLOAD option\n"); in timerlat_top_apply_config()
696 return -1; in timerlat_top_apply_config()
700 * timerlat_init_top - initialize a timerlat top tool with parameters
705 struct osnoise_tool *top; in timerlat_init_top() local
710 top = osnoise_init_tool("timerlat_top"); in timerlat_init_top()
711 if (!top) in timerlat_init_top()
714 top->data = timerlat_alloc_top(nr_cpus); in timerlat_init_top()
715 if (!top->data) in timerlat_init_top()
718 top->params = params; in timerlat_init_top()
720 tep_register_event_handler(top->trace.tep, -1, "ftrace", "timerlat", in timerlat_init_top()
721 timerlat_top_handler, top); in timerlat_init_top()
723 return top; in timerlat_init_top()
726 osnoise_destroy_tool(top); in timerlat_init_top()
737 * timerlat_top_set_signals - handles the signal to stop the tool
743 if (params->duration) { in timerlat_top_set_signals()
745 alarm(params->duration); in timerlat_top_set_signals()
754 struct osnoise_tool *top = NULL; in timerlat_top_main() local
757 int dma_latency_fd = -1; in timerlat_top_main()
767 top = timerlat_init_top(params); in timerlat_top_main()
768 if (!top) { in timerlat_top_main()
769 err_msg("Could not init osnoise top\n"); in timerlat_top_main()
773 retval = timerlat_top_apply_config(top, params); in timerlat_top_main()
779 trace = &top->trace; in timerlat_top_main()
787 if (params->set_sched) { in timerlat_top_main()
788 retval = set_comm_sched_attr("timerlat/", &params->sched_param); in timerlat_top_main()
790 err_msg("Failed to set sched parameters\n"); in timerlat_top_main()
795 if (params->cgroup && !params->user_top) { in timerlat_top_main()
796 retval = set_comm_cgroup("timerlat/", params->cgroup_name); in timerlat_top_main()
803 if (params->dma_latency >= 0) { in timerlat_top_main()
804 dma_latency_fd = set_cpu_dma_latency(params->dma_latency); in timerlat_top_main()
806 err_msg("Could not set /dev/cpu_dma_latency.\n"); in timerlat_top_main()
811 if (params->trace_output) { in timerlat_top_main()
818 if (params->events) { in timerlat_top_main()
819 retval = trace_events_enable(&record->trace, params->events); in timerlat_top_main()
825 if (!params->no_aa) { in timerlat_top_main()
826 if (params->aa_only) { in timerlat_top_main()
827 /* as top is not used for display, use it for aa */ in timerlat_top_main()
828 aa = top; in timerlat_top_main()
836 retval = timerlat_aa_init(aa, params->dump_tasks); in timerlat_top_main()
842 /* if it is re-using the main instance, there is no need to start it */ in timerlat_top_main()
843 if (aa != top) { in timerlat_top_main()
844 retval = enable_timerlat(&aa->trace); in timerlat_top_main()
853 * Start the tracers here, after having set all instances. in timerlat_top_main()
859 if (params->trace_output) in timerlat_top_main()
860 trace_instance_start(&record->trace); in timerlat_top_main()
861 if (!params->no_aa && aa != top) in timerlat_top_main()
862 trace_instance_start(&aa->trace); in timerlat_top_main()
865 top->start_time = time(NULL); in timerlat_top_main()
868 if (params->user_top) { in timerlat_top_main()
874 params_u.set = &params->monitored_cpus; in timerlat_top_main()
875 if (params->set_sched) in timerlat_top_main()
876 params_u.sched_param = &params->sched_param; in timerlat_top_main()
880 params_u.cgroup_name = params->cgroup_name; in timerlat_top_main()
884 err_msg("Error creating timerlat user-space threads\n"); in timerlat_top_main()
888 sleep(params->sleep_time); in timerlat_top_main()
890 if (params->aa_only && !trace_is_off(&top->trace, &record->trace)) in timerlat_top_main()
893 retval = tracefs_iterate_raw_events(trace->tep, in timerlat_top_main()
894 trace->inst, in timerlat_top_main()
904 if (!params->quiet) in timerlat_top_main()
905 timerlat_print_stats(params, top); in timerlat_top_main()
907 if (trace_is_off(&top->trace, &record->trace)) in timerlat_top_main()
910 /* is there still any user-threads ? */ in timerlat_top_main()
911 if (params->user_top) { in timerlat_top_main()
919 if (params->user_top && !params_u.stopped_running) { in timerlat_top_main()
924 timerlat_print_stats(params, top); in timerlat_top_main()
928 if (trace_is_off(&top->trace, &record->trace)) { in timerlat_top_main()
931 if (!params->no_aa) in timerlat_top_main()
932 timerlat_auto_analysis(params->stop_us, params->stop_total_us); in timerlat_top_main()
934 if (params->trace_output) { in timerlat_top_main()
935 printf(" Saving trace to %s\n", params->trace_output); in timerlat_top_main()
936 save_trace_to_file(record->trace.inst, params->trace_output); in timerlat_top_main()
938 } else if (params->aa_only) { in timerlat_top_main()
940 * If the trace did not stop with --aa-only, at least print the in timerlat_top_main()
943 max_lat = tracefs_instance_file_read(trace->inst, "tracing_max_latency", NULL); in timerlat_top_main()
954 trace_events_destroy(&record->trace, params->events); in timerlat_top_main()
955 params->events = NULL; in timerlat_top_main()
957 timerlat_free_top(top->data); in timerlat_top_main()
958 if (aa && aa != top) in timerlat_top_main()
961 osnoise_destroy_tool(top); in timerlat_top_main()