diff options
Diffstat (limited to 'tools/tracing/rtla/src/osnoise.c')
| -rw-r--r-- | tools/tracing/rtla/src/osnoise.c | 159 |
1 files changed, 135 insertions, 24 deletions
diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osnoise.c index 245e9344932b..312c511fa004 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -3,6 +3,7 @@ * Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org> */ +#define _GNU_SOURCE #include <sys/types.h> #include <sys/stat.h> #include <pthread.h> @@ -12,9 +13,12 @@ #include <errno.h> #include <fcntl.h> #include <stdio.h> +#include <sched.h> #include "osnoise.h" -#include "utils.h" + +#define DEFAULT_SAMPLE_PERIOD 1000000 /* 1s */ +#define DEFAULT_SAMPLE_RUNTIME 1000000 /* 1s */ /* * osnoise_get_cpus - return the original "osnoise/cpus" content @@ -867,7 +871,7 @@ int osnoise_set_workload(struct osnoise_context *context, bool onoff) retval = osnoise_options_set_option("OSNOISE_WORKLOAD", onoff); if (retval < 0) - return -1; + return -2; context->opt_workload = onoff; @@ -902,22 +906,6 @@ static void osnoise_put_workload(struct osnoise_context *context) context->orig_opt_workload = OSNOISE_OPTION_INIT_VAL; } -/* - * enable_osnoise - enable osnoise tracer in the trace_instance - */ -int enable_osnoise(struct trace_instance *trace) -{ - return enable_tracer_by_name(trace->inst, "osnoise"); -} - -/* - * enable_timerlat - enable timerlat tracer in the trace_instance - */ -int enable_timerlat(struct trace_instance *trace) -{ - return enable_tracer_by_name(trace->inst, "timerlat"); -} - enum { FLAG_CONTEXT_NEWLY_CREATED = (1 << 0), FLAG_CONTEXT_DELETED = (1 << 1), @@ -1052,7 +1040,7 @@ out_err: /* * osnoise_init_trace_tool - init a tracer instance to trace osnoise events */ -struct osnoise_tool *osnoise_init_trace_tool(char *tracer) +struct osnoise_tool *osnoise_init_trace_tool(const char *tracer) { struct osnoise_tool *trace; int retval; @@ -1079,6 +1067,129 @@ out_err: return NULL; } +bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record) +{ + /* + * The tool instance is always present, it is the one used to collect + * data. + */ + if (!tracefs_trace_is_on(tool->trace.inst)) + return true; + + /* + * The trace record instance is only enabled when -t is set. IOW, when the system + * is tracing. + */ + return record && !tracefs_trace_is_on(record->trace.inst); +} + +/* + * osnoise_report_missed_events - report number of events dropped by trace + * buffer + */ +void +osnoise_report_missed_events(struct osnoise_tool *tool) +{ + unsigned long long total_events; + + if (tool->trace.missed_events == UINT64_MAX) + printf("unknown number of events missed, results might not be accurate\n"); + else if (tool->trace.missed_events > 0) { + total_events = tool->trace.processed_events + tool->trace.missed_events; + + printf("%lld (%.2f%%) events missed, results might not be accurate\n", + tool->trace.missed_events, + (double) tool->trace.missed_events / total_events * 100.0); + } +} + +/* + * osnoise_apply_config - apply osnoise configs to the initialized tool + */ +int +osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params) +{ + int retval; + + params->common.kernel_workload = true; + + if (params->runtime || params->period) { + retval = osnoise_set_runtime_period(tool->context, + params->runtime, + params->period); + } else { + retval = osnoise_set_runtime_period(tool->context, + DEFAULT_SAMPLE_PERIOD, + DEFAULT_SAMPLE_RUNTIME); + } + + if (retval) { + err_msg("Failed to set runtime and/or period\n"); + goto out_err; + } + + retval = osnoise_set_stop_us(tool->context, params->common.stop_us); + if (retval) { + err_msg("Failed to set stop us\n"); + goto out_err; + } + + retval = osnoise_set_stop_total_us(tool->context, params->common.stop_total_us); + if (retval) { + err_msg("Failed to set stop total us\n"); + goto out_err; + } + + retval = osnoise_set_tracing_thresh(tool->context, params->threshold); + if (retval) { + err_msg("Failed to set tracing_thresh\n"); + goto out_err; + } + + return common_apply_config(tool, ¶ms->common); + +out_err: + return -1; +} + +int osnoise_enable(struct osnoise_tool *tool) +{ + struct osnoise_params *params = to_osnoise_params(tool->params); + int retval; + + /* + * Start the tracer here, after having set all instances. + * + * Let the trace instance start first for the case of hitting a stop + * tracing while enabling other instances. The trace instance is the + * one with most valuable information. + */ + if (tool->record) + trace_instance_start(&tool->record->trace); + trace_instance_start(&tool->trace); + + if (params->common.warmup > 0) { + debug_msg("Warming up for %d seconds\n", params->common.warmup); + sleep(params->common.warmup); + if (stop_tracing) + return -1; + + /* + * Clean up the buffer. The osnoise workload do not run + * with tracing off to avoid creating a performance penalty + * when not needed. + */ + retval = tracefs_instance_file_write(tool->trace.inst, "trace", ""); + if (retval < 0) { + debug_msg("Error cleaning up the buffer"); + return retval; + } + + } + + return 0; +} + static void osnoise_usage(int err) { int i; @@ -1112,7 +1223,7 @@ int osnoise_main(int argc, char *argv[]) * default cmdline. */ if (argc == 1) { - osnoise_top_main(argc, argv); + run_tool(&osnoise_top_ops, argc, argv); exit(0); } @@ -1120,13 +1231,13 @@ int osnoise_main(int argc, char *argv[]) osnoise_usage(0); } else if (strncmp(argv[1], "-", 1) == 0) { /* the user skipped the tool, call the default one */ - osnoise_top_main(argc, argv); + run_tool(&osnoise_top_ops, argc, argv); exit(0); } else if (strcmp(argv[1], "top") == 0) { - osnoise_top_main(argc-1, &argv[1]); + run_tool(&osnoise_top_ops, argc-1, &argv[1]); exit(0); } else if (strcmp(argv[1], "hist") == 0) { - osnoise_hist_main(argc-1, &argv[1]); + run_tool(&osnoise_hist_ops, argc-1, &argv[1]); exit(0); } @@ -1137,6 +1248,6 @@ usage: int hwnoise_main(int argc, char *argv[]) { - osnoise_top_main(argc, argv); + run_tool(&osnoise_top_ops, argc, argv); exit(0); } |
