lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAFnufp3Ce-ssx4143_+zc4HWPMx4Rn9kAsVwoK=tqBfSXG0-qQ@mail.gmail.com>
Date: Fri, 30 Jan 2026 00:36:30 +0100
From: Matteo Croce <technoboy85@...il.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-kernel@...r.kernel.org
Subject: Re: [PATCH] KUnit: memcpy: add benchmark

Il giorno ven 30 gen 2026 alle ore 00:20 Andrew Morton
<akpm@...ux-foundation.org> ha scritto:
>
> On Thu, 29 Jan 2026 01:43:28 +0100 Matteo Croce <technoboy85@...il.com> 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();
> > +
>

Right. In a previous version I was doing
preempt_disable()/preempt_enable() around the two ktime_get_ns(), but
then I thought that enabling and disabling preemption 100 time was too
much.
I'll restore the preempt macros around the actual copy and remove
cond_resched().
Thanks.

-- 
Matteo Croce

perl -e 'for($t=0;;$t++){print chr($t*($t>>8|$t>>13)&255)}' |aplay

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ