Commit c219d4ee authored by Crystal Wood's avatar Crystal Wood Committed by Tomas Glozar
Browse files

rtla: Set stop threshold after all instances are enabled



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: default avatarCrystal Wood <crwood@redhat.com>
Link: https://lore.kernel.org/r/20251112152529.956778-6-crwood@redhat.com


Signed-off-by: default avatarTomas Glozar <tglozar@redhat.com>
parent 11aa4a18
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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;
}
+4 −0
Original line number Diff line number Diff line
@@ -152,7 +152,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);
+4 −13
Original line number Diff line number Diff line
@@ -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;
}

+0 −5
Original line number Diff line number Diff line
@@ -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,
+10 −19
Original line number Diff line number Diff line
@@ -48,25 +48,6 @@ timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
		}
	}

	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 :
@@ -184,6 +165,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;
}