Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7374745rwb; Tue, 6 Dec 2022 05:06:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf6fwOF1M/Ml1Xvm8+VYb9sOAwacEbkpdmfFpqU2q//oBqNE8a6w6oZvxKfAeTlSjmGX8jPO X-Received: by 2002:a17:90a:a4e:b0:219:6737:b20e with SMTP id o72-20020a17090a0a4e00b002196737b20emr30886383pjo.178.1670332009269; Tue, 06 Dec 2022 05:06:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670332009; cv=none; d=google.com; s=arc-20160816; b=tQgZSgAe+C03DbHwj/u4GrmzmPCy25Ibjp0eqxnTYjHNtqy0tje0iraqzJscWWziRY 35QwU67V99MBh7fFlWU74JVfAMEdAvRZT3Z3iASDXY5pl/kUY7R8ZnhtmlraA3iPek0h jWsD84hWJgaxAkIfIBd0tnUSvmY5TZvpZK8CuFrH+n0wztHl6J8eub2MYFc6x4Gd18XB Qoh788YmsElHbcUWtBteU66O1QWfgsS4U6TG9vMlNcQ/k1s8UCVA3D6c3ATVz+17t1U+ FaLMB/AXfz+mpvTQ903e6S3lgbDi0S2EyPncLv6MwJuJZFqhxD973VFZYK6co5kKKFzy eUIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=IsTdNmthgpCH2hdeI4BN2uARnnGp2fQR2YOtPsi8SJI=; b=JaeMAuWHV/5ANGlAdEwE4bTl8ZhMOKsgc8KTiXu3Jvy6IRob1RpTS0ydReaNIqsDhG Z3yoAQjKAAXXPnY6CnMUOtZAQlVbNdlMyj+pnH4G3d1sEXpC0FC0tSR5F5nBLKH5VQlG J6UafJGYb3Wi3c6/6afs+fNAUGrbYX2O2M1+GxGEQk/2bc7T4Y/SmDU6RoTOPYxqkr3T vJcjNB+vjTsBshHy7YmITy13rbQDzYRVlmoux3Wfn2v7Cr9UOecQLvtMEBpCpO7m44Bg CclE43c3uygrPggPAoM/wgE8QhSLHV0SRZHusum/fd1uqo27OAtYm21RtyxTUFVsiZwY KucQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Pl0mLg6/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i25-20020a632219000000b004771126e2f7si16773728pgi.142.2022.12.06.05.06.38; Tue, 06 Dec 2022 05:06:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Pl0mLg6/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233366AbiLFMuU (ORCPT + 79 others); Tue, 6 Dec 2022 07:50:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbiLFMuS (ORCPT ); Tue, 6 Dec 2022 07:50:18 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B969DFA8; Tue, 6 Dec 2022 04:50:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 261B1B815A6; Tue, 6 Dec 2022 12:50:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 966D2C433C1; Tue, 6 Dec 2022 12:50:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670331013; bh=5fkVXllCSjBZuVo8Uv46ZK/hvRL1/H1PEhU3z7MLu9U=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Pl0mLg6/LiKcbhhSy0QHR1e32ydRmRC+61dwkYzb/s06blHeIrSqAXDAOUctG6l6C 0Z5tCluonCZ66PUPkB3+flY/v5c7MLvc4CQ3JR45gOtJdw5g8PGq3lQMqY7acWIcFt wRrkj0B/xseEs/Y5odZNwPgYoFP7D0li3cLTAy1DbRzNnQVOzCHZBOXJY6OCok8GBf HO51IJjrXBsZtjXmzw1O/u5j+iEwVXknWuJWqRCD0JoaRvlYOHAmvljkDgSlXCwt+4 bZ0VQ68sTh91wcjEYe9MZ9mcajrf55N8sUL4OtWWOd1QM74NANjuiU1nJ8jnj780wg xkjBZkpxi9Nlg== Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 7A6E982E386; Tue, 6 Dec 2022 13:50:10 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: "Jason A. Donenfeld" , Daniel Borkmann Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrii Nakryiko , Martin KaFai Lau Subject: Re: [PATCH] bpf: call get_random_u32() for random integers In-Reply-To: References: <20221205181534.612702-1-Jason@zx2c4.com> <730fd355-ad86-a8fa-6583-df23d39e0c23@iogearbox.net> X-Clacks-Overhead: GNU Terry Pratchett Date: Tue, 06 Dec 2022 13:50:10 +0100 Message-ID: <87lenku265.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Jason A. Donenfeld" writes: > On Mon, Dec 05, 2022 at 11:21:51PM +0100, Daniel Borkmann wrote: >> On 12/5/22 7:15 PM, Jason A. Donenfeld wrote: >> > Since BPF's bpf_user_rnd_u32() was introduced, there have been three >> > significant developments in the RNG: 1) get_random_u32() returns the >> > same types of bytes as /dev/urandom, eliminating the distinction between >> > "kernel random bytes" and "userspace random bytes", 2) get_random_u32() >> > operates mostly locklessly over percpu state, 3) get_random_u32() has >> > become quite fast. >> >> Wrt "quite fast", do you have a comparison between the two? Asking as its >> often used in networking worst case on per packet basis (e.g. via XDP), would >> be useful to state concrete numbers for the two on a given machine. > > Median of 25 cycles vs median of 38, on my Tiger Lake machine. So a > little slower, but too small of a difference to matter. Assuming a 3Ghz CPU clock (so 3 cycles per nanosecond), that's an additional overhead of ~4.3 ns. When processing 10 Gbps at line rate with small packets, the per-packet processing budget is 67.2 ns, so those extra 4.3 ns will eat up ~6.4% of the budget. So in other words, "too small a difference to matter" is definitely not true in general. It really depends on the use case; if someone is using this to, say, draw per-packet random numbers to compute a drop frequency on ingress, that extra processing time will most likely result in a quite measurable drop in performance. -Toke