Skip to contentSkip to conversation

cyclictest: write tracemark if latency above spike value

PATCH Marcelo Tosatti 1 participant 1 message Mar 1, 2023

lore
Share & tools
lore
#0 lore raw

It is useful to have the following ranges:

	Value			Behaviour

	> break_lat	   -> write tracemark entry, quit cyclictest.

	[spike, break_lat] -> write tracemark entry, continue execution.

	< spike		   -> no tracemark entry, continue execution.

So one can know which events are causing "close to break value" (and their causes).

src/cyclictest/cyclictest.c +4 -1
index 82759d1..22eab05 100644
@@ -1698,6 +1698,9 @@ static void trigger_update(struct thread_param *par, int diff, int64_t ts)
 	}
 	spikes++;
 	pthread_mutex_unlock(&trigger_lock);
+	if (trace_marker && diff > trigger) {
+		tracemark_nostop("hit latency trigger (%d > %d)", diff, trigger);
+	}
 }
 
 /* Running status shared memory open */
@@ -1892,7 +1895,7 @@ int main(int argc, char **argv)
 	/* use the /dev/cpu_dma_latency trick if it's there */
 	set_latency_target();
 
-	if (tracelimit && trace_marker)
+	if ((tracelimit && trace_marker) || (trigger && trace_marker))
 		enable_trace_mark();
 
 	if (check_timer())
src/include/rt-utils.h +1 -0
index f6b3fed..85a459f 100644
@@ -32,6 +32,7 @@ int parse_mem_string(char *str, uint64_t *val);
 
 void enable_trace_mark(void);
 void tracemark(char *fmt, ...) __attribute__((format(printf, 1, 2)));
+void tracemark_nostop(char *fmt, ...) __attribute__((format(printf, 1, 2)));
 void disable_trace_mark(void);
 
 #define MSEC_PER_SEC		1000
src/lib/rt-utils.c +16 -1
index 6c0235d..daa8bb8 100644
@@ -458,7 +458,7 @@ static void debugfs_prepare(void)
 		     "debug fs not mounted");
 }
 
-void tracemark(char *fmt, ...)
+void tracemark_nostop(char *fmt, ...)
 {
 	va_list ap;
 	int len;
@@ -474,6 +474,21 @@ void tracemark(char *fmt, ...)
 
 	/* write the tracemark message */
 	write(tracemark_fd, tracebuf, len);
+}
+
+void tracemark(char *fmt, ...)
+{
+	va_list ap;
+	int len;
+
+	/* bail out if we're not tracing */
+	/* or if the kernel doesn't support trace_mark */
+	if (tracemark_fd < 0 || trace_fd < 0)
+		return;
+
+	va_start(ap, fmt);
+	len = vsnprintf(tracebuf, TRACEBUFSIZ, fmt, ap);
+	va_end(ap);
 
 	/* now stop any trace */
 	write(trace_fd, "0\n", 2);