From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAADEC433E0 for ; Mon, 10 Aug 2020 12:03:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84DA820729 for ; Mon, 10 Aug 2020 12:03:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726531AbgHJMDK (ORCPT ); Mon, 10 Aug 2020 08:03:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbgHJMDK (ORCPT ); Mon, 10 Aug 2020 08:03:10 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:12e:520::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8C68C061756 for ; Mon, 10 Aug 2020 05:03:09 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1k56W6-00023S-Jo; Mon, 10 Aug 2020 14:03:02 +0200 Date: Mon, 10 Aug 2020 14:03:02 +0200 From: Florian Westphal To: Willy Tarreau Cc: George Spelvin , netdev@vger.kernel.org, aksecurity@gmail.com, torvalds@linux-foundation.org, edumazet@google.com, Jason@zx2c4.com, luto@kernel.org, keescook@chromium.org, tglx@linutronix.de, peterz@infradead.org, tytso@mit.edu, lkml.mplumb@gmail.com, stephen@networkplumber.org, fw@strlen.de Subject: Re: [DRAFT PATCH] random32: make prandom_u32() output unpredictable Message-ID: <20200810120302.GD19310@breakpoint.cc> References: <20200808152628.GA27941@SDF.ORG> <20200809065744.GA17668@SDF.ORG> <20200809093805.GA7928@1wt.eu> <20200809170639.GB25124@SDF.ORG> <20200809173302.GA8027@1wt.eu> <20200809183017.GC25124@SDF.ORG> <20200810114700.GB8474@1wt.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200810114700.GB8474@1wt.eu> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Willy Tarreau wrote: > On Sun, Aug 09, 2020 at 06:30:17PM +0000, George Spelvin wrote: > > Even something simple like buffering 8 TSC samples, and adding them > > at 32-bit offsets across the state every 8th call, would make a huge > > difference. > > Doing testing on real hardware showed that retrieving the TSC on every > call had a non negligible cost, causing a loss of 2.5% on the accept() > rate and 4% on packet rate when using iptables -m statistics. However > I reused your idea of accumulating old TSCs to increase the uncertainty > about their exact value, except that I retrieve it only on 1/8 calls > and use the previous noise in this case. With this I observe the same > performance as plain 5.8. Below are the connection rates accepted on > a single core : > > 5.8 5.8+patch 5.8+patch+tsc > 192900-197900 188800->192200 194500-197500 (conn/s) > > This was on a core i7-8700K. I looked at the asm code for the function > and it remains reasonably light, in the same order of complexity as the > original one, so I think we could go with that. > > My proposed change is below, in case you have any improvements to suggest. As this relates to networking, you could also hook perturbation into rx/tx softirq processing. E.g. once for each new napi poll round or only once for each softnet invocation, depending on cost. IIRC the proposed draft left a unused prandom_seed() stub around, you could re-use that to place extra data to include in the hash in percpu data.