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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0E53C43217 for ; Tue, 5 Oct 2021 05:41:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 86B54610FB for ; Tue, 5 Oct 2021 05:41:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 86B54610FB 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 2A4376B007E; Tue, 5 Oct 2021 01:41:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2537C900002; Tue, 5 Oct 2021 01:41:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CD366B0081; Tue, 5 Oct 2021 01:41:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id F32006B007E for ; Tue, 5 Oct 2021 01:41:26 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B32452CBCE for ; Tue, 5 Oct 2021 05:41:26 +0000 (UTC) X-FDA: 78661286172.27.DE1747D Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf04.hostedemail.com (Postfix) with ESMTP id 72319500153C for ; Tue, 5 Oct 2021 05:41:26 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id 66so18333248pgc.9 for ; Mon, 04 Oct 2021 22:41:26 -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=PN1SnsAr5qtcccHhg1TXrsqv+SN4IjsrbS3fnYHlx48=; b=nTEY1+qTJaEFsV4dMUSRInRVjU5PmvSR+bq2viqVuFW4zLuYhON05f27dmvEp+Of/v PjM0BenijyhPSLUGByu3U14Z323wLir16Z5TPlIvMgTvvs/tKr6FRK4WxBsy6e1A1gE7 1Nn4aK5V3lHKyMqzdOq5AqRF8rLLQyYb/Sz374i0x6RCqo9avGOlQCNuoR84x9mpifu0 HDJFQ0xQCETwZ3QeE78H4Q5s0a6tPCB8InTjdgwTnUMy57xuX4k8vucrfDP2LielaV7/ W5NXQh6iuY/FR0b74ckdzOPXRQ7koZFuijHvtc+OCHwPj22Oe550c26EkXgRpjCHjC/3 o4+w== 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=PN1SnsAr5qtcccHhg1TXrsqv+SN4IjsrbS3fnYHlx48=; b=TRb05QLYGku/Oonh8WzhXZGaGaO4rXLZF0XDnyma1OL70E4lOemEEz4FqztTmz2EDO c7Lstu4r/UgfhJ0G+JnV+6jcXovcBXoRQ4iuW3biGA88mmHxfSnj4EXsRSIKETEyY4kB rfjGmj3R9IKo7pmMhptGOprgkbaKkMBVo8/FPu3V58932dhMdDLHqfZ6XasFT9n62g3h zyL2lTntktw6lGxnyifpJb2JSMXjfQ4IE3GqRfT5my5zN+PNXxFuob0f+ILIPVN4zM1y 8zOcFjC+m4s4Y1k0RCBSsYow1cWyj2Eh9tcumgKzqP2tyXHtX4VJ4tAHxlpU+MTlJeBJ pXaA== X-Gm-Message-State: AOAM533jzGAcoJzL746C5fl6Ch/LogcRAs7qkg+MeuWZYZ63DccH98fu x2oUvAqwhA/8m4wv0ZNDjK4= X-Google-Smtp-Source: ABdhPJy4xT5z1reZAEMRl4Zo/gyKf7y4Xhui/F+FUAn6N2CEUOisZ8Bwxqia7dhoUC4OzTnFiC7HCQ== X-Received: by 2002:aa7:97bc:0:b0:44c:53f:fbd with SMTP id d28-20020aa797bc000000b0044c053f0fbdmr25161717pfq.19.1633412485481; Mon, 04 Oct 2021 22:41:25 -0700 (PDT) Received: from localhost (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id g3sm15719059pgj.66.2021.10.04.22.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Oct 2021 22:41:25 -0700 (PDT) From: Yury Norov To: Stephen Rothwell Cc: Yury Norov , 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 Subject: [PATCH 09/16] cpumask: replace cpumask_next_* with cpumask_first_* where appropriate Date: Mon, 4 Oct 2021 22:40:52 -0700 Message-Id: <20211005054059.475634-10-yury.norov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211005054059.475634-1-yury.norov@gmail.com> References: <20211005054059.475634-1-yury.norov@gmail.com> MIME-Version: 1.0 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=nTEY1+qT; spf=pass (imf04.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=yury.norov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 72319500153C X-Stat-Signature: hxbmp1g3m37sqn77f7cr8weit8o9zyxh X-HE-Tag: 1633412486-95896 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 108a352051be..d4f5a05f4470 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2536,7 +2536,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 79bd2585ec6b..a3b16790846c 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2085,7 +2085,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 c7be6c5b7523..862856fe0056 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 b8a14d2fb5ba..f29d1a524fa5 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -257,7 +257,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)) @@ -279,7 +279,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