Skip to contentSkip to conversation

rt-tests: cyclictest: Add MTBF calculation for latency spikes

PATCH New Costa Shulyupin 1 participant 1 message Oct 16, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rt-tests: cyclictest: Add MTBF calculation for latency spikes

Cyclictest reports the number of latency spikes but provides no information about their frequency distribution over time. This makes it difficult to compare results - a test with 10 spikes over 1 hour is very different from 10 spikes over 24 hours, but both show 'spikes = 10'.

Add Mean Time Between Failures (MTBF) calculation to quantify spike frequency.

By definition MTBF = total operating time / number of failures.

In a practical environment where the number of failures is not very high, this formula is biased. For example, imagine stable periodic failures. The total operating time will include time before the first failure and after the last failure. These intervals are determined by when the test starts and stops, not by the system’s failure behavior, which adds measurement bias. The resulting MTBF will vary between runs even for stable periodic failures.

To reduce this bias, calculate MTBF using only the time between the first and last failure, divided by the number of intervals (failures minus one):

MTBF = (timestamp of last failure - timestamp of first failure) / (number of failures - 1)

In Cyclictest, the failures are called spikes.

This metric enables meaningful comparison of real-time performance consistency across different test runs, hardware configurations, and kernel versions. It can be considered a KPI for real-time stability, relevant for certification and SLA evaluation.

---
 src/cyclictest/cyclictest.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
src/cyclictest/cyclictest.c +12 -2
index b4bce8915b43..8ffd05a22b44 100644
@@ -165,6 +165,8 @@ struct thread_trigger *head = NULL;
 struct thread_trigger *tail = NULL;
 struct thread_trigger *current = NULL;
 static int spikes;	/* count of the number of spikes */
+static int64_t first_spike_ts;
+static int64_t last_spike_ts;
 
 static int trigger_init();
 static void trigger_print();
@@ -1753,8 +1755,13 @@ static void trigger_print()
 		fprintf(stdout, fmt,  trig->tnum, trig->diff, trig->ts);
 		trig = trig->next;
 	}
-		fprintf(stdout, fmt,  trig->tnum, trig->diff, trig->ts);
-		printf("spikes = %d\n\n", spikes);
+	fprintf(stdout, fmt,  trig->tnum, trig->diff, trig->ts);
+	printf("spikes = %d\n", spikes);
+	if (spikes > 1) {
+		double mtbf_sec = (last_spike_ts - first_spike_ts) / (spikes - 1) / 1e6;
+		printf("MTBF = %.3f\n", mtbf_sec);
+	}
+	printf("\n");
 }
 
 static void trigger_update(struct thread_param *par, int diff, int64_t ts)
@@ -1767,6 +1774,9 @@ static void trigger_update(struct thread_param *par, int diff, int64_t ts)
 		current = current->next;
 	}
 	spikes++;
+	if (!first_spike_ts)
+		first_spike_ts = ts;
+	last_spike_ts = ts;
 	pthread_mutex_unlock(&trigger_lock);
 }
 
Signature · 1 line
2.51.0