From owner-svn-src-head@FreeBSD.ORG Wed Jul 31 02:13:37 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 3A28648F for ; Wed, 31 Jul 2013 02:13:37 +0000 (UTC) (envelope-from mailer-daemon@vniz.net) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com [209.85.217.178]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B26C72471 for ; Wed, 31 Jul 2013 02:13:36 +0000 (UTC) Received: by mail-lb0-f178.google.com with SMTP id z5so171740lbh.23 for ; Tue, 30 Jul 2013 19:13:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:openpgp:content-type :content-transfer-encoding:x-gm-message-state; bh=69tq1R+mszX5UOsO4qMDD0OXDDmMRO4nZbzyypQfNgI=; b=jZTCMNBt4AXp7cxlKsPDrx1e6kcooIEkSw7xMzSjuL03mesnDk+v6aUHqKTPU0j8r2 ldCAc7SywapE13IgKg03/7cxXntqKqyyvoXtDJx8UhCTZdTGbk0FOvIoHO5aMUDnE/Co aUbTBDsUK2BnURnXgocE9VvIenYSZDG69oXxSr10enZq9vb2CumFRmWXy54VjEVU1/cc /9Soh152TIXNolpJVOoNVC3+F2uXjT2tjpi44EuZP6VYf4p5V35i+7xkGRAYuKOIQdcE mAf1JX8rgPQ/bCGvHfMyvpdswneRL9X7vRPY6kFi4p0OtI9jC1ZM0TTGAn0voJMcNcjR 1pfg== X-Received: by 10.152.45.65 with SMTP id k1mr29928443lam.78.1375236807821; Tue, 30 Jul 2013 19:13:27 -0700 (PDT) Received: from [192.168.1.2] ([89.169.173.68]) by mx.google.com with ESMTPSA id m1sm27204622lag.3.2013.07.30.19.13.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Jul 2013 19:13:27 -0700 (PDT) Message-ID: <51F872C5.6020508@freebsd.org> Date: Wed, 31 Jul 2013 06:13:25 +0400 From: Andrey Chernov User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: obrien@freebsd.org Subject: Re: svn commit: r253786 - in head/sys: dev/random modules/padlock_rng modules/rdrand_rng modules/yarrow_rng References: <201307292058.r6TKwA56031193@svn.freebsd.org> <51F6E0AB.3010001@freebsd.org> <20130731000746.GA65806@dragon.NUXI.org> <20130731001551.GA67237@dragon.NUXI.org> In-Reply-To: <20130731001551.GA67237@dragon.NUXI.org> OpenPGP: id=964474DD Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQno5Hb19N4J7IrIXXkbHwjHOpu1qZ1rsog5ZMrP1iwzwYc4Sslndc2IDMyB32q2TBghHxVK Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Jul 2013 02:13:37 -0000 On 31.07.2013 4:15, David O'Brien wrote: > On Tue, Jul 30, 2013 at 05:07:46PM -0700, David O'Brien (@FreeBSD) wrote: >> I believe you're talking about this code in >> sys/libkern/arc4random.c:arc4rand() >> >> if (atomic_cmpset_int(&arc4rand_iniseed_state, ARC4_ENTR_HAVE, >> ARC4_ENTR_SEED) || reseed || >> (arc4_numruns > ARC4_RESEED_BYTES) || >> (tv.tv_sec > arc4_t_reseed)) >> arc4_randomstir(); > > Looking at this, seems to me that it would be more optimized if we tested > the things that are most likely to be TRUE first instead of those things > most likely to be FALSE? ARC4_ENTR_HAVE->ARC4_ENTR_SEED can only happen > once per boot, and the 'reseed' flag is '0' in the majority of the > arc4rand() callers. > This code can be called concurrently, so the first part is to reseed immediately if we have good entropy, making other threads wait for the lock released in arc4_randomstir() and arc4_t_reseed, arc4_numruns reset, so they don't call arc4_randomstir() in chain, if possible (small window still exists, as it was in original code). While there is no harm for arc4 algo itself to call arc4_randomstir() several times in line, it is just CPU waste. I don't touch the order of the rest conditions. -- http://ache.vniz.net/ bitcoin:1G6ugdNY6e5jx1GVnAU2ntj2NEfmjKG85r