Lines Matching +full:duration +full:- +full:us

1 // SPDX-License-Identifier: GPL-2.0
38 int duration; member
73 * osnoise_free_top - free runtime data
78 free(data->cpu_data); in osnoise_free_top()
83 * osnoise_alloc_histogram - alloc runtime data
93 data->nr_cpus = nr_cpus; in osnoise_alloc_top()
96 data->cpu_data = calloc(1, sizeof(*data->cpu_data) * nr_cpus); in osnoise_alloc_top()
97 if (!data->cpu_data) in osnoise_alloc_top()
108 * osnoise_top_handler - this is the handler for osnoise tracer events
119 int cpu = record->cpu; in osnoise_top_handler()
123 data = tool->data; in osnoise_top_handler()
124 cpu_data = &data->cpu_data[cpu]; in osnoise_top_handler()
126 cpu_data->sum_cycles++; in osnoise_top_handler()
129 update_sum(&cpu_data->sum_runtime, &val); in osnoise_top_handler()
132 update_max(&cpu_data->max_noise, &val); in osnoise_top_handler()
133 update_sum(&cpu_data->sum_noise, &val); in osnoise_top_handler()
136 update_max(&cpu_data->max_sample, &val); in osnoise_top_handler()
139 update_sum(&cpu_data->hw_count, &val); in osnoise_top_handler()
142 update_sum(&cpu_data->nmi_count, &val); in osnoise_top_handler()
145 update_sum(&cpu_data->irq_count, &val); in osnoise_top_handler()
148 update_sum(&cpu_data->softirq_count, &val); in osnoise_top_handler()
151 update_sum(&cpu_data->thread_count, &val); in osnoise_top_handler()
157 * osnoise_top_header - print the header of the tool output
161 struct osnoise_top_params *params = top->params; in osnoise_top_header()
162 struct trace_seq *s = top->trace.seq; in osnoise_top_header()
163 char duration[26]; in osnoise_top_header() local
165 get_duration(top->start_time, duration, sizeof(duration)); in osnoise_top_header()
167 if (params->pretty_output) in osnoise_top_header()
172 if (params->mode == MODE_OSNOISE) { in osnoise_top_header()
175 } else if (params->mode == MODE_HWNOISE) { in osnoise_top_header()
176 trace_seq_printf(s, "Hardware-related Noise"); in osnoise_top_header()
181 if (params->pretty_output) in osnoise_top_header()
185 trace_seq_printf(s, "duration: %9s | time is in us\n", duration); in osnoise_top_header()
187 if (params->pretty_output) in osnoise_top_header()
196 if (params->mode == MODE_HWNOISE) in osnoise_top_header()
202 if (params->pretty_output) in osnoise_top_header()
208 * clear_terminal - clears the output terminal
217 * osnoise_top_print - prints the output of a given CPU
221 struct osnoise_top_params *params = tool->params; in osnoise_top_print()
222 struct trace_seq *s = tool->trace.seq; in osnoise_top_print()
228 data = tool->data; in osnoise_top_print()
229 cpu_data = &data->cpu_data[cpu]; in osnoise_top_print()
231 if (!cpu_data->sum_runtime) in osnoise_top_print()
234 percentage = ((cpu_data->sum_runtime - cpu_data->sum_noise) * 10000000) in osnoise_top_print()
235 / cpu_data->sum_runtime; in osnoise_top_print()
239 trace_seq_printf(s, "%3d #%-6d %12llu ", cpu, cpu_data->sum_cycles, cpu_data->sum_runtime); in osnoise_top_print()
240 trace_seq_printf(s, "%12llu ", cpu_data->sum_noise); in osnoise_top_print()
242 trace_seq_printf(s, "%12llu %12llu", cpu_data->max_noise, cpu_data->max_sample); in osnoise_top_print()
244 trace_seq_printf(s, "%12llu ", cpu_data->hw_count); in osnoise_top_print()
245 trace_seq_printf(s, "%12llu ", cpu_data->nmi_count); in osnoise_top_print()
247 if (params->mode == MODE_HWNOISE) { in osnoise_top_print()
252 trace_seq_printf(s, "%12llu ", cpu_data->irq_count); in osnoise_top_print()
253 trace_seq_printf(s, "%12llu ", cpu_data->softirq_count); in osnoise_top_print()
254 trace_seq_printf(s, "%12llu\n", cpu_data->thread_count); in osnoise_top_print()
258 * osnoise_print_stats - print data for all cpus
263 struct trace_instance *trace = &top->trace; in osnoise_print_stats()
264 static int nr_cpus = -1; in osnoise_print_stats()
267 if (nr_cpus == -1) in osnoise_print_stats()
270 if (!params->quiet) in osnoise_print_stats()
271 clear_terminal(trace->seq); in osnoise_print_stats()
276 if (params->cpus && !CPU_ISSET(i, &params->monitored_cpus)) in osnoise_print_stats()
281 trace_seq_do_printf(trace->seq); in osnoise_print_stats()
282 trace_seq_reset(trace->seq); in osnoise_print_stats()
286 * osnoise_top_usage - prints osnoise top usage message
293 " [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", in osnoise_top_usage()
294 " [-T us] [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\", in osnoise_top_usage()
295 " [-c cpu-list] [-H cpu-list] [-P priority] [-C[=cgroup_name]] [--warm-up s]", in osnoise_top_usage()
297 " -h/--help: print this menu", in osnoise_top_usage()
298 " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", in osnoise_top_usage()
299 " -p/--period us: osnoise period in us", in osnoise_top_usage()
300 " -r/--runtime us: osnoise runtime in us", in osnoise_top_usage()
301 " -s/--stop us: stop trace if a single sample is higher than the argument in us", in osnoise_top_usage()
302 " -S/--stop-total us: stop trace if the total sample is higher than the argument in us", in osnoise_top_usage()
303 " -T/--threshold us: the minimum delta to be considered a noise", in osnoise_top_usage()
304 " -c/--cpus cpu-list: list of cpus to run osnoise threads", in osnoise_top_usage()
305 " -H/--house-keeping cpus: run rtla control threads only on the given cpus", in osnoise_top_usage()
306 …" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be … in osnoise_top_usage()
307 " -d/--duration time[s|m|h|d]: duration of the session", in osnoise_top_usage()
308 " -D/--debug: print debug info", in osnoise_top_usage()
309 " -t/--trace[file]: save the stopped trace to [file|osnoise_trace.txt]", in osnoise_top_usage()
310 …" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed", in osnoise_top_usage()
311 " --filter <filter>: enable a trace event filter to the previous -e event", in osnoise_top_usage()
312 " --trigger <trigger>: enable a trace event trigger to the previous -e event", in osnoise_top_usage()
313 " -q/--quiet print only a summary at the end", in osnoise_top_usage()
314 " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", in osnoise_top_usage()
315 " o:prio - use SCHED_OTHER with prio", in osnoise_top_usage()
316 " r:prio - use SCHED_RR with prio", in osnoise_top_usage()
317 " f:prio - use SCHED_FIFO with prio", in osnoise_top_usage()
318 " d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period", in osnoise_top_usage()
320 " --warm-up s: let the workload run for s seconds before collecting data", in osnoise_top_usage()
321 " --trace-buffer-size kB: set the per-cpu trace buffer size in kB", in osnoise_top_usage()
328 if (params->mode == MODE_OSNOISE) { in osnoise_top_usage()
330 "rtla osnoise top: a per-cpu summary of the OS noise (version %s)\n", in osnoise_top_usage()
336 if (params->mode == MODE_HWNOISE) { in osnoise_top_usage()
338 "rtla hwnoise: a summary of hardware-related noise (version %s)\n", in osnoise_top_usage()
354 * osnoise_top_parse_args - allocs, parse and fill the cmd line parameters
368 params->mode = MODE_HWNOISE; in osnoise_top_parse_args()
372 params->runtime = 750000; in osnoise_top_parse_args()
373 params->period = 1000000; in osnoise_top_parse_args()
382 {"duration", required_argument, 0, 'd'}, in osnoise_top_parse_args()
384 {"house-keeping", required_argument, 0, 'H'}, in osnoise_top_parse_args()
391 {"stop-total", required_argument, 0, 'S'}, in osnoise_top_parse_args()
396 {"warm-up", required_argument, 0, '2'}, in osnoise_top_parse_args()
397 {"trace-buffer-size", required_argument, 0, '3'}, in osnoise_top_parse_args()
408 if (c == -1) in osnoise_top_parse_args()
414 params->stop_us = get_llong_from_str(optarg); in osnoise_top_parse_args()
417 params->threshold = 1; in osnoise_top_parse_args()
420 params->trace_output = "osnoise_trace.txt"; in osnoise_top_parse_args()
424 retval = parse_cpu_set(optarg, &params->monitored_cpus); in osnoise_top_parse_args()
426 osnoise_top_usage(params, "\nInvalid -c cpu list\n"); in osnoise_top_parse_args()
427 params->cpus = optarg; in osnoise_top_parse_args()
430 params->cgroup = 1; in osnoise_top_parse_args()
433 params->cgroup_name = NULL; in osnoise_top_parse_args()
436 params->cgroup_name = ++optarg; in osnoise_top_parse_args()
443 params->duration = parse_seconds_duration(optarg); in osnoise_top_parse_args()
444 if (!params->duration) in osnoise_top_parse_args()
445 osnoise_top_usage(params, "Invalid -d duration\n"); in osnoise_top_parse_args()
454 if (params->events) in osnoise_top_parse_args()
455 tevent->next = params->events; in osnoise_top_parse_args()
456 params->events = tevent; in osnoise_top_parse_args()
464 params->hk_cpus = 1; in osnoise_top_parse_args()
465 retval = parse_cpu_set(optarg, &params->hk_cpu_set); in osnoise_top_parse_args()
472 params->period = get_llong_from_str(optarg); in osnoise_top_parse_args()
473 if (params->period > 10000000) in osnoise_top_parse_args()
477 retval = parse_prio(optarg, &params->sched_param); in osnoise_top_parse_args()
478 if (retval == -1) in osnoise_top_parse_args()
479 osnoise_top_usage(params, "Invalid -P priority"); in osnoise_top_parse_args()
480 params->set_sched = 1; in osnoise_top_parse_args()
483 params->quiet = 1; in osnoise_top_parse_args()
486 params->runtime = get_llong_from_str(optarg); in osnoise_top_parse_args()
487 if (params->runtime < 100) in osnoise_top_parse_args()
488 osnoise_top_usage(params, "Runtime shorter than 100 us\n"); in osnoise_top_parse_args()
491 params->stop_us = get_llong_from_str(optarg); in osnoise_top_parse_args()
494 params->stop_total_us = get_llong_from_str(optarg); in osnoise_top_parse_args()
499 params->trace_output = &optarg[1]; in osnoise_top_parse_args()
501 params->trace_output = &optarg[0]; in osnoise_top_parse_args()
502 } else if (optind < argc && argv[optind][0] != '-') in osnoise_top_parse_args()
503 params->trace_output = argv[optind]; in osnoise_top_parse_args()
505 params->trace_output = "osnoise_trace.txt"; in osnoise_top_parse_args()
508 params->threshold = get_llong_from_str(optarg); in osnoise_top_parse_args()
511 if (params->events) { in osnoise_top_parse_args()
512 retval = trace_event_add_trigger(params->events, optarg); in osnoise_top_parse_args()
518 osnoise_top_usage(params, "--trigger requires a previous -e\n"); in osnoise_top_parse_args()
522 if (params->events) { in osnoise_top_parse_args()
523 retval = trace_event_add_filter(params->events, optarg); in osnoise_top_parse_args()
529 osnoise_top_usage(params, "--filter requires a previous -e\n"); in osnoise_top_parse_args()
533 params->warmup = get_llong_from_str(optarg); in osnoise_top_parse_args()
536 params->buffer_size = get_llong_from_str(optarg); in osnoise_top_parse_args()
552 * osnoise_top_apply_config - apply the top configs to the initialized tool
559 if (!params->sleep_time) in osnoise_top_apply_config()
560 params->sleep_time = 1; in osnoise_top_apply_config()
562 if (params->cpus) { in osnoise_top_apply_config()
563 retval = osnoise_set_cpus(tool->context, params->cpus); in osnoise_top_apply_config()
570 if (params->runtime || params->period) { in osnoise_top_apply_config()
571 retval = osnoise_set_runtime_period(tool->context, in osnoise_top_apply_config()
572 params->runtime, in osnoise_top_apply_config()
573 params->period); in osnoise_top_apply_config()
580 if (params->stop_us) { in osnoise_top_apply_config()
581 retval = osnoise_set_stop_us(tool->context, params->stop_us); in osnoise_top_apply_config()
583 err_msg("Failed to set stop us\n"); in osnoise_top_apply_config()
588 if (params->stop_total_us) { in osnoise_top_apply_config()
589 retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us); in osnoise_top_apply_config()
591 err_msg("Failed to set stop total us\n"); in osnoise_top_apply_config()
596 if (params->threshold) { in osnoise_top_apply_config()
597 retval = osnoise_set_tracing_thresh(tool->context, params->threshold); in osnoise_top_apply_config()
604 if (params->mode == MODE_HWNOISE) { in osnoise_top_apply_config()
605 retval = osnoise_set_irq_disable(tool->context, 1); in osnoise_top_apply_config()
612 if (params->hk_cpus) { in osnoise_top_apply_config()
613 retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set), in osnoise_top_apply_config()
614 &params->hk_cpu_set); in osnoise_top_apply_config()
615 if (retval == -1) { in osnoise_top_apply_config()
619 } else if (params->cpus) { in osnoise_top_apply_config()
621 * Even if the user do not set a house-keeping CPU, try to in osnoise_top_apply_config()
627 auto_house_keeping(&params->monitored_cpus); in osnoise_top_apply_config()
630 if (isatty(STDOUT_FILENO) && !params->quiet) in osnoise_top_apply_config()
631 params->pretty_output = 1; in osnoise_top_apply_config()
636 return -1; in osnoise_top_apply_config()
640 * osnoise_init_top - initialize a osnoise top tool with parameters
653 tool->data = osnoise_alloc_top(nr_cpus); in osnoise_init_top()
654 if (!tool->data) { in osnoise_init_top()
659 tool->params = params; in osnoise_init_top()
661 tep_register_event_handler(tool->trace.tep, -1, "ftrace", "osnoise", in osnoise_init_top()
674 * osnoise_top_set_signals - handles the signal to stop the tool
679 if (params->duration) { in osnoise_top_set_signals()
681 alarm(params->duration); in osnoise_top_set_signals()
710 trace = &tool->trace; in osnoise_top_main()
718 if (params->set_sched) { in osnoise_top_main()
719 retval = set_comm_sched_attr("osnoise/", &params->sched_param); in osnoise_top_main()
726 if (params->cgroup) { in osnoise_top_main()
727 retval = set_comm_cgroup("osnoise/", params->cgroup_name); in osnoise_top_main()
734 if (params->trace_output) { in osnoise_top_main()
741 if (params->events) { in osnoise_top_main()
742 retval = trace_events_enable(&record->trace, params->events); in osnoise_top_main()
747 if (params->buffer_size > 0) { in osnoise_top_main()
748 retval = trace_set_buffer_size(&record->trace, params->buffer_size); in osnoise_top_main()
761 if (params->trace_output) in osnoise_top_main()
762 trace_instance_start(&record->trace); in osnoise_top_main()
765 if (params->warmup > 0) { in osnoise_top_main()
766 debug_msg("Warming up for %d seconds\n", params->warmup); in osnoise_top_main()
767 sleep(params->warmup); in osnoise_top_main()
776 retval = tracefs_instance_file_write(trace->inst, "trace", ""); in osnoise_top_main()
784 tool->start_time = time(NULL); in osnoise_top_main()
788 sleep(params->sleep_time); in osnoise_top_main()
790 retval = tracefs_iterate_raw_events(trace->tep, in osnoise_top_main()
791 trace->inst, in osnoise_top_main()
801 if (!params->quiet) in osnoise_top_main()
804 if (trace_is_off(&tool->trace, &record->trace)) in osnoise_top_main()
813 if (trace_is_off(&tool->trace, &record->trace)) { in osnoise_top_main()
815 if (params->trace_output) { in osnoise_top_main()
816 printf(" Saving trace to %s\n", params->trace_output); in osnoise_top_main()
817 save_trace_to_file(record->trace.inst, params->trace_output); in osnoise_top_main()
822 trace_events_destroy(&record->trace, params->events); in osnoise_top_main()
823 params->events = NULL; in osnoise_top_main()
825 osnoise_free_top(tool->data); in osnoise_top_main()