Re: [PATCH] KUnit: memcpy: add benchmark
From: Andrew Morton
Date: Thu Jan 29 2026 - 18:20:43 EST
On Thu, 29 Jan 2026 01:43:28 +0100 Matteo Croce <technoboy85@xxxxxxxxx> wrote:
> Add optional benchmarks for memcpy() and memmove() functions.
> Each benchmark is run twice: first with buffers aligned and then with
> buffers unaligned, to spot unaligned accesses on platforms where they
> have a noticeable performance impact.
>
> ...
>
> +static int memcpy_bench_align(struct kunit *test, bool unalign)
> +{
> + u64 start, end, total_ns = 0;
> + char *buf1;
> + char *buf2;
> + int ret = 0;
> +
> + buf1 = kzalloc(COPY_SIZE, GFP_KERNEL);
> + if (!buf1)
> + return -ENOMEM;
> +
> + buf2 = kzalloc(COPY_SIZE, GFP_KERNEL);
> + if (!buf2) {
> + ret = -ENOMEM;
> + goto out_free;
> + }
> +
> + preempt_disable();
> + for (int i = 0; i < COPIES_NUM; i++) {
> + start = ktime_get_ns();
> + memcpy(buf1 + unalign, buf2, COPY_SIZE - unalign);
> + end = ktime_get_ns();
> + total_ns += end - start;
> + cond_resched();
Is cond_resched() inside preempt_disable() actually legal?
Might be, but it doesn't make a lot of sense, does it?
> + }
> + preempt_enable();
> +