Linux RAID subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christoph Hellwig" <hch@lst.de>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH 2/8] xor: improve the runtime selection benchmark
Date: Wed, 15 Jul 2026 15:04:02 +0000	[thread overview]
Message-ID: <20260715150402.93DE21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260715144825.95432-3-hch@lst.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Replacing clock-tick synchronization with a fixed number of loop iterations causes zero-duration time deltas on coarse clocks, leading to artificial throughput inflation, integer overflow, and random algorithm selection.
--

--- Patch [2]: [PATCH 2/8] xor: improve the runtime selection benchmark ---
commit 2205984bf337f5c013e14971e819bb6346e19853
Author: Christoph Hellwig <hch@lst.de>

xor: improve the runtime selection benchmark

This commit modifies the XOR block benchmark to use ktime_get_ns for timing
and switches to 4 + 1 disks for a more realistic load. It also reports the
throughput on the data disks instead of the parity disk.

> diff --git a/lib/raid/xor/xor-core.c b/lib/raid/xor/xor-core.c
> index 50931fbf0324e..f9d61b096b117 100644
> --- a/lib/raid/xor/xor-core.c
> +++ b/lib/raid/xor/xor-core.c

[ ... ]

> -#define BENCH_SIZE	4096
> +#define BENCH_SIZE	SZ_4K
> +#define NR_SRCS		4
>  #define REPS		800U
>  
> -static void __init
> -do_xor_speed(struct xor_block_template *tmpl, void *b1, void *b2)
> +static void __init do_xor_speed(struct xor_block_template *tmpl, void *dest,
> +		void *srcs[NR_SRCS])
>  {
> -	int speed;
> -	unsigned long reps;
> -	ktime_t min, start, t0;
> -	void *srcs[1] = { b2 };
> +	u64 t;
> +	int i;
>  
>  	preempt_disable();
> -
> -	reps = 0;
> -	t0 = ktime_get();
> -	/* delay start until time has advanced */
> -	while ((start = ktime_get()) == t0)
> -		cpu_relax();
> -	do {
> +	t = ktime_get_ns();
> +	for (i = 0; i < REPS; i++) {
>  		mb(); /* prevent loop optimization */
> -		tmpl->xor_gen(b1, srcs, 1, BENCH_SIZE);
> +		tmpl->xor_gen(dest, srcs, NR_SRCS, BENCH_SIZE);
>  		mb();
> -	} while (reps++ < REPS || (t0 = ktime_get()) == start);
> -	min = ktime_sub(t0, start);
> -
> +	}
> +	t = max(ktime_get_ns() - t, 1);

[Severity: High]
Does removing the clock-tick synchronization create an issue with low
resolution clocks?

If a high-resolution clocksource is not yet available during early boot,
the 800 loop iterations might complete within a single clock tick. If that
happens, the elapsed time t evaluates to 0 and gets clamped to 1.

>  	preempt_enable();
>  
> -	// bytes/ns == GB/s, multiply by 1000 to get MB/s [not MiB/s]
> -	speed = (1000 * reps * BENCH_SIZE) / (unsigned int)ktime_to_ns(min);
> -	tmpl->speed = speed;
> +	/* bytes/ns == GB/s, multiply by 1000 to get MB/s [not MiB/s] */
> +	tmpl->speed = div64_u64((u64)BENCH_SIZE * REPS * NR_SRCS * 1000, t);

[Severity: High]
Can this division silently overflow the 32-bit signed integer tmpl->speed?

If t is clamped to 1 ns, it yields a quotient of approximately 13.1 billion.
This overflows the 32-bit integer and could result in negative or
astronomically high throughput values. 

This might break the calibration logic and cause the kernel to select a
suboptimal XOR algorithm.

>  
> -	pr_info("   %-16s: %5d MB/sec\n", tmpl->name, speed);
> +	pr_info("   %-16s: %5d MB/sec\n", tmpl->name, tmpl->speed);
>  }

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260715144825.95432-1-hch@lst.de?part=2

  reply	other threads:[~2026-07-15 15:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15 14:47 misc lib/raid/ improvements v2 Christoph Hellwig
2026-07-15 14:47 ` [PATCH 1/8] xor: enable lock context analysis Christoph Hellwig
2026-07-15 14:47 ` [PATCH 2/8] xor: improve the runtime selection benchmark Christoph Hellwig
2026-07-15 15:04   ` sashiko-bot [this message]
2026-07-15 14:47 ` [PATCH 3/8] xor/kunit: fix a spelling error Christoph Hellwig
2026-07-15 14:47 ` [PATCH 4/8] xor/kunit: add a benchmark Christoph Hellwig
2026-07-15 15:05   ` sashiko-bot
2026-07-15 14:47 ` [PATCH 5/8] raid6: enable lock context analysis Christoph Hellwig
2026-07-15 14:47 ` [PATCH 6/8] raid6: defer implementation selection when built-in Christoph Hellwig
2026-07-15 14:47 ` [PATCH 7/8] raid6: improve the runtime selection benchmark Christoph Hellwig
2026-07-15 14:59   ` sashiko-bot
2026-07-15 14:47 ` [PATCH 8/8] raid6/kunit: add a benchmark Christoph Hellwig
2026-07-15 15:01   ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-07-08  9:07 misc lib/raid/ improvements Christoph Hellwig
2026-07-08  9:07 ` [PATCH 2/8] xor: improve the runtime selection benchmark Christoph Hellwig
2026-07-08  9:18   ` sashiko-bot
2026-07-08  9:05 misc lib/raid/ improvements Christoph Hellwig
2026-07-08  9:05 ` [PATCH 2/8] xor: improve the runtime selection benchmark Christoph Hellwig

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=20260715150402.93DE21F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-raid@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yukuai@fygo.io \
    /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