linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Costa Shulyupin <costa.shul@redhat.com>
To: linux-rt-users <linux-rt-users@vger.kernel.org>,
	John Kacur <jkacur@redhat.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Tomas Glozar <tglozar@redhat.com>,
	Crystal Wood <crwood@redhat.com>,
	Costa Shulyupin <costa.shul@redhat.com>
Subject: [PATCH v1] rt-tests: cyclictest: Add MTBF calculation for latency spikes
Date: Thu, 16 Oct 2025 14:58:10 +0300	[thread overview]
Message-ID: <20251016115810.390980-1-costa.shul@redhat.com> (raw)

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.

Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
---
 src/cyclictest/cyclictest.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index b4bce8915b43..8ffd05a22b44 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -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);
 }
 
-- 
2.51.0


                 reply	other threads:[~2025-10-16 11:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251016115810.390980-1-costa.shul@redhat.com \
    --to=costa.shul@redhat.com \
    --cc=bigeasy@linutronix.de \
    --cc=crwood@redhat.com \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=tglozar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).