Message ID | 20221208183101.1162006-6-yury.norov@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp357655wrr; Thu, 8 Dec 2022 10:34:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf417DwDK5u+AtF4k1RDSrFCt4cmTO7RDfNbbK/fCac7uD/rp8yfsXg08KFt/wlUPO0FK61E X-Received: by 2002:a17:907:a0ca:b0:7c0:b4bc:eed3 with SMTP id hw10-20020a170907a0ca00b007c0b4bceed3mr24655335ejc.735.1670524454085; Thu, 08 Dec 2022 10:34:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670524454; cv=none; d=google.com; s=arc-20160816; b=oveuVwaGyb/rcFnZH7a7PYzOg0IOPQ+oRHmo+ee2iqhdQrXwJYE/vlOF6OgrgKqAI2 vOEFeDzk47rXlIW538shIF0ck5D5G+5uMtdVD4GWI4/YxX72u23PiH/NbpZHs9sOLYaA MThwVINyVX5I3UUczwopxJ8U1LymSq9/8ERPm7rrF3Bu2w95BnhYyUHzI05YVA63P4xS /npX5xEl/E7ciFxHLKgy6lBSCHxsRBPkxHztBCb12C4Ri2cxNPNJgJL+ArtHE6aEY6r6 OSMqJ4LdHtivq6mT92eaGEJ6oHYB22n/X4tnosFv6Hx8zTGBtnodlRHEai4oUGCMSwf6 PWGA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k44aAa8w+g09OTVc3BtKD/GeVUZOQmCH52b2zgD7vNE=; b=sZH+KL+GaRTi3F9C2ySu/jrSHS03m5OCXPu1ctigh66kKSfM948Ao8WG0BIOCoUH3g 6hDaf9EJ064iGRWV8HISLni6Co5foCYcmrj437EcNCQRj9b4C3LvTUshLgc5YKJHUHq4 QKul3JJxjSw01bzQl1HqH0vPxE+AEIbg/2TNybpDVSdsqyAbcDJR0+t0ts4O7C0dr0E2 pg+TBXzyliVJQNvQDKkbRltewQhW8nwx2i7cYjIxuXob9T4BDJCqQSM27mGDzEFYkB2K K1u+9JQ8U2LjS996G+fe7Z8o4hcXExUOGcs0wvquRSjQ6gdJ1abHx2OYr6+nV/8di1YQ sX5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kJnn8W88; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr10-20020a1709073f8a00b007c0fa820f08si3029708ejc.203.2022.12.08.10.33.50; Thu, 08 Dec 2022 10:34:14 -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=@gmail.com header.s=20210112 header.b=kJnn8W88; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229878AbiLHScB (ORCPT <rfc822;foxyelen666@gmail.com> + 99 others); Thu, 8 Dec 2022 13:32:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbiLHSbS (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 8 Dec 2022 13:31:18 -0500 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0279AE4FD; Thu, 8 Dec 2022 10:31:14 -0800 (PST) Received: by mail-ot1-x329.google.com with SMTP id l8-20020a056830054800b006705fd35eceso1362463otb.12; Thu, 08 Dec 2022 10:31:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k44aAa8w+g09OTVc3BtKD/GeVUZOQmCH52b2zgD7vNE=; b=kJnn8W88eYCSTCdaionDWs5lanPHeksZRwOquRqQpTBf+8LE/3uQ6Kb7qIiD+I2JFB NXC1hNgGIMNa4RtjALbAPIj6NPXaAplZSYXFpEgFkCE4Kuvr62KzE9Db6q3E1uaCKomN EIMjj/zqnYLqPfVe+aWersTJ5haEMRKBNYkkM/2+XbFQAQ4YHH1RxjnPmpxvHaUnjvU2 ZRhNYhUEHZFxgLz1LFrWWFbSfevTzqa0HvdTj1q3AuGflLvTvBTsVo/X2HEusft2UGsW Q7Ih9kt50RqgUeUUITRHBrHUwXI7bvDSkpH02dZ/dQN5XFutYGi6lP5X4TUXs6MCZIRn fFTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k44aAa8w+g09OTVc3BtKD/GeVUZOQmCH52b2zgD7vNE=; b=AS8kMgIt5wpLTCjPlxvwekueIeibvqTLzAiC78348nVkbvNKMVPaVf/BuvXISj8gIL n52qWIaJqzpSMTeW7w/ekN7bmfTuuknKFGHKcY5hGxl2cYv8aQaVL3zqLr1YSzFy4WWt pjhBiYSSfRhBjMx4YLDsPZMU3Kbx3dOp/GaVkHrBNE20uieS3bsalN8Ihuzh7V/z5cEO D5m7xqaXG5EyZeyMGbU5H3R6SXdipq4xRcN5gz/Ee+4EPXotrSuWq6wNhR7BsABCJpUa lbwg6zTWwLlwp3f8VYtCidQHUrxf+vxhO2rVKJQKbJdTyxTNHKYoD/q7wbRiDwYL/FdL 0iLA== X-Gm-Message-State: ANoB5pm12qik4BhbF3BA73eNYRQcFcAWtjIWX7mKVdMPpojd2Mm+/pke TLxhxkJN2FeiA9ZAGNMy4cg9xmPzPG8= X-Received: by 2002:a9d:5f02:0:b0:66d:a5fa:5c54 with SMTP id f2-20020a9d5f02000000b0066da5fa5c54mr1449103oti.1.1670524273395; Thu, 08 Dec 2022 10:31:13 -0800 (PST) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id x26-20020a9d629a000000b006705e35c4e2sm3077138otk.35.2022.12.08.10.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 10:31:13 -0800 (PST) From: Yury Norov <yury.norov@gmail.com> To: linux-kernel@vger.kernel.org, "David S. Miller" <davem@davemloft.net>, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, Barry Song <baohua@kernel.org>, Ben Segall <bsegall@google.com>, haniel Bristot de Oliveira <bristot@redhat.com>, Dietmar Eggemann <dietmar.eggemann@arm.com>, Gal Pressman <gal@nvidia.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Heiko Carstens <hca@linux.ibm.com>, Ingo Molnar <mingo@redhat.com>, Jakub Kicinski <kuba@kernel.org>, Jason Gunthorpe <jgg@nvidia.com>, Jesse Brandeburg <jesse.brandeburg@intel.com>, Jonathan Cameron <Jonathan.Cameron@huawei.com>, Juri Lelli <juri.lelli@redhat.com>, Leon Romanovsky <leonro@nvidia.com>, Mel Gorman <mgorman@suse.de>, Peter Zijlstra <peterz@infradead.org>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, Saeed Mahameed <saeedm@nvidia.com>, Steven Rostedt <rostedt@goodmis.org>, Tariq Toukan <tariqt@nvidia.com>, Tariq Toukan <ttoukan.linux@gmail.com>, Tony Luck <tony.luck@intel.com>, Valentin Schneider <vschneid@redhat.com>, Vincent Guittot <vincent.guittot@linaro.org> Cc: Yury Norov <yury.norov@gmail.com>, linux-crypto@vger.kernel.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH v3 5/5] lib/cpumask: reorganize cpumask_local_spread() logic Date: Thu, 8 Dec 2022 10:31:01 -0800 Message-Id: <20221208183101.1162006-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221208183101.1162006-1-yury.norov@gmail.com> References: <20221208183101.1162006-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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?1751671850265009581?= X-GMAIL-MSGID: =?utf-8?q?1751671850265009581?= |
Series |
cpumask: improve on cpumask_local_spread() locality
|
|
Commit Message
Yury Norov
Dec. 8, 2022, 6:31 p.m. UTC
Now after moving all NUMA logic into sched_numa_find_nth_cpu(),
else-branch of cpumask_local_spread() is just a function call, and
we can simplify logic by using ternary operator.
While here, replace BUG() with WARN().
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
lib/cpumask.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
Comments
> Now after moving all NUMA logic into sched_numa_find_nth_cpu(), > else-branch of cpumask_local_spread() is just a function call, and > we can simplify logic by using ternary operator. > > While here, replace BUG() with WARN(). Why make this change? It's still as bad to hit the WARN_ON as it was before. > Signed-off-by: Yury Norov yury.norov@gmail.com > > --- > lib/cpumask.c | 16 ++++++---------- > 1 file changed, 6 insertions(+), 10 deletions(-) > > diff --git a/lib/cpumask.c b/lib/cpumask.c > index 255974cd6734..c7029fb3c372 100644 > --- a/lib/cpumask.c > +++ b/lib/cpumask.c > @@ -127,16 +127,12 @@ unsigned int cpumask_local_spread(unsigned int i, int node) > /* Wrap: we always want a cpu. */ > i %= num_online_cpus(); > > - if (node == NUMA_NO_NODE) { > - cpu = cpumask_nth(i, cpu_online_mask); > - if (cpu < nr_cpu_ids) > - return cpu; > - } else { > - cpu = sched_numa_find_nth_cpu(cpu_online_mask, i, node); > - if (cpu < nr_cpu_ids) > - return cpu; > - } > - BUG(); > + cpu = node == NUMA_NO_NODE ? > + cpumask_nth(i, cpu_online_mask) : > + sched_numa_find_nth_cpu(cpu_online_mask, i, node); I find the if version clearer, and cleaner too if you drop the brackets. For the ternary version it would be nice to parenthesize the equality like you did in cmp() in 3/5. > + > + WARN_ON(cpu >= nr_cpu_ids); > > + return cpu; > } > EXPORT_SYMBOL(cpumask_local_spread); > > -- > 2.34.1 Minor nit: cmp() in 3/5 could use a longer name. The file's long, and cmp() doesn't explain _what_ it's comparing. How about cmp_cpumask() or something related to the function using it? Other than the above particularities, the whole series looks good to me. Reviewed-by: Peter Lafreniere <peter@n8pjl.ca>
On Thu, Dec 08, 2022 at 08:17:22PM +0000, Peter Lafreniere wrote: > > Now after moving all NUMA logic into sched_numa_find_nth_cpu(), > > else-branch of cpumask_local_spread() is just a function call, and > > we can simplify logic by using ternary operator. > > > > While here, replace BUG() with WARN(). > Why make this change? It's still as bad to hit the WARN_ON as it was before. For example, because of this: > Greg, please don't do this > > > ChangeSet@1.614, 2002-09-05 08:33:20-07:00, greg@kroah.com > > USB: storage driver: replace show_trace() with BUG() > > that BUG() thing is _way_ out of line, and has killed a few of my machines > several times for no good reason. It actively hurts debuggability, because > the machine is totally dead after it, and the whole and ONLY point of > BUG() messages is to help debugging and make it clear that we can't handle > something. > > In this case, we _can_ handle it, and we're much better off with a machine > that works and that you can look up the messages with than killing it. > > Rule of thumb: BUG() is only good for something that never happens and > that we really have no other option for (ie state is so corrupt that > continuing is deadly). > > Linus
> On Thu, Dec 08, 2022 at 08:17:22PM +0000, Peter Lafreniere wrote: > > > Now after moving all NUMA logic into sched_numa_find_nth_cpu(), > > > else-branch of cpumask_local_spread() is just a function call, and > > > we can simplify logic by using ternary operator. > > > > > > While here, replace BUG() with WARN(). > > Why make this change? It's still as bad to hit the WARN_ON as it was before. > > For example, because of this: > > > Greg, please don't do this > > > > > ChangeSet@1.614, 2002-09-05 08:33:20-07:00, greg@kroah.com > > > USB: storage driver: replace show_trace() with BUG() > > > > that BUG() thing is _way_ out of line, and has killed a few of my machines > > several times for no good reason. It actively hurts debuggability, because > > the machine is totally dead after it, and the whole and ONLY point of > > BUG() messages is to help debugging and make it clear that we can't handle > > something. > > > > In this case, we _can_ handle it, and we're much better off with a machine > > that works and that you can look up the messages with than killing it. > > > > Rule of thumb: BUG() is only good for something that never happens and > > that we really have no other option for (ie state is so corrupt that > > continuing is deadly). > > > > Linus Fair enough. It's not like it'll be hit anyway. My concern was for if any of the 23 callers get an invalid result. I guess that if that causes a crash, then so be it. We have the warning to track down the cause. Thanks for the explanation, Peter Lafreniere <peter@n8pjl.ca>
diff --git a/lib/cpumask.c b/lib/cpumask.c index 255974cd6734..c7029fb3c372 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -127,16 +127,12 @@ unsigned int cpumask_local_spread(unsigned int i, int node) /* Wrap: we always want a cpu. */ i %= num_online_cpus(); - if (node == NUMA_NO_NODE) { - cpu = cpumask_nth(i, cpu_online_mask); - if (cpu < nr_cpu_ids) - return cpu; - } else { - cpu = sched_numa_find_nth_cpu(cpu_online_mask, i, node); - if (cpu < nr_cpu_ids) - return cpu; - } - BUG(); + cpu = node == NUMA_NO_NODE ? + cpumask_nth(i, cpu_online_mask) : + sched_numa_find_nth_cpu(cpu_online_mask, i, node); + + WARN_ON(cpu >= nr_cpu_ids); + return cpu; } EXPORT_SYMBOL(cpumask_local_spread);