Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1707536imi; Sat, 23 Jul 2022 14:52:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v7AOuSUdZdhDdHOQyv0uTXBKuidz9MEK7CRs9tXlA+IILYd4PfHIRXqa3nDRznhKKs/RIi X-Received: by 2002:a17:907:3daa:b0:72b:7656:d4d2 with SMTP id he42-20020a1709073daa00b0072b7656d4d2mr4619126ejc.166.1658613161342; Sat, 23 Jul 2022 14:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658613161; cv=none; d=google.com; s=arc-20160816; b=nimgmkivqSGLl1BBCRpcOU6YqYzybOAQrIiUnN3C0acJATXCWxSaIyGPjuNCtUsIVz OZ96FlpGKCYj785UYPar4oewWirQE3PEtb1uraZXbMhJri4J/14paHB7zfPcFPEYSUQD zJFxnS55Kfrhfn2Y8hzkZhlc/ADUHicWAAkMYdxcnupZ/KTbArtooE5HzejKZ3U3sAaD NFJcVMpEpFGQW8LT1kdmSASg4xotYi/IBk17sgXXgZbllkUhFytxcuINJsMwRcJhLrgH D/pLL+kGHWmvVNvbu0FuuQA4k2O3BL8oIcDzWZvxHB9ZmBslWjaB/7K+Qv3MI53LxTfx 5HhQ== 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=zanwdLBSKuenMXk1so8se+lxPJyj0nx7EB+yjkrFe/o=; b=s5xePo/6JlfVFV8PSa5kxaAissDMeO396Mx9QNuVmvw0P6R6q588AEK0cCObbhAWTK aTD36gbdUDdwtkYwUyuCYVnacn436zvIABabxkCivdLADV1qWoBX2FJTE9Yjl7aICLYP nuxIPUQqxIFuHU6NMaIs9n9GxHW+gM71nKij2wag9s3vxWWJ5whLvWQh1Y88YkqC8pol 30tBP9YmtLMKJw7WuQmfdJrAMDCrNkzQC+kA2XrjZ30xuhWguIowHeD7k3bJKdVodkmm 5o1N8NJDFrkF6urk2ULPWwgpu3Rvn/cttVCPBMHh9l3ZnEh258pm1DDSFOIJiOOOSTNM 9ibg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="ABNOp66/"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk38-20020a1709077fa600b0072ab62ae019si10451354ejc.859.2022.07.23.14.52.16; Sat, 23 Jul 2022 14:52:41 -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=@gmail.com header.s=20210112 header.b="ABNOp66/"; 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 S238468AbiGWVpq (ORCPT + 99 others); Sat, 23 Jul 2022 17:45:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232663AbiGWVpo (ORCPT ); Sat, 23 Jul 2022 17:45:44 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42B7BE00D for ; Sat, 23 Jul 2022 14:45:43 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id mh14so5859124qvb.1 for ; Sat, 23 Jul 2022 14:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zanwdLBSKuenMXk1so8se+lxPJyj0nx7EB+yjkrFe/o=; b=ABNOp66/VYqY3jEnDnPLBaq4zdHPZUVCkl0bi9IJa0l5O05esh6ZD2a+M0yUsRyvcS q4dQO17dfGLRqTb+USaB0J563S0jDgXnQyFIO5MCxeczAamedeigG2esjotGwsqb0nvO mYoSosW0y4MYPVZcPibUs2kiBTZxJradjkE53hCV1GKudTxmzBPVgg9YExVuiqUdHZvK pcTkzxMvT7Us4EmuxjMLSXIgou+3FVHM6pxeGcEmJ6ODIvHArn/LcP4YTKfeYfzfS1x8 bN2p1/757yWPV4RxsncxhrCMhRWSvGWzWkrfro319eMpCTCd01Q+vgukchYJe8fnLZ1S Y4Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zanwdLBSKuenMXk1so8se+lxPJyj0nx7EB+yjkrFe/o=; b=lnBqI3hex1qVL0o3bai8GkA1IjBYykH2Gyj2hSmm4XOz2xjGyKV+GhAmDaVsnu42Th V1oQXm76cXzL+OUQnZOiAq8zrUEZVdHAUcvtSmahD2rAUGrCyuFFKcDKIeVQJZH+MQEW BHBZLsnzUBZvmu/qnwyg/8n94zroQLuy1RwGcPIj4CJ2XU9irPywLJ9tcXNgI9SK+Qra M6dNLxXrYaT9ldtnM8h0wwfpdu1QQe18TCJHi1+mkfTR+kAZJzqJEzo6aknTLn7b6/KU usSISJ2gspQFIi1LFx613VI/scaO63fJ+kuVjT+rHDS1SlPSqCddKrkCrzuzHvOb/h16 Rk8Q== X-Gm-Message-State: AJIora+EydQNVHIIcm16Iae7WVCe/++GMhc29wnfCd3STPzJdvhgmYJH x0eEnIcl5rTIPUC9eKRJAYtFFEyAksI= X-Received: by 2002:a0c:c506:0:b0:470:8e86:de0 with SMTP id x6-20020a0cc506000000b004708e860de0mr4943625qvi.104.1658612742153; Sat, 23 Jul 2022 14:45:42 -0700 (PDT) Received: from localhost ([2601:4c1:c100:1230:6235:40e3:a1d2:6281]) by smtp.gmail.com with ESMTPSA id n14-20020a05622a040e00b0031b18d29864sm5228665qtx.64.2022.07.23.14.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jul 2022 14:45:41 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Stephen Rothwell Cc: Yury Norov Subject: [RESEND PATCH 2/2] lib/nodemask: inline next_node_in() and node_random() Date: Sat, 23 Jul 2022 14:45:37 -0700 Message-Id: <20220723214537.2054208-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220723214537.2054208-1-yury.norov@gmail.com> References: <20220723214537.2054208-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: X-Mailing-List: linux-kernel@vger.kernel.org The functions are pretty thin wrappers around find_bit engine, and keeping them in c-file prevents compiler from small_const_nbits() optimization, which must take place for all systems with MAX_NUMNODES less than BITS_PER_LONG (default is 16 for me). Moving them to header file doesn't blow up the kernel size: add/remove: 1/2 grow/shrink: 9/5 up/down: 968/-88 (880) CC: Andy Shevchenko CC: Rasmus Villemoes Signed-off-by: Yury Norov --- MAINTAINERS | 1 - include/linux/nodemask.h | 27 ++++++++++++++++++++++----- lib/Makefile | 2 +- lib/nodemask.c | 30 ------------------------------ 4 files changed, 23 insertions(+), 37 deletions(-) delete mode 100644 lib/nodemask.c diff --git a/MAINTAINERS b/MAINTAINERS index 7c0b8f28aa25..19c8d0ef1177 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3540,7 +3540,6 @@ F: lib/bitmap.c F: lib/cpumask.c F: lib/find_bit.c F: lib/find_bit_benchmark.c -F: lib/nodemask.c F: lib/test_bitmap.c F: tools/include/linux/bitmap.h F: tools/include/linux/find.h diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index 0f233b76c9ce..48ebe4007955 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h @@ -94,6 +94,7 @@ #include #include #include +#include typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t; extern nodemask_t _unused_nodemask_arg_; @@ -276,7 +277,14 @@ static inline unsigned int __next_node(int n, const nodemask_t *srcp) * the first node in src if needed. Returns MAX_NUMNODES if src is empty. */ #define next_node_in(n, src) __next_node_in((n), &(src)) -unsigned int __next_node_in(int node, const nodemask_t *srcp); +static inline unsigned int __next_node_in(int node, const nodemask_t *srcp) +{ + unsigned int ret = __next_node(node, srcp); + + if (ret == MAX_NUMNODES) + ret = __first_node(srcp); + return ret; +} static inline void init_nodemask_of_node(nodemask_t *mask, int node) { @@ -493,14 +501,23 @@ static inline int num_node_state(enum node_states state) #endif +/* + * Return the bit number of a random bit set in the nodemask. + * (returns NUMA_NO_NODE if nodemask is empty) + */ +static inline int node_random(const nodemask_t *maskp) +{ #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1) -extern int node_random(const nodemask_t *maskp); + int w, bit = NUMA_NO_NODE; + + w = nodes_weight(*maskp); + if (w) + bit = find_nth_bit(maskp->bits, MAX_NUMNODES, get_random_int() % w); + return bit; #else -static inline int node_random(const nodemask_t *mask) -{ return 0; -} #endif +} #define node_online_map node_states[N_ONLINE] #define node_possible_map node_states[N_POSSIBLE] diff --git a/lib/Makefile b/lib/Makefile index f99bf61f8bbc..731cea0342d1 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -33,7 +33,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ flex_proportions.o ratelimit.o show_mem.o \ is_single_threaded.o plist.o decompress.o kobject_uevent.o \ earlycpio.o seq_buf.o siphash.o dec_and_lock.o \ - nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o \ + nmi_backtrace.o win_minmax.o memcat_p.o \ buildid.o lib-$(CONFIG_PRINTK) += dump_stack.o diff --git a/lib/nodemask.c b/lib/nodemask.c deleted file mode 100644 index 7dad4ce8ff59..000000000000 --- a/lib/nodemask.c +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include - -unsigned int __next_node_in(int node, const nodemask_t *srcp) -{ - unsigned int ret = __next_node(node, srcp); - - if (ret == MAX_NUMNODES) - ret = __first_node(srcp); - return ret; -} -EXPORT_SYMBOL(__next_node_in); - -#ifdef CONFIG_NUMA -/* - * Return the bit number of a random bit set in the nodemask. - * (returns NUMA_NO_NODE if nodemask is empty) - */ -int node_random(const nodemask_t *maskp) -{ - int w, bit = NUMA_NO_NODE; - - w = nodes_weight(*maskp); - if (w) - bit = find_nth_bit(maskp->bits, MAX_NUMNODES, get_random_int() % w); - return bit; -} -#endif -- 2.34.1