mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Hannes Frederic Sowa <hannes@stressinduktion.org>,
	Andy Lutomirski <luto@amacapital.net>
Subject: Re: [PATCH 1/2] random: use chacha20 for get_random_int/long
Date: Fri, 20 Jan 2017 09:28:52 -0500	[thread overview]
Message-ID: <20170120142852.lznr25go4pbdlwdt@thunk.org> (raw)
In-Reply-To: <CAHmME9qRHdTQj_wmLV1tBv1SdO+xy1HhYtTJohs6V1sFZZZeyg@mail.gmail.com>

On Fri, Jan 20, 2017 at 06:27:19AM +0100, Jason A. Donenfeld wrote:
> This is most certainly not the case. Read closely.
> 
> I use a different variable for each function. get_random_u32 only
> touches batched_entropy_u32, and get_random_u64 only touches
> bached_entropy_u64. Under no circumstances will one function use the
> other's batched entropy.
> 
> I use a union so that only one struct must be declared. If you think
> that's unclear, I can declare two separate structs instead. Let me
> know which strategy you prefer -- what I have now, or splitting it
> into two structs.

What I would probably do is just use one array and one array index,
denominated in 32-bit words, and just grab two 32-bit words for the
64-bit case.  Optimizing away the overhead of assembling two 32-bit
words for a 64-bit word, and the possibility that we might have to
touch two cache lines instead of one --- is it really worth it?

Compare that to the fact that you're wasting up to 66% of the
generated words in the batched entropy array, and certainly on average
you're wasting CPU cycles, even if you are reducing the cost of
calling get_random_u{32,64} by a handful of cycles....

      	  	      	      	     - Ted
				     

  reply	other threads:[~2017-01-20 14:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-06 18:32 Jason A. Donenfeld
2017-01-06 18:32 ` [PATCH 2/2] random: convert get_random_int/long into get_random_u32/u64 Jason A. Donenfeld
2017-01-18  3:49 ` [PATCH 1/2] random: use chacha20 for get_random_int/long Theodore Ts'o
2017-01-20  5:27   ` Jason A. Donenfeld
2017-01-20 14:28     ` Theodore Ts'o [this message]
2017-01-20 15:38       ` Jason A. Donenfeld
2017-01-21  0:10         ` Theodore Ts'o
2017-01-21  0:13           ` Jason A. Donenfeld
2017-01-20 15:47       ` Jason A. Donenfeld
2017-01-21  0:15         ` Theodore Ts'o
2017-01-21  0:16           ` Jason A. Donenfeld
2017-01-21  6:24             ` Theodore Ts'o
2017-01-21 14:08               ` Jason A. Donenfeld
2017-01-22 11:24                 ` Greg Kroah-Hartman
2017-01-22 12:21                   ` Jason A. Donenfeld
2017-01-22 15:20                     ` Greg Kroah-Hartman
2017-01-22 15:34                       ` Jason A. Donenfeld
2017-01-22 15:34                         ` [PATCH 2/2] random: convert get_random_int/long into get_random_u32/u64 Jason A. Donenfeld
2017-01-22 22:28                       ` [PATCH 1/2] random: use chacha20 for get_random_int/long Theodore Ts'o
2017-01-22 22:49                         ` Jason A. Donenfeld
2017-01-23  0:33                           ` Theodore Ts'o
2017-01-23  8:12                         ` Greg Kroah-Hartman
  -- strict thread matches above, loose matches on Subject: below --
2016-12-22 18:07 Jason A. Donenfeld

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=20170120142852.lznr25go4pbdlwdt@thunk.org \
    --to=tytso@mit.edu \
    --cc=Jason@zx2c4.com \
    --cc=hannes@stressinduktion.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    /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

all inboxes | Powered by JetHome®