From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752598AbdATO27 (ORCPT ); Fri, 20 Jan 2017 09:28:59 -0500 Received: from imap.thunk.org ([74.207.234.97]:37358 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752167AbdATO25 (ORCPT ); Fri, 20 Jan 2017 09:28:57 -0500 Date: Fri, 20 Jan 2017 09:28:52 -0500 From: "Theodore Ts'o" To: "Jason A. Donenfeld" Cc: LKML , Hannes Frederic Sowa , Andy Lutomirski Subject: Re: [PATCH 1/2] random: use chacha20 for get_random_int/long Message-ID: <20170120142852.lznr25go4pbdlwdt@thunk.org> Mail-Followup-To: Theodore Ts'o , "Jason A. Donenfeld" , LKML , Hannes Frederic Sowa , Andy Lutomirski References: <20170106183202.5035-1-Jason@zx2c4.com> <20170118034907.spozwf4erlvx5s4x@thunk.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20161126 (1.7.1) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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