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

1 // SPDX-License-Identifier: GPL-2.0
25 * osnoise top parameters
70 * osnoise_free_top - free runtime data
75 free(data->cpu_data); in osnoise_free_top()
80 * osnoise_alloc_histogram - alloc runtime data
90 data->nr_cpus = nr_cpus; in osnoise_alloc_top()
92 /* one set of histograms per CPU */ in osnoise_alloc_top()
93 data->cpu_data = calloc(1, sizeof(*data->cpu_data) * nr_cpus); in osnoise_alloc_top()
94 if (!data->cpu_data) in osnoise_alloc_top()
105 * osnoise_top_handler - this is the handler for osnoise tracer events
116 int cpu = record->cpu; in osnoise_top_handler()
120 data = tool->data; in osnoise_top_handler()
121 cpu_data = &data->cpu_data[cpu]; in osnoise_top_handler()
123 cpu_data->sum_cycles++; in osnoise_top_handler()
126 update_sum(&cpu_data->sum_runtime, &val); in osnoise_top_handler()
129 update_max(&cpu_data->max_noise, &val); in osnoise_top_handler()
130 update_sum(&cpu_data->sum_noise, &val); in osnoise_top_handler()
133 update_max(&cpu_data->max_sample, &val); in osnoise_top_handler()
136 update_sum(&cpu_data->hw_count, &val); in osnoise_top_handler()
139 update_sum(&cpu_data->nmi_count, &val); in osnoise_top_handler()
142 update_sum(&cpu_data->irq_count, &val); in osnoise_top_handler()
145 update_sum(&cpu_data->softirq_count, &val); in osnoise_top_handler()
148 update_sum(&cpu_data->thread_count, &val); in osnoise_top_handler()
154 * osnoise_top_header - print the header of the tool output
156 static void osnoise_top_header(struct osnoise_tool *top) in osnoise_top_header() argument
158 struct osnoise_top_params *params = top->params; in osnoise_top_header()
159 struct trace_seq *s = top->trace.seq; in osnoise_top_header()
162 get_duration(top->start_time, duration, sizeof(duration)); in osnoise_top_header()
167 if (params->mode == MODE_OSNOISE) { in osnoise_top_header()
170 } else if (params->mode == MODE_HWNOISE) { in osnoise_top_header()
171 trace_seq_printf(s, "Hardware-related Noise"); in osnoise_top_header()
187 if (params->mode == MODE_HWNOISE) in osnoise_top_header()
198 * clear_terminal - clears the output terminal
207 * osnoise_top_print - prints the output of a given CPU
211 struct osnoise_top_params *params = tool->params; in osnoise_top_print()
212 struct trace_seq *s = tool->trace.seq; in osnoise_top_print()
218 data = tool->data; in osnoise_top_print()
219 cpu_data = &data->cpu_data[cpu]; in osnoise_top_print()
221 if (!cpu_data->sum_runtime) in osnoise_top_print()
224 percentage = ((cpu_data->sum_runtime - cpu_data->sum_noise) * 10000000) in osnoise_top_print()
225 / cpu_data->sum_runtime; in osnoise_top_print()
229 trace_seq_printf(s, "%3d #%-6d %12llu ", cpu, cpu_data->sum_cycles, cpu_data->sum_runtime); in osnoise_top_print()
230 trace_seq_printf(s, "%12llu ", cpu_data->sum_noise); in osnoise_top_print()
232 trace_seq_printf(s, "%12llu %12llu", cpu_data->max_noise, cpu_data->max_sample); in osnoise_top_print()
234 trace_seq_printf(s, "%12llu ", cpu_data->hw_count); in osnoise_top_print()
235 trace_seq_printf(s, "%12llu ", cpu_data->nmi_count); in osnoise_top_print()
237 if (params->mode == MODE_HWNOISE) { in osnoise_top_print()
242 trace_seq_printf(s, "%12llu ", cpu_data->irq_count); in osnoise_top_print()
243 trace_seq_printf(s, "%12llu ", cpu_data->softirq_count); in osnoise_top_print()
244 trace_seq_printf(s, "%12llu\n", cpu_data->thread_count); in osnoise_top_print()
248 * osnoise_print_stats - print data for all cpus
251 osnoise_print_stats(struct osnoise_top_params *params, struct osnoise_tool *top) in osnoise_print_stats() argument
253 struct trace_instance *trace = &top->trace; in osnoise_print_stats()
254 static int nr_cpus = -1; in osnoise_print_stats()
257 if (nr_cpus == -1) in osnoise_print_stats()
260 if (!params->quiet) in osnoise_print_stats()
261 clear_terminal(trace->seq); in osnoise_print_stats()
263 osnoise_top_header(top); in osnoise_print_stats()
266 if (params->cpus && !CPU_ISSET(i, &params->monitored_cpus)) in osnoise_print_stats()
268 osnoise_top_print(top, i); in osnoise_print_stats()
271 trace_seq_do_printf(trace->seq); in osnoise_print_stats()
272 trace_seq_reset(trace->seq); in osnoise_print_stats()
276 * osnoise_top_usage - prints osnoise top usage message
283 " [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", in osnoise_top_usage()
284 " [-T us] [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\", in osnoise_top_usage()
285 " [-c cpu-list] [-H cpu-list] [-P priority] [-C[=cgroup_name]]", in osnoise_top_usage()
287 " -h/--help: print this menu", in osnoise_top_usage()
288 " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", in osnoise_top_usage()
289 " -p/--period us: osnoise period in us", in osnoise_top_usage()
290 " -r/--runtime us: osnoise runtime in us", in osnoise_top_usage()
291 " -s/--stop us: stop trace if a single sample is higher than the argument in us", in osnoise_top_usage()
292 " -S/--stop-total us: stop trace if the total sample is higher than the argument in us", in osnoise_top_usage()
293 " -T/--threshold us: the minimum delta to be considered a noise", in osnoise_top_usage()
294 " -c/--cpus cpu-list: list of cpus to run osnoise threads", in osnoise_top_usage()
295 " -H/--house-keeping cpus: run rtla control threads only on the given cpus", in osnoise_top_usage()
296 …" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be … in osnoise_top_usage()
297 " -d/--duration time[s|m|h|d]: duration of the session", in osnoise_top_usage()
298 " -D/--debug: print debug info", in osnoise_top_usage()
299 " -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]", in osnoise_top_usage()
300 …" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed", in osnoise_top_usage()
301 " --filter <filter>: enable a trace event filter to the previous -e event", in osnoise_top_usage()
302 " --trigger <trigger>: enable a trace event trigger to the previous -e event", in osnoise_top_usage()
303 " -q/--quiet print only a summary at the end", in osnoise_top_usage()
304 " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", in osnoise_top_usage()
305 " o:prio - use SCHED_OTHER with prio", in osnoise_top_usage()
306 " r:prio - use SCHED_RR with prio", in osnoise_top_usage()
307 " f:prio - use SCHED_FIFO with prio", in osnoise_top_usage()
308 " d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period", in osnoise_top_usage()
316 if (params->mode == MODE_OSNOISE) { in osnoise_top_usage()
318 "rtla osnoise top: a per-cpu summary of the OS noise (version %s)\n", in osnoise_top_usage()
321 fprintf(stderr, " usage: rtla osnoise [top]"); in osnoise_top_usage()
324 if (params->mode == MODE_HWNOISE) { in osnoise_top_usage()
326 "rtla hwnoise: a summary of hardware-related noise (version %s)\n", in osnoise_top_usage()
338 * osnoise_top_parse_args - allocs, parse and fill the cmd line parameters
352 params->mode = MODE_HWNOISE; in osnoise_top_parse_args()
356 params->runtime = 750000; in osnoise_top_parse_args()
357 params->period = 1000000; in osnoise_top_parse_args()
368 {"house-keeping", required_argument, 0, 'H'}, in osnoise_top_parse_args()
375 {"stop-total", required_argument, 0, 'S'}, in osnoise_top_parse_args()
390 if (c == -1) in osnoise_top_parse_args()
395 /* set sample stop to auto_thresh */ in osnoise_top_parse_args()
396 params->stop_us = get_llong_from_str(optarg); in osnoise_top_parse_args()
398 /* set sample threshold to 1 */ in osnoise_top_parse_args()
399 params->threshold = 1; in osnoise_top_parse_args()
401 /* set trace */ in osnoise_top_parse_args()
402 params->trace_output = "osnoise_trace.txt"; in osnoise_top_parse_args()
406 retval = parse_cpu_set(optarg, &params->monitored_cpus); in osnoise_top_parse_args()
408 osnoise_top_usage(params, "\nInvalid -c cpu list\n"); in osnoise_top_parse_args()
409 params->cpus = optarg; in osnoise_top_parse_args()
412 params->cgroup = 1; in osnoise_top_parse_args()
415 params->cgroup_name = NULL; in osnoise_top_parse_args()
418 params->cgroup_name = ++optarg; in osnoise_top_parse_args()
425 params->duration = parse_seconds_duration(optarg); in osnoise_top_parse_args()
426 if (!params->duration) in osnoise_top_parse_args()
427 osnoise_top_usage(params, "Invalid -D duration\n"); in osnoise_top_parse_args()
436 if (params->events) in osnoise_top_parse_args()
437 tevent->next = params->events; in osnoise_top_parse_args()
438 params->events = tevent; in osnoise_top_parse_args()
446 params->hk_cpus = 1; in osnoise_top_parse_args()
447 retval = parse_cpu_set(optarg, &params->hk_cpu_set); in osnoise_top_parse_args()
454 params->period = get_llong_from_str(optarg); in osnoise_top_parse_args()
455 if (params->period > 10000000) in osnoise_top_parse_args()
459 retval = parse_prio(optarg, &params->sched_param); in osnoise_top_parse_args()
460 if (retval == -1) in osnoise_top_parse_args()
461 osnoise_top_usage(params, "Invalid -P priority"); in osnoise_top_parse_args()
462 params->set_sched = 1; in osnoise_top_parse_args()
465 params->quiet = 1; in osnoise_top_parse_args()
468 params->runtime = get_llong_from_str(optarg); in osnoise_top_parse_args()
469 if (params->runtime < 100) in osnoise_top_parse_args()
473 params->stop_us = get_llong_from_str(optarg); in osnoise_top_parse_args()
476 params->stop_total_us = get_llong_from_str(optarg); in osnoise_top_parse_args()
481 params->trace_output = &optarg[1]; in osnoise_top_parse_args()
483 params->trace_output = "osnoise_trace.txt"; in osnoise_top_parse_args()
486 params->threshold = get_llong_from_str(optarg); in osnoise_top_parse_args()
489 if (params->events) { in osnoise_top_parse_args()
490 retval = trace_event_add_trigger(params->events, optarg); in osnoise_top_parse_args()
496 osnoise_top_usage(params, "--trigger requires a previous -e\n"); in osnoise_top_parse_args()
500 if (params->events) { in osnoise_top_parse_args()
501 retval = trace_event_add_filter(params->events, optarg); in osnoise_top_parse_args()
507 osnoise_top_usage(params, "--filter requires a previous -e\n"); in osnoise_top_parse_args()
524 * osnoise_top_apply_config - apply the top configs to the initialized tool
531 if (!params->sleep_time) in osnoise_top_apply_config()
532 params->sleep_time = 1; in osnoise_top_apply_config()
534 if (params->cpus) { in osnoise_top_apply_config()
535 retval = osnoise_set_cpus(tool->context, params->cpus); in osnoise_top_apply_config()
542 if (params->runtime || params->period) { in osnoise_top_apply_config()
543 retval = osnoise_set_runtime_period(tool->context, in osnoise_top_apply_config()
544 params->runtime, in osnoise_top_apply_config()
545 params->period); in osnoise_top_apply_config()
547 err_msg("Failed to set runtime and/or period\n"); in osnoise_top_apply_config()
552 if (params->stop_us) { in osnoise_top_apply_config()
553 retval = osnoise_set_stop_us(tool->context, params->stop_us); in osnoise_top_apply_config()
555 err_msg("Failed to set stop us\n"); in osnoise_top_apply_config()
560 if (params->stop_total_us) { in osnoise_top_apply_config()
561 retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us); in osnoise_top_apply_config()
563 err_msg("Failed to set stop total us\n"); in osnoise_top_apply_config()
568 if (params->threshold) { in osnoise_top_apply_config()
569 retval = osnoise_set_tracing_thresh(tool->context, params->threshold); in osnoise_top_apply_config()
571 err_msg("Failed to set tracing_thresh\n"); in osnoise_top_apply_config()
576 if (params->mode == MODE_HWNOISE) { in osnoise_top_apply_config()
577 retval = osnoise_set_irq_disable(tool->context, 1); in osnoise_top_apply_config()
579 err_msg("Failed to set OSNOISE_IRQ_DISABLE option\n"); in osnoise_top_apply_config()
584 if (params->hk_cpus) { in osnoise_top_apply_config()
585 retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set), in osnoise_top_apply_config()
586 &params->hk_cpu_set); in osnoise_top_apply_config()
587 if (retval == -1) { in osnoise_top_apply_config()
588 err_msg("Failed to set rtla to the house keeping CPUs\n"); in osnoise_top_apply_config()
591 } else if (params->cpus) { in osnoise_top_apply_config()
593 * Even if the user do not set a house-keeping CPU, try to in osnoise_top_apply_config()
594 * move rtla to a CPU set different to the one where the user in osnoise_top_apply_config()
595 * set the workload to run. in osnoise_top_apply_config()
599 auto_house_keeping(&params->monitored_cpus); in osnoise_top_apply_config()
605 return -1; in osnoise_top_apply_config()
609 * osnoise_init_top - initialize a osnoise top tool with parameters
622 tool->data = osnoise_alloc_top(nr_cpus); in osnoise_init_top()
623 if (!tool->data) in osnoise_init_top()
626 tool->params = params; in osnoise_init_top()
628 tep_register_event_handler(tool->trace.tep, -1, "ftrace", "osnoise", in osnoise_init_top()
634 osnoise_free_top(tool->data); in osnoise_init_top()
646 * osnoise_top_set_signals - handles the signal to stop the tool
651 if (params->duration) { in osnoise_top_set_signals()
653 alarm(params->duration); in osnoise_top_set_signals()
672 err_msg("Could not init osnoise top\n"); in osnoise_top_main()
682 trace = &tool->trace; in osnoise_top_main()
690 if (params->set_sched) { in osnoise_top_main()
691 retval = set_comm_sched_attr("osnoise/", &params->sched_param); in osnoise_top_main()
693 err_msg("Failed to set sched parameters\n"); in osnoise_top_main()
698 if (params->cgroup) { in osnoise_top_main()
699 retval = set_comm_cgroup("osnoise/", params->cgroup_name); in osnoise_top_main()
706 if (params->trace_output) { in osnoise_top_main()
713 if (params->events) { in osnoise_top_main()
714 retval = trace_events_enable(&record->trace, params->events); in osnoise_top_main()
721 * Start the tracer here, after having set all instances. in osnoise_top_main()
727 if (params->trace_output) in osnoise_top_main()
728 trace_instance_start(&record->trace); in osnoise_top_main()
731 tool->start_time = time(NULL); in osnoise_top_main()
735 sleep(params->sleep_time); in osnoise_top_main()
737 retval = tracefs_iterate_raw_events(trace->tep, in osnoise_top_main()
738 trace->inst, in osnoise_top_main()
748 if (!params->quiet) in osnoise_top_main()
751 if (trace_is_off(&tool->trace, &record->trace)) in osnoise_top_main()
760 if (trace_is_off(&tool->trace, &record->trace)) { in osnoise_top_main()
762 if (params->trace_output) { in osnoise_top_main()
763 printf(" Saving trace to %s\n", params->trace_output); in osnoise_top_main()
764 save_trace_to_file(record->trace.inst, params->trace_output); in osnoise_top_main()
769 trace_events_destroy(&record->trace, params->events); in osnoise_top_main()
770 params->events = NULL; in osnoise_top_main()
772 osnoise_free_top(tool->data); in osnoise_top_main()