* [PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU
@ 2026-03-17 15:06 David Carlier
2026-03-17 15:32 ` Mathieu Desnoyers
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: David Carlier @ 2026-03-17 15:06 UTC (permalink / raw)
To: Andrew Morton, Mathieu Desnoyers, Josh Law, Mark Brown
Cc: linux-kernel, David Carlier
On single-CPU topologies, accuracy_multiplier is zero, making both
approx_accuracy_range.under and .over zero. The boundary tests in
hpcc_test_compare_value_boundaries and hpcc_test_compare_counter_boundaries
then degenerate to comparing 0 vs 0, which correctly returns 0 (equal)
but the tests expect nonzero results.
Skip these boundary tests with kunit_skip() when accuracy is zero,
since approximation boundaries are meaningless without multi-CPU carry
propagation.
Fixes: ebc1ff504f55 ("lib: add kunit boundary tests for percpu_counter_tree comparisons")
Signed-off-by: David Carlier <devnexen@gmail.com>
---
lib/tests/percpu_counter_tree_kunit.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/tests/percpu_counter_tree_kunit.c b/lib/tests/percpu_counter_tree_kunit.c
index 4d058bc78f7d..609992bfaa21 100644
--- a/lib/tests/percpu_counter_tree_kunit.c
+++ b/lib/tests/percpu_counter_tree_kunit.c
@@ -101,6 +101,9 @@ static void hpcc_test_compare_value_boundaries(struct kunit *test)
percpu_counter_tree_set(&pct, 0);
percpu_counter_tree_approximate_accuracy_range(&pct, &under, &over);
+ if (!under && !over)
+ kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
/*
* With approx_sum = precise_sum = 0, from the accuracy invariant:
* approx_sum - over <= precise_sum <= approx_sum + under
@@ -214,6 +217,9 @@ static void hpcc_test_compare_counter_boundaries(struct kunit *test)
*/
combined = under + over;
+ if (!combined)
+ kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
/* --- percpu_counter_tree_approximate_compare --- */
/* At boundary: indeterminate */
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU
2026-03-17 15:06 [PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU David Carlier
@ 2026-03-17 15:32 ` Mathieu Desnoyers
2026-03-17 15:39 ` David Carlier
2026-03-17 16:09 ` Josh Law
2 siblings, 0 replies; 6+ messages in thread
From: Mathieu Desnoyers @ 2026-03-17 15:32 UTC (permalink / raw)
To: David Carlier, Andrew Morton, Josh Law, Mark Brown; +Cc: linux-kernel
On 2026-03-17 11:06, David Carlier wrote:
> On single-CPU topologies, accuracy_multiplier is zero, making both
> approx_accuracy_range.under and .over zero. The boundary tests in
> hpcc_test_compare_value_boundaries and hpcc_test_compare_counter_boundaries
> then degenerate to comparing 0 vs 0, which correctly returns 0 (equal)
> but the tests expect nonzero results.
>
> Skip these boundary tests with kunit_skip() when accuracy is zero,
> since approximation boundaries are meaningless without multi-CPU carry
> propagation.
AFAIU kunit_skip is implemented with kunit_try_catch_throw, which aborts
the specific test function. The placement of those kunit_skip appears to
leak memory allocated with kzalloc(). Am I missing something ?
Thanks,
Mathieu
>
> Fixes: ebc1ff504f55 ("lib: add kunit boundary tests for percpu_counter_tree comparisons")
> Signed-off-by: David Carlier <devnexen@gmail.com>
> ---
> lib/tests/percpu_counter_tree_kunit.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/lib/tests/percpu_counter_tree_kunit.c b/lib/tests/percpu_counter_tree_kunit.c
> index 4d058bc78f7d..609992bfaa21 100644
> --- a/lib/tests/percpu_counter_tree_kunit.c
> +++ b/lib/tests/percpu_counter_tree_kunit.c
> @@ -101,6 +101,9 @@ static void hpcc_test_compare_value_boundaries(struct kunit *test)
> percpu_counter_tree_set(&pct, 0);
> percpu_counter_tree_approximate_accuracy_range(&pct, &under, &over);
>
> + if (!under && !over)
> + kunit_skip(test, "no approximation accuracy on single-CPU topology");
> +
> /*
> * With approx_sum = precise_sum = 0, from the accuracy invariant:
> * approx_sum - over <= precise_sum <= approx_sum + under
> @@ -214,6 +217,9 @@ static void hpcc_test_compare_counter_boundaries(struct kunit *test)
> */
> combined = under + over;
>
> + if (!combined)
> + kunit_skip(test, "no approximation accuracy on single-CPU topology");
> +
> /* --- percpu_counter_tree_approximate_compare --- */
>
> /* At boundary: indeterminate */
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU
2026-03-17 15:06 [PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU David Carlier
2026-03-17 15:32 ` Mathieu Desnoyers
@ 2026-03-17 15:39 ` David Carlier
2026-03-17 15:41 ` Mathieu Desnoyers
2026-03-17 15:54 ` Mark Brown
2026-03-17 16:09 ` Josh Law
2 siblings, 2 replies; 6+ messages in thread
From: David Carlier @ 2026-03-17 15:39 UTC (permalink / raw)
To: Andrew Morton, Mathieu Desnoyers, Josh Law, Mark Brown
Cc: linux-kernel, David Carlier
On single-CPU topologies, accuracy_multiplier is zero, making both
approx_accuracy_range.under and .over zero. The boundary tests in
hpcc_test_compare_value_boundaries and hpcc_test_compare_counter_boundaries
then degenerate to comparing 0 vs 0, which correctly returns 0 (equal)
but the tests expect nonzero results.
Skip these boundary tests with kunit_skip() when accuracy is zero,
since approximation boundaries are meaningless without multi-CPU carry
propagation. Use percpu_counter_tree_items_size() as the topology check
before any allocations to avoid leaking memory on skip.
Fixes: ebc1ff504f55 ("lib: add kunit boundary tests for percpu_counter_tree comparisons")
Signed-off-by: David Carlier <devnexen@gmail.com>
---
lib/tests/percpu_counter_tree_kunit.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/tests/percpu_counter_tree_kunit.c b/lib/tests/percpu_counter_tree_kunit.c
index 4d058bc78f7d..b773d20867d4 100644
--- a/lib/tests/percpu_counter_tree_kunit.c
+++ b/lib/tests/percpu_counter_tree_kunit.c
@@ -93,6 +93,9 @@ static void hpcc_test_compare_value_boundaries(struct kunit *test)
unsigned long under = 0, over = 0;
int ret;
+ if (!percpu_counter_tree_items_size())
+ kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
counter_items = kzalloc(percpu_counter_tree_items_size(), GFP_KERNEL);
KUNIT_ASSERT_PTR_NE(test, counter_items, NULL);
ret = percpu_counter_tree_init(&pct, counter_items, 32, GFP_KERNEL);
@@ -197,6 +200,9 @@ static void hpcc_test_compare_counter_boundaries(struct kunit *test)
unsigned long combined;
int ret;
+ if (!percpu_counter_tree_items_size())
+ kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
counter_items = kzalloc(percpu_counter_tree_items_size() * 2,
GFP_KERNEL);
KUNIT_ASSERT_PTR_NE(test, counter_items, NULL);
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU
2026-03-17 15:39 ` David Carlier
@ 2026-03-17 15:41 ` Mathieu Desnoyers
2026-03-17 15:54 ` Mark Brown
1 sibling, 0 replies; 6+ messages in thread
From: Mathieu Desnoyers @ 2026-03-17 15:41 UTC (permalink / raw)
To: David Carlier, Andrew Morton, Josh Law, Mark Brown; +Cc: linux-kernel
On 2026-03-17 11:39, David Carlier wrote:
> On single-CPU topologies, accuracy_multiplier is zero, making both
> approx_accuracy_range.under and .over zero. The boundary tests in
> hpcc_test_compare_value_boundaries and hpcc_test_compare_counter_boundaries
> then degenerate to comparing 0 vs 0, which correctly returns 0 (equal)
> but the tests expect nonzero results.
>
> Skip these boundary tests with kunit_skip() when accuracy is zero,
> since approximation boundaries are meaningless without multi-CPU carry
> propagation. Use percpu_counter_tree_items_size() as the topology check
> before any allocations to avoid leaking memory on skip.
>
> Fixes: ebc1ff504f55 ("lib: add kunit boundary tests for percpu_counter_tree comparisons")
> Signed-off-by: David Carlier <devnexen@gmail.com>
Thanks!
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> ---
> lib/tests/percpu_counter_tree_kunit.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/lib/tests/percpu_counter_tree_kunit.c b/lib/tests/percpu_counter_tree_kunit.c
> index 4d058bc78f7d..b773d20867d4 100644
> --- a/lib/tests/percpu_counter_tree_kunit.c
> +++ b/lib/tests/percpu_counter_tree_kunit.c
> @@ -93,6 +93,9 @@ static void hpcc_test_compare_value_boundaries(struct kunit *test)
> unsigned long under = 0, over = 0;
> int ret;
>
> + if (!percpu_counter_tree_items_size())
> + kunit_skip(test, "no approximation accuracy on single-CPU topology");
> +
> counter_items = kzalloc(percpu_counter_tree_items_size(), GFP_KERNEL);
> KUNIT_ASSERT_PTR_NE(test, counter_items, NULL);
> ret = percpu_counter_tree_init(&pct, counter_items, 32, GFP_KERNEL);
> @@ -197,6 +200,9 @@ static void hpcc_test_compare_counter_boundaries(struct kunit *test)
> unsigned long combined;
> int ret;
>
> + if (!percpu_counter_tree_items_size())
> + kunit_skip(test, "no approximation accuracy on single-CPU topology");
> +
> counter_items = kzalloc(percpu_counter_tree_items_size() * 2,
> GFP_KERNEL);
> KUNIT_ASSERT_PTR_NE(test, counter_items, NULL);
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU
2026-03-17 15:39 ` David Carlier
2026-03-17 15:41 ` Mathieu Desnoyers
@ 2026-03-17 15:54 ` Mark Brown
1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2026-03-17 15:54 UTC (permalink / raw)
To: David Carlier; +Cc: Andrew Morton, Mathieu Desnoyers, Josh Law, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 738 bytes --]
On Tue, Mar 17, 2026 at 03:39:15PM +0000, David Carlier wrote:
> On single-CPU topologies, accuracy_multiplier is zero, making both
> approx_accuracy_range.under and .over zero. The boundary tests in
> hpcc_test_compare_value_boundaries and hpcc_test_compare_counter_boundaries
> then degenerate to comparing 0 vs 0, which correctly returns 0 (equal)
> but the tests expect nonzero results.
>
> Skip these boundary tests with kunit_skip() when accuracy is zero,
> since approximation boundaries are meaningless without multi-CPU carry
> propagation. Use percpu_counter_tree_items_size() as the topology check
> before any allocations to avoid leaking memory on skip.
Reviewed-by: Mark Brown <broonie@kernel.org>
Thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU
2026-03-17 15:06 [PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU David Carlier
2026-03-17 15:32 ` Mathieu Desnoyers
2026-03-17 15:39 ` David Carlier
@ 2026-03-17 16:09 ` Josh Law
2 siblings, 0 replies; 6+ messages in thread
From: Josh Law @ 2026-03-17 16:09 UTC (permalink / raw)
To: David Carlier, Andrew Morton, Mathieu Desnoyers, Mark Brown; +Cc: linux-kernel
On 17 March 2026 15:06:38 GMT, David Carlier <devnexen@gmail.com> wrote:
>On single-CPU topologies, accuracy_multiplier is zero, making both
>approx_accuracy_range.under and .over zero. The boundary tests in
>hpcc_test_compare_value_boundaries and hpcc_test_compare_counter_boundaries
>then degenerate to comparing 0 vs 0, which correctly returns 0 (equal)
>but the tests expect nonzero results.
>
>Skip these boundary tests with kunit_skip() when accuracy is zero,
>since approximation boundaries are meaningless without multi-CPU carry
>propagation.
>
>Fixes: ebc1ff504f55 ("lib: add kunit boundary tests for percpu_counter_tree comparisons")
>Signed-off-by: David Carlier <devnexen@gmail.com>
>---
> lib/tests/percpu_counter_tree_kunit.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
>diff --git a/lib/tests/percpu_counter_tree_kunit.c b/lib/tests/percpu_counter_tree_kunit.c
>index 4d058bc78f7d..609992bfaa21 100644
>--- a/lib/tests/percpu_counter_tree_kunit.c
>+++ b/lib/tests/percpu_counter_tree_kunit.c
>@@ -101,6 +101,9 @@ static void hpcc_test_compare_value_boundaries(struct kunit *test)
> percpu_counter_tree_set(&pct, 0);
> percpu_counter_tree_approximate_accuracy_range(&pct, &under, &over);
>
>+ if (!under && !over)
>+ kunit_skip(test, "no approximation accuracy on single-CPU topology");
>+
> /*
> * With approx_sum = precise_sum = 0, from the accuracy invariant:
> * approx_sum - over <= precise_sum <= approx_sum + under
>@@ -214,6 +217,9 @@ static void hpcc_test_compare_counter_boundaries(struct kunit *test)
> */
> combined = under + over;
>
>+ if (!combined)
>+ kunit_skip(test, "no approximation accuracy on single-CPU topology");
>+
> /* --- percpu_counter_tree_approximate_compare --- */
>
> /* At boundary: indeterminate */
Keep it up!
Have a great day!
Reviewed-by: Josh Law <objecting@objecting.org>
V/R
Josh Law
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-17 16:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17 15:06 [PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU David Carlier
2026-03-17 15:32 ` Mathieu Desnoyers
2026-03-17 15:39 ` David Carlier
2026-03-17 15:41 ` Mathieu Desnoyers
2026-03-17 15:54 ` Mark Brown
2026-03-17 16:09 ` Josh Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox