From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65631C4338F for ; Sat, 14 Aug 2021 21:18:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E80C560F46 for ; Sat, 14 Aug 2021 21:18:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E80C560F46 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8CF258D000B; Sat, 14 Aug 2021 17:18:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80A048D0009; Sat, 14 Aug 2021 17:18:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60EBE8D000B; Sat, 14 Aug 2021 17:18:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0089.hostedemail.com [216.40.44.89]) by kanga.kvack.org (Postfix) with ESMTP id 3B6FA8D0009 for ; Sat, 14 Aug 2021 17:18:30 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id DBFC9180226F1 for ; Sat, 14 Aug 2021 21:18:29 +0000 (UTC) X-FDA: 78474949938.37.9F17247 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf02.hostedemail.com (Postfix) with ESMTP id 9F2DB7002B86 for ; Sat, 14 Aug 2021 21:18:29 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id w14so20545065pjh.5 for ; Sat, 14 Aug 2021 14:18:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=63VdXzd4E2fRb/oaCNOigO3VzkytLa69hErQBY25S+8=; b=dR0YXJfND8qk00ZmTgqaj6j5GlOdlX+XdW/D0TW2WYUjJ/9flTfXodaVEW8Reos/4y LrNE6tNpI+aZyGz/8JtvgoSHGKV+XOfyD+uIJpU0eFO2Eog3F52oe/ZzOBcSYQVBHHhc y8N1VhOlXYaOD+s8lbtEWqlIIMfLlUbV/w/sRc9PCOf1tP5VwToRs6LslDq2Mxu7NNZ/ pv1SuCXSxHX99PNKntdJ5hgPWSyIkdtpfNrvrm/zxDYFz9/9yaWayo4MclYpzW/yYzxk 9QQgr1m1wuVKRLmwQhOMC8VczN/rvknAavol8vNfPp8h1RQSIdwakfQRQrWr9kni6hlx 8Qlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=63VdXzd4E2fRb/oaCNOigO3VzkytLa69hErQBY25S+8=; b=PKBKmjqex3dNxhD58ElvSkXQTb+nWW3H4Q834oElQQJjFvKj/KmKe0Fo1DdAN+CkS/ 3GN66uA97GgIJP0fB7k1TRRGWb+DlzULR1U3p2MaXRQHMgF4L6mo89CrRZnF+FxCj9gV LIzZdjXkeeAT4I1YAyLxVaJsN6z/DhLYLgUf0QswbQltrN/TOopdAdq1FF5tfjzB2gnX g3rSlinaEpbTOmlTU7PNTfFyGJdRzLV4AluJStZ+d2NI16OzIfgElZMif3dM2BkJ/R6G 7D2WKqSKjMMkeMWNFvfPEkgswNK1fmO8xBmdiJuseK+dxU/49UWJgR7AzkFY05V3AXOs T32g== X-Gm-Message-State: AOAM533UL78vl08HprDCKzjIQcXLvtxHDYixIQmZzIRLTLKX5D+MpVoX HU/3oUi1Q0EdWLQ9YQBIjQY= X-Google-Smtp-Source: ABdhPJwN79hEQGsoVuNN0U3YkqZ0EkBT6am9F0TZ+nk0injd+0GeASDj6pdO9J8NFPyFdmXlp/L69Q== X-Received: by 2002:a17:90a:c58b:: with SMTP id l11mr127586pjt.212.1628975908528; Sat, 14 Aug 2021 14:18:28 -0700 (PDT) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id r9sm6655499pfh.135.2021.08.14.14.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Aug 2021 14:18:28 -0700 (PDT) From: Yury Norov To: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mmc@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, "James E.J. Bottomley" , Alexander Lobakin , Alexander Shishkin , Alexey Klimov , Andrea Merello , Andy Shevchenko , Arnaldo Carvalho de Melo , Arnd Bergmann , Ben Gardon , Benjamin Herrenschmidt , Brian Cain , Catalin Marinas , Christoph Lameter , Daniel Bristot de Oliveira , David Hildenbrand , Dennis Zhou , Geert Uytterhoeven , Heiko Carstens , Ian Rogers , Ingo Molnar , Jaegeuk Kim , Jakub Kicinski , Jiri Olsa , Joe Perches , Jonas Bonn , Leo Yan , Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paolo Bonzini , Peter Xu , Peter Zijlstra , Petr Mladek , Rasmus Villemoes , Rich Felker , Samuel Mendoza-Jonas , Sean Christopherson , Sergey Senozhatsky , Shuah Khan , Stefan Kristiansson , Steven Rostedt , Tejun Heo , Thomas Bogendoerfer , Ulf Hansson , Will Deacon , Wolfram Sang , Yoshinori Sato , Yury Norov Subject: [PATCH 09/17] cpumask: replace cpumask_next_* with cpumask_first_* where appropriate Date: Sat, 14 Aug 2021 14:17:05 -0700 Message-Id: <20210814211713.180533-10-yury.norov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210814211713.180533-1-yury.norov@gmail.com> References: <20210814211713.180533-1-yury.norov@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9F2DB7002B86 X-Stat-Signature: rzwko96r5e8h93bj45xyikegc9z51kqr Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=dR0YXJfN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of yurynorov@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=yurynorov@gmail.com X-HE-Tag: 1628975909-411193 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: cpumask_first() is a more effective analogue of 'next' version if n =3D=3D= -1 (which means start =3D=3D 0). This patch replaces 'next' with 'first' whe= re things look trivial. There's no cpumask_first_zero() function, so create it. Signed-off-by: Yury Norov Tested-by: Wolfram Sang --- arch/powerpc/include/asm/cputhreads.h | 2 +- block/blk-mq.c | 2 +- drivers/net/virtio_net.c | 2 +- drivers/soc/fsl/qbman/bman_portal.c | 2 +- drivers/soc/fsl/qbman/qman_portal.c | 2 +- include/linux/cpumask.h | 16 ++++++++++++++++ kernel/time/clocksource.c | 4 ++-- 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/include/asm/cputhreads.h b/arch/powerpc/include= /asm/cputhreads.h index b167186aaee4..44286df21d2a 100644 --- a/arch/powerpc/include/asm/cputhreads.h +++ b/arch/powerpc/include/asm/cputhreads.h @@ -52,7 +52,7 @@ static inline cpumask_t cpu_thread_mask_to_cores(const = struct cpumask *threads) for (i =3D 0; i < NR_CPUS; i +=3D threads_per_core) { cpumask_shift_left(&tmp, &threads_core_mask, i); if (cpumask_intersects(threads, &tmp)) { - cpu =3D cpumask_next_and(-1, &tmp, cpu_online_mask); + cpu =3D cpumask_first_and(&tmp, cpu_online_mask); if (cpu < nr_cpu_ids) cpumask_set_cpu(cpu, &res); } diff --git a/block/blk-mq.c b/block/blk-mq.c index 3ab4540320ca..39c38a8a996d 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2544,7 +2544,7 @@ static bool blk_mq_hctx_has_requests(struct blk_mq_= hw_ctx *hctx) static inline bool blk_mq_last_cpu_in_hctx(unsigned int cpu, struct blk_mq_hw_ctx *hctx) { - if (cpumask_next_and(-1, hctx->cpumask, cpu_online_mask) !=3D cpu) + if (cpumask_first_and(hctx->cpumask, cpu_online_mask) !=3D cpu) return false; if (cpumask_next_and(cpu, hctx->cpumask, cpu_online_mask) < nr_cpu_ids) return false; diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 2e42210a6503..7fb87f8a7973 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2080,7 +2080,7 @@ static void virtnet_set_affinity(struct virtnet_inf= o *vi) stragglers =3D num_cpu >=3D vi->curr_queue_pairs ? num_cpu % vi->curr_queue_pairs : 0; - cpu =3D cpumask_next(-1, cpu_online_mask); + cpu =3D cpumask_first(cpu_online_mask); =20 for (i =3D 0; i < vi->curr_queue_pairs; i++) { group_size =3D stride + (i < stragglers ? 1 : 0); diff --git a/drivers/soc/fsl/qbman/bman_portal.c b/drivers/soc/fsl/qbman/= bman_portal.c index acda8a5637c5..4d7b9caee1c4 100644 --- a/drivers/soc/fsl/qbman/bman_portal.c +++ b/drivers/soc/fsl/qbman/bman_portal.c @@ -155,7 +155,7 @@ static int bman_portal_probe(struct platform_device *= pdev) } =20 spin_lock(&bman_lock); - cpu =3D cpumask_next_zero(-1, &portal_cpus); + cpu =3D cpumask_first_zero(&portal_cpus); if (cpu >=3D nr_cpu_ids) { __bman_portals_probed =3D 1; /* unassigned portal, skip init */ diff --git a/drivers/soc/fsl/qbman/qman_portal.c b/drivers/soc/fsl/qbman/= qman_portal.c index 96f74a1dc603..e23b60618c1a 100644 --- a/drivers/soc/fsl/qbman/qman_portal.c +++ b/drivers/soc/fsl/qbman/qman_portal.c @@ -248,7 +248,7 @@ static int qman_portal_probe(struct platform_device *= pdev) pcfg->pools =3D qm_get_pools_sdqcr(); =20 spin_lock(&qman_lock); - cpu =3D cpumask_next_zero(-1, &portal_cpus); + cpu =3D cpumask_first_zero(&portal_cpus); if (cpu >=3D nr_cpu_ids) { __qman_portals_probed =3D 1; /* unassigned portal, skip init */ diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 4a03f6636e6c..f5883a8f28ca 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -123,6 +123,11 @@ static inline unsigned int cpumask_first(const struc= t cpumask *srcp) return 0; } =20 +static inline unsigned int cpumask_first_zero(const struct cpumask *srcp= ) +{ + return 0; +} + static inline unsigned int cpumask_first_and(const struct cpumask *srcp1= , const struct cpumask *srcp2) { @@ -201,6 +206,17 @@ static inline unsigned int cpumask_first(const struc= t cpumask *srcp) return find_first_bit(cpumask_bits(srcp), nr_cpumask_bits); } =20 +/** + * cpumask_first_zero - get the first unset cpu in a cpumask + * @srcp: the cpumask pointer + * + * Returns >=3D nr_cpu_ids if all cpus are set. + */ +static inline unsigned int cpumask_first_zero(const struct cpumask *srcp= ) +{ + return find_first_zero_bit(cpumask_bits(srcp), nr_cpumask_bits); +} + /** * cpumask_first_and - return the first cpu from *srcp1 & *srcp2 * @src1p: the first input diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index b038b81f8d32..2f170383b00a 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -262,7 +262,7 @@ static void clocksource_verify_choose_cpus(void) return; =20 /* Make sure to select at least one CPU other than the current CPU. */ - cpu =3D cpumask_next(-1, cpu_online_mask); + cpu =3D cpumask_first(cpu_online_mask); if (cpu =3D=3D smp_processor_id()) cpu =3D cpumask_next(cpu, cpu_online_mask); if (WARN_ON_ONCE(cpu >=3D nr_cpu_ids)) @@ -284,7 +284,7 @@ static void clocksource_verify_choose_cpus(void) cpu =3D prandom_u32() % nr_cpu_ids; cpu =3D cpumask_next(cpu - 1, cpu_online_mask); if (cpu >=3D nr_cpu_ids) - cpu =3D cpumask_next(-1, cpu_online_mask); + cpu =3D cpumask_first(cpu_online_mask); if (!WARN_ON_ONCE(cpu >=3D nr_cpu_ids)) cpumask_set_cpu(cpu, &cpus_chosen); } --=20 2.30.2