Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Oliver Mangold <o.mangold@gmail.com>
To: linux-crypto@vger.kernel.org
Subject: Re: Poor RNG performance on Ryzen
Date: Fri, 21 Jul 2017 13:39:13 +0200	[thread overview]
Message-ID: <09c9be2b-8b4d-ee06-8071-4f748fdb5970@gmail.com> (raw)
In-Reply-To: <20170721092656.GA18604@wintermute>

On 21.07.2017 11:26, Jan Glauber wrote:
>
> Nice catch. How much does the performance improve on Ryzen when you
> use arch_get_random_int()?

Okay, now I have some results for you:

On Ryzen 1800X (using arch_get_random_int()):

---
# dd if=/dev/urandom of=/dev/null bs=1M status=progress
8751415296 bytes (8,8 GB, 8,2 GiB) copied, 71,0079 s, 123 MB/s
# perf top
    57,37%  [kernel]                    [k] _extract_crng
    26,20%  [kernel]                    [k] chacha20_block
---

Better, but obviously there is still much room for improvement by 
reducing the number of calls to RDRAND.

On Ryzen 1800X (with nordrand kernel option):

---
# dd if=/dev/urandom of=/dev/null bs=1M status=progress
22643998720 bytes (23 GB, 21 GiB) copied, 67,0025 s, 338 MB/s
---

Here is the patch I used:

--- drivers/char/random.c.orig  2017-07-03 01:07:02.000000000 +0200
+++ drivers/char/random.c       2017-07-21 11:57:40.541677118 +0200
@@ -859,13 +859,14 @@
   static void _extract_crng(struct crng_state *crng,
                            __u8 out[CHACHA20_BLOCK_SIZE])
   {
-       unsigned long v, flags;
+       unsigned int v;
+       unsigned long flags;

          if (crng_init > 1 &&
              time_after(jiffies, crng->init_time + CRNG_RESEED_INTERVAL))
                  crng_reseed(crng, crng == &primary_crng ? &input_pool 
: NULL);
          spin_lock_irqsave(&crng->lock, flags);
-       if (arch_get_random_long(&v))
+       if (arch_get_random_int(&v))
                  crng->state[14] ^= v;
          chacha20_block(&crng->state[0], out);
          if (crng->state[12] == 0)

  reply	other threads:[~2017-07-21 11:39 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
2017-07-21 11:39   ` Oliver Mangold [this message]
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=09c9be2b-8b4d-ee06-8071-4f748fdb5970@gmail.com \
    --to=o.mangold@gmail.com \
    --cc=linux-crypto@vger.kernel.org \
    /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