public inbox for linux-next@vger.kernel.org 
 help / color / mirror / Atom feed
From: Ankur Arora <ankur.a.arora@oracle•com>
To: linux-kernel@vger•kernel.org, linux-arch@vger•kernel.org,
	linux-arm-kernel@lists•infradead.org, linux-pm@vger•kernel.org,
	linux-next@vger•kernel.org, bpf@vger•kernel.org
Cc: arnd@arndb•de, catalin.marinas@arm•com, will@kernel•org,
	peterz@infradead•org, akpm@linux-foundation•org,
	mark.rutland@arm•com, harisokn@amazon•com, cl@gentwo•org,
	ast@kernel•org, rafael@kernel•org, daniel.lezcano@linaro•org,
	memxor@gmail•com, zhenglifeng1@huawei•com,
	xueshuai@linux•alibaba.com, rdunlap@infradead•org,
	david.laight.linux@gmail•com, joao.m.martins@oracle•com,
	boris.ostrovsky@oracle•com, konrad.wilk@oracle•com,
	ashok.bhat@arm•com, Ankur Arora <ankur.a.arora@oracle•com>,
	Boqun Feng <boqun.feng@gmail•com>, Boqun Feng <boqun@kernel•org>,
	Christoph Lameter <cl@linux•com>, Ingo Molnar <mingo@kernel•org>,
	Konrad Dybcio <konradybcio@kernel•org>,
	Mark Brown <broonie@kernel•org>
Subject: [PATCH v11 2/2] kunit: add clock tests for smp_cond_load_relaxed_timeout()
Date: Thu, 21 May 2026 01:30:38 -0700	[thread overview]
Message-ID: <20260521083038.134260-2-ankur.a.arora@oracle.com> (raw)
In-Reply-To: <20260521083038.134260-1-ankur.a.arora@oracle.com>

Add a few clock tests for smp_cond_load_relaxed_timeout(). These
ensure that the implementation doesn't do any funny stuff with the
clock (like multiple accesses per iteration.)

Also ensure that edge cases are handled sanely. Note that two edge
cases fail: S64_MAX and U64_MAX. However, both of those are quite
far out and if needed, can be addressed in the implementation of
the interface.

Also, this tests only smp_cond_load_relaxed_timeout(). The acquire
variant uses an identical clock path and testing wouldn't add anything.

Signed-off-by: Ankur Arora <ankur.a.arora@oracle•com>
Cc: Andrew Morton <akpm@linux-foundation•org>
Cc: Arnd Bergmann <arnd@arndb•de>
Cc: Boqun Feng <boqun.feng@gmail•com>
Cc: Boqun Feng <boqun@kernel•org>
Cc: Catalin Marinas <catalin.marinas@arm•com>
Cc: Christoph Lameter <cl@linux•com>
Cc: Haris Okanovic <harisokn@amazon•com>
Cc: Ingo Molnar <mingo@kernel•org>
Cc: Konrad Dybcio <konradybcio@kernel•org>
Cc: Mark Brown <broonie@kernel•org>
Cc: Peter Zijlstra <peterz@infradead•org>
Cc: Will Deacon <will@kernel•org>
---
 lib/tests/barrier-timeout-test.c | 57 ++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/lib/tests/barrier-timeout-test.c b/lib/tests/barrier-timeout-test.c
index 2160844b27b8..6ce6c7b0fc44 100644
--- a/lib/tests/barrier-timeout-test.c
+++ b/lib/tests/barrier-timeout-test.c
@@ -19,6 +19,8 @@ MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
 struct clock_state {
 	s64	start_time;
 	s64	end_time;
+	s64	extra;
+	u32	niters;
 };
 
 #define TIMEOUT_MSEC	2
@@ -112,8 +114,63 @@ static void test_smp_cond_timeout(struct kunit *test)
 		KUNIT_EXPECT_GE(test, runtime, timeout_ns);
 }
 
+static s64 synthetic_clock(struct clock_state *clk) {
+	clk->end_time += clk->extra;
+	clk->niters++;
+
+	return clk->end_time;
+}
+
+
+struct smp_cond_expiry_params {
+	char	*desc;
+	s64	timeout;
+	s64	clk_inc;
+	u32	niters;
+};
+
+static const struct smp_cond_expiry_params expiry_params_list[] = {
+	{ .clk_inc = (0x1ULL << 28), .timeout = -1LL,		.niters = 1,		  	.desc = "-1LL",    },
+	{ .clk_inc = (0x1ULL << 28), .timeout = (0x1ULL << 30), .niters = 1 + (1 << (30-28)),	.desc = "1<<30",   },
+	{ .clk_inc = (0x1ULL << 28), .timeout = S32_MAX,	.niters = 1 + (1 << (31-28)),	.desc = "S32_MAX", },
+	{ .clk_inc = (0x1ULL << 28), .timeout = U32_MAX,	.niters = 1 + (1 << (32-28)),	.desc = "U32_MAX", },
+	{ .clk_inc = (0x1ULL << 28), .timeout = (0x1ULL << 33), .niters = 1 + (1 << (33-28)),	.desc = "1<<33",   },
+};
+
+static void expiry_param_to_desc(const struct smp_cond_expiry_params *p, char *desc)
+{
+	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "smp_cond_%s_timeout: clock-%s, timeout=%s, iterations=%u",
+		"relaxed", "synthetic", p->desc, p->niters);
+}
+
+static void test_smp_cond_expiry(struct kunit *test)
+{
+	const struct smp_cond_expiry_params *p = test->param_value;
+	struct clock_state clk = {
+		.start_time = 0,
+		.end_time = 0,
+		.extra = p->clk_inc,
+		.niters = 0,
+	};
+	unsigned int result;
+	s64 runtime;
+
+	flag = 0;
+	result = smp_cond_load_relaxed_timeout(&flag,
+					       0,
+					       synthetic_clock(&clk),
+					       p->timeout);
+
+	runtime = (u64)clk.end_time - (u64)clk.start_time;
+	KUNIT_EXPECT_EQ(test, clk.niters, p->niters);
+	KUNIT_EXPECT_GE(test, runtime, p->timeout);
+}
+
+
+KUNIT_ARRAY_PARAM(smp_cond_expiry_params, expiry_params_list, expiry_param_to_desc);
 static struct kunit_case barrier_timeout_test_cases[] = {
 	KUNIT_CASE_PARAM(test_smp_cond_timeout, smp_cond_update_params_gen_params),
+	KUNIT_CASE_PARAM(test_smp_cond_expiry, smp_cond_expiry_params_gen_params),
 	{}
 };
 
-- 
2.43.7


  reply	other threads:[~2026-05-21  8:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260408122538.3610871-15-ankur.a.arora@oracle.com>
2026-05-21  8:30 ` [PATCH v11 1/2] kunit: add tests for smp_cond_load_*_timeout() Ankur Arora
2026-05-21  8:30   ` Ankur Arora [this message]
2026-05-21 21:46   ` Andrew Morton
2026-05-21 21:57     ` Mark Brown
2026-05-22  5:10     ` Ankur Arora

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=20260521083038.134260-2-ankur.a.arora@oracle.com \
    --to=ankur.a.arora@oracle$(echo .)com \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=arnd@arndb$(echo .)de \
    --cc=ashok.bhat@arm$(echo .)com \
    --cc=ast@kernel$(echo .)org \
    --cc=boqun.feng@gmail$(echo .)com \
    --cc=boqun@kernel$(echo .)org \
    --cc=boris.ostrovsky@oracle$(echo .)com \
    --cc=bpf@vger$(echo .)kernel.org \
    --cc=broonie@kernel$(echo .)org \
    --cc=catalin.marinas@arm$(echo .)com \
    --cc=cl@gentwo$(echo .)org \
    --cc=cl@linux$(echo .)com \
    --cc=daniel.lezcano@linaro$(echo .)org \
    --cc=david.laight.linux@gmail$(echo .)com \
    --cc=harisokn@amazon$(echo .)com \
    --cc=joao.m.martins@oracle$(echo .)com \
    --cc=konrad.wilk@oracle$(echo .)com \
    --cc=konradybcio@kernel$(echo .)org \
    --cc=linux-arch@vger$(echo .)kernel.org \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-next@vger$(echo .)kernel.org \
    --cc=linux-pm@vger$(echo .)kernel.org \
    --cc=mark.rutland@arm$(echo .)com \
    --cc=memxor@gmail$(echo .)com \
    --cc=mingo@kernel$(echo .)org \
    --cc=peterz@infradead$(echo .)org \
    --cc=rafael@kernel$(echo .)org \
    --cc=rdunlap@infradead$(echo .)org \
    --cc=will@kernel$(echo .)org \
    --cc=xueshuai@linux$(echo .)alibaba.com \
    --cc=zhenglifeng1@huawei$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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