Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7458548rwb; Tue, 6 Dec 2022 06:08:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf61NhcEmp+T5pxVeLk81oY7Z8tp3gd57Nk05xvXJLPvUIdxX51ZcF/uHDWNrB0lC4b1eGeu X-Received: by 2002:a05:6402:1381:b0:468:5b78:6381 with SMTP id b1-20020a056402138100b004685b786381mr66008032edv.373.1670335687352; Tue, 06 Dec 2022 06:08:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670335687; cv=none; d=google.com; s=arc-20160816; b=gQFrVxHP2c3/SANCio8yWivCr6socQP0xDwBXvsbXsdGCyKIAFeG8DzowicXs10H4C NUQC6MNd+D7GapQRH1FRJtdMjUm3dOcOdkN7m7Ri3PUXgMG3TyqXQGOFvIgtsMzZqRz3 5UOaVANbf5LUdrUd4YWZ+IOj+EoDpUQ5DKn80IOQDpWkQO0gSmhTp7rJqlw5GvgIivev /mBt8gmoVUzhKqhs78IPljmckNI6BKQ4J6GxSvUlaF37fIp6Bowgr6fWQ8c8AX36fr0/ f+X+SorVSbHNdteCvfOJUbutFrYkr5+nu9dvXujZBGzMUd+p+h6UK/dn9yi3w/LQcCil RnRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=pLK21N5d/EKb/syw7sI9+Uws4wdPPOjQjHEhyt51XUU=; b=Ee1aZqCMickhCQhAi6nJm4qdnWsgI6AUJlDzgeGY9xrf5NImDezfIeV1uiEIhkPVLn 1zBon/MeHG4AUXjxOEsCKB+wxE7703Put9/Kezby0x0pcbCKJsyb0UNo15jVSjftuKQk womCnXQdqvWpWA52+X4kQ02VjVJxpnWuPZD0F9HpwazK/nuCPqeVnKfykgzY6VBF21/C viORPY06Qh2Uqqbt1Fau/pA77xZtpNa5LPO69RXLDdm2QLWuDaYuDs17t+BIFX/pABa2 huHJi15yBHByhsXk6dCr+z4SmnijNViC+MELibPlWbebPidOYnZ6IQPIyPTtqqxZhGJL u1UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nO+bo8un; 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 k15-20020aa7c04f000000b004673015ab88si1752237edo.19.2022.12.06.06.07.47; Tue, 06 Dec 2022 06:08:07 -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=nO+bo8un; 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 S234428AbiLFNxb (ORCPT + 79 others); Tue, 6 Dec 2022 08:53:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233495AbiLFNx2 (ORCPT ); Tue, 6 Dec 2022 08:53:28 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE6F62B19D; Tue, 6 Dec 2022 05:53:27 -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 9B122B80DF3; Tue, 6 Dec 2022 13:53:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19BDDC433C1; Tue, 6 Dec 2022 13:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670334805; bh=pLK21N5d/EKb/syw7sI9+Uws4wdPPOjQjHEhyt51XUU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=nO+bo8un+V+ofnRZf16zv9tcWuY2QT1r4KaWAHFjvB4zhdNlHOs0P7x48LTLInYdo ZJPXalJcwpWZvZkF/+tET+dbFBmLEGZI1i9qflg73cO2OL3VVqJP8DszO/zo2nnkUe fZZmojkVMq5EtU6tqsezgJH3MJ4bS0FLY1e76kUofcj+x0xnCBCPAdRuv47ITB4ISX a7UlNZIy/04HGnwExrFBORnxC9BPSoFUZnl9m35meQWaNisFSWjlmjMohi2He+l6Su L4KqmG7N3mdvvuBrbzEPXcD1G+HTS5cMKWoCJ+S4UprT/lj4cU4znD3x/kH7ORFBv4 u2zRcq0kvCA5A== Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 1C00582E399; Tue, 6 Dec 2022 14:53:22 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: "Jason A. Donenfeld" Cc: Daniel Borkmann , 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> <87lenku265.fsf@toke.dk> <87iliou0hd.fsf@toke.dk> X-Clacks-Overhead: GNU Terry Pratchett Date: Tue, 06 Dec 2022 14:53:22 +0100 Message-ID: <87edtctz8t.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: > Hi Toke, > > On Tue, Dec 6, 2022 at 2:26 PM Toke H=C3=B8iland-J=C3=B8rgensen wrote: >> So for instance, if there's a large fixed component of the overhead of >> get_random_u32(), we could have bpf_user_rnd_u32() populate a larger >> per-CPU buffer and then just emit u32 chunks of that as long as we're >> still in the same NAPI loop as the first call. Or something to that >> effect. Not sure if this makes sense for this use case, but figured I'd >> throw the idea out there :) > > Actually, this already is how get_random_u32() works! It buffers a > bunch of u32s in percpu batches, and doles them out as requested. Ah, right. Not terribly surprised you already did this! > However, this API currently works in all contexts, including in > interrupts. So each call results in disabling irqs and reenabling > them. If I bifurcated batches into irq batches and non-irq batches, so > that we only needed to disable preemption for the non-irq batches, > that'd probably improve things quite a bit, since then the overhead > really would reduce to just a memcpy for the majority of calls. But I > don't know if adding that duplication of all code paths is really > worth the huge hassle. Right, makes sense; happy to leave that decision entirely up to you :) -Toke