]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rtla/osnoise: Add support to adjust the tracing_thresh
authorDaniel Bristot de Oliveira <bristot@kernel.org>
Wed, 2 Mar 2022 19:01:26 +0000 (20:01 +0100)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 15 Mar 2022 18:36:48 +0000 (14:36 -0400)
osnoise uses the tracing_thresh parameter to define the delta between
two reads of the time to be considered a noise.

Add support to get and set the tracing_thresh from osnoise tools.

Link: https://lkml.kernel.org/r/715ad2a53fd40e41bab8c3f1214c1a94e12fb595.1646247211.git.bristot@kernel.org
Cc: Daniel Bristot de Oliveira <bristot@kernel.org>
Cc: Clark Williams <williams@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
tools/tracing/rtla/src/osnoise.c
tools/tracing/rtla/src/osnoise.h

index e60f1862bad09901f509a619fda2cd847ada2535..b8ec6c15bccb1509e952640bcc02525de586bcb8 100644 (file)
@@ -655,6 +655,85 @@ void osnoise_put_print_stack(struct osnoise_context *context)
        context->orig_print_stack = OSNOISE_OPTION_INIT_VAL;
 }
 
+/*
+ * osnoise_get_tracing_thresh - read and save the original "tracing_thresh"
+ */
+static long long
+osnoise_get_tracing_thresh(struct osnoise_context *context)
+{
+       long long tracing_thresh;
+
+       if (context->tracing_thresh != OSNOISE_OPTION_INIT_VAL)
+               return context->tracing_thresh;
+
+       if (context->orig_tracing_thresh != OSNOISE_OPTION_INIT_VAL)
+               return context->orig_tracing_thresh;
+
+       tracing_thresh = osnoise_read_ll_config("tracing_thresh");
+       if (tracing_thresh < 0)
+               goto out_err;
+
+       context->orig_tracing_thresh = tracing_thresh;
+       return tracing_thresh;
+
+out_err:
+       return OSNOISE_OPTION_INIT_VAL;
+}
+
+/*
+ * osnoise_set_tracing_thresh - set "tracing_thresh"
+ */
+int osnoise_set_tracing_thresh(struct osnoise_context *context, long long tracing_thresh)
+{
+       long long curr_tracing_thresh = osnoise_get_tracing_thresh(context);
+       int retval;
+
+       if (curr_tracing_thresh == OSNOISE_OPTION_INIT_VAL)
+               return -1;
+
+       retval = osnoise_write_ll_config("tracing_thresh", tracing_thresh);
+       if (retval < 0)
+               return -1;
+
+       context->tracing_thresh = tracing_thresh;
+
+       return 0;
+}
+
+/*
+ * osnoise_restore_tracing_thresh - restore the original "tracing_thresh"
+ */
+void osnoise_restore_tracing_thresh(struct osnoise_context *context)
+{
+       int retval;
+
+       if (context->orig_tracing_thresh == OSNOISE_OPTION_INIT_VAL)
+               return;
+
+       if (context->orig_tracing_thresh == context->tracing_thresh)
+               goto out_done;
+
+       retval = osnoise_write_ll_config("tracing_thresh", context->orig_tracing_thresh);
+       if (retval < 0)
+               err_msg("Could not restore original tracing_thresh\n");
+
+out_done:
+       context->tracing_thresh = OSNOISE_OPTION_INIT_VAL;
+}
+
+/*
+ * osnoise_put_tracing_thresh - restore original values and cleanup data
+ */
+void osnoise_put_tracing_thresh(struct osnoise_context *context)
+{
+       osnoise_restore_tracing_thresh(context);
+
+       if (context->orig_tracing_thresh == OSNOISE_OPTION_INIT_VAL)
+               return;
+
+       context->orig_tracing_thresh = OSNOISE_OPTION_INIT_VAL;
+}
+
 /*
  * enable_osnoise - enable osnoise tracer in the trace_instance
  */
@@ -716,6 +795,9 @@ struct osnoise_context *osnoise_context_alloc(void)
        context->orig_print_stack       = OSNOISE_OPTION_INIT_VAL;
        context->print_stack            = OSNOISE_OPTION_INIT_VAL;
 
+       context->orig_tracing_thresh    = OSNOISE_OPTION_INIT_VAL;
+       context->tracing_thresh         = OSNOISE_OPTION_INIT_VAL;
+
        osnoise_get_context(context);
 
        return context;
@@ -741,6 +823,7 @@ void osnoise_put_context(struct osnoise_context *context)
        osnoise_put_stop_total_us(context);
        osnoise_put_timerlat_period_us(context);
        osnoise_put_print_stack(context);
+       osnoise_put_tracing_thresh(context);
 
        free(context);
 }
index 9e4b2e2a4559f48c875771a151e0e5c9bfda2329..04a4384cc544a080dd1fc9c697dc0caf31ad7413 100644 (file)
@@ -23,6 +23,10 @@ struct osnoise_context {
        long long               orig_timerlat_period_us;
        long long               timerlat_period_us;
 
+       /* 0 as init value */
+       long long               orig_tracing_thresh;
+       long long               tracing_thresh;
+
        /* -1 as init value because 0 is disabled */
        long long               orig_stop_us;
        long long               stop_us;
@@ -67,6 +71,10 @@ int osnoise_set_timerlat_period_us(struct osnoise_context *context,
                                   long long timerlat_period_us);
 void osnoise_restore_timerlat_period_us(struct osnoise_context *context);
 
+int osnoise_set_tracing_thresh(struct osnoise_context *context,
+                              long long tracing_thresh);
+void osnoise_restore_tracing_thresh(struct osnoise_context *context);
+
 void osnoise_restore_print_stack(struct osnoise_context *context);
 int osnoise_set_print_stack(struct osnoise_context *context,
                            long long print_stack);