Currently the rv tool enables tracing when running with -t and that allows to see tracepoints generated from both in-kernel and BPF monitors. In-kernel monitors can be controlled also by other tools but BPF ones cannot, so if a user is only interested in seeing errors, they need to bear the performance overhead of other events too. Add the -E/--errors-only flag. If it's passed with -t, only enable error tracepoints. On BPF monitors, if -E is passed but -t isn't, still load the monitor with error tracing enabled, so the user can enable the error events in other tools. Signed-off-by: Gabriele Monaco --- Documentation/tools/rv/common_ikm.rst | 6 ++++++ tools/verification/rv/include/utils.h | 1 + tools/verification/rv/src/bpf_monitor.c | 4 +++- tools/verification/rv/src/trace.c | 11 +++++++---- tools/verification/rv/src/utils.c | 9 +++++++-- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Documentation/tools/rv/common_ikm.rst b/Documentation/tools/rv/common_ikm.rst index e50a5f8a7142..b2594f9c35e8 100644 --- a/Documentation/tools/rv/common_ikm.rst +++ b/Documentation/tools/rv/common_ikm.rst @@ -19,3 +19,9 @@ **-v**, **--verbose** Print debug messages. + +**-E**, **--errors-only** + + When tracing (**-t**), trace only error events, skipping the monitor's + state transitions. Specifying this without tracing is meaningful only + for BPF monitors. diff --git a/tools/verification/rv/include/utils.h b/tools/verification/rv/include/utils.h index 397a37981932..2fec9ef7c0b3 100644 --- a/tools/verification/rv/include/utils.h +++ b/tools/verification/rv/include/utils.h @@ -16,6 +16,7 @@ struct config { bool debug; bool is_container; bool trace; + bool trace_errors_only; bool is_bpf; int my_pid; char *initial_reactor; diff --git a/tools/verification/rv/src/bpf_monitor.c b/tools/verification/rv/src/bpf_monitor.c index 1ff76a4ffb68..12cb407c55bc 100644 --- a/tools/verification/rv/src/bpf_monitor.c +++ b/tools/verification/rv/src/bpf_monitor.c @@ -411,7 +411,9 @@ static int bpf_enable_tracing(struct bpf_object *obj, struct bpf_monitor_ctx *ct if (!trace_level || data_size != sizeof(*trace_level)) return -1; - *trace_level = ctx->trace_types[TRACE_TYPE_EVENT]; + *trace_level = config.trace_errors_only ? + ctx->trace_types[TRACE_TYPE_ERROR] : + ctx->trace_types[TRACE_TYPE_EVENT]; return 0; } diff --git a/tools/verification/rv/src/trace.c b/tools/verification/rv/src/trace.c index 6fdbff2c28d4..629b4f63e147 100644 --- a/tools/verification/rv/src/trace.c +++ b/tools/verification/rv/src/trace.c @@ -213,7 +213,7 @@ static int enable_generic_event(struct trace_instance *inst, const char *event_n */ static int enable_bpf_events(struct trace_instance *inst, char *name) { - if (enable_generic_event(inst, "event_monitor", name)) + if (!config.trace_errors_only && enable_generic_event(inst, "event_monitor", name)) return -1; if (enable_generic_event(inst, "error_monitor", name)) @@ -228,6 +228,7 @@ static int enable_bpf_events(struct trace_instance *inst, char *name) * Enable the rv:event_"monitor" and rv:error_"monitor" events in the * given trace instance, and register the filters for these events. * If enabled, the filter for self pid (-s) is applied here. + * Skip the "event" events if errors only (-E) is specified. * * Returns 0 on success, -1 otherwise. */ @@ -238,9 +239,11 @@ static int trace_enable_monitor_events(struct trace_instance *inst, char *name) if (config.is_bpf) return enable_bpf_events(inst, name); - snprintf(event, sizeof(event), "event_%s", name); - if (enable_specific_event(inst, event)) - return -1; + if (!config.trace_errors_only) { + snprintf(event, sizeof(event), "event_%s", name); + if (enable_specific_event(inst, event)) + return -1; + } snprintf(event, sizeof(event), "error_%s", name); if (enable_specific_event(inst, event)) diff --git a/tools/verification/rv/src/utils.c b/tools/verification/rv/src/utils.c index 1b1ad7a3ca32..854028324325 100644 --- a/tools/verification/rv/src/utils.c +++ b/tools/verification/rv/src/utils.c @@ -65,6 +65,7 @@ void mon_usage(int exit_val, char *monitor_name, const char *fmt, ...) " -r/--reactor 'reactor': enables the 'reactor'", " -s/--self: when tracing (-t), also trace rv command", " -t/--trace: trace monitor's event", + " -E/--errors-only: when tracing (-t), trace only errors", " -v/--verbose: print debug messages", "", NULL, @@ -76,7 +77,7 @@ void mon_usage(int exit_val, char *monitor_name, const char *fmt, ...) fprintf(stderr, " %s\n", message); - fprintf(stderr, "\n usage: rv mon %s [-h] [-q] [-r reactor] [-s] [-v]", monitor_name); + fprintf(stderr, "\n usage: rv mon %s [-E] [-h] [-r reactor] [-s] [-t] [-v]", monitor_name); for (i = 0; usage[i]; i++) fprintf(stderr, "%s\n", usage[i]); @@ -103,6 +104,7 @@ int parse_arguments(char *monitor_name, int argc, char **argv) {"reactor", required_argument, 0, 'r'}, {"self", no_argument, 0, 's'}, {"trace", no_argument, 0, 't'}, + {"errors-only", no_argument, 0, 'E'}, {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0} }; @@ -110,7 +112,7 @@ int parse_arguments(char *monitor_name, int argc, char **argv) /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "hr:stv", long_options, &option_index); + c = getopt_long(argc, argv, "hr:stvE", long_options, &option_index); /* detect the end of the options. */ if (c == -1) @@ -132,6 +134,9 @@ int parse_arguments(char *monitor_name, int argc, char **argv) case 'v': config.debug = 1; break; + case 'E': + config.trace_errors_only = 1; + break; } } -- 2.56.1