Message ID | 20221013175145.919301297@linuxfoundation.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp411334wrs; Thu, 13 Oct 2022 11:08:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5VOuFLTEpEN7+t1V/Jk0qXiiHYbDp7uYjD/sPg4IdYwfyRikccEN7Tt7M7Up3PG9yIv6Zs X-Received: by 2002:a17:902:8bc3:b0:178:8563:8e42 with SMTP id r3-20020a1709028bc300b0017885638e42mr937652plo.0.1665684504276; Thu, 13 Oct 2022 11:08:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665684504; cv=none; d=google.com; s=arc-20160816; b=uyZlB1iX/H0HFju2dU1046doQ3p5DGaOHYA+yKYuDXNseEOkvDIJ/OvdxWZY0/a5sE Te+wLc6IYpD18bTU8xP9smI0yy19qCptquk9FDv0EH5w6XY2v/9x+QFqhCT9ghBWtrT0 n2bdXzvH/Pay9jy6Js7jo4FGsA5+aGW5XI729gbG1JJECkPTnuDsdsShuowXPE2hRU/1 1ZHavfY/hVT669RwnVTaH2KNYo1FoPq5KTSoGYz9nu1+ePi8f+5337C+TCVyH/7jtMeL 6Bx9oVVbTMH8oPxRcktaaFym60YgjQ2067MKYl+FwLtQYguDb0YMF/Cpg6oLCp5DOGXQ CHiw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eo0A/1OAkV5pfmL88E2k8D8hcn44pcpikzxYWnGlW5U=; b=cI9fEVpn4A1vBn82QRrgGVoyZMgk/os1fB9/CDLVul8+NXMKDCNqPq5UdXKCzzXej3 wfY0OmBNFps7aC35ha1zqOU4YzmQITqBzQBlZdfknPRXoiPR+lC+vwLfAL4GSi0SG2bD Y1JpifDEWIXVuC0CBB0uVD5A8Why3xQSBxKH2ghAFe5siRl6F8BLa3PBT0IbMntSSDJT Xzrb11n86uH2LyLxBivWy+YjutYaIHFUzjxtgTk80iLw/ecZylPXgQdSDirZAk94C5r/ rGxCRMjE2vxyKRDJPfYxQnoFqXuyMWg766LV53e4GLUUIsC7L1Vy1wRuMSur7YqtrjjW SL9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wESsBqSL; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7-20020a635d07000000b0044c634e3051si84440pgb.274.2022.10.13.11.08.11; Thu, 13 Oct 2022 11:08:24 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=wESsBqSL; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231335AbiJMSH5 (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Thu, 13 Oct 2022 14:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231511AbiJMSGe (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 13 Oct 2022 14:06:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E5EF437DB; Thu, 13 Oct 2022 11:05:23 -0700 (PDT) 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 99095B82065; Thu, 13 Oct 2022 18:00:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5A3CC433C1; Thu, 13 Oct 2022 18:00:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665684026; bh=BLsZ3M6JOHN9+LrdwWJRcShlBn9OykEOl6tyUen3xuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wESsBqSLbO5SgIBmjsO/TLsTQPzKgi6C3PeS3xxli95JkcAmr+UVbkinc+ea871x0 EUCogEO7Xwf0bJKN4JskmFbzT7iaIHs+dklJQ1JeG1//uJxuvJHYxPnrG/pI5XFdXM X9eXilk2zfKpjvpAm02XR7yB400sUiePB12D6px8= From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, stable@vger.kernel.org, Sherry Yang <sherry.yang@oracle.com>, Paul Webb <paul.x.webb@oracle.com>, Phillip Goerl <phillip.goerl@oracle.com>, Jack Vogel <jack.vogel@oracle.com>, Nicky Veitch <nicky.veitch@oracle.com>, Colm Harrington <colm.harrington@oracle.com>, Ramanan Govindarajan <ramanan.govindarajan@oracle.com>, Sebastian Andrzej Siewior <bigeasy@linutronix.de>, Dominik Brodowski <linux@dominikbrodowski.net>, Tejun Heo <tj@kernel.org>, Sultan Alsawaf <sultan@kerneltoast.com>, "Jason A. Donenfeld" <Jason@zx2c4.com> Subject: [PATCH 5.19 19/33] random: use expired timer rather than wq for mixing fast pool Date: Thu, 13 Oct 2022 19:52:51 +0200 Message-Id: <20221013175145.919301297@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175145.236739253@linuxfoundation.org> References: <20221013175145.236739253@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746596794780100250?= X-GMAIL-MSGID: =?utf-8?q?1746596794780100250?= |
Series |
None
|
|
Commit Message
Greg KH
Oct. 13, 2022, 5:52 p.m. UTC
From: Jason A. Donenfeld <Jason@zx2c4.com> commit 748bc4dd9e663f23448d8ad7e58c011a67ea1eca upstream. Previously, the fast pool was dumped into the main pool periodically in the fast pool's hard IRQ handler. This worked fine and there weren't problems with it, until RT came around. Since RT converts spinlocks into sleeping locks, problems cropped up. Rather than switching to raw spinlocks, the RT developers preferred we make the transformation from originally doing: do_some_stuff() spin_lock() do_some_other_stuff() spin_unlock() to doing: do_some_stuff() queue_work_on(some_other_stuff_worker) This is an ordinary pattern done all over the kernel. However, Sherry noticed a 10% performance regression in qperf TCP over a 40gbps InfiniBand card. Quoting her message: > MT27500 Family [ConnectX-3] cards: > Infiniband device 'mlx4_0' port 1 status: > default gid: fe80:0000:0000:0000:0010:e000:0178:9eb1 > base lid: 0x6 > sm lid: 0x1 > state: 4: ACTIVE > phys state: 5: LinkUp > rate: 40 Gb/sec (4X QDR) > link_layer: InfiniBand > > Cards are configured with IP addresses on private subnet for IPoIB > performance testing. > Regression identified in this bug is in TCP latency in this stack as reported > by qperf tcp_lat metric: > > We have one system listen as a qperf server: > [root@yourQperfServer ~]# qperf > > Have the other system connect to qperf server as a client (in this > case, it’s X7 server with Mellanox card): > [root@yourQperfClient ~]# numactl -m0 -N0 qperf 20.20.20.101 -v -uu -ub --time 60 --wait_server 20 -oo msg_size:4K:1024K:*2 tcp_lat Rather than incur the scheduling latency from queue_work_on, we can instead switch to running on the next timer tick, on the same core. This also batches things a bit more -- once per jiffy -- which is okay now that mix_interrupt_randomness() can credit multiple bits at once. Reported-by: Sherry Yang <sherry.yang@oracle.com> Tested-by: Paul Webb <paul.x.webb@oracle.com> Cc: Sherry Yang <sherry.yang@oracle.com> Cc: Phillip Goerl <phillip.goerl@oracle.com> Cc: Jack Vogel <jack.vogel@oracle.com> Cc: Nicky Veitch <nicky.veitch@oracle.com> Cc: Colm Harrington <colm.harrington@oracle.com> Cc: Ramanan Govindarajan <ramanan.govindarajan@oracle.com> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: Tejun Heo <tj@kernel.org> Cc: Sultan Alsawaf <sultan@kerneltoast.com> Cc: stable@vger.kernel.org Fixes: 58340f8e952b ("random: defer fast pool mixing to worker") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> --- drivers/char/random.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
--- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -906,17 +906,20 @@ struct fast_pool { unsigned long pool[4]; unsigned long last; unsigned int count; - struct work_struct mix; + struct timer_list mix; }; +static void mix_interrupt_randomness(struct timer_list *work); + static DEFINE_PER_CPU(struct fast_pool, irq_randomness) = { #ifdef CONFIG_64BIT #define FASTMIX_PERM SIPHASH_PERMUTATION - .pool = { SIPHASH_CONST_0, SIPHASH_CONST_1, SIPHASH_CONST_2, SIPHASH_CONST_3 } + .pool = { SIPHASH_CONST_0, SIPHASH_CONST_1, SIPHASH_CONST_2, SIPHASH_CONST_3 }, #else #define FASTMIX_PERM HSIPHASH_PERMUTATION - .pool = { HSIPHASH_CONST_0, HSIPHASH_CONST_1, HSIPHASH_CONST_2, HSIPHASH_CONST_3 } + .pool = { HSIPHASH_CONST_0, HSIPHASH_CONST_1, HSIPHASH_CONST_2, HSIPHASH_CONST_3 }, #endif + .mix = __TIMER_INITIALIZER(mix_interrupt_randomness, 0) }; /* @@ -958,7 +961,7 @@ int __cold random_online_cpu(unsigned in } #endif -static void mix_interrupt_randomness(struct work_struct *work) +static void mix_interrupt_randomness(struct timer_list *work) { struct fast_pool *fast_pool = container_of(work, struct fast_pool, mix); /* @@ -1012,10 +1015,11 @@ void add_interrupt_randomness(int irq) if (new_count < 1024 && !time_is_before_jiffies(fast_pool->last + HZ)) return; - if (unlikely(!fast_pool->mix.func)) - INIT_WORK(&fast_pool->mix, mix_interrupt_randomness); fast_pool->count |= MIX_INFLIGHT; - queue_work_on(raw_smp_processor_id(), system_highpri_wq, &fast_pool->mix); + if (!timer_pending(&fast_pool->mix)) { + fast_pool->mix.expires = jiffies; + add_timer_on(&fast_pool->mix, raw_smp_processor_id()); + } } EXPORT_SYMBOL_GPL(add_interrupt_randomness);