This avoids startup races where one of the instances hit a threshold
before all instances were enabled, and thus tracing stops without
the relevant event.  In particular, this is not uncommon with the
tests that set a very tight threshold and then complain if there's
no analysis.

This also ensures that we don't stop tracing during a warmup.

The downside is a small chance of having an event over the threshold
early in the output, without stopping on it, which could cause user
confusion.  This should be less likely if the warmup feature is used, but
that doesn't eliminate the race window, just the odds of an unusual spike
right at that moment.

Signed-off-by: Crystal Wood <[email protected]>
---
 tools/tracing/rtla/src/common.c   | 20 ++++++++++++++++++++
 tools/tracing/rtla/src/common.h   |  4 ++++
 tools/tracing/rtla/src/osnoise.c  | 17 ++++-------------
 tools/tracing/rtla/src/osnoise.h  |  5 -----
 tools/tracing/rtla/src/timerlat.c | 29 ++++++++++-------------------
 5 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/common.c
index b197037fc58b..46e0263d6ae8 100644
--- a/tools/tracing/rtla/src/common.c
+++ b/tools/tracing/rtla/src/common.c
@@ -348,3 +348,23 @@ int hist_main_loop(struct osnoise_tool *tool)
 
        return retval;
 }
+
+int osn_set_stop(struct osnoise_tool *tool)
+{
+       struct common_params *params = tool->params;
+       int retval;
+
+       retval = osnoise_set_stop_us(tool->context, params->stop_us);
+       if (retval) {
+               err_msg("Failed to set stop us\n");
+               return retval;
+       }
+
+       retval = osnoise_set_stop_total_us(tool->context, 
params->stop_total_us);
+       if (retval) {
+               err_msg("Failed to set stop total us\n");
+               return retval;
+       }
+
+       return 0;
+}
diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/common.h
index 355f113a14a3..64004a030a56 100644
--- a/tools/tracing/rtla/src/common.h
+++ b/tools/tracing/rtla/src/common.h
@@ -148,7 +148,11 @@ void osnoise_destroy_tool(struct osnoise_tool *top);
 struct osnoise_tool *osnoise_init_tool(char *tool_name);
 struct osnoise_tool *osnoise_init_trace_tool(const char *tracer);
 bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool 
*record);
+int osnoise_set_stop_us(struct osnoise_context *context, long long stop_us);
+int osnoise_set_stop_total_us(struct osnoise_context *context,
+                             long long stop_total_us);
 
 int common_apply_config(struct osnoise_tool *tool, struct common_params 
*params);
 int top_main_loop(struct osnoise_tool *tool);
 int hist_main_loop(struct osnoise_tool *tool);
+int osn_set_stop(struct osnoise_tool *tool);
diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osnoise.c
index 312c511fa004..945eb61efc46 100644
--- a/tools/tracing/rtla/src/osnoise.c
+++ b/tools/tracing/rtla/src/osnoise.c
@@ -1128,18 +1128,6 @@ osnoise_apply_config(struct osnoise_tool *tool, struct 
osnoise_params *params)
                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");
@@ -1184,9 +1172,12 @@ int osnoise_enable(struct osnoise_tool *tool)
                        debug_msg("Error cleaning up the buffer");
                        return retval;
                }
-
        }
 
+       retval = osn_set_stop(tool);
+       if (retval)
+               return retval;
+
        return 0;
 }
 
diff --git a/tools/tracing/rtla/src/osnoise.h b/tools/tracing/rtla/src/osnoise.h
index 895687030c0b..3c927c179b35 100644
--- a/tools/tracing/rtla/src/osnoise.h
+++ b/tools/tracing/rtla/src/osnoise.h
@@ -34,12 +34,7 @@ int osnoise_set_runtime_period(struct osnoise_context 
*context,
                               unsigned long long period);
 void osnoise_restore_runtime_period(struct osnoise_context *context);
 
-int osnoise_set_stop_us(struct osnoise_context *context,
-                       long long stop_us);
 void osnoise_restore_stop_us(struct osnoise_context *context);
-
-int osnoise_set_stop_total_us(struct osnoise_context *context,
-                             long long stop_total_us);
 void osnoise_restore_stop_total_us(struct osnoise_context *context);
 
 int osnoise_set_timerlat_period_us(struct osnoise_context *context,
diff --git a/tools/tracing/rtla/src/timerlat.c 
b/tools/tracing/rtla/src/timerlat.c
index 19bab3d189f9..fe93cdc5354f 100644
--- a/tools/tracing/rtla/src/timerlat.c
+++ b/tools/tracing/rtla/src/timerlat.c
@@ -59,25 +59,6 @@ timerlat_apply_config(struct osnoise_tool *tool, struct 
timerlat_params *params)
                        goto out_err;
        }
 
-       if (params->mode != TRACING_MODE_BPF) {
-               /*
-                * In tracefs and mixed mode, timerlat tracer handles stopping
-                * on threshold
-                */
-               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_timerlat_period_us(tool->context,
                                                params->timerlat_period_us ?
                                                params->timerlat_period_us :
@@ -200,6 +181,16 @@ int timerlat_enable(struct osnoise_tool *tool)
                }
        }
 
+       /*
+        * In tracefs and mixed mode, timerlat tracer handles stopping
+        * on threshold
+        */
+       if (params->mode != TRACING_MODE_BPF) {
+               retval = osn_set_stop(tool);
+               if (retval)
+                       return retval;
+       }
+
        return 0;
 }
 
-- 
2.48.1


Reply via email to