From: Jan Glauber <jglauber@cavium.com>
To: Oliver Mangold <o.mangold@gmail.com>
Cc: linux-crypto@vger.kernel.org
Subject: Re: Poor RNG performance on Ryzen
Date: Fri, 21 Jul 2017 11:26:57 +0200 [thread overview]
Message-ID: <20170721092656.GA18604@wintermute> (raw)
In-Reply-To: <1218e9b7-4eeb-d8a0-02b2-8ddd672ec454@gmail.com>
On Fri, Jul 21, 2017 at 09:12:01AM +0200, Oliver Mangold wrote:
> Hi,
>
> I was wondering why reading from /dev/urandom is much slower on
> Ryzen than on Intel, and did some analysis. It turns out that the
> RDRAND instruction is at fault, which takes much longer on AMD.
>
> if I read this correctly:
>
> --- drivers/char/random.c ---
> 862 spin_lock_irqsave(&crng->lock, flags);
> 863 if (arch_get_random_long(&v))
> 864 crng->state[14] ^= v;
> 865 chacha20_block(&crng->state[0], out);
>
> one call to RDRAND (with 64-bit operand) is issued per computation
> of a chacha20 block. According to the measurements I did, it seems
> on Ryzen this dominates the time usage:
>
> On Broadwell E5-2650 v4:
>
> ---
> # dd if=/dev/urandom of=/dev/null bs=1M status=progress
> 28827451392 bytes (29 GB) copied, 143.290349 s, 201 MB/s
> # perf top
> 49.88% [kernel] [k] chacha20_block
> 31.22% [kernel] [k] _extract_crng
> ---
>
> On Ryzen 1800X:
>
> ---
> # dd if=/dev/urandom of=/dev/null bs=1M status=progress
> 3169845248 bytes (3,2 GB, 3,0 GiB) copied, 42,0106 s, 75,5 MB/s
> # perf top
> 76,40% [kernel] [k] _extract_crng
> 13,05% [kernel] [k] chacha20_block
> ---
>
> An easy improvement might be to replace the usage of
> arch_get_random_long() by arch_get_random_int(), as the state array
> contains just 32-bit elements, and (contrary to Intel) on Ryzen
> 32-bit RDRAND is supposed to be faster by roughly a factor of 2.
Nice catch. How much does the performance improve on Ryzen when you
use arch_get_random_int()?
--Jan
> Best regards,
>
> OM
next prev parent reply other threads:[~2017-07-21 9:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-21 7:12 Poor RNG performance on Ryzen Oliver Mangold
2017-07-21 9:26 ` Jan Glauber [this message]
2017-07-21 11:39 ` Oliver Mangold
2017-07-21 14:47 ` Theodore Ts'o
2017-07-21 14:55 ` Oliver Mangold
2017-07-22 18:16 ` Theodore Ts'o
2017-07-25 6:20 ` Jan Glauber
2017-07-21 15:04 ` Gary R Hook
2017-07-21 12:11 ` Jeffrey Walton
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=20170721092656.GA18604@wintermute \
--to=jglauber@cavium.com \
--cc=linux-crypto@vger.kernel.org \
--cc=o.mangold@gmail.com \
/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