From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C0CDC433EF for ; Thu, 10 Feb 2022 22:54:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345308AbiBJWyE (ORCPT ); Thu, 10 Feb 2022 17:54:04 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238083AbiBJWyB (ORCPT ); Thu, 10 Feb 2022 17:54:01 -0500 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AD0F55A4; Thu, 10 Feb 2022 14:54:02 -0800 (PST) Received: by mail-io1-xd2d.google.com with SMTP id h7so9358264iof.3; Thu, 10 Feb 2022 14:54:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=VUKtrHLt0fjPmTgGEZzFREYA4A6F0kdoS7SyUvKa0qA=; b=O4LOqpJXDQnBxYPr0uj95YnMfkewxiGbbQ/CJY8h9XDEPOvDjwh5qXW6DLwNj/4efC P5rQp/xAmEmeII8/061Ts7JTt7EVmLB+11xoYOuxl7Aj0qEYkDOLJXycZvl5sufYs5DF 4vgFdiDGtrUyNKnS0E80RAJT2kAGsFDMrBOB59uXItyZqs3bPTBgtjGn6yYWYd71QIEW 8KOtB1BJ6WgWf06cjSV8ERv8TMMgsw5f8McINFBn9SGaJ/oPcElXl8/Qyis/NPO2ABMh WOFjIQmst1HJnqh3/u46Cy212ZQva5eXTTBHPDZw+ohS/wXIhQ4nIa2v1/cyXJNuAQAX FndA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VUKtrHLt0fjPmTgGEZzFREYA4A6F0kdoS7SyUvKa0qA=; b=ChNSB6q5ku8zlDdlNMr7s6ZV4KdXrcvnRGXcNXTUii0pJwXgivl1Ag29XMp9HHeYQn teG2SSycs0FxW6k+SJZvPBwY0YOnT33z6or8FFwz+l+Fl9A7vdiTIjAd67bBxJBxzzOF D1g5u65zm4HSUw7PolBbfrja/d6FPUjxfLN6A8tmZOGcSzRBLYl2xIPlyijjeNf3+MfH wazvh9dMghQFf9xfgBJLW+5hbqVFGtLqog9IqCCt9jbv94fQRZGnWVAwKLWhX1pQkaOc uNBHynbqVVnoLIoCbOaaJ5JOOpy66LRYwYpf4hiORQtMuvwWSz3wr6X4ivc2bEqSusHP jA+g== X-Gm-Message-State: AOAM530oEcxM0DdC/p7UYeWBrAYcCcFWtZliBpATdg8cqsPBWLHXQqrg i2GqOUZX8dmSWqOY1ENYTh4= X-Google-Smtp-Source: ABdhPJzaRpwSbO6X1WBTl+WfBx/q4TwWiCIEqIJ9Q6DkzZZR70REkK2F4cQiJwbzEUceoLbWMe36Mg== X-Received: by 2002:a02:cd0a:: with SMTP id g10mr5229490jaq.223.1644533641691; Thu, 10 Feb 2022 14:54:01 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id a15sm6591675ilq.24.2022.02.10.14.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 14:54:01 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Subject: [PATCH 01/49] net: dsa: don't use bitmap_weight() in b53_arl_read() Date: Thu, 10 Feb 2022 14:48:45 -0800 Message-Id: <20220210224933.379149-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Don't call bitmap_weight() if the following code can get by without it. Signed-off-by: Yury Norov Acked-by: Florian Fainelli --- drivers/net/dsa/b53/b53_common.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_com= mon.c index a3b98992f180..d99813bf3cdd 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -1620,12 +1620,8 @@ static int b53_arl_read(struct b53_device *dev, u64 = mac, return 0; } =20 - if (bitmap_weight(free_bins, dev->num_arl_bins) =3D=3D 0) - return -ENOSPC; - *idx =3D find_first_bit(free_bins, dev->num_arl_bins); - - return -ENOENT; + return *idx >=3D dev->num_arl_bins ? -ENOSPC : -ENOENT; } =20 static int b53_arl_op(struct b53_device *dev, int op, int port, --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AAB3C433F5 for ; Thu, 10 Feb 2022 22:56:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345346AbiBJW4S (ORCPT ); Thu, 10 Feb 2022 17:56:18 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:44046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344698AbiBJW4P (ORCPT ); Thu, 10 Feb 2022 17:56:15 -0500 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D213A55A4; Thu, 10 Feb 2022 14:56:15 -0800 (PST) Received: by mail-qv1-xf31.google.com with SMTP id a28so6647069qvb.10; Thu, 10 Feb 2022 14:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=U+3vkzFEGdGmmOjt1hV/DkqJX2a2lDje4tkvz+fEZaQ=; b=MFInfE/srC1pPDAgWjrnrRsQPNZIeBeOJeGNEpcwJWUHy5BMVWL1fOMhBwZlPtHJ7U 5+f1DO4pOifTAEDBOPhFoA/C+0OyKnEvmniHExfoa6cTBor9+2wvjUlLQzfxqeEybm6x qfWlqqfDBqMeSdLtUXEtDSRryd+N7lu01bXnLYqvyo4/FLvUFyU4wZhtVt6jvLtVSECd cOuSyWxl738PHxvFhnUvNoeVKQigAJ6KajAfW0lsUfEAMrvkcq+FyMbshLeXQjStCI0k b6MEWuwYm17L7/+dtp8iAPjFhhLX/TUU5rfVoBX6mQtu/ioNLZ9o8CSaMO4yQWr5+vEO SLPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U+3vkzFEGdGmmOjt1hV/DkqJX2a2lDje4tkvz+fEZaQ=; b=Jij3xI+ZDRGhCfg92+HwenrtsDp8cz0RK+VUAyv6qf6609SToArghho8x0sizok/hi j404Z9aBc/thtlUg8Lkfxk67SVdeH33PnTTGA0908QTNTe0/YD2mR8NK8tYBHDESMpgf 6/2eTwb/BQq7ZPpiX47I3V0gZEAGKbenDXLRUTJD1/2sfKKdc3igknFedJRbzDPwD/P+ ZrFM+KM8QH2xzOIkN/ySfTGJ+vcRbrC9/w3mRUvxGPm6xR+YT7THNCFLM3vEgUO4TAQr 17+HvrO4E36IUrRuRvhRliZn0hR7mS7WjWAOdXYu8bQqlEFjbN1otsUYukp6kmv5PX6J 9tJA== X-Gm-Message-State: AOAM530AVFC6wCWZ0bXL5zqjOdP8QaPnmzsG9edPF4Xdc17gv/fH1fd6 g0YP8GOdRykwNegTR40ORao= X-Google-Smtp-Source: ABdhPJwtwRaFQJWdH3kBC2E+PysWAfr7+FtW7sdEitaMsJ++lw+fh4m6p8FaQrmqF1WnluhFWEb7Zw== X-Received: by 2002:a05:6214:401c:: with SMTP id kd28mr2551247qvb.111.1644533774923; Thu, 10 Feb 2022 14:56:14 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id g17sm9045729qkl.122.2022.02.10.14.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 14:56:14 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Florian Fainelli , "David S . Miller " , Jakub Kicinski , bcm-kernel-feedback-list@broadcom.com, netdev@vger.kernel.org Subject: [PATCH 02/49] net: systemport: don't use bitmap_weight() in bcm_sysport_rule_set() Date: Thu, 10 Feb 2022 14:48:46 -0800 Message-Id: <20220210224933.379149-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Don't call bitmap_weight() if the following code can get by without it. Signed-off-by: Yury Norov Acked-by: Florian Fainelli --- drivers/net/ethernet/broadcom/bcmsysport.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ether= net/broadcom/bcmsysport.c index 60dde29974bf..5284a5c961db 100644 --- a/drivers/net/ethernet/broadcom/bcmsysport.c +++ b/drivers/net/ethernet/broadcom/bcmsysport.c @@ -2180,13 +2180,9 @@ static int bcm_sysport_rule_set(struct bcm_sysport_p= riv *priv, if (nfc->fs.ring_cookie !=3D RX_CLS_FLOW_WAKE) return -EOPNOTSUPP; =20 - /* All filters are already in use, we cannot match more rules */ - if (bitmap_weight(priv->filters, RXCHK_BRCM_TAG_MAX) =3D=3D - RXCHK_BRCM_TAG_MAX) - return -ENOSPC; - index =3D find_first_zero_bit(priv->filters, RXCHK_BRCM_TAG_MAX); if (index >=3D RXCHK_BRCM_TAG_MAX) + /* All filters are already in use, we cannot match more rules */ return -ENOSPC; =20 /* Location is the classification ID, and index is the position --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66AFBC433F5 for ; Thu, 10 Feb 2022 22:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345377AbiBJW63 (ORCPT ); Thu, 10 Feb 2022 17:58:29 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345076AbiBJW62 (ORCPT ); Thu, 10 Feb 2022 17:58:28 -0500 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84655D55; Thu, 10 Feb 2022 14:58:28 -0800 (PST) Received: by mail-io1-xd32.google.com with SMTP id y84so9453406iof.0; Thu, 10 Feb 2022 14:58:28 -0800 (PST) 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=XYy86s2wR72p6r/7wpjvLb/OKofqlzUO1lKoSKLkUaY=; b=GfoXmsy9OpsI0OUdTBsf8IR4ajwQp9B61y2YZqssjRjF7V9z7xqXziZfHGBkYCwCmL 1PSWc90PT5G4wzh9ekZWXyslsjc1Y1Q7D8Ee3FLuxB6QT6k+8y1SOSs3OIDzWzKxgqpk ktHoLe1XdTac0DYooEO+3f3cr0hGiVyfxFjeTkTNzcVIUjWhfU/tfuf5Rnmh6KU4OC0X JcT+eq7/YHjTgDRfj3+c73PFTx+1egKj1wf4d5iWa8rl6pfzvFao/GP7BhzwFpqOFRYb 5JE2/VJ86qCSIKiaLm8GcX8qbB2Vg7d4YHygBKfsOq633OCB0JpJh5yRRhQvwEJ5+Q45 DPUA== 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=XYy86s2wR72p6r/7wpjvLb/OKofqlzUO1lKoSKLkUaY=; b=sOYvopSbh4lLJzlifYTnejloyTo9lFe6lzvmeM4pKAvUwTrQBa2CGZXFY3qOjjWBPg kvx+CjS9n2SfI+ZASwF72fV9WGXNH922uF512gwze76V2lHnC3Nn8U9lh4gHBdSyp9hN N96Vb6sxQ2LrIG7uOwS1Scvw1tKc7uCWWG6WAlW0QLM8OtpUXNRMjdb20O1KFiG11CVC jYv/VVUQDqIxSbsNO1PSPMoS6ohKLEv3tFRzy7ijKHxlUE80llQmkD96pZHOClOC7ygC 5gVt27l2U52Xd+SKZeP61OcbgBUoY90/eaO/1meQqRyNmHMFE9Ip6Y8o2MoQ5PgCV4l9 JbCA== X-Gm-Message-State: AOAM530Ye91i7AjMEE8pC16470LNkAUlyx5+eo3g5CAO0lE9zidY89uj zkwPEZKcheoMC0w2MvMDNyk= X-Google-Smtp-Source: ABdhPJzrMeXGVC4jElCJVqUIPD6D/g/ZpwjVl5H+pjBDEX7x9b74y2u2c99GD7i+ELA1S4TT7Vmizw== X-Received: by 2002:a6b:720f:: with SMTP id n15mr4925855ioc.158.1644533907800; Thu, 10 Feb 2022 14:58:27 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id r7sm5726416ilm.14.2022.02.10.14.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 14:58:27 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Sebastian Andrzej Siewior , Christophe JAILLET , Rikard Falkeborn , linux-pm@vger.kernel.org Cc: Tariq Toukan Subject: [PATCH 03/49] net: mellanox: fix open-coded for_each_set_bit() Date: Thu, 10 Feb 2022 14:48:47 -0800 Message-Id: <20220210224933.379149-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Mellanox driver has an open-coded for_each_set_bit(). Fix it. Signed-off-by: Yury Norov Reviewed-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx4/cmd.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/etherne= t/mellanox/mlx4/cmd.c index e10b7b04b894..c56d2194cbfc 100644 --- a/drivers/net/ethernet/mellanox/mlx4/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c @@ -1994,21 +1994,16 @@ static void mlx4_allocate_port_vpps(struct mlx4_dev= *dev, int port) =20 static int mlx4_master_activate_admin_state(struct mlx4_priv *priv, int sl= ave) { - int port, err; + int p, port, err; struct mlx4_vport_state *vp_admin; struct mlx4_vport_oper_state *vp_oper; struct mlx4_slave_state *slave_state =3D &priv->mfunc.master.slave_state[slave]; struct mlx4_active_ports actv_ports =3D mlx4_get_active_ports( &priv->dev, slave); - int min_port =3D find_first_bit(actv_ports.ports, - priv->dev.caps.num_ports) + 1; - int max_port =3D min_port - 1 + - bitmap_weight(actv_ports.ports, priv->dev.caps.num_ports); =20 - for (port =3D min_port; port <=3D max_port; port++) { - if (!test_bit(port - 1, actv_ports.ports)) - continue; + for_each_set_bit(p, actv_ports.ports, priv->dev.caps.num_ports) { + port =3D p + 1; priv->mfunc.master.vf_oper[slave].smi_enabled[port] =3D priv->mfunc.master.vf_admin[slave].enable_smi[port]; vp_oper =3D &priv->mfunc.master.vf_oper[slave].vport[port]; @@ -2063,19 +2058,13 @@ static int mlx4_master_activate_admin_state(struct = mlx4_priv *priv, int slave) =20 static void mlx4_master_deactivate_admin_state(struct mlx4_priv *priv, int= slave) { - int port; + int p, port; struct mlx4_vport_oper_state *vp_oper; struct mlx4_active_ports actv_ports =3D mlx4_get_active_ports( &priv->dev, slave); - int min_port =3D find_first_bit(actv_ports.ports, - priv->dev.caps.num_ports) + 1; - int max_port =3D min_port - 1 + - bitmap_weight(actv_ports.ports, priv->dev.caps.num_ports); =20 - - for (port =3D min_port; port <=3D max_port; port++) { - if (!test_bit(port - 1, actv_ports.ports)) - continue; + for_each_set_bit(p, actv_ports.ports, priv->dev.caps.num_ports) { + port =3D p + 1; priv->mfunc.master.vf_oper[slave].smi_enabled[port] =3D MLX4_VF_SMI_DISABLED; vp_oper =3D &priv->mfunc.master.vf_oper[slave].vport[port]; --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E007C433FE for ; Thu, 10 Feb 2022 23:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345247AbiBJXAo (ORCPT ); Thu, 10 Feb 2022 18:00:44 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344698AbiBJXAm (ORCPT ); Thu, 10 Feb 2022 18:00:42 -0500 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05AB21105; Thu, 10 Feb 2022 15:00:43 -0800 (PST) Received: by mail-il1-x134.google.com with SMTP id e8so5588189ilm.13; Thu, 10 Feb 2022 15:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=r7B1u3StVmNn+cEV4ztOlK7kYJWbJkFyeLauH29gYM8=; b=dzLBz2h9W3+P1fTFVwJCXjMzkDS/do2ayswvINxgwRV6LLNSkbDxlUQcxdk+LJZ5Gx vwqdX6D12rc1Yvd9fQaPcwN9sVvGOovH2iqr9zxZY7dauw3jnWm/j6Ep0mU30c80bSMn x0XJB822IsAmPLlczCETi3PVgDyd0smheFP2USkn/XObVyW1NxHYcT0aTPxrxtrBTRYb xBuWoEUXkdw3rPyD+c8jdwY2BMCXVdxzxFDgblYiKQjVEL6J813R1xNRtcpVL4OQ0a7u fhfqQFn9ElMVCLQ6Sq8p4ZBLU1HYI1JL0a8nEn94OxrS6Mh7CubSmLYNEUawMDPT+DL4 V42g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r7B1u3StVmNn+cEV4ztOlK7kYJWbJkFyeLauH29gYM8=; b=JYbrZX5/FO5si8lHPf+AzsAUwkBUJgaAl7Yn7PRPyZwtMwA2kk32CdCwLLyhEsMUf0 Eqmw3Hu03yJdf1M/HEaFivr7GdNAUETVnIB+CAYZEu/O6zPbrUOciCEw0gVhBH/6Hd14 wFoF5BWBvWIy6LJdNR0xK8leWG0d6ACLurnIjYNVog7lzu7086875h7k1fkRTsOC8nnR ZUTyViEiI3AT01R/lquqMVdPlUdKHPs1782F06GtYcv6Q8ZkzwKCGtK200lrtupWy08d fyL+WKJHW579cJKRT+ufO217XxkiyEGyT9IThPtbdUx6u7Hjt38JC+gnjMqKeg6t+l+g V4sw== X-Gm-Message-State: AOAM532gfznWk9reF0lj1jgrtS69IiyJ0w8O+vDQvAooN4w3QCTZM9sY andOPrXBKsmPxHFx4UV4CNI= X-Google-Smtp-Source: ABdhPJyDaHsNtIqicj2d5g0OLH9mju+tDwyc+D9hx93ef0eytT5AHJVFdIVfEcBuRUZkUUoFK32Fgg== X-Received: by 2002:a05:6e02:1d12:: with SMTP id i18mr4925637ila.323.1644534042346; Thu, 10 Feb 2022 15:00:42 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id y9sm7235385ilg.58.2022.02.10.15.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:00:41 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Jonathan Cameron , Lars-Peter Clausen , Alexandru Ardelean , Nathan Chancellor , linux-iio@vger.kernel.org Subject: [PATCH 04/49] iio: fix opencoded for_each_set_bit() Date: Thu, 10 Feb 2022 14:48:48 -0800 Message-Id: <20220210224933.379149-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" iio_simple_dummy_trigger_h() is mostly an opencoded for_each_set_bit(). Using for_each_set_bit() make code much cleaner, and more effective. Signed-off-by: Yury Norov Reviewed-by: Andy Shevchenko --- drivers/iio/dummy/iio_simple_dummy_buffer.c | 48 ++++++++------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/drivers/iio/dummy/iio_simple_dummy_buffer.c b/drivers/iio/dumm= y/iio_simple_dummy_buffer.c index d81c2b2dad82..3bc1b7529e2a 100644 --- a/drivers/iio/dummy/iio_simple_dummy_buffer.c +++ b/drivers/iio/dummy/iio_simple_dummy_buffer.c @@ -45,41 +45,31 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, = void *p) { struct iio_poll_func *pf =3D p; struct iio_dev *indio_dev =3D pf->indio_dev; + int i =3D 0, j; u16 *data; =20 data =3D kmalloc(indio_dev->scan_bytes, GFP_KERNEL); if (!data) goto done; =20 - if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) { - /* - * Three common options here: - * hardware scans: certain combinations of channels make - * up a fast read. The capture will consist of all of them. - * Hence we just call the grab data function and fill the - * buffer without processing. - * software scans: can be considered to be random access - * so efficient reading is just a case of minimal bus - * transactions. - * software culled hardware scans: - * occasionally a driver may process the nearest hardware - * scan to avoid storing elements that are not desired. This - * is the fiddliest option by far. - * Here let's pretend we have random access. And the values are - * in the constant table fakedata. - */ - int i, j; - - for (i =3D 0, j =3D 0; - i < bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); - i++, j++) { - j =3D find_next_bit(indio_dev->active_scan_mask, - indio_dev->masklength, j); - /* random access read from the 'device' */ - data[i] =3D fakedata[j]; - } - } + /* + * Three common options here: + * hardware scans: certain combinations of channels make + * up a fast read. The capture will consist of all of them. + * Hence we just call the grab data function and fill the + * buffer without processing. + * software scans: can be considered to be random access + * so efficient reading is just a case of minimal bus + * transactions. + * software culled hardware scans: + * occasionally a driver may process the nearest hardware + * scan to avoid storing elements that are not desired. This + * is the fiddliest option by far. + * Here let's pretend we have random access. And the values are + * in the constant table fakedata. + */ + for_each_set_bit(j, indio_dev->active_scan_mask, indio_dev->masklength) + data[i++] =3D fakedata[j]; =20 iio_push_to_buffers_with_timestamp(indio_dev, data, iio_get_time_ns(indio_dev)); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AACAAC433FE for ; Thu, 10 Feb 2022 23:03:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345392AbiBJXC6 (ORCPT ); Thu, 10 Feb 2022 18:02:58 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345039AbiBJXCy (ORCPT ); Thu, 10 Feb 2022 18:02:54 -0500 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E0CD1107; Thu, 10 Feb 2022 15:02:54 -0800 (PST) Received: by mail-il1-x12f.google.com with SMTP id m8so5613457ilg.7; Thu, 10 Feb 2022 15:02:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=x5y11i0zdnz/BX0MaBmAp+uRfUX2Rak/fHPY7uFI9V0=; b=CSDL1Vj/nWsuuxYBwx/1wZqFN7bmDSB+ohNjATtPUS/FmhKwM8U3HzQsAuHa9fxhdw 4Jz3dKN1fN/o+4qihImxLWv+8hHfE0gxZLyEK1R//WED6Y4hZewiadnqdFSpUy5z0lxd lmW8scFb12dfcMOtEH2AdhXB3ZaHAM6AzRoLsapN1LJb1Ng2nN7e6DuYgJSNhKBPQv37 Za/uaPxa9OZzjDClHWB4tE9R4ub2sYccHlPLr9lZL9ZjugJwdvgdi67a+QlwHiDQXNF8 gufo35FdLMxm4rYABpmBVhdRWQxoj1egoyHZJzvxhzdCt+PUML3+Uln5r0OWfgGCDVoa uptw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x5y11i0zdnz/BX0MaBmAp+uRfUX2Rak/fHPY7uFI9V0=; b=1xg0xXMb9MCzKdp6ToWjUCV87e1WFC+7uyVu5Mc9AQ7v/YDo+F07OB1lZ6U0A9BXDr UxODn5JZ4LBwCrmND86/C4fiyyJ2rtSCXtH9eFoX/Whcdszza8w+y/RO1bkfeIS8pV+d Tnx2whCGX1aVfAwKihEp9ZCmqP64FFA+WtEgrX8MreEF+zLULxoj1ewBUa70qknnq/Lb xD+nGMSvQspGkHvPSbFHisFOVNivj8ShitbcKv3FgtOUeoewtaqlpSS+22weWT4xZ5K3 mTu3UXMp5njuvZNuR1zfOIEd0bmKj1OtIB7WaBSIIRw4kRtkbEeuM9HvRRxDZl3NDalJ K2tg== X-Gm-Message-State: AOAM5324b9HOfdIcdOoYESoY3tImeMnEzwgTZTb/LrKem461CNyn2moO 6Zm9ENFA6LidaM06OHfPpow= X-Google-Smtp-Source: ABdhPJzPA3K644w+KPqoBt0nZGj9yYw0gW84+vIzUuBQFk1Yiwg2zu/FkqSM3NWQY8+eYGjQJPYgSw== X-Received: by 2002:a05:6e02:1090:: with SMTP id r16mr5059802ilj.183.1644534173993; Thu, 10 Feb 2022 15:02:53 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id d12sm11567868ilv.42.2022.02.10.15.02.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:02:53 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Ariel Elior , Manish Chopra , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Subject: [RFC PATCH 05/49] qed: rework qed_rdma_bmap_free() Date: Thu, 10 Feb 2022 14:48:49 -0800 Message-Id: <20220210224933.379149-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" qed_rdma_bmap_free() is mostly an opencoded version of printk("%*pb"). Using %*pb format simplifies the code, and helps to avoid inefficient usage of bitmap_weight(). While here, reorganize logic to avoid calculating bmap weight if check is false. Signed-off-by: Yury Norov Reviewed-by: Andy Shevchenko --- This is RFC because it changes lines printing format to bitmap %*pb. If it hurts userspace, it's better to drop the patch. drivers/net/ethernet/qlogic/qed/qed_rdma.c | 45 +++++++--------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qed/qed_rdma.c b/drivers/net/ether= net/qlogic/qed/qed_rdma.c index 23b668de4640..f4c04af9d4dd 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_rdma.c +++ b/drivers/net/ethernet/qlogic/qed/qed_rdma.c @@ -319,44 +319,27 @@ static int qed_rdma_alloc(struct qed_hwfn *p_hwfn) void qed_rdma_bmap_free(struct qed_hwfn *p_hwfn, struct qed_bmap *bmap, bool check) { - int weight =3D bitmap_weight(bmap->bitmap, bmap->max_count); - int last_line =3D bmap->max_count / (64 * 8); - int last_item =3D last_line * 8 + - DIV_ROUND_UP(bmap->max_count % (64 * 8), 64); - u64 *pmap =3D (u64 *)bmap->bitmap; - int line, item, offset; - u8 str_last_line[200] =3D { 0 }; - - if (!weight || !check) + unsigned int bit, weight, nbits; + unsigned long *b; + + if (!check) + goto end; + + weight =3D bitmap_weight(bmap->bitmap, bmap->max_count); + if (!weight) goto end; =20 DP_NOTICE(p_hwfn, "%s bitmap not free - size=3D%d, weight=3D%d, 512 bits per line\n", bmap->name, bmap->max_count, weight); =20 - /* print aligned non-zero lines, if any */ - for (item =3D 0, line =3D 0; line < last_line; line++, item +=3D 8) - if (bitmap_weight((unsigned long *)&pmap[item], 64 * 8)) + for (bit =3D 0; bit < bmap->max_count; bit +=3D 512) { + b =3D bmap->bitmap + BITS_TO_LONGS(bit); + nbits =3D min(bmap->max_count - bit, 512); + + if (!bitmap_empty(b, nbits)) DP_NOTICE(p_hwfn, - "line 0x%04x: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%0= 16llx 0x%016llx 0x%016llx\n", - line, - pmap[item], - pmap[item + 1], - pmap[item + 2], - pmap[item + 3], - pmap[item + 4], - pmap[item + 5], - pmap[item + 6], pmap[item + 7]); - - /* print last unaligned non-zero line, if any */ - if ((bmap->max_count % (64 * 8)) && - (bitmap_weight((unsigned long *)&pmap[item], - bmap->max_count - item * 64))) { - offset =3D sprintf(str_last_line, "line 0x%04x: ", line); - for (; item < last_item; item++) - offset +=3D sprintf(str_last_line + offset, - "0x%016llx ", pmap[item]); - DP_NOTICE(p_hwfn, "%s\n", str_last_line); + "line 0x%04x: %*pb\n", bit / 512, nbits, b); } =20 end: --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24AD8C433EF for ; Thu, 10 Feb 2022 23:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345395AbiBJXFI (ORCPT ); Thu, 10 Feb 2022 18:05:08 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239716AbiBJXFG (ORCPT ); Thu, 10 Feb 2022 18:05:06 -0500 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 348011125; Thu, 10 Feb 2022 15:05:06 -0800 (PST) Received: by mail-qv1-xf30.google.com with SMTP id d7so6703065qvk.2; Thu, 10 Feb 2022 15:05:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=KXOSpbk+RXW+DBP53WQyWN4jwpILDSDDpj6Jr1j/OXk=; b=HI2mnNYtTkfI3G65nubNt3EonUdah48+r1Un+jjkwIm5WTUeKo1DSh7mwr1RNCRMgE bziELpIikolO6+XLfN0wr0paDV5evv5uQUe7vVM82nIsTufGcwsTZAklK8FgskeB/Gxs YgPcjoQxWhmMSZW92o3z3PKTdUgV6SSsVrFSHaVYahPoIiJ9jt9mz1ETwAec6RlUOezB PjTKHGc7yT7dL7Jk6cnosjN72yiOPlOXg2Z3zFIPWOIuIsIPzL/GRn8T29YfLAMDtaM7 hpgWjT8yH+viYHDWG/BFQtM59cR+p85vdEojzwXcypdnEpm5UXp9OFxTycC6GnmsV3Js azPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KXOSpbk+RXW+DBP53WQyWN4jwpILDSDDpj6Jr1j/OXk=; b=cpe/XXTxD2SxUfGsQWxJA8l+XqAtYwphlmDqQrnEzsF0sTWggfSPfJfXrpiUH8kv6f 22xiSVeASTR2fDs0j+ykJxhF9RXBC7FQmnwLwRKgYpXoDMooeuFWaMB3XpYm1Q/U1Dzy ts2N+dLKzW6GxUqrVh+rYcWah2cVArCdpvKYY6Z3J0lYs7aQ59ycw1mlz1TiTiTrljZo PnrVcou+fBSuGr28eLWRJPHGYbe6IWjQ+usY1dA51WV54CqDGTA0yuCyOdkci4eL8QWY fezdQGC3KV/vSj3rldAV5X3i0sEi2FRnI5Yjhkb/D6JnMyQnvIGIpQ9Kc8cOyqZG9+Xs JoXQ== X-Gm-Message-State: AOAM530zVrV0Ggq3KvwDh9FtTZ7RwVcuLPvUnizqLlAgad22dkt1xvdB 7Mi0O/TVA+BYgsWRHeLlbIc= X-Google-Smtp-Source: ABdhPJyoK1UXHarwQjdmthhpKPhuaMIGYQTI8x7ciOZ5He2zfHWTRwLo34b0L8nU6akmLcRZSIYSow== X-Received: by 2002:a05:6214:194d:: with SMTP id q13mr6709929qvk.8.1644534305337; Thu, 10 Feb 2022 15:05:05 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id w10sm12438294qtj.73.2022.02.10.15.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:05:04 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Nick Hu , Greentime Hu , Vincent Chen , linux-perf-users@vger.kernel.org Subject: [PATCH 06/49] nds32: perf: replace bitmap_weight with bitmap_empty where appropriate Date: Thu, 10 Feb 2022 14:48:50 -0800 Message-Id: <20220210224933.379149-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" nds32_pmu_enable calls bitmap_weight() to check if any bit of a given bitmap is set. It's better to use bitmap_empty() in that case because bitmap_empty() stops traversing the bitmap as soon as it finds first set bit, while bitmap_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- arch/nds32/kernel/perf_event_cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/nds32/kernel/perf_event_cpu.c b/arch/nds32/kernel/perf_ev= ent_cpu.c index a78a879e7ef1..ea44e9ecb5c7 100644 --- a/arch/nds32/kernel/perf_event_cpu.c +++ b/arch/nds32/kernel/perf_event_cpu.c @@ -695,7 +695,7 @@ static void nds32_pmu_enable(struct pmu *pmu) { struct nds32_pmu *nds32_pmu =3D to_nds32_pmu(pmu); struct pmu_hw_events *hw_events =3D nds32_pmu->get_hw_events(); - int enabled =3D bitmap_weight(hw_events->used_mask, + bool enabled =3D !bitmap_empty(hw_events->used_mask, nds32_pmu->num_events); =20 if (enabled) --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57F81C433EF for ; Thu, 10 Feb 2022 23:07:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345420AbiBJXHV (ORCPT ); Thu, 10 Feb 2022 18:07:21 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239716AbiBJXHS (ORCPT ); Thu, 10 Feb 2022 18:07:18 -0500 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5055655BB; Thu, 10 Feb 2022 15:07:19 -0800 (PST) Received: by mail-qt1-x833.google.com with SMTP id p14so7212026qtx.0; Thu, 10 Feb 2022 15:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=sS42IV/IyJJJQe1oR3KUsg/jNaiYCRP226dHL2TKSfc=; b=eocimBnfXPFWj8+E/eB1AYv5kSg66Mv6qkEhHGxwdqK6+dpi+peRet6nrjcRYlb1tJ HLjsHeS4HoimMpuxEg6Q1KFwlnDiLHRIUxX6DAS8BAJyYe1Wb5ZRuGjIJMKR1q4x1tax mR0v16h3AqcOHy0zSKKbFeKUUpHpXQKLT1K/LlXJmTYON2jCyhCt2CbAHCunDJet+SQf qB3xSxKlgbKAtVXuJt2VZ7Ky2ByxUPWa//VI9ZAvnNBy9epN/zB3cnDTCxQ9bKhG9BuX 3+3BcwaBmibYIEse7pP1iJqUGgPQy06oSK9nozPDLkXHxtbCOZzb3pzwlcco0UUiQ3qe mySw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sS42IV/IyJJJQe1oR3KUsg/jNaiYCRP226dHL2TKSfc=; b=lk6t8MLwgU2dFFqPnJwRFF3vFOnCc7KeDA7EdJASpDozZmB0ue7q1Wr7QBzJ8fouGk aPfiYoFK/4UF9xm7blwfJIwCLyxVTAKkEPxkcuG50WHLkU3WqSyBSbNOyqCflQklxPas s6yFFJC22a/qVrh5yzNk+jDWP40XViZ+igg15GYl1Pbni3ZTUvS9N4qiAat1fF0Q1eE3 /B4k5Ryq00hCq9me7kLRkQAao2CrHDuUE/PiHBcLHnut8Feq4EG3ew61oKc2WwrMNH2A tNhFicd6ayz4vcuzxdzgpvCYlo+Jam0wn+vdMTmFDL6wZn35Nq9kZNRpodxK/jAUO91V 7ETg== X-Gm-Message-State: AOAM5316ViZc0B6pYJGF7tq3pfuH8cfqM0uaq/Fes6fe0lvi/i9aSzs3 jsQXEwjcpsDt49w9oGyzC9A= X-Google-Smtp-Source: ABdhPJzsKhjH0E928PMWg14kbD+gJ7XaexanfTXEjOjfj8p4ucvwelQVCnWVujQwOdKeD0pnOszvBg== X-Received: by 2002:ac8:7f82:: with SMTP id z2mr6441488qtj.591.1644534438427; Thu, 10 Feb 2022 15:07:18 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id o13sm11924755qtv.36.2022.02.10.15.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:07:17 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org Subject: [PATCH 07/49] KVM: x86: replace bitmap_weight with bitmap_empty where appropriate Date: Thu, 10 Feb 2022 14:48:51 -0800 Message-Id: <20220210224933.379149-8-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In some places kvm/hyperv.c code calls bitmap_weight() to check if any bit of a given bitmap is set. It's better to use bitmap_empty() in that case because bitmap_empty() stops traversing the bitmap as soon as it finds first set bit, while bitmap_weight() counts all bits unconditionally. Signed-off-by: Yury Norov Reviewed-by: Vitaly Kuznetsov Reviewed-by: Sean Christopherson --- arch/x86/kvm/hyperv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 6e38a7d22e97..06c2a5603123 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -90,7 +90,7 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic = *synic, { struct kvm_vcpu *vcpu =3D hv_synic_to_vcpu(synic); struct kvm_hv *hv =3D to_kvm_hv(vcpu->kvm); - int auto_eoi_old, auto_eoi_new; + bool auto_eoi_old, auto_eoi_new; =20 if (vector < HV_SYNIC_FIRST_VALID_VECTOR) return; @@ -100,16 +100,16 @@ static void synic_update_vector(struct kvm_vcpu_hv_sy= nic *synic, else __clear_bit(vector, synic->vec_bitmap); =20 - auto_eoi_old =3D bitmap_weight(synic->auto_eoi_bitmap, 256); + auto_eoi_old =3D !bitmap_empty(synic->auto_eoi_bitmap, 256); =20 if (synic_has_vector_auto_eoi(synic, vector)) __set_bit(vector, synic->auto_eoi_bitmap); else __clear_bit(vector, synic->auto_eoi_bitmap); =20 - auto_eoi_new =3D bitmap_weight(synic->auto_eoi_bitmap, 256); + auto_eoi_new =3D !bitmap_empty(synic->auto_eoi_bitmap, 256); =20 - if (!!auto_eoi_old =3D=3D !!auto_eoi_new) + if (auto_eoi_old =3D=3D auto_eoi_new) return; =20 down_write(&vcpu->kvm->arch.apicv_update_lock); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70C46C4332F for ; Thu, 10 Feb 2022 23:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345445AbiBJXJd (ORCPT ); Thu, 10 Feb 2022 18:09:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238904AbiBJXJc (ORCPT ); Thu, 10 Feb 2022 18:09:32 -0500 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7646FC66; Thu, 10 Feb 2022 15:09:32 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id o3so7144365qtm.12; Thu, 10 Feb 2022 15:09:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Il/njuSffEOrDW4E6Z5WwCggqy6XxgY6UGpPrL0AIR4=; b=JHJhNoUxh9ZuIiGYQov/FCIzAnjDxw6DqtVPkL1Zy1CLrsVwmf/L1YO0+GvOXbDRZ1 pqP9mY9GzQYWTgjathqD6S833i3Jn5LhtxZir6zDdzPkcq0f+VaqtHxlBS6ulo5m01Uc 5DJQwrfoKFPrAReQX/OlzhfusR6gY3jUDmZ2vXh/MK0XJxvb+JBDrj+24HC4sMqKBH2x kal6x+3q2ykI4/TCu98o6Mozggc8N7XorGZWzB7iKSz5i9wIizC8TdU+Cz+wzu1nNQay JFJ9W+P6+SkdtD9v9e2pIYBVGBN0oQwzdYpdb3O/UPoDayEfqa2+ziM7S0gFtv3xwP3k JINw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Il/njuSffEOrDW4E6Z5WwCggqy6XxgY6UGpPrL0AIR4=; b=wij2CJmAo1Sp0oor3zOLtoYdXM4d3E+sJqga2rLIYQpwhx534e0hFSct8wQQrRaQhS NhPZkLGQEuHtXVV4ChYHwuJdD/euv+VwP9yyuFiIWk96GYs4wNdyPgLN0ynE2MpeDLoS HxH9UXgVAtiOks0S3JpR1+xKjmyO1giJT+WByxuxqZKsBRykOM1fDkuNPhCqpmGKecJv kwn/Tv3Qx7HGk5O8T70c7VaHeEF4q3rBVR23YkKUDazxCA5XxBRTZxIaYZ+Xu+8b8/nb 0NdTEcCpH7JGBGcHjbDk4usEK1lqOpaKKSwAuSkv2P2r3Lw+AbQqTPQtnZdhmgvYjh7q Xb8w== X-Gm-Message-State: AOAM531n4VugdfmWm5lXpAOD1/sDzuv0QK0YGPZbuWtZKmH17QvNqVyA C/IU3zPms1zPU9BBKi40vkc= X-Google-Smtp-Source: ABdhPJyv7MT5wCGfdlfCLRk0wYTBM2q1x++ztUAm4XQN4J6MUGrqRSzzk5Brej8rnmEAO7fi58Ap6g== X-Received: by 2002:a05:622a:1304:: with SMTP id v4mr6649618qtk.359.1644534571568; Thu, 10 Feb 2022 15:09:31 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id s6sm11824113qtw.18.2022.02.10.15.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:09:31 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Rob Clark , Sean Paul , Abhinav Kumar , David Airlie , Daniel Vetter , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org Subject: [PATCH 08/49] drm: replace bitmap_weight with bitmap_empty where appropriate Date: Thu, 10 Feb 2022 14:48:52 -0800 Message-Id: <20220210224933.379149-9-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" smp_request_block() in drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c calls bitmap_weight() to check if any bit of a given bitmap is set. It's better to use bitmap_empty() in that case because bitmap_empty() stops traversing the bitmap as soon as it finds first set bit, while bitmap_weight() counts all bits unconditionally. Signed-off-by: Yury Norov Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c b/drivers/gpu/drm/msm= /disp/mdp5/mdp5_smp.c index d7fa2c49e741..56a3063545ec 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c @@ -68,7 +68,7 @@ static int smp_request_block(struct mdp5_smp *smp, uint8_t reserved; =20 /* we shouldn't be requesting blocks for an in-use client: */ - WARN_ON(bitmap_weight(cs, cnt) > 0); + WARN_ON(!bitmap_empty(cs, cnt)); =20 reserved =3D smp->reserved[cid]; =20 --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 494EBC433F5 for ; Thu, 10 Feb 2022 23:11:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345507AbiBJXLq (ORCPT ); Thu, 10 Feb 2022 18:11:46 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242400AbiBJXLp (ORCPT ); Thu, 10 Feb 2022 18:11:45 -0500 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99D415F45; Thu, 10 Feb 2022 15:11:45 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id x5so7142207qtw.10; Thu, 10 Feb 2022 15:11:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZBdSYHCr3USYo6W485UfRkjDE4guUfBuyMH5Mb4JqDU=; b=noirHY6GF4V4i8t+uu5JZQoNb9aCpruRdnEm1zuUkGMxjiGL/QA+2jJvW5q696QSYt ArH2xdXNKzx5VAWJf1ZbXj6Kin8p6qbXiG8tHG5RXG6uOggXjgywln0c3VNSq7sLigyy z7NvvKNREN8owyh9M01OFt2t8EjXllkRx7rL32xroe+PX7EzcvAgPKIArIqn+8ZjlOOK BwiWD5bNNWfkAbLL7OZzG+zIgoGXfWQmbCHioMYE/Hixd6D2RclBD1TwsJtxlKfyxR1a 3Iql8/K0PmZQ89a+14GQBXllOV38XKrUISn4vaAL9wPTv2tPQ/awzdPhwhPpDuTRlRvK fafA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZBdSYHCr3USYo6W485UfRkjDE4guUfBuyMH5Mb4JqDU=; b=T/ArRcZvgshtDP5falXRVxZIoXaUH3aibUQH7mteOqyVjtM888YPFuSl+n4AR1dAAY 0y8G9wD7pgV0mnfRErAWxNap014CmfLCG468+8YuH0ge3XLIXaQCC4z3eKZ8pvWT+bhn fauyjpfMGvN5o+h9opSRZ5mcdZz3KTV2ToQeFBSmvxo5Qh8gb7NZD5M0Yx743qPgNcIo KXKhenNcsIM2T19WbOEjNvnXPP2olxlRGlGmEUpJAGsENAfV3k3KhM6EJhsP2Bpf4jnE C8H9zUKkQ0iigpx6f3mor0+r4OGlTps+KUMLVcV6oluLPyHbUhxAUNEfZai9v2EJ6fc/ fH2w== X-Gm-Message-State: AOAM530mccGS8+RQAR+VBqiWOmDy6BA4CM2eQsStI65ra4Gb/OagNf4y GLGnXvNBObXrlJGSB1BSFEU= X-Google-Smtp-Source: ABdhPJyRNHJTVVPj+RR6tyohLG29mySY3xnZq28upNS8nrO1spe/OPmQyWpzHExT/NjogD+tlz2nxw== X-Received: by 2002:a05:622a:349:: with SMTP id r9mr6655005qtw.37.1644534704732; Thu, 10 Feb 2022 15:11:44 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id h5sm11242509qti.95.2022.02.10.15.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:11:44 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Jakub Kicinski , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org Subject: [PATCH 09/49] ice: replace bitmap_weight with bitmap_empty Date: Thu, 10 Feb 2022 14:48:53 -0800 Message-Id: <20220210224933.379149-10-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The ice_vf_has_no_qs_ena() calls bitmap_weight() to check if any bit of a given bitmap is set. It's better to use bitmap_empty() in that case because bitmap_empty() stops traversing the bitmap as soon as it finds first set bit, while bitmap_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c b/drivers/net= /ethernet/intel/ice/ice_virtchnl_pf.c index 39b80124d282..9a86eeb6e3f2 100644 --- a/drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c @@ -267,8 +267,8 @@ ice_set_pfe_link(struct ice_vf *vf, struct virtchnl_pf_= event *pfe, */ static bool ice_vf_has_no_qs_ena(struct ice_vf *vf) { - return (!bitmap_weight(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF) && - !bitmap_weight(vf->txq_ena, ICE_MAX_RSS_QS_PER_VF)); + return bitmap_empty(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF) && + bitmap_empty(vf->txq_ena, ICE_MAX_RSS_QS_PER_VF); } =20 /** --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BAD3C433FE for ; Thu, 10 Feb 2022 23:14:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345513AbiBJXN7 (ORCPT ); Thu, 10 Feb 2022 18:13:59 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243041AbiBJXN6 (ORCPT ); Thu, 10 Feb 2022 18:13:58 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BF2555A4; Thu, 10 Feb 2022 15:13:58 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id j12so7208355qtr.2; Thu, 10 Feb 2022 15:13:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=7FL52FrXNIHTozrcS4UAHCYMPxTzl2RTxQeoy1tQzZU=; b=AGBuTbR1DDTmbip/u/WZx2mNt0jPGvuO3BycAp6q2VmWJ1XpinqhZGjzxMYykQs1+h 9ZwK9nV2Hza30UOMDXrLFK15LOSULvD7ZjJxE9dsXejT1uWe+NyRJMgTaXeV1WmNgel9 eLii97p7+4ojaqGef/1vF3/S8W8Rgtj6O0GJTl0T6A2RIPF7e9C9EPh0fpAZj0VOPEjo nwjqptD59NnDlqInCC5Xcz7zI6Zdwo+X80xnVSm9eNlJ/x+5G4Rsb0PAvF1FL5QnrdSm ZkZCUR0Del2ERA0vC9l/qhTmRfA93zM+A7aiM1dWPj88KXvNexP7raFIi+zqIMF7LFdx 3osA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7FL52FrXNIHTozrcS4UAHCYMPxTzl2RTxQeoy1tQzZU=; b=roIilZ70b7b4OqHEr5LH/sdm2zdzv0llS/qx3vWCE0K5Q9r3vv0NaQoOtCTRaEDDcp MD4zKXl9cbFqiiSIcQsplDZB/8G7DdgX1g/qpecw0cyQHRmOsoHKZ/Wmn0QAz2l249DV tuRCi97OKpi9JeJFxCMVSrIulbqgB5mjbhWDQ9g7WSwIr5jkhTpqIIpnht0/Ix5b45ph Wg8Llp1KK6nyMAW3mk+nkTh/nw0B71xDLmCW6xB4943bAMKjSasGBk7rGbGGolXDsQH+ xSpuq8cl+A8obCygamYOiRVJheSsmjFjy/oIPhKRZnLH5/r1MGfx9tzeCsro0kTabTXP Xlhw== X-Gm-Message-State: AOAM532xIJDxukIp8LSDs4D3h68EkPIZ7NwbP+Th7W9KdVq/wPeorcHm 7PpA8HcXgTZPxLPH5da9SVc= X-Google-Smtp-Source: ABdhPJyziDNVK4gHlSQTL8oiGDJLo7w3dJcb5KZC+Jm81CQxXWEXD3+ANBnrP6vi6uDJfSyzoSW4VA== X-Received: by 2002:ac8:7d16:: with SMTP id g22mr6640405qtb.180.1644534837689; Thu, 10 Feb 2022 15:13:57 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id u6sm10751221qki.136.2022.02.10.15.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:13:57 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Sunil Goutham , Geetha sowjanya , Subbaraya Sundeep , hariprasad , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Subject: [PATCH 10/49] octeontx2-pf: replace bitmap_weight with bitmap_empty where appropriate Date: Thu, 10 Feb 2022 14:48:54 -0800 Message-Id: <20220210224933.379149-11-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In some places, octeontx2 code calls bitmap_weight() to check if any bit of a given bitmap is set. It's better to use bitmap_empty() in that case because bitmap_empty() stops traversing the bitmap as soon as it finds first set bit, while bitmap_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c | 4 ++-- drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c b/driv= ers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c index 77a13fb555fb..80b2d64b4136 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c @@ -353,7 +353,7 @@ int otx2_add_macfilter(struct net_device *netdev, const= u8 *mac) { struct otx2_nic *pf =3D netdev_priv(netdev); =20 - if (bitmap_weight(&pf->flow_cfg->dmacflt_bmap, + if (!bitmap_empty(&pf->flow_cfg->dmacflt_bmap, pf->flow_cfg->dmacflt_max_flows)) netdev_warn(netdev, "Add %pM to CGX/RPM DMAC filters list as well\n", @@ -436,7 +436,7 @@ int otx2_get_maxflows(struct otx2_flow_config *flow_cfg) return 0; =20 if (flow_cfg->nr_flows =3D=3D flow_cfg->max_flows || - bitmap_weight(&flow_cfg->dmacflt_bmap, + !bitmap_empty(&flow_cfg->dmacflt_bmap, flow_cfg->dmacflt_max_flows)) return flow_cfg->max_flows + flow_cfg->dmacflt_max_flows; else diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers= /net/ethernet/marvell/octeontx2/nic/otx2_pf.c index 86c1c2f77bd7..0f671df46694 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c @@ -1120,7 +1120,7 @@ static int otx2_cgx_config_loopback(struct otx2_nic *= pf, bool enable) struct msg_req *msg; int err; =20 - if (enable && bitmap_weight(&pf->flow_cfg->dmacflt_bmap, + if (enable && !bitmap_empty(&pf->flow_cfg->dmacflt_bmap, pf->flow_cfg->dmacflt_max_flows)) netdev_warn(pf->netdev, "CGX/RPM internal loopback might not work as DMAC filters are activ= e\n"); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33E9FC433EF for ; Thu, 10 Feb 2022 23:16:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345570AbiBJXQQ (ORCPT ); Thu, 10 Feb 2022 18:16:16 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:35036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345568AbiBJXQL (ORCPT ); Thu, 10 Feb 2022 18:16:11 -0500 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FD305F57; Thu, 10 Feb 2022 15:16:11 -0800 (PST) Received: by mail-il1-x129.google.com with SMTP id f13so5648145ilq.5; Thu, 10 Feb 2022 15:16:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=h1925twPT3iSM3qheWQhZ9lCv/Q+dhcPfdo+0L9UR6M=; b=FmZrCbIuuWKcUa6zV5OkwYnsnhTEUlIwU3u7B4rFa9iv9rogxDfUrkC8iT50ElDrDJ V/LzmYUzN4KTICqQQrjcvGO0wHklus09GVJUy44lN8vcaxmXjobi8Dr6/6a6Gheo1UIf 6ZVGk/RUan0TW8dFSwWVwH57oqfIjLrfKcmhzfFRgYG7Twbk86HqrSoSWZt8ZFX533Cn 4V8AlTRgOg62gIynVCyufSHpgzhDihN3Mipttmzn2Ub5dY+etr1IqCTmeJOPXe8QvPRv rAcqxTsM6XK/RIMsgAA5tCXqxJdSESyW1TcRBcT5YER/neKAsTtsfzTPBB0ie0DRQnPO wGmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h1925twPT3iSM3qheWQhZ9lCv/Q+dhcPfdo+0L9UR6M=; b=xc+wZTL5Y5Oflh9zNZPBoY6OYGuFSESO3dv8YR3uxcVM7JL5c1Zusz3D2C3V3xE5Wi DUjMdcSbCwQm584d8PjLAlU0Mg8Ob+V0XrRk11GkOTFH+IUjmNHVtrh2lwQjFdbf4GvV iKIIMXxa6u07vmFVWecMge0KCzPX2Qu5N+cjOMrYFOt5VZoBTZu0DKr6YWFS4AjLZZLD 78GaLfxS++vel5Zx0b/yxLT7mXMbDaNQ+ffLbFmd1zbWC7aXY82tXdxGVYeYdljFmHgI SKrbh5Fiv10G6xbz7kTKk8zXtDvrRkIbiVTr5wafXqhW5BfbIAFslwPRgCWbArz6Kgzk 9pfw== X-Gm-Message-State: AOAM530psnUwDkBWscs5LlQomuZ4JSN4fYB0rKCB0GLP3uLyM/3g8aMs gYWJynspUenhlykVV3DL2VM= X-Google-Smtp-Source: ABdhPJwNz15I7lWfFObm7DT3E8n4zBq2XHpU9H/Y5oNqt2y0xQ5ILb07o8ZNPvUbz9qZoJ7yYmpd8Q== X-Received: by 2002:a05:6e02:144d:: with SMTP id p13mr5306936ilo.47.1644534970739; Thu, 10 Feb 2022 15:16:10 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id h3sm11666270ild.11.2022.02.10.15.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:16:10 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Ariel Elior , Manish Chopra , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Subject: [PATCH 11/49] qed: replace bitmap_weight with bitmap_empty in qed_roce_stop() Date: Thu, 10 Feb 2022 14:48:55 -0800 Message-Id: <20220210224933.379149-12-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" qed_roce_stop() calls bitmap_weight() to check if any bit of a given bitmap is set. We can do it more efficiently with bitmap_empty() because bitmap_empty() stops traversing the bitmap as soon as it finds first set bit, while bitmap_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- drivers/net/ethernet/qlogic/qed/qed_roce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/qlogic/qed/qed_roce.c b/drivers/net/ether= net/qlogic/qed/qed_roce.c index 071b4aeaddf2..134ecfca96a3 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_roce.c +++ b/drivers/net/ethernet/qlogic/qed/qed_roce.c @@ -76,7 +76,7 @@ void qed_roce_stop(struct qed_hwfn *p_hwfn) * We delay for a short while if an async destroy QP is still expected. * Beyond the added delay we clear the bitmap anyway. */ - while (bitmap_weight(rcid_map->bitmap, rcid_map->max_count)) { + while (!bitmap_empty(rcid_map->bitmap, rcid_map->max_count)) { /* If the HW device is during recovery, all resources are * immediately reset without receiving a per-cid indication * from HW. In this case we don't expect the cid bitmap to be --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E1DBC433EF for ; Thu, 10 Feb 2022 23:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345589AbiBJXSX (ORCPT ); Thu, 10 Feb 2022 18:18:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:36610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345151AbiBJXSW (ORCPT ); Thu, 10 Feb 2022 18:18:22 -0500 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B2225F4E for ; Thu, 10 Feb 2022 15:18:22 -0800 (PST) Received: by mail-io1-xd2a.google.com with SMTP id s18so9364978ioa.12 for ; Thu, 10 Feb 2022 15:18:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=TZjvXmQL+ezx3++i6ywjCYX2+WSMiXHIFAoZu2xGMQA=; b=dh1iu5XVFR9JgGmMSioQ2P16YMuiIHmUjr61dP4GMbiQ/DBV+xy86sSdWmO7JGy9if SiLJjyrhAkltJyEffBig8nn7rsqFuMeuHJldrAgRTAtSTjv8EpjOdC6vIIDTuX1vQG8X tyHGhTZ88Kz+/3L0/sgBvY4LT8htAeWWCbvSN6jtFh9goqGhVxab8f4MrhWEbhotDg6L D4rDahldztLcHt5JGGWa7cSD6YDdH1+OScMRhdxHt5HBLYDySnNVxkvB/+UwZ4lyLXil hJs2m820KUfV0pMU7wth5QjgU8v0NZ4f1LIii2okFvCOfDuYH3BHp1hpFfvaosO6XBbb ncUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TZjvXmQL+ezx3++i6ywjCYX2+WSMiXHIFAoZu2xGMQA=; b=RXBY0e9SZqhaGPhmOXPDDLMnnBG9M2q5sFG3WxbPh0F1RbBlEi0z+x4P1IgQMQA23a AsfU0+1QfOQXYA02JBuBOwO2Fsej8GuyxCde5vSkh2a/sN6m8b0RcOL+PpFMNJuHUJkG eH+hlioj2G0lfP+/ChvKGZZOR5FIkN+83QxzHl5UiyDjqs4rqwOOpA6Snn0fY1wX+ftm rVqvsDKFNE+4CQ3dVQZNzBYyp875g855vQQ4LJruF3Ut5r3PhTzOExM49KTXahkX18kC b3GtjHlaFnA8wfRYOa/4SgBIW+eKiLpeICLzKf6JS42eODV52LpjR+ljS1mfCktgDuhc FgmQ== X-Gm-Message-State: AOAM532OAke8JNP3A14NoEn7xdVmCsYTLiH17VVSAQpszoSExCh3akXI cHfmuqzV0EfOo8nywD0cHrU= X-Google-Smtp-Source: ABdhPJzpdxrXi7jABYsEM7idoWZV3Dcam0pULppAeFkiKjAPVbRQOvUhQvFaYJB7D2HMiS0CGqRkmw== X-Received: by 2002:a05:6602:2b10:: with SMTP id p16mr5163745iov.44.1644535101887; Thu, 10 Feb 2022 15:18:21 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id p16sm8877673ilm.85.2022.02.10.15.18.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:18:21 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Will Deacon , Mark Rutland , Shaokun Zhang , Qi Liu , Khuong Dinh , linux-arm-kernel@lists.infradead.org Subject: [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate Date: Thu, 10 Feb 2022 14:48:56 -0800 Message-Id: <20220210224933.379149-13-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In some places, drivers/perf code calls bitmap_weight() to check if any bit of a given bitmap is set. It's better to use bitmap_empty() in that case because bitmap_empty() stops traversing the bitmap as soon as it finds first set bit, while bitmap_weight() counts all bits unconditionally. Signed-off-by: Yury Norov Acked-by: Mark Rutland --- drivers/perf/arm-cci.c | 2 +- drivers/perf/arm_pmu.c | 4 ++-- drivers/perf/hisilicon/hisi_uncore_pmu.c | 2 +- drivers/perf/xgene_pmu.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c index 54aca3a62814..96e09fa40909 100644 --- a/drivers/perf/arm-cci.c +++ b/drivers/perf/arm-cci.c @@ -1096,7 +1096,7 @@ static void cci_pmu_enable(struct pmu *pmu) { struct cci_pmu *cci_pmu =3D to_cci_pmu(pmu); struct cci_pmu_hw_events *hw_events =3D &cci_pmu->hw_events; - int enabled =3D bitmap_weight(hw_events->used_mask, cci_pmu->num_cntrs); + bool enabled =3D !bitmap_empty(hw_events->used_mask, cci_pmu->num_cntrs); unsigned long flags; =20 if (!enabled) diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c index 295cc7952d0e..a31b302b0ade 100644 --- a/drivers/perf/arm_pmu.c +++ b/drivers/perf/arm_pmu.c @@ -524,7 +524,7 @@ static void armpmu_enable(struct pmu *pmu) { struct arm_pmu *armpmu =3D to_arm_pmu(pmu); struct pmu_hw_events *hw_events =3D this_cpu_ptr(armpmu->hw_events); - int enabled =3D bitmap_weight(hw_events->used_mask, armpmu->num_events); + bool enabled =3D !bitmap_empty(hw_events->used_mask, armpmu->num_events); =20 /* For task-bound events we may be called on other CPUs */ if (!cpumask_test_cpu(smp_processor_id(), &armpmu->supported_cpus)) @@ -785,7 +785,7 @@ static int cpu_pm_pmu_notify(struct notifier_block *b, = unsigned long cmd, { struct arm_pmu *armpmu =3D container_of(b, struct arm_pmu, cpu_pm_nb); struct pmu_hw_events *hw_events =3D this_cpu_ptr(armpmu->hw_events); - int enabled =3D bitmap_weight(hw_events->used_mask, armpmu->num_events); + bool enabled =3D !bitmap_empty(hw_events->used_mask, armpmu->num_events); =20 if (!cpumask_test_cpu(smp_processor_id(), &armpmu->supported_cpus)) return NOTIFY_DONE; diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisili= con/hisi_uncore_pmu.c index a738aeab5c04..358e4e284a62 100644 --- a/drivers/perf/hisilicon/hisi_uncore_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c @@ -393,7 +393,7 @@ EXPORT_SYMBOL_GPL(hisi_uncore_pmu_read); void hisi_uncore_pmu_enable(struct pmu *pmu) { struct hisi_pmu *hisi_pmu =3D to_hisi_pmu(pmu); - int enabled =3D bitmap_weight(hisi_pmu->pmu_events.used_mask, + bool enabled =3D !bitmap_empty(hisi_pmu->pmu_events.used_mask, hisi_pmu->num_counters); =20 if (!enabled) diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c index 5283608dc055..0c32dffc7ede 100644 --- a/drivers/perf/xgene_pmu.c +++ b/drivers/perf/xgene_pmu.c @@ -867,7 +867,7 @@ static void xgene_perf_pmu_enable(struct pmu *pmu) { struct xgene_pmu_dev *pmu_dev =3D to_pmu_dev(pmu); struct xgene_pmu *xgene_pmu =3D pmu_dev->parent; - int enabled =3D bitmap_weight(pmu_dev->cntr_assign_mask, + bool enabled =3D !bitmap_empty(pmu_dev->cntr_assign_mask, pmu_dev->max_counters); =20 if (!enabled) --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E397C433EF for ; Thu, 10 Feb 2022 23:20:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345595AbiBJXUm (ORCPT ); Thu, 10 Feb 2022 18:20:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:37670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345587AbiBJXUi (ORCPT ); Thu, 10 Feb 2022 18:20:38 -0500 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0B9B5F57; Thu, 10 Feb 2022 15:20:35 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id 200so6608218qki.2; Thu, 10 Feb 2022 15:20:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OI8hrqvEfZeAPpQf8rC+vBfmKoqD6QuGtPPDNoK9uS4=; b=EQfXcPTDBcYmVj4+j4y/o25JVZVDwsWDx+EHUAOF3zMYUn3kQLX/MQfzHc/YKh7FN+ wm3IVR3uXroLe/72PTmQlUcmmno8zHVeYAM0auen7rv+y/jThDNnkafJjcgmONPKaZx5 gDKoXCQtUHorfeynZcINw3BfDvjNFg1UfPdLYBp9UNxk8+r/ONDMKXrWVWxHFGs4MioI 4Qo6KmzZXo6xLcPq6A2malt5UGXvTQ0/AN4hdbapLw/4UqjI/nUuIbUbfUEXo9K8538z v9P/ZZOoEfZt7peFCpLO9LS5MNJS7WxJgbU0lBrAZ25AQUta31Bg+sR9XeKHm/qqs1wE GMsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OI8hrqvEfZeAPpQf8rC+vBfmKoqD6QuGtPPDNoK9uS4=; b=UCYQSb3Pzs2xa8qitu7UTbrUwQ72zJbSk+i29PfseM5LzrMK5pODUFPc5fT9ERWToW 7n+l6fe7qgjUuvyopYxxioJGZUtP/KmGGt1/V/yHS0euf0agDasPsuEYvLdjTlGKLA/G MszWX06Yk8G3YRjWSbckyKxh9r59szR28HtpqcTB9v7T6gkaCc2fNkBegr3g6fsvp/QH /cEIdxT+ub8P/1iPeLrvYtSjfZoe6+S2tJ8s34nTip0CepDri9Bq7MyUfkCFghgqf50E 0254QeweafMDsuHT1ouRr6GcbyGlr4bktF1ZukHzcpUmcofYVn4Fh+EM8tieIVhZKUrh mSuQ== X-Gm-Message-State: AOAM532jO7txafanMGY7sBYAGKS69YBNbzmYdQ65tzUOWafDfO/FZXXB NNg6A3cAs3qIgCotqJ/nG+M= X-Google-Smtp-Source: ABdhPJyfmC4ftc0tGVwbWyGGCrs8QXCUCRrbYeGrdw/pzG5Dj57MnQrgDJcGdetfGIydZXZ3xW6zSg== X-Received: by 2002:a05:620a:4043:: with SMTP id i3mr5211591qko.14.1644535235068; Thu, 10 Feb 2022 15:20:35 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id v12sm10661466qkl.74.2022.02.10.15.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:20:34 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org Subject: [PATCH 13/49] perf tools: replace bitmap_weight with bitmap_empty where appropriate Date: Thu, 10 Feb 2022 14:48:57 -0800 Message-Id: <20220210224933.379149-14-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some code in builtin-c2c.c calls bitmap_weight() to check if any bit of a given bitmap is set. It's better to use bitmap_empty() in that case because bitmap_empty() stops traversing the bitmap as soon as it finds first set bit, while bitmap_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- tools/perf/builtin-c2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 77dd4afacca4..14f787c67140 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -1080,7 +1080,7 @@ node_entry(struct perf_hpp_fmt *fmt __maybe_unused, s= truct perf_hpp *hpp, bitmap_zero(set, c2c.cpus_cnt); bitmap_and(set, c2c_he->cpuset, c2c.nodes[node], c2c.cpus_cnt); =20 - if (!bitmap_weight(set, c2c.cpus_cnt)) { + if (bitmap_empty(set, c2c.cpus_cnt)) { if (c2c.node_info =3D=3D 1) { ret =3D scnprintf(hpp->buf, hpp->size, "%21s", " "); advance_hpp(hpp, ret); @@ -1944,7 +1944,7 @@ static int set_nodestr(struct c2c_hist_entry *c2c_he) if (c2c_he->nodestr) return 0; =20 - if (bitmap_weight(c2c_he->nodeset, c2c.nodes_cnt)) { + if (!bitmap_empty(c2c_he->nodeset, c2c.nodes_cnt)) { len =3D bitmap_scnprintf(c2c_he->nodeset, c2c.nodes_cnt, buf, sizeof(buf)); } else { --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC87FC433EF for ; Thu, 10 Feb 2022 23:22:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345636AbiBJXWv (ORCPT ); Thu, 10 Feb 2022 18:22:51 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345626AbiBJXWs (ORCPT ); Thu, 10 Feb 2022 18:22:48 -0500 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6633E88; Thu, 10 Feb 2022 15:22:48 -0800 (PST) Received: by mail-il1-x135.google.com with SMTP id f13so5657416ilq.5; Thu, 10 Feb 2022 15:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=dreoFKrn4wH6smW2GLCfxxjyjJhnljmILHzGoj0K5Es=; b=nLj6aJoGZkZ+ciKqW/DpUozk1sjRaY94bK8YuXc85MMjn3ka8sf0yQDAo55lM3nr9s 1UIDIaeoEc4NFplxVMfgEZe4JIrvw8GFfSt1bRxcGbE0R7FyhYrq+5ERL2XmXd+8DMkk msBJbFAY1A+uHQjX7pxCUlcRExj2gbm5HbdzAQorQnEsygPb0hInpXn+NwVt3GhNOenQ J0K9n2OBOnFaqIu1bZ69zDwx9EEDX1LJK5djkopX8BKeW9OK8X83/KG1m+Y67AzZEzoo b5YViod/+8inu3M7Flygc6qvfuFZ1LVXz4M9bMQ7qyAMxhj5BHtXI5n7+YviS6OqDhuk u4FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dreoFKrn4wH6smW2GLCfxxjyjJhnljmILHzGoj0K5Es=; b=BdZ5mf8XOyTXv/AoUZ0FkAeaR/f5BYJNKHQtPqEPImDnh/hquRzCNetdhyVGSejExO 8f3gh0pK0sMydmV6NrSObPEdM2BHtP6d0/e6s7Y5DqqFPHbzx2nNfLf9ugstXQQT3MlG y357IS3anr6pGgYyHwEPEagXnbucQ9Fht3DY8Ffn3CTydVlqkCDTJEsbiWnWVZ70P7gv 1e8kNVdYFx5LnWiA/pvUbVPSdv5oYFy0OZDHRM+G8vqfzUTPsDFls3U9fK5G1BX1FfXW XEsp+AiqY6pXP+s4aJ7rz/A3uh/r2q58ARztWl9XRHKMtS8NIr92ya3jy+O9vERLQBID iqfg== X-Gm-Message-State: AOAM532//5hpNDgCRpYTltpVX240ShTNZkK8qMi9AziuoI61lpegd4+Q yNemIsrlg5np+YlHCn6z5+A= X-Google-Smtp-Source: ABdhPJzuNm5GQuSv8w6TkAKuXFVsVX65utYXnMni+atUYXD3oSutdfGyrMKCf7cbLeQuGZaxI0sXhA== X-Received: by 2002:a92:c52f:: with SMTP id m15mr4414085ili.160.1644535368211; Thu, 10 Feb 2022 15:22:48 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id p5sm7962108ilq.71.2022.02.10.15.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:22:47 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Richard Henderson , Ivan Kokshaysky , Matt Turner , Geert Uytterhoeven , Davidlohr Bueso , "Russell King (Oracle)" , Kees Cook , Zheng Yongjun , Jens Axboe , linux-alpha@vger.kernel.org Subject: [PATCH 14/49] arch/alpha: replace cpumask_weight with cpumask_empty where appropriate Date: Thu, 10 Feb 2022 14:48:58 -0800 Message-Id: <20220210224933.379149-15-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" common_shutdown_1() calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- arch/alpha/kernel/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c index 5f8527081da9..0d4bc60828bf 100644 --- a/arch/alpha/kernel/process.c +++ b/arch/alpha/kernel/process.c @@ -125,7 +125,7 @@ common_shutdown_1(void *generic_ptr) /* Wait for the secondaries to halt. */ set_cpu_present(boot_cpuid, false); set_cpu_possible(boot_cpuid, false); - while (cpumask_weight(cpu_present_mask)) + while (!cpumask_empty(cpu_present_mask)) barrier(); #endif =20 --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 863DEC433F5 for ; Thu, 10 Feb 2022 23:25:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345641AbiBJXZD (ORCPT ); Thu, 10 Feb 2022 18:25:03 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345626AbiBJXZB (ORCPT ); Thu, 10 Feb 2022 18:25:01 -0500 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F009C5F59; Thu, 10 Feb 2022 15:25:01 -0800 (PST) Received: by mail-io1-xd29.google.com with SMTP id n17so9423204iod.4; Thu, 10 Feb 2022 15:25:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LzHqTGHmePwb1HFpWGG6zaHocU/Khr4mZgW/QCywhtg=; b=KoLazyQAnXN19qSU6nxWkSGgxQn6EmVBtr3qzwTfLRB+aGELf8bGFJhozbakQx1iEk PUxM6wzuTaKRHeTsIZprdOuj6sqTkkrYzDIMDi5E8i7nYXpUhdzxEBwdiYaAvlDeIx1t 96VWVZ+975D/8O5jcAhI/mVegz8gGrktTeM2drEHa2GwMOUrikKDaXM3igq7417lQ3Lj Jlv8mrTTijUYUii2uunxvnpSZ4j+jz0TmvY27ElurL8V93UVXEPTvPxECxkFrNgnQ58g Hz5kP7ojDYf5OqRMRQows6fd45mycpx9LVjVxidT4apDBoraMBdlb0hNqNhzz/hXHq3S uPTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LzHqTGHmePwb1HFpWGG6zaHocU/Khr4mZgW/QCywhtg=; b=2TI23dzxDGHKXONlvezeJa1UxDOjY1qKuRJNt3DTSURK8tvyvqwo41jgrZ1oOdRUrX cXlitWvv5zi2GksCFT2uSjZ3sIeDVBs/LDe0YnIY76v6sfQhgXOEFnwSoVROSeSH1YUa VNCxxNuepqeDBP3VAFnRv1lP/3hBW5j70l9fZi23DeM7Nr5nwkb9NEtEA5VYwbRiU9v1 b3N/ZJYgew28mmEzLu+E2o+O+P/OBKSogz1mBUxzalGz2bl6151MAmAAQ4i9RYNnqFTq V/tbXkj4viRviboJs7YP9tuPrA39Z2WdHynNkLfwI0qkPWTmNFhoVE4JwtpS1tBnYNPk vnRA== X-Gm-Message-State: AOAM530h3Kg2DMQiaFVPWRItpCgNzm94r92+wXYQGnNEvJKBWryIgCD4 oKVp/evGmKFOB+ED0RN6Xxl+MJC0xwQSOA== X-Google-Smtp-Source: ABdhPJzO7Wh2ZWhAjGAIU3578tz0nBbH5iZ7BL9c68JQSZumb6v58jDO8OJm/FlZeMxdi0nFwkVgBw== X-Received: by 2002:a6b:500a:: with SMTP id e10mr5030200iob.157.1644535501349; Thu, 10 Feb 2022 15:25:01 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id k10sm487246ilo.8.2022.02.10.15.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:25:00 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Geert Uytterhoeven , Yang Guang , linux-ia64@vger.kernel.org Subject: [PATCH 15/49] arch/ia64: replace cpumask_weight with cpumask_empty where appropriate Date: Thu, 10 Feb 2022 14:48:59 -0800 Message-Id: <20220210224933.379149-16-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" setup_arch() calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- arch/ia64/kernel/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c index 5010348fa21b..fd6301eafa9d 100644 --- a/arch/ia64/kernel/setup.c +++ b/arch/ia64/kernel/setup.c @@ -572,7 +572,7 @@ setup_arch (char **cmdline_p) #ifdef CONFIG_ACPI_HOTPLUG_CPU prefill_possible_map(); #endif - per_cpu_scan_finalize((cpumask_weight(&early_cpu_possible_map) =3D=3D 0 ? + per_cpu_scan_finalize((cpumask_empty(&early_cpu_possible_map) ? 32 : cpumask_weight(&early_cpu_possible_map)), additional_cpus > 0 ? additional_cpus : 0); #endif /* CONFIG_ACPI_NUMA */ --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2586C433EF for ; Thu, 10 Feb 2022 23:27:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345643AbiBJX1Q (ORCPT ); Thu, 10 Feb 2022 18:27:16 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345624AbiBJX1O (ORCPT ); Thu, 10 Feb 2022 18:27:14 -0500 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE7365F64; Thu, 10 Feb 2022 15:27:14 -0800 (PST) Received: by mail-io1-xd34.google.com with SMTP id p63so9373194iod.11; Thu, 10 Feb 2022 15:27:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=yuZUTT/rXi5dMjISKVJYU5DzInQNJ+fNjCOO2/f7G8k=; b=j55OXYXTjVhdPRBFTmJ0hd/eeXByGxC4t0B3i9rQKb3+0S3rnp8xzD+hSP60/pxcNO Be9jAJMFxu9ZbzBlEOboyCGBPjddFJA1TXkBcqAY+z9d3CdxBM5uLsA17zCPm+yi23p/ gSlhIvQ62GWYaoCo0t7FoT8VN3Q114+NR9c+g5+jWF4I1d9Jspb9+pcEmnD1SDzkq4Z6 Tf3I6aiau8yOugjCCnnL34w85f4avkSj1tiZzP1lz19DrCs3U9/H4Eqcj1915r+1/LfB qOMjkORvNHKFa7feKj7YS2lbBSjbFfOFEUxlI+R9/OPdTHEf6h3Bnl6UeYP7tyc2kNHw YQ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yuZUTT/rXi5dMjISKVJYU5DzInQNJ+fNjCOO2/f7G8k=; b=1+rSGKHDnW0ix2VML0ixEzn9tpE7OpM+1+iiBGahwmdzPFYgG7EeYIo0sUaaH1Xzwe UK7nCEsAk1g7qXIukzYbO1o56kTBU6UEQ0M8fX8bbgqV4210Bx/0aPvPT+fd1us6dBGp 3G2zWH9B02FnGloOnmWYzHWQfGq3WkciKWrrZF369SukRcuKcooJ4790ZUu+voCzo9Wg n/v0XVDyEjzVXXeCZoQ5vLft823H707V0SIF2wI67hb7Nj2c7EHONiyeokELDLMiLOf9 dCSAGhnMnA907DbZLBClT421E6ZHtecRUDKN3kJB1VdnMx5JCzOX1hrnjvPsrdfV3hKS V07g== X-Gm-Message-State: AOAM5311UTXUYtHg+BMEDwTCJlJ9WJknQY6///RJmbqDGrma39eN1owh d9+9Iw1/ApFxaGrUCftxe8g= X-Google-Smtp-Source: ABdhPJyuJyeIJ/FFP5Y/oWwaiFFlMwtt8E2cOYzuTD6rFFwrutNggg6s1UO76PCAuQUYz5PAgS7eNQ== X-Received: by 2002:a05:6638:101:: with SMTP id x1mr859923jao.23.1644535634329; Thu, 10 Feb 2022 15:27:14 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id t195sm5516476iof.47.2022.02.10.15.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:27:13 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Steven Rostedt , Karol Herbst , Pekka Paalanen , Andy Lutomirski , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson , Darren Hart , Andy Shevchenko , x86@kernel.org, nouveau@lists.freedesktop.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 16/49] arch/x86: replace cpumask_weight with cpumask_empty where appropriate Date: Thu, 10 Feb 2022 14:49:00 -0800 Message-Id: <20220210224933.379149-17-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In some cases, arch/x86 code calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov Reviewed-by: Steve Wahl --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 14 +++++++------- arch/x86/mm/mmio-mod.c | 2 +- arch/x86/platform/uv/uv_nmi.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index b57b3db9a6a7..e23ff03290b8 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -341,14 +341,14 @@ static int cpus_mon_write(struct rdtgroup *rdtgrp, cp= umask_var_t newmask, =20 /* Check whether cpus belong to parent ctrl group */ cpumask_andnot(tmpmask, newmask, &prgrp->cpu_mask); - if (cpumask_weight(tmpmask)) { + if (!cpumask_empty(tmpmask)) { rdt_last_cmd_puts("Can only add CPUs to mongroup that belong to parent\n= "); return -EINVAL; } =20 /* Check whether cpus are dropped from this group */ cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask); - if (cpumask_weight(tmpmask)) { + if (!cpumask_empty(tmpmask)) { /* Give any dropped cpus to parent rdtgroup */ cpumask_or(&prgrp->cpu_mask, &prgrp->cpu_mask, tmpmask); update_closid_rmid(tmpmask, prgrp); @@ -359,7 +359,7 @@ static int cpus_mon_write(struct rdtgroup *rdtgrp, cpum= ask_var_t newmask, * and update per-cpu rmid */ cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask); - if (cpumask_weight(tmpmask)) { + if (!cpumask_empty(tmpmask)) { head =3D &prgrp->mon.crdtgrp_list; list_for_each_entry(crgrp, head, mon.crdtgrp_list) { if (crgrp =3D=3D rdtgrp) @@ -394,7 +394,7 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpu= mask_var_t newmask, =20 /* Check whether cpus are dropped from this group */ cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask); - if (cpumask_weight(tmpmask)) { + if (!cpumask_empty(tmpmask)) { /* Can't drop from default group */ if (rdtgrp =3D=3D &rdtgroup_default) { rdt_last_cmd_puts("Can't drop CPUs from default group\n"); @@ -413,12 +413,12 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, c= pumask_var_t newmask, * and update per-cpu closid/rmid. */ cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask); - if (cpumask_weight(tmpmask)) { + if (!cpumask_empty(tmpmask)) { list_for_each_entry(r, &rdt_all_groups, rdtgroup_list) { if (r =3D=3D rdtgrp) continue; cpumask_and(tmpmask1, &r->cpu_mask, tmpmask); - if (cpumask_weight(tmpmask1)) + if (!cpumask_empty(tmpmask1)) cpumask_rdtgrp_clear(r, tmpmask1); } update_closid_rmid(tmpmask, rdtgrp); @@ -488,7 +488,7 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_f= ile *of, =20 /* check that user didn't specify any offline cpus */ cpumask_andnot(tmpmask, newmask, cpu_online_mask); - if (cpumask_weight(tmpmask)) { + if (!cpumask_empty(tmpmask)) { ret =3D -EINVAL; rdt_last_cmd_puts("Can only assign online CPUs\n"); goto unlock; diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c index 933a2ebad471..c3317f0650d8 100644 --- a/arch/x86/mm/mmio-mod.c +++ b/arch/x86/mm/mmio-mod.c @@ -400,7 +400,7 @@ static void leave_uniprocessor(void) int cpu; int err; =20 - if (!cpumask_available(downed_cpus) || cpumask_weight(downed_cpus) =3D=3D= 0) + if (!cpumask_available(downed_cpus) || cpumask_empty(downed_cpus)) return; pr_notice("Re-enabling CPUs...\n"); for_each_cpu(cpu, downed_cpus) { diff --git a/arch/x86/platform/uv/uv_nmi.c b/arch/x86/platform/uv/uv_nmi.c index 1e9ff28bc2e0..ea277fc08357 100644 --- a/arch/x86/platform/uv/uv_nmi.c +++ b/arch/x86/platform/uv/uv_nmi.c @@ -985,7 +985,7 @@ static int uv_handle_nmi(unsigned int reason, struct pt= _regs *regs) =20 /* Clear global flags */ if (master) { - if (cpumask_weight(uv_nmi_cpu_mask)) + if (!cpumask_empty(uv_nmi_cpu_mask)) uv_nmi_cleanup_mask(); atomic_set(&uv_nmi_cpus_in_nmi, -1); atomic_set(&uv_nmi_cpu, -1); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6801C433FE for ; Thu, 10 Feb 2022 23:29:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345674AbiBJX32 (ORCPT ); Thu, 10 Feb 2022 18:29:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231627AbiBJX31 (ORCPT ); Thu, 10 Feb 2022 18:29:27 -0500 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E31A7116D; Thu, 10 Feb 2022 15:29:27 -0800 (PST) Received: by mail-il1-x12e.google.com with SMTP id h11so5640655ilq.9; Thu, 10 Feb 2022 15:29:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=3bNm5/uTnBAzIRKqMnmZ8YYfpkxkteIvyaUY7P/5B+o=; b=fLgRM4uji0XMP07LvJA5cjBtqm7zXPbJEBYtQDz8uGRsGjNkvOmu1mZZGhE7PFB0h8 7PGHiZ+HnW21lWBjG1Hp5A/io3C7i6JtUrMDThpe5y92omUL2lBUuwmbVl7bS3bU0t7o bZq4lw7FX7tlNYB2G04YnPLZMYUK5kOrXpdscRdaz4TtPLlDq3oaDeUrODGU15pKMaSD ocKLNnWjsh+fu2AZ1ivgdj8WAlWXHXIdIRLnA9L7DsQS1etO2PvLwSwJhPDSSGAXJiZV jG0tuxn4fxzCTULGAwmomyB/ly9laDnDKG1pIYbAduDcAzKjTa3UKRbikmrRgcduFqam Yaeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3bNm5/uTnBAzIRKqMnmZ8YYfpkxkteIvyaUY7P/5B+o=; b=0Bm/AANPXhtOTo4MvPfcduVvG7vNSHkhabvMkghPwmHeuiDTPX5YNFnPb/g9EHGqh2 fjBVFl9N10jUrCgB5t38PHPm3jlztY+pehrrx1MMCAcJ2Yue6teBJn1lFTAwGdgfiipI PDaKcrRSlf4USIghBewlGAdUFX+c/bYcg4MfEB2XZ4vd64vxoALvA30DN/Bm/ky8F7PK 216++5dECfxYb5FHmaa6ahJp40y5NKaUWK2UO8Sd0NYhOusX6TWdp58TcJ4m3CjRmzPK xhITWlYkeAg6YlFNH/1z2pgJtp6icyRW4r92IidNqwkFXgBraDUT8TXAVOEA+vfz1D0x FZHg== X-Gm-Message-State: AOAM531VaDJnNz8oCOhMo8TUYCPkobIuWSAu+FAt/9Y+DhrxN1ADEHfs cN9sFvWFTluSzEGt95CRZiQ= X-Google-Smtp-Source: ABdhPJxG4wLZX5EPMqNJ2GZN9s/YWLmAmUwDDdSVvbnGhVn58IPPvR5sZVSRf3Lr6OSWj7N5cae0BA== X-Received: by 2002:a92:d64e:: with SMTP id x14mr5598201ilp.97.1644535767261; Thu, 10 Feb 2022 15:29:27 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id b5sm6717209ilr.0.2022.02.10.15.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:29:26 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Andy Gross , Bjorn Andersson , "Rafael J. Wysocki" , Viresh Kumar , Sudeep Holla , Cristian Marussi , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 17/49] cpufreq: replace cpumask_weight with cpumask_empty where appropriate Date: Thu, 10 Feb 2022 14:49:01 -0800 Message-Id: <20220210224933.379149-18-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" drivers/cpufreq calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov Reviewed-by: Sudeep Holla (for SCMI cpufreq driver) --- drivers/cpufreq/qcom-cpufreq-hw.c | 2 +- drivers/cpufreq/scmi-cpufreq.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufr= eq-hw.c index 05f3d7876e44..95a0c57ab5bb 100644 --- a/drivers/cpufreq/qcom-cpufreq-hw.c +++ b/drivers/cpufreq/qcom-cpufreq-hw.c @@ -482,7 +482,7 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_poli= cy *policy) } =20 qcom_get_related_cpus(index, policy->cpus); - if (!cpumask_weight(policy->cpus)) { + if (cpumask_empty(policy->cpus)) { dev_err(dev, "Domain-%d failed to get related CPUs\n", index); ret =3D -ENOENT; goto error; diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c index 1e0cd4d165f0..919fa6e3f462 100644 --- a/drivers/cpufreq/scmi-cpufreq.c +++ b/drivers/cpufreq/scmi-cpufreq.c @@ -154,7 +154,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *pol= icy) * table and opp-shared. */ ret =3D dev_pm_opp_of_get_sharing_cpus(cpu_dev, priv->opp_shared_cpus); - if (ret || !cpumask_weight(priv->opp_shared_cpus)) { + if (ret || cpumask_empty(priv->opp_shared_cpus)) { /* * Either opp-table is not set or no opp-shared was found. * Use the CPU mask from SCMI to designate CPUs sharing an OPP --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41CBEC433EF for ; Thu, 10 Feb 2022 23:31:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345700AbiBJXbk (ORCPT ); Thu, 10 Feb 2022 18:31:40 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231627AbiBJXbi (ORCPT ); Thu, 10 Feb 2022 18:31:38 -0500 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03BCF55AD for ; Thu, 10 Feb 2022 15:31:39 -0800 (PST) Received: by mail-il1-x12d.google.com with SMTP id h11so5643990ilq.9 for ; Thu, 10 Feb 2022 15:31:38 -0800 (PST) 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=cBa2U3XOOVlsojEDVXj/o83IuBw5ETmXBNJi4yT/mck=; b=jHSBDPHH5F/Vu7vkrUGPef+o7tUEfAEhl2PoRlxgkCIVVBSidmw9uoJm5ymTT6uz7U 3pffuiDZNdBK94zTP95WUpBGuA4KamvVVf+MC7XSjB2nZG+dK2TvwXlQ6Bckx4CEO+Yo e0MBSfMLtj2iby5Q2GF35xLHWDBso6GFt1XjoBnPxNu86jWo1lCR2vG4HtD5+tH/9aJP OAruOIYwdHx6XDS8/GY+DdK51p13TeK26Uf/QDWOoZldYjOXc5rWsvHHoTuWsRjT3/AS 10ubpI+g8KCocxoIO6IF2muT6+nBFRdueT1NFzZW82akR34riORhlm6VJ3wgO4FgV413 BSJQ== 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=cBa2U3XOOVlsojEDVXj/o83IuBw5ETmXBNJi4yT/mck=; b=zquFIBEOb2WeNy7b5INI8vuNexyM8BkJ9d4OfdwsSqX5CGcmYxA7IwV47x09PXBv5P v4aFfG5akTPOMehLA5DkRtElJzNK8NT9YED46HrRJ1OP6sto4w9PxcKYqqcJbiBCXy3T rj6AHpDf778V4ttb14P2/TLNoP0cnQKkNtrhsbM0ABZLnJMAIHuyhLnXH2z+xHpLQRbt 82SOMPq7LehTuvGuGP3Q0EGkrrEvlmdzfyn0ZIRjMhIxJQNVlGL8aggGAupLGVlmeLQ3 0CS/I5JE+q/dhiFgFm3R/oiRUbmDqVoUXHaIBeG+uMH2W+RCVcOMt8J3NJ5hhlw3pSM6 1Qmg== X-Gm-Message-State: AOAM5334VhWz2CyeAG0f2pgX2xlXHRcZctO0k8sWtg2ThQd1UVYiF558 wk+ODqHvj6eo1xYMQvC5FKA= X-Google-Smtp-Source: ABdhPJy8lL1944IEHiv7kjDJbzucordqvuC8LbtZQRP1RQFcCYSZIqSbwhqVBTtPLxpQaswpU1x/lA== X-Received: by 2002:a05:6e02:148:: with SMTP id j8mr4737390ilr.218.1644535898397; Thu, 10 Feb 2022 15:31:38 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id l6sm7395096ilt.16.2022.02.10.15.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:31:38 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Tvrtko Ursulin Subject: [PATCH 18/49] drm/i915/pmu: replace cpumask_weight with cpumask_empty where appropriate Date: Thu, 10 Feb 2022 14:49:02 -0800 Message-Id: <20220210224933.379149-19-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" i915_pmu_cpu_online() calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov Reviewed-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pm= u.c index cfc21042499d..7299ed9937dd 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -1050,7 +1050,7 @@ static int i915_pmu_cpu_online(unsigned int cpu, stru= ct hlist_node *node) GEM_BUG_ON(!pmu->base.event_init); =20 /* Select the first online CPU as a designated reader. */ - if (!cpumask_weight(&i915_pmu_cpumask)) + if (cpumask_empty(&i915_pmu_cpumask)) cpumask_set_cpu(cpu, &i915_pmu_cpumask); =20 return 0; --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EFBFC433F5 for ; Thu, 10 Feb 2022 23:33:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345704AbiBJXdv (ORCPT ); Thu, 10 Feb 2022 18:33:51 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231627AbiBJXdu (ORCPT ); Thu, 10 Feb 2022 18:33:50 -0500 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CF07E83; Thu, 10 Feb 2022 15:33:50 -0800 (PST) Received: by mail-io1-xd2a.google.com with SMTP id h7so9454812iof.3; Thu, 10 Feb 2022 15:33:50 -0800 (PST) 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=scQQOeGEKS1UtnSb4hDa2pMn49T7lX7tre18iE1yAHU=; b=RIBQ3M1+e7Un6Pm8klMv7JFRyzLD6R+Ak9wA8JMgVvjGGuFJshj+1pYyY0wdO/sViu r/Sy2qLBoQJw0gRyu/afxAsCIuXSI2sSFdu1izZtWcqnwuDs2ZTvAzbFVFezEXxG+raL rq/FBsjW8A6NSkaXInMpTgc7OsquM6YmI2Q63qt5QOeHsXoQ5u90pe3WWu3iprephA1b d0YrHC/kIfZUHXhzpfBTs1G6T6tsaKxLKbBCCmFVfbNLDUavDbYlK9LcgOLDw3KGs7S3 wm2wh5bErKqLnwUFNL6fS5uN9xQAWwZpWzgQoRe4pwJHGyYuKaQt+yygbiUWOaPEYZjL 3Pgw== 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=scQQOeGEKS1UtnSb4hDa2pMn49T7lX7tre18iE1yAHU=; b=C8SmWh+6uKqhsdY9wcTHH1Q+8J6e+I/9iDDCevvC01JVMNcg65rGOADum2u3y5rAzE Qi0G8IKSiCJjVGgNeqSynxoUWX+IN//foBKNge5CAOLiOZ8BA3jV+TuQT4jbwlQth5rV Es83+JviYMHc6wmecRicKeJQfHYJ2JmPR+e4yga1zL7CBf+rSaksFFfZEi/tNLFtFWte dYdvAf7h4lxul/ScALTwVh65518WpeY5jDm57TBNkha5gumJpGLbJKiZ7m/C3rb6WjqM YAzwTUTkYGufW6ZEW4Pq3imslVDpk5VVMn8s8nKFH+kMiRzdkzw4piYnmoYYCjaPWzvY 8cog== X-Gm-Message-State: AOAM532wtBBhOsREiskDMFqhbov5p+WEcY0kEbuQ/4Pt010ds4zfat1B PNC9Tc1WvAtEG5zEssS9Ltg= X-Google-Smtp-Source: ABdhPJwXeQ/bXUwb8aHBaOdNFbuQO4MW/NT2Fa7afUSNlrVEzUO80EGBGp2QuHnt22Zclxq0J+BZVg== X-Received: by 2002:a05:6638:1607:: with SMTP id x7mr1605707jas.226.1644536029481; Thu, 10 Feb 2022 15:33:49 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id d80sm8376224iof.15.2022.02.10.15.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:33:49 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Mike Marciniszyn , Dennis Dalessandro , Jason Gunthorpe , linux-rdma@vger.kernel.org Cc: Leon Romanovsky Subject: [PATCH 19/49] RDMA/hfi: replace cpumask_weight with cpumask_empty where appropriate Date: Thu, 10 Feb 2022 14:49:03 -0800 Message-Id: <20220210224933.379149-20-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" drivers/infiniband/hw/hfi1/affinity.c code calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov Reviewed-by: Leon Romanovsky --- drivers/infiniband/hw/hfi1/affinity.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/= hfi1/affinity.c index 706b3b659713..877f8e84a672 100644 --- a/drivers/infiniband/hw/hfi1/affinity.c +++ b/drivers/infiniband/hw/hfi1/affinity.c @@ -666,7 +666,7 @@ int hfi1_dev_affinity_init(struct hfi1_devdata *dd) * engines, use the same CPU cores as general/control * context. */ - if (cpumask_weight(&entry->def_intr.mask) =3D=3D 0) + if (cpumask_empty(&entry->def_intr.mask)) cpumask_copy(&entry->def_intr.mask, &entry->general_intr_mask); } @@ -686,7 +686,7 @@ int hfi1_dev_affinity_init(struct hfi1_devdata *dd) * vectors, use the same CPU core as the general/control * context. */ - if (cpumask_weight(&entry->comp_vect_mask) =3D=3D 0) + if (cpumask_empty(&entry->comp_vect_mask)) cpumask_copy(&entry->comp_vect_mask, &entry->general_intr_mask); } --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67D5AC433F5 for ; Thu, 10 Feb 2022 23:36:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345745AbiBJXgD (ORCPT ); Thu, 10 Feb 2022 18:36:03 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:45170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345734AbiBJXgB (ORCPT ); Thu, 10 Feb 2022 18:36:01 -0500 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 609875F6B; Thu, 10 Feb 2022 15:36:01 -0800 (PST) Received: by mail-il1-x132.google.com with SMTP id o10so5711977ilh.0; Thu, 10 Feb 2022 15:36:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+6fGWOvKupFRHqASATl4H7ePp2/LogONFRX5QE2erMk=; b=c5TKy1a65HE0+KDrrZ0l/0nyjG2KwQMjf+LTDiNfbSE5RPViIvGC8K2sHtLqVEcATl s9UJ/l/F0Gz6sTG4Um9A9x+I5/IKHSGqrabca7G/pE0GFSn3XrH1YGeZFwiQrdeYQ2OO wRYGq1zhoyCG6jEZqlxFK4gKdjeLjsn3FyH/9KWUGJa5YZSktM3YXMRDDCVu/rR+AA2Z oA78RSF7auCtcAT5js4nUbb4fLc9eIrWmHdj2Xyew4TFqMHZNPCFuVgHQyJVH43uWM+x hbbn18w+pjBpT7F/P3oXQdsqSOIcktcYds/lAjybQxjTdeU0egJ1F0ul5vz3eBMhF1Qg zMvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+6fGWOvKupFRHqASATl4H7ePp2/LogONFRX5QE2erMk=; b=Je0WUv8LTZFb/06BB0tyffvW5e+Oc7MqqdghD3pFwzPq1WhT6yfLFUhxLkl1RsCcEg 7JW8ssOV6hUweOq6Uu9htKUk/oOQnFkssshDDPwt9IHjp5tf4bFY9UItTtBQP3zYcV9Y 7Z0qVWVMj8rhz+q/CLVYPg2FiRvKIgt3+/tLSLQQdMUq/nt9W6Mqwo9I06WiBY+1AlMa l51BhzCu6EdHkDLQoh1LXDLNZtV8ipEtkU0xbfsF610BC3V2ckhaHu+/FXRTXCzZW851 a5WtVzooDXFuD+i+SEYrm2sY56MHrYjwVQ2TokMOjJr++ZAVHSkPQh/IHPmo7/Z23r35 feCA== X-Gm-Message-State: AOAM533CM9eYh7FtzcLm2Q2NI++rCkX4i/+hfMwl246sK+2oi6h9Ih+D FLCa1+cN5WdOmhPe120HajE= X-Google-Smtp-Source: ABdhPJxIyAONwSqovY5ap0uN+hIkP7cYxn35rT83uobFJrTicWBOWExdY8XujcVELZYNJmB7R5CauA== X-Received: by 2002:a92:db0e:: with SMTP id b14mr5408913iln.153.1644536160698; Thu, 10 Feb 2022 15:36:00 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id a10sm12126701ilv.44.2022.02.10.15.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:36:00 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Florian Fainelli , Thomas Gleixner , Marc Zyngier , bcm-kernel-feedback-list@broadcom.com, linux-mips@vger.kernel.org Subject: [PATCH 20/49] irq: mips: replace cpumask_weight with cpumask_empty where appropriate Date: Thu, 10 Feb 2022 14:49:04 -0800 Message-Id: <20220210224933.379149-21-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" bcm6345_l1_of_init() calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov Acked-by: Florian Fainelli --- drivers/irqchip/irq-bcm6345-l1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/irqchip/irq-bcm6345-l1.c b/drivers/irqchip/irq-bcm6345= -l1.c index fd079215c17f..142a7431745f 100644 --- a/drivers/irqchip/irq-bcm6345-l1.c +++ b/drivers/irqchip/irq-bcm6345-l1.c @@ -315,7 +315,7 @@ static int __init bcm6345_l1_of_init(struct device_node= *dn, cpumask_set_cpu(idx, &intc->cpumask); } =20 - if (!cpumask_weight(&intc->cpumask)) { + if (cpumask_empty(&intc->cpumask)) { ret =3D -ENODEV; goto out_free; } --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E726C433EF for ; Thu, 10 Feb 2022 23:38:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345792AbiBJXiQ (ORCPT ); Thu, 10 Feb 2022 18:38:16 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345608AbiBJXiO (ORCPT ); Thu, 10 Feb 2022 18:38:14 -0500 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 898255F64 for ; Thu, 10 Feb 2022 15:38:14 -0800 (PST) Received: by mail-io1-xd32.google.com with SMTP id i62so9480612ioa.1 for ; Thu, 10 Feb 2022 15:38:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=9n2DdSbneN7v4fxKizWFeu7+3tSFKKa+21duzKl95Yk=; b=AK2McL5crq3P5W/HMrl+HVMBiBdnvJJs/I9DFxsN28iywuaN2UqJNQpufEM/5yB+NS WM8Ah7v54tNxhaygGs78Emy4tgph4sPVpst0aVD0SguR55ocuOu/qsF08EpW0Wo6U1tk qpnL9Snt8YrLfZRyjPxqcx31oSV0Szk7umC8BTcBZNlJIlKF5M44te4ICNt/Vq+7Ofls sv9Wi7ie72uM1j3zsENRKACYxiKCrC+kQFAKF4OXcd25TcneaY+BVbKSZq1hYZ7qX2Hh lQVNwMxWZZsr0i3Zg+dYucoa5y4DOQy2eMNRoLj/XhULZxe7PEV/GOvG2TIrXHiLtJi4 nb7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9n2DdSbneN7v4fxKizWFeu7+3tSFKKa+21duzKl95Yk=; b=XcyNqCB0i7E1jOgntG7qJ/GD89w4EX4kPLiwd5YZA7c+K2l/xM5o7xZcVsmwtNpJkS Omwy8Fx2I9Yc0KtT2cCuve0XVYYIktVILURUoymgwrjxN1PBP/rZW0/mNazdd2INNIZh tNVBS+akdnrKrISOxEpqHjgEdfd0hkhupaW/vTjaslc1dhZRXtHPhWocXVLm3qX+v9D2 gcnUZ5P+D91AgZ6alRWKBobkXyIRVeq4oyWgmv3PZ39Ur4ZTBJoNpEUSx3HKZ3pYumG8 6RNMZzsOdJkO8qW1W56OT47GWVRVScdcCFrr/BhHT2e7kcf3eO8dXNyZqtYF1mWI5Lz4 MVRA== X-Gm-Message-State: AOAM5306QP8QAhjXzyosn4qdYtk4hyXiTm/MWweCLxMy0JLNmrlQ+l9z PhSYKxg8kBtT+Dx8OAzPqOM= X-Google-Smtp-Source: ABdhPJwQ659D3gO5ecBLF2AX0FyOLgCZ61yewOIUm7N0UW53PsKRiHqI+c9w8ufSKRcbdtxUOYhoAg== X-Received: by 2002:a05:6602:2c08:: with SMTP id w8mr5090325iov.182.1644536293918; Thu, 10 Feb 2022 15:38:13 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id i30sm4549007ila.32.2022.02.10.15.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:38:13 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Thomas Gleixner Subject: [PATCH 21/49] genirq/affinity: replace cpumask_weight with cpumask_empty where appropriate Date: Thu, 10 Feb 2022 14:49:05 -0800 Message-Id: <20220210224933.379149-22-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" __irq_build_affinity_masks() calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- kernel/irq/affinity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c index f7ff8919dc9b..18740faf0eb1 100644 --- a/kernel/irq/affinity.c +++ b/kernel/irq/affinity.c @@ -258,7 +258,7 @@ static int __irq_build_affinity_masks(unsigned int star= tvec, nodemask_t nodemsk =3D NODE_MASK_NONE; struct node_vectors *node_vectors; =20 - if (!cpumask_weight(cpu_mask)) + if (cpumask_empty(cpu_mask)) return 0; =20 nodes =3D get_nodes_in_cpumask(node_to_cpumask, cpu_mask, &nodemsk); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF11AC433F5 for ; Thu, 10 Feb 2022 23:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345798AbiBJXk3 (ORCPT ); Thu, 10 Feb 2022 18:40:29 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:47768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345799AbiBJXk1 (ORCPT ); Thu, 10 Feb 2022 18:40:27 -0500 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 830595F71 for ; Thu, 10 Feb 2022 15:40:27 -0800 (PST) Received: by mail-il1-x135.google.com with SMTP id m8so5668046ilg.7 for ; Thu, 10 Feb 2022 15:40:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5r/gzaAkgy75rCqFlvPrMs1wcw7KKnaGDY3klmZfIuI=; b=fm0i2hSs8fnadbMOheCvaYS79Sd7CX1F06n12cepJ4/C8ZDDyJoMTvbSkbC6HljlFQ CMm3YaRXCiY7izDi7nzyLexOXQXJYymrbzD3srdtOj6AbWuWPCAAsODOcPEfgtdcCeq9 FrSXRA5dGUp0iFzKP7DSJ7Ntb2YEUmQRnHgUo7d0V4CRbDl4CXOZC6TwiAG1Q4ziSCag GyGFb76sgKCv+yYQuJ25Jrvc0fGN/v94iSIltLqwgD3gZrLmPTQl+H/B8AnY6BnbJRjx 7ywMgKmIcWRFBk5vsBYSCAl+yob/KwIP//ylvGkKOiGRLMQnzWJ2cDViq9wWQUD4rZE8 4Jmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5r/gzaAkgy75rCqFlvPrMs1wcw7KKnaGDY3klmZfIuI=; b=MS6OpXgBVUZ2nH1HiJfzZzCRcbB1XNFqn5RAbOtrGwF9UY9Cu1EuOq5wdQ9H1qkArF Vn05WbzYLvuh2er0J1dVnPb8TT3kdIB1sonFnO3ogJx85F29USgWI7K0WkuT9l5wZkEf No23U9KK8Aq3s6gVf9FIWJs/5UdiB1CiWznhF7PwGJSBu52jFG2vtNntu8CcyWC/9mu0 VB1W53Gtzg6JqrJ1EByeb9XfDjZixn3lAvCi+gHCv6hbeGO9sCSvSLYNWY5Iruw+WQtV 3vxcrG9uMQ04UCG2YrGWDljkhO1Merjd4ZO7tiSS7rWxA0fNrWVsYgQWyPXD8dcKySgj 4+CA== X-Gm-Message-State: AOAM5302e79917dgzBnQ1APqRWsFuXOFSkKQxzEFO7WO0RUOlbDq7P3s vkJLEvqh9AeTt1cxTYb4XbvcrOVbiHLolw== X-Google-Smtp-Source: ABdhPJyLhro79jJ3w57du7eysK31wHXhRUklAWC49/k2kVHLqEqjBApmH03mGMDbLgz2LsxsvRUE9A== X-Received: by 2002:a05:6e02:1a8d:: with SMTP id k13mr5362636ilv.257.1644536426899; Thu, 10 Feb 2022 15:40:26 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id q18sm8230178ils.78.2022.02.10.15.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:40:26 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Subject: [PATCH 22/49] sched: replace cpumask_weight with cpumask_empty where appropriate Date: Thu, 10 Feb 2022 14:49:06 -0800 Message-Id: <20220210224933.379149-23-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In some places, kernel/sched code calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- kernel/sched/core.c | 2 +- kernel/sched/topology.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 28d1b7af03dc..ed7b392945b7 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8711,7 +8711,7 @@ int cpuset_cpumask_can_shrink(const struct cpumask *c= ur, { int ret =3D 1; =20 - if (!cpumask_weight(cur)) + if (cpumask_empty(cur)) return ret; =20 ret =3D dl_cpuset_cpumask_can_shrink(cur, trial); diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index d201a7052a29..8478e2a8cd65 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -74,7 +74,7 @@ static int sched_domain_debug_one(struct sched_domain *sd= , int cpu, int level, break; } =20 - if (!cpumask_weight(sched_group_span(group))) { + if (cpumask_empty(sched_group_span(group))) { printk(KERN_CONT "\n"); printk(KERN_ERR "ERROR: empty group\n"); break; --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84E77C433EF for ; Thu, 10 Feb 2022 23:42:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345817AbiBJXmm (ORCPT ); Thu, 10 Feb 2022 18:42:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240069AbiBJXmk (ORCPT ); Thu, 10 Feb 2022 18:42:40 -0500 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86BA4AF for ; Thu, 10 Feb 2022 15:42:40 -0800 (PST) Received: by mail-il1-x135.google.com with SMTP id h11so5659016ilq.9 for ; Thu, 10 Feb 2022 15:42:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=IfuV7BErsL/W0NpxTgurt/IeS+0DSJusaRrjkOZT71M=; b=V/sbZHygSE1dk4L3f+z50ccoEdc9sz/a/RRC4yulJXVwN6WdNnOhqjtQ5cK1rlbwpC mMMvV3GAPff6zbHgTIblif68WqzZegiNCcV8+EvQkiKppnfLw1/wFAQddm+MAuLz5hKn YJHfx/spl1RzxGn8l+lCGkhtEkCZryEYEk0XVL5UsN/rJX43G+VBpRb5VlBtQ3Lld4eW d8i3QirNuscL7GPG9HtrTU50V0QMM5olYoLQ6p/BehBgEqIM2qWzD8Fuhisb0Xfn+I4g z7bcSzNOZ2Ed+7oZBLJNvnIiQ1G9MDl6KXspbq41/2Cq6r94bgtfU6of+oGXWHNlkEKr zs5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IfuV7BErsL/W0NpxTgurt/IeS+0DSJusaRrjkOZT71M=; b=JPbxmK5ScKnLqplFNg8upz1WZs3Had6Go2Cui/7FgL/o1SwoXJgnfou9ZhJ3PniOnF PT25qEVOiG46LAXNASoIY7GcGL0sL8fPI6+lOslet2c5Gh3VU3NYf83nI87Yj1JAdq+K ZZuVTjlAqxOk3pLAolp5W4Xa4cZJWKQCRwgcUmd1KmecexCaeXuyiX5XD8DvDzXi+rqA IBN9zfYt8R36Hz/vXOu/cyrt68/hbjCa0jApRithOH5lfdeIjwULsR0Y2kvL8IIBckHk SouFizYFG8P9yLuaAupHLnZjt6e6DGzlFR/rAMonOxLGOusTdfAaHgEXyw7711RFSLYJ S6cg== X-Gm-Message-State: AOAM530dpx8NEU2czQRHdW5uxB76cIloO7sd5vSxJO5MH8UJw0XW17oN HxW+bjfj6b0nf1bhtCpeXnA= X-Google-Smtp-Source: ABdhPJyMCRQgDaf6eA53pG3YvPxmIVTNvMprTGUlUaqGwilmflBxGPm7MqMOwsRkroMJ9y4fsTf4uw== X-Received: by 2002:a05:6e02:1489:: with SMTP id n9mr4735605ilk.49.1644536559934; Thu, 10 Feb 2022 15:42:39 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id x10sm3286383ill.60.2022.02.10.15.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:42:39 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, John Stultz , Thomas Gleixner , Stephen Boyd Subject: [PATCH 23/49] clocksource: replace cpumask_weight with cpumask_empty in clocksource.c Date: Thu, 10 Feb 2022 14:49:07 -0800 Message-Id: <20220210224933.379149-24-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" clocksource_verify_percpu() calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- kernel/time/clocksource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 95d7ca35bdf2..cee5da1e54c4 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -343,7 +343,7 @@ void clocksource_verify_percpu(struct clocksource *cs) cpus_read_lock(); preempt_disable(); clocksource_verify_choose_cpus(); - if (cpumask_weight(&cpus_chosen) =3D=3D 0) { + if (cpumask_empty(&cpus_chosen)) { preempt_enable(); cpus_read_unlock(); pr_warn("Not enough CPUs to check clocksource '%s'.\n", cs->name); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 681B1C433F5 for ; Thu, 10 Feb 2022 23:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345846AbiBJXow (ORCPT ); Thu, 10 Feb 2022 18:44:52 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245292AbiBJXov (ORCPT ); Thu, 10 Feb 2022 18:44:51 -0500 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CEFCF01 for ; Thu, 10 Feb 2022 15:44:52 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id j12so7284895qtr.2 for ; Thu, 10 Feb 2022 15:44:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=kme7HdDPBLdZ4YQtPbT4M8C1s/pmrIz1qdi0gwByHEo=; b=Bk7rx9gKhdGsR9i8jgVS556YE2ujf0DSOvVCpTdc9PT65IOYqaQn9aot/Y9Xwof7ki cOnVYvWJbPeDast2MgmpVU8Y4Imurlc5MhQl99D0snMgl+6Gu4ehybSGgqRGOefPOoBX 5PEfm69qkAlLEYPK6MkW0jclxUqt7bd8ulqPZGiRaFYvX9dZSOUqEUCbmBDOYFYCflDj g0rF49yNULJKrkgSYVUWolWWUDbQHWS3s4jqHjk5D/DAtrm+AgzV8WvsVC9KB33nSjTz AtmQPfPBeTjUMZLE49hquJI0Dt7lAFl1HT2b050DpuOl8+hOzXAF14k5nUPeiK20UT0y Zq5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kme7HdDPBLdZ4YQtPbT4M8C1s/pmrIz1qdi0gwByHEo=; b=8NMMxHdqzyP5UXIcQ/EXyYFLfZ3t/IR7pXZPCfgAqWdznms6k1zhZ18X/sglbcf1Ev b/VC3GlQ4A8V3Mhjk0zrq3eOqESlGreUOikpcuq63e0ZFLrQ1ZbiVi/D5+f2vzjqonP7 YFm8Agoei65WwOD8rrdtrsdLA1AAnWmse7p6T617XDv/gEuIWaccgQ3HVeMBxq0sNMFu kw1FUxzVvUnZxaBBMNjrRihE8aL/PthtN0j5LRPgYAnljMKXrRmNZ3HGLQrIj3tRWOad C9rpszFzRY9mx2AJc9dP5YOTrh3M2rnbm7Z9CgSqO464KDkEWEWLqHt3hpc/MZhJp7uk PRog== X-Gm-Message-State: AOAM532OkOP93G0gn0SkWD8MIqyJBBX0PRxo9dCFGvpM0lIvltUR19yk cmc5TtLOOCc/TJHyGrj0Ut4= X-Google-Smtp-Source: ABdhPJweRk+ewB0DrkLNcDIrsEhPbiqs1Kx+pnRXJsHT5Dn4ekm9Sd6GVVslYeAffagwYjFFuj89hQ== X-Received: by 2002:ac8:5711:: with SMTP id 17mr6533353qtw.287.1644536691131; Thu, 10 Feb 2022 15:44:51 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id w10sm12500893qtj.73.2022.02.10.15.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:44:50 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 24/49] mm/vmstat: replace cpumask_weight with cpumask_empty where appropriate Date: Thu, 10 Feb 2022 14:49:08 -0800 Message-Id: <20220210224933.379149-25-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" mm/vmstat.c code calls cpumask_weight() to check if any bit of a given cpumask is set. We can do it more efficiently with cpumask_empty() because cpumask_empty() stops traversing the cpumask as soon as it finds first set bit, while cpumask_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- mm/vmstat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/vmstat.c b/mm/vmstat.c index d5cc8d739fac..27a94afd4ee5 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -2041,7 +2041,7 @@ static void __init init_cpu_node_state(void) int node; =20 for_each_online_node(node) { - if (cpumask_weight(cpumask_of_node(node)) > 0) + if (!cpumask_empty(cpumask_of_node(node))) node_set_state(node, N_CPU); } } @@ -2068,7 +2068,7 @@ static int vmstat_cpu_dead(unsigned int cpu) =20 refresh_zone_stat_thresholds(); node_cpus =3D cpumask_of_node(node); - if (cpumask_weight(node_cpus) > 0) + if (!cpumask_empty(node_cpus)) return 0; =20 node_clear_state(node, N_CPU); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFA1AC433F5 for ; Thu, 10 Feb 2022 23:47:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345863AbiBJXrG (ORCPT ); Thu, 10 Feb 2022 18:47:06 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245029AbiBJXrF (ORCPT ); Thu, 10 Feb 2022 18:47:05 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DBA15F6C for ; Thu, 10 Feb 2022 15:47:05 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id j24so6629990qkk.10 for ; Thu, 10 Feb 2022 15:47:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=gGkHPLqBQKDsGoPmAyVSh4TYPJ0or382g4vYKeAbj9k=; b=Z0iEVeiDJDrqgnuQUo4TAvgwcXJbVN1mbL1mlhsB41Xu/KhWJJf9aEtOe3JS5rAqVM /WXBakO1J2nP9r0LWFX+8wyhYMALfRyk4QxyRLlXe8q4TqP9pk8UA6OLvtrFFEcRYMXj +lTkqDl2XhNNZ5A19ONY7fUxXo4cGkVHQGkNmOeIwiWwtza+Pk7FVhdT4U9O7dyZQ0ew msfnGNc2QANssGVLDL28MoVZJem4RYA3hZO5fyJZgcDntdlO0qsBoyK+Rqp09uKpNy1c iBhgf3hgjhEfTS4ijGMv3lYg9dL68LzoyO+Vdh0RDbWOE6IF8l0/qfjLq8ucpGI6YZ6h vnuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gGkHPLqBQKDsGoPmAyVSh4TYPJ0or382g4vYKeAbj9k=; b=O80+Qfogg8gOuT+5iwEuOibD/5Hxrdm7dVuhoMvjTGWSNqxXyIx550N0uI4DgYcVBf lGIUeHdXmuIsHx25xbmgGzApvHspjKd6iyu8JqtVM1KyptdV1lbtLGMMynx+ajlQxvli J3SRnCnDZ8XEJbpkOn374EegVbkDyz+ncz6zrdNKFGxPPMAN3fraGq3UNuoWx9PR44iD pkD5EmjLfj3+O4EQtqvdSEgMxQBqJz26rKPdVue9/ZS3f98YAFLiqQOjDI+Ceae0Ikqo ylPlfU/N8561TJVg3ye3omjbjAqhNvi/zbQOTgDcLk0YOMHxF1yQjbiuMBtPnV769+hO Y6Vw== X-Gm-Message-State: AOAM530nNtyOmAxLwCgWSSNvdLYiQnpep5aBpZ3WOvZrEQHZcOje18XJ TXRiPZhjNBbmZmmCOCe4wAo= X-Google-Smtp-Source: ABdhPJx6mdswTdq3gyvbThBS8ISzTGJZyPjLxz4l3MqVL6OVv538vYhN/VnV6TPMLq64RMV/nMqiKQ== X-Received: by 2002:a05:620a:4502:: with SMTP id t2mr5111507qkp.311.1644536824596; Thu, 10 Feb 2022 15:47:04 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id bp37sm10202111qkb.135.2022.02.10.15.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:47:04 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Dave Hansen , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH 25/49] arch/x86: replace nodes_weight with nodes_empty where appropriate Date: Thu, 10 Feb 2022 14:49:09 -0800 Message-Id: <20220210224933.379149-26-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" mm code calls nodes_weight() to check if any bit of a given nodemask is set. We can do it more efficiently with nodes_empty() because nodes_empty() stops traversing the nodemask as soon as it finds first set bit, while nodes_weight() counts all bits unconditionally. Signed-off-by: Yury Norov --- arch/x86/mm/amdtopology.c | 2 +- arch/x86/mm/numa_emulation.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/amdtopology.c b/arch/x86/mm/amdtopology.c index 058b2f36b3a6..b3ca7d23e4b0 100644 --- a/arch/x86/mm/amdtopology.c +++ b/arch/x86/mm/amdtopology.c @@ -154,7 +154,7 @@ int __init amd_numa_init(void) node_set(nodeid, numa_nodes_parsed); } =20 - if (!nodes_weight(numa_nodes_parsed)) + if (nodes_empty(numa_nodes_parsed)) return -ENOENT; =20 /* diff --git a/arch/x86/mm/numa_emulation.c b/arch/x86/mm/numa_emulation.c index 1a02b791d273..9a9305367fdd 100644 --- a/arch/x86/mm/numa_emulation.c +++ b/arch/x86/mm/numa_emulation.c @@ -123,7 +123,7 @@ static int __init split_nodes_interleave(struct numa_me= minfo *ei, * Continue to fill physical nodes with fake nodes until there is no * memory left on any of them. */ - while (nodes_weight(physnode_mask)) { + while (!nodes_empty(physnode_mask)) { for_each_node_mask(i, physnode_mask) { u64 dma32_end =3D PFN_PHYS(MAX_DMA32_PFN); u64 start, limit, end; @@ -270,7 +270,7 @@ static int __init split_nodes_size_interleave_uniform(s= truct numa_meminfo *ei, * Fill physical nodes with fake nodes of size until there is no memory * left on any of them. */ - while (nodes_weight(physnode_mask)) { + while (!nodes_empty(physnode_mask)) { for_each_node_mask(i, physnode_mask) { u64 dma32_end =3D PFN_PHYS(MAX_DMA32_PFN); u64 start, limit, end; --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F270C433EF for ; Thu, 10 Feb 2022 23:49:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345890AbiBJXtS (ORCPT ); Thu, 10 Feb 2022 18:49:18 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345882AbiBJXtR (ORCPT ); Thu, 10 Feb 2022 18:49:17 -0500 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4FBA2675 for ; Thu, 10 Feb 2022 15:49:17 -0800 (PST) Received: by mail-io1-xd31.google.com with SMTP id h7so9487226iof.3 for ; Thu, 10 Feb 2022 15:49:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=2cLL6GgieOi8PSHYt1Oj179zJLe2EJ32f4QVxiwhrqo=; b=a5GbJPLgc4uajvB15v596nI+6UEwqRoTDFrUKemBv8TQBFWA5FTKz0vURTzG3bIQav 6Uo3KwPYtPg9WM5SOfVnW1gZZEYGoJRfl4J9jja0X/H/LN6i3DZmvvVGXL0beOF1veWX XK54fNnfnjn3AlggVgBpbLlw/EBHNurXTE5XoFOsWykX9w6mOb+bme6S7hfp2gEdG2kb IkVrpF/bzjS7au4UF8Ylj1S/lrPOn8Uq2nrMOxiO8HmiG9CQzsJ+MSsTf/U8hzEaYy0i ZlwDE/tqw56A234JdLK4/CKgISg55ij+Ewz3sKPFrVUYb7FWbY4GfXi+CXaXL+ATnTLW t+rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2cLL6GgieOi8PSHYt1Oj179zJLe2EJ32f4QVxiwhrqo=; b=r2HK+6NivxxcjHh3Xu6Be0sBKLNKjfQLKRn4uDJ+55zPkHdiJF+YcgiCHUCWK7VbHI xTImXDo4t0ZpqdJs0taf+4z520iChWzo9qa6PmHqP7skwaNIMARWbSUWRtWj70E4taHu +H1jf5vf9CdyDWRFFymP2wNC6f/ATj4RiXFw2f+9/6Wd7s8Hmq+yc2I7Lv0ZNn6qONrY onbHtMnSk0XZK5RLeDwHtTb5SYMnc+aGQILDbZYt2dchKrMirr6la3W9D+Phvo+RSbTc 0eMM+1SfTayvMd+uQ+vJzbQggbjFr2DZyHl1vg+ymiBV+afluExa3uXhAJuSeCSKvi4W RMgA== X-Gm-Message-State: AOAM533P18xEgxjYhZYznWphADTZXsu+5ImVQJszdB5dsoftDkPF/keA CuGN278KWunAFMyWpzTx1bI= X-Google-Smtp-Source: ABdhPJxIjSyathMj2m6V4TRCgp/Or81uA26s7EOPH7C4cGg8mcV+gXDI5+rYpe4/og7fG3sxY22MRQ== X-Received: by 2002:a05:6638:38a3:: with SMTP id b35mr5392270jav.180.1644536957205; Thu, 10 Feb 2022 15:49:17 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id i3sm11859959ilu.28.2022.02.10.15.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:49:16 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org Subject: [PATCH 26/49] bitmap: add bitmap_weight_{cmp, eq, gt, ge, lt, le} functions Date: Thu, 10 Feb 2022 14:49:10 -0800 Message-Id: <20220210224933.379149-27-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Many kernel users use bitmap_weight() to compare the result against some number or expression: if (bitmap_weight(...) > 1) do_something(); It works OK, but may be significantly improved for large bitmaps: if first few words count set bits to a number greater than given, we can stop counting and immediately return. The same idea would work in other direction: if we know that the number of set bits that we counted so far is small enough, so that it would be smaller than required number even if all bits of the rest of the bitmap are set, we can stop counting earlier. This patch adds new bitmap_weight_cmp() as suggested by Micha=C5=82 Miros= =C5=82aw and a family of eq, gt, ge, lt, and le wrappers to allow this optimization. The following patches apply new functions where appropriate. Suggested-by: Micha=C5=82 Miros=C5=82aw (for bitm= ap_weight_cmp) Signed-off-by: Yury Norov Reviewed-by: Matti Vaittinen --- include/linux/bitmap.h | 78 ++++++++++++++++++++++++++++++++++++++++++ lib/bitmap.c | 21 ++++++++++++ 2 files changed, 99 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 7dba0847510c..a89b626d0fbe 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -51,6 +51,12 @@ struct device; * bitmap_empty(src, nbits) Are all bits zero in *src? * bitmap_full(src, nbits) Are all bits set in *src? * bitmap_weight(src, nbits) Hamming Weight: number set= bits + * bitmap_weight_cmp(src, nbits) compare Hamming Weight wit= h a number + * bitmap_weight_eq(src, nbits, num) Hamming Weight =3D=3D num + * bitmap_weight_gt(src, nbits, num) Hamming Weight > num + * bitmap_weight_ge(src, nbits, num) Hamming Weight >=3D num + * bitmap_weight_lt(src, nbits, num) Hamming Weight < num + * bitmap_weight_le(src, nbits, num) Hamming Weight <=3D num * bitmap_set(dst, pos, nbits) Set specified bit area * bitmap_clear(dst, pos, nbits) Clear specified bit area * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area @@ -162,6 +168,7 @@ int __bitmap_intersects(const unsigned long *bitmap1, int __bitmap_subset(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int nbits); int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); +int __bitmap_weight_cmp(const unsigned long *bitmap, unsigned int bits, in= t num); void __bitmap_set(unsigned long *map, unsigned int start, int len); void __bitmap_clear(unsigned long *map, unsigned int start, int len); =20 @@ -403,6 +410,77 @@ static __always_inline int bitmap_weight(const unsigne= d long *src, unsigned int return __bitmap_weight(src, nbits); } =20 +/** + * bitmap_weight_cmp - compares number of set bits in @src with @num. + * @src: source bitmap + * @nbits: length of bitmap in bits + * @num: number to compare with + * + * As opposite to bitmap_weight() this function doesn't necessarily + * traverse full bitmap and may return earlier. + * + * Because number of set bits cannot decrease while counting, when user + * wants to know if the number of set bits in the bitmap is less than + * @num, calling + * bitmap_weight_cmp(..., @num) < 0 + * is potentially less effective than + * bitmap_weight_cmp(..., @num - 1) <=3D 0 + * + * Consider an example: + * bitmap_weight_cmp(1000 0000 0000 0000, 1) < 0 + * ^ + * stop here + * + * bitmap_weight_cmp(1000 0000 0000 0000, 0) <=3D 0 + * ^ + * stop here + * + * Returns: zero if weight of @src is equal to @num; + * negative number if weight of @src is less than @num; + * positive number if weight of @src is greater than @num. + */ +static __always_inline +int bitmap_weight_cmp(const unsigned long *src, unsigned int nbits, int nu= m) +{ + if ((unsigned int)num > nbits) + return -num; + + if (small_const_nbits(nbits)) + return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)) - num; + + return __bitmap_weight_cmp(src, nbits, num); +} + +static __always_inline +bool bitmap_weight_eq(const unsigned long *src, unsigned int nbits, int nu= m) +{ + return bitmap_weight_cmp(src, nbits, num) =3D=3D 0; +} + +static __always_inline +bool bitmap_weight_gt(const unsigned long *src, unsigned int nbits, int nu= m) +{ + return bitmap_weight_cmp(src, nbits, num) > 0; +} + +static __always_inline +bool bitmap_weight_ge(const unsigned long *src, unsigned int nbits, int nu= m) +{ + return bitmap_weight_cmp(src, nbits, num - 1) > 0; +} + +static __always_inline +bool bitmap_weight_lt(const unsigned long *src, unsigned int nbits, int nu= m) +{ + return bitmap_weight_cmp(src, nbits, num - 1) <=3D 0; +} + +static __always_inline +bool bitmap_weight_le(const unsigned long *src, unsigned int nbits, int nu= m) +{ + return bitmap_weight_cmp(src, nbits, num) <=3D 0; +} + static __always_inline void bitmap_set(unsigned long *map, unsigned int st= art, unsigned int nbits) { diff --git a/lib/bitmap.c b/lib/bitmap.c index 926408883456..fb84ca70c5d9 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -348,6 +348,27 @@ int __bitmap_weight(const unsigned long *bitmap, unsig= ned int bits) } EXPORT_SYMBOL(__bitmap_weight); =20 +int __bitmap_weight_cmp(const unsigned long *bitmap, unsigned int bits, in= t num) +{ + unsigned int k, w, lim =3D bits / BITS_PER_LONG; + + for (k =3D 0, w =3D 0; k < lim; k++) { + if (w + bits - k * BITS_PER_LONG < num) + goto out; + + w +=3D hweight_long(bitmap[k]); + + if (w > num) + goto out; + } + + if (bits % BITS_PER_LONG) + w +=3D hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); +out: + return w - num; +} +EXPORT_SYMBOL(__bitmap_weight_cmp); + void __bitmap_set(unsigned long *map, unsigned int start, int len) { unsigned long *p =3D map + BIT_WORD(start); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23929C433F5 for ; Thu, 10 Feb 2022 23:51:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345902AbiBJXva (ORCPT ); Thu, 10 Feb 2022 18:51:30 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345898AbiBJXv2 (ORCPT ); Thu, 10 Feb 2022 18:51:28 -0500 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F35885F75 for ; Thu, 10 Feb 2022 15:51:28 -0800 (PST) Received: by mail-io1-xd36.google.com with SMTP id c188so9467168iof.6 for ; Thu, 10 Feb 2022 15:51:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5dCk4FzrvHhwMLJneJLOY/dcPEyndJPxlHaJYZoEpFk=; b=B1e0SDNthk73k00xBMHULPHNIG3scZT8MMQCtDDPnU+ASlc9VWbUNkMJUQyffY7IX3 ivfLQgs2A0MMN67WzKhJN1yYRIeVxUbOJC97r1Uo7/Ud5PSY+sMUmiE3J2p98UTQG6GP YjbJLQlKrjHocWLIvy91hrv2GnSfof1DojUtZvNFpr9clikRnI5AbeBFI8/LzGFF8yvc PWBDZnWUwg3yTvitIhOsZbIsvGDr8RlY2ppLGa1yYFFJnLF0RsW89FGsn0vD0bLq0Qua O/Y5CXY31dui1uTHUtqZeyfGc1gsBTxupgmi1RZNfFmWHPLRsj52a+D//O0z3xR4USab Kklw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5dCk4FzrvHhwMLJneJLOY/dcPEyndJPxlHaJYZoEpFk=; b=PT3WSn7aZetEyB6g/82iMAbOqd285RIgUXzgjD5LgGXP+gIjtRB4GfFe0FC2GlgmBe H6aXXJB+c27ATtDx3ux2eL4Tv5NdWBaPTM54jZvbzfbrH7+XYgvj6TjoOyUY4sgomOaT AQIHzpH0L3cS+2OhQMqtEAf31OQCB9wuZ0Q9l1KpWcQTFg4Vi3d/75J2JIdJnXT5vo1T Wk5/ECRWMTBawJjhGs/hSlU/4q8AHqdby1DgG8yJ4/3eGigT6DBBi1t0yu86WnL+UEPw QVnSdG1ZPh7OmgTpX0I5rynFxE4dffVOCgo832YJoB1F1DTYCII0fP9Y4QcLgkqzAL/q 8o0A== X-Gm-Message-State: AOAM5317RTrqx914BWwHZb/bZ2R3URHblD6JJdbeCIsRqoqc9ZgB+WPp rrO0A6KWsSBDwsajsVZzEWc= X-Google-Smtp-Source: ABdhPJysecqyF1xHXIb448cPo+Fqbe1UTP2z1seIWAOfE9T/8KCaZ4AyX268s5gQTwQDF3OArZz/Ag== X-Received: by 2002:a05:6638:260b:: with SMTP id m11mr5150240jat.55.1644537088359; Thu, 10 Feb 2022 15:51:28 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id q2sm6614751ilt.33.2022.02.10.15.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:51:27 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH 27/49] arch/x86: replace bitmap_weight with bitmap_weight_{eq,gt,ge,lt,le} where appropriate Date: Thu, 10 Feb 2022 14:49:11 -0800 Message-Id: <20220210224933.379149-28-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" __init_one_rdt_domain in rdtgroup.c code calls bitmap_weight() to compare the weight of bitmap with a given number. We can do it more efficiently with bitmap_weight_lt because conditional bitmap_weight() may stop traversing the bitmap earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index e23ff03290b8..9d42e592c1cf 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -2752,7 +2752,7 @@ static int __init_one_rdt_domain(struct rdt_domain *d= , struct resctrl_schema *s, * bitmap_weight() does not access out-of-bound memory. */ tmp_cbm =3D cfg->new_ctrl; - if (bitmap_weight(&tmp_cbm, r->cache.cbm_len) < r->cache.min_cbm_bits) { + if (bitmap_weight_lt(&tmp_cbm, r->cache.cbm_len, r->cache.min_cbm_bits)) { rdt_last_cmd_printf("No space on %s:%d\n", s->name, d->id); return -ENOSPC; } --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAF76C433EF for ; Thu, 10 Feb 2022 23:53:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345909AbiBJXxp (ORCPT ); Thu, 10 Feb 2022 18:53:45 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240464AbiBJXxl (ORCPT ); Thu, 10 Feb 2022 18:53:41 -0500 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0831D5F75; Thu, 10 Feb 2022 15:53:42 -0800 (PST) Received: by mail-io1-xd30.google.com with SMTP id q204so9473512iod.8; Thu, 10 Feb 2022 15:53:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=dlcn0c8FYc7DODG7QrUeh/RDtAB+I+F4Kdfoio51FaI=; b=pT8V02cRnyvge4g/jEw/vfDpSCJQ6mG8f5/2aDrsolSd6MEJ2MeTditvg5HTS3jTiY WtGZZX0/SoKQZhzIgkP9n0Dcpz+r0Ry6EqlDS1ADj+r+2ulVo+sw3mWYm6spJo0j4izv N1Ts5gZLSbXcfXixzzF1vDOzXCcZZGoO1De22gzUYl4uxS93hxyIA0QHPiwWxW7NznE1 lewNaZm3nBzJFJx6tYvobMi78QVigZ22b58D/vnMuMkpRkUzPV6fqocJUenoiOeZYDlQ W543WAQd+q0/+WonyRm+lCqOpJHOTkjXAKKjvaVnXKxFWTPxKbP0S6V7BC0ngGjwAxig dinw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dlcn0c8FYc7DODG7QrUeh/RDtAB+I+F4Kdfoio51FaI=; b=3A6NIwIeavoUYipRWjuzK5wDwLiStp3ujhMBqkbMCPiFG2V1zHwhxY5wL+EGKT0/vM ekStjIW8QaWB7flsLaAq6TiLJpgtyEHRDRnrow64mvjGxxXzg2yyIwLgOZWiwlayXUW1 Y2hrDRA3+yncT6Ip1zF7G+yGNrT1/lqphYY7ybP2zkEPIiL/wICxzhlnY2WPk9D6Fcn3 DCnrcauleYcUKIsdDpVHGmvRxtb2ve61bRcEHFliF/nPKOrL7fG2KOG5/mDgOvqQFxXC zNTIe9OKSk2xoYNQyciNnGg0Jvi5NWE88C5zLegXeY6xx8fLScAeQP0V1/9hwm3UjZRq mT+Q== X-Gm-Message-State: AOAM531XCfY+wDmFG2PImSr9TRASQNlQg6DQ3lWygVqdoYJb+MglgtYV MH+A6fjHm8frxgfWu4r2a64= X-Google-Smtp-Source: ABdhPJy1cnRyAEVSz8FK6oisjYTOYyOW5apveqRHtmqXfgAdrv7GPswYZO2OmUFJkYqdisR1K1A0IQ== X-Received: by 2002:a05:6602:2c8d:: with SMTP id i13mr5215640iow.181.1644537221384; Thu, 10 Feb 2022 15:53:41 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id e17sm11144879ilm.67.2022.02.10.15.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:53:41 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Jakub Kicinski , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org Subject: [PATCH 28/49] iio: replace bitmap_weight() with bitmap_weight_{eq,gt} where appropriate Date: Thu, 10 Feb 2022 14:49:12 -0800 Message-Id: <20220210224933.379149-29-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" drivers/iio calls bitmap_weight() to compare the weight of bitmap with a given number. We can do it more efficiently with bitmap_weight_eq because conditional bitmap_weight may stop traversing the bitmap earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- drivers/iio/industrialio-trigger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-= trigger.c index f504ed351b3e..98c54022fecf 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -331,7 +331,7 @@ int iio_trigger_detach_poll_func(struct iio_trigger *tr= ig, { struct iio_dev_opaque *iio_dev_opaque =3D to_iio_dev_opaque(pf->indio_dev= ); bool no_other_users =3D - bitmap_weight(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER) =3D=3D 1; + bitmap_weight_eq(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER, 1); int ret =3D 0; =20 if (trig->ops && trig->ops->set_trigger_state && no_other_users) { --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C5E2C433EF for ; Thu, 10 Feb 2022 23:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345951AbiBJXz4 (ORCPT ); Thu, 10 Feb 2022 18:55:56 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345909AbiBJXzz (ORCPT ); Thu, 10 Feb 2022 18:55:55 -0500 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ADE65F83; Thu, 10 Feb 2022 15:55:55 -0800 (PST) Received: by mail-io1-xd31.google.com with SMTP id c188so9475771iof.6; Thu, 10 Feb 2022 15:55:55 -0800 (PST) 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=9Poe1QU0FyqYAnHH8Q+q/1vr6hVBL5HGB2D6185D4Dc=; b=g31QJrIdHnrArxOcj+UtssUsmwnWEpH4lQAi2PZOos3OiL1YRpDRz8LhpX0UqO019M VbAjG0CpxRcTaZ9F2Z5FfMfKvoymkuIxkojwKOyOspqzdoQuZuukn/CD6iH4hXlMql6a y1emREWzbvfX8nKyVV+eNehAExdOMASWVGrEC5hJRbX6TlrY29oEs7aIlM/9mRm9xHgV Rre3uyOgzPJZl799rdCZyxHLg7qjtxkKfJHCwnLgkd0TTvy57u4IHey9pRNlwJqKLpgN dNTv5O/2hn7LRQQh2QoZ7blZYoTLIx3M6TjJwkeAUSxg/+K3RWUmOxa+YMxKXRQeSygm 6arQ== 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=9Poe1QU0FyqYAnHH8Q+q/1vr6hVBL5HGB2D6185D4Dc=; b=7QpP4semKo/wDBdvWxzR+iiha9Fp1mX2js8qSXiO9q8pqSXEI+wFFfpYV4clqmtvaj D5wJksbwKiVkbF6fklMbBbm+TAWm4c0pUOwEKsd3lL8krXad5h7P6yvm72hPckWh6lsB zrKqEfRAKG2ubY9kTAuxmU81gzSJg83l3rFy8gSD9V3OyWCJY2RfWI0pZfhxb1bkt/YV 1M4HBsl69teBu8oZr2oAJfMxy23Ta3PMUSik8AoImZen2rAI1kpNzebkLeo7CKd0xfFg E//hyTANlhDr141vnD0GD4ULM9VfsbIjJq6upoz+LrqkdUciQLUYio5MpoyRhV6k2yW8 9A+w== X-Gm-Message-State: AOAM531l6+DnVytj+ykAv+cLciKRlvygdPhW2ylInC1ydFfLcpvUHF1j OevOTrBeFD4YpgmmiTHK3bw= X-Google-Smtp-Source: ABdhPJxH+VGiGx9FUazjFDcnU7odGVOPzznh3sg75Vp+ADEFdLGkzCpLhCud0L3DRIIA/OcM2o86vA== X-Received: by 2002:a02:3f42:: with SMTP id c2mr5403680jaf.161.1644537354570; Thu, 10 Feb 2022 15:55:54 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id e20sm6388176ioc.35.2022.02.10.15.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:55:54 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Maxim Levitsky , Alex Dubov , Ulf Hansson , Jens Axboe , Luis Chamberlain , Colin Ian King , Arnd Bergmann , Shubhankar Kuranagatti , linux-mmc@vger.kernel.org Cc: Shubhankar Kuranagatti Subject: [PATCH 29/49] memstick: replace bitmap_weight with bitmap_weight_eq where appropriate Date: Thu, 10 Feb 2022 14:49:13 -0800 Message-Id: <20220210224933.379149-30-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" msb_validate_used_block_bitmap() calls bitmap_weight() to compare the weight of bitmap with a given number. We can do it more efficiently with bitmap_weight_eq because conditional bitmap_weight may stop traversing the bitmap earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov Acked-by: Ulf Hansson Acked-by: Shubhankar Kuranagatti --- drivers/memstick/core/ms_block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_bl= ock.c index 0cda6c6baefc..5cdd987e78f7 100644 --- a/drivers/memstick/core/ms_block.c +++ b/drivers/memstick/core/ms_block.c @@ -155,8 +155,8 @@ static int msb_validate_used_block_bitmap(struct msb_da= ta *msb) for (i =3D 0; i < msb->zone_count; i++) total_free_blocks +=3D msb->free_block_count[i]; =20 - if (msb->block_count - bitmap_weight(msb->used_blocks_bitmap, - msb->block_count) =3D=3D total_free_blocks) + if (bitmap_weight_eq(msb->used_blocks_bitmap, msb->block_count, + msb->block_count - total_free_blocks)) return 0; =20 pr_err("BUG: free block counts don't match the bitmap"); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 945A5C433EF for ; Thu, 10 Feb 2022 23:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345975AbiBJX6H (ORCPT ); Thu, 10 Feb 2022 18:58:07 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345964AbiBJX6F (ORCPT ); Thu, 10 Feb 2022 18:58:05 -0500 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 354723AF; Thu, 10 Feb 2022 15:58:06 -0800 (PST) Received: by mail-io1-xd29.google.com with SMTP id c188so9480085iof.6; Thu, 10 Feb 2022 15:58:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=wCe8l6BzIf39UXY71HrtaLDcF4n6vO18YFKJdpw4cXQ=; b=fI2SwxxZTVMqpxGhquBSWDyfIQ9U9DsAgpF9gRFwhpoAula9Vdzc1QlFVFHC1U6hwI ABtDL5EahVrOMWQOjSc1cxNHQioV9menjUMsuOH/Cnz8hecA97jxN6sPuk95u7nVfkQV v9wtNrSgpkd8oKfTH9OUi7v/x70ZavMozIl54AC5RULi2izx6U5HggOLYqF4OGCV8xvC S2cFxQ+81wUoSrp358Cp/BnH7gOLObY9fktA/0i7ZL+H0LeU4Gh8hM6p7+fRhxCwSkx6 mo4eV4AeXA5Mg/ksXKxD2Mw7++3/aR12BIxW+0jlVA0zfkk45kSAnE0jXh1mlQ8+k9e9 HVjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wCe8l6BzIf39UXY71HrtaLDcF4n6vO18YFKJdpw4cXQ=; b=vOoOGJkTXl1/xJAci7WVAv8LPEgWzHzOUoeu+uu+6AUAe/we+WIt278IVZddlc/BfE w42Noycd7YAaNw/nGfBFjnVtr17Lfo5re7NQByJPGO41uuXS/+5MLvlloQ9ZRu7d3Afw n8tDWxUDtbIbdDoxyK+sckpgdUI3Ez+ygeuhFyAQB/j8ys1XeeBwDeHuhZY0xnlrjBB3 JECbe6MRTradiW6PNfa1303aMTpw6YruLgHZj65xTgXOg572vOxHzBTSShFOstMEFnqJ 3JLAHisLYOGEiJ+QFm9V+O0u6Rvy6tAHRVU4TrLYYLNkhDvS4cDZAwOepfw9Uc6XGgxw 2YhA== X-Gm-Message-State: AOAM533H8A67IBTF9xr0wqatuIj3UO0xWQEkWCweRHfXiv+8YVKd0TZx 4wkr3xP1fP+i42Q5pXuFUj0= X-Google-Smtp-Source: ABdhPJyy7xzUjWAsxQE/FjXnUixngXgx0pMBOB0uizulIEe8wbp5Hbd+lionqAo02gVkXrx+e9ndLw== X-Received: by 2002:a05:6602:492:: with SMTP id y18mr4939747iov.95.1644537485609; Thu, 10 Feb 2022 15:58:05 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id t6sm12773865iov.39.2022.02.10.15.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 15:58:05 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Jakub Kicinski , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org Subject: [PATCH 30/49] ixgbe: replace bitmap_weight with bitmap_weight_eq Date: Thu, 10 Feb 2022 14:49:14 -0800 Message-Id: <20220210224933.379149-31-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" ixgbe_disable_sriov calls bitmap_weight() to compare the weight of bitmap with a given number. We can do it more efficiently with bitmap_weight_eq because conditional bitmap_weight may stop traversing the bitmap earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/e= thernet/intel/ixgbe/ixgbe_sriov.c index 214a38de3f41..35297d8a488b 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c @@ -246,7 +246,7 @@ int ixgbe_disable_sriov(struct ixgbe_adapter *adapter) #endif =20 /* Disable VMDq flag so device will be set in VM mode */ - if (bitmap_weight(adapter->fwd_bitmask, adapter->num_rx_pools) =3D=3D 1) { + if (bitmap_weight_eq(adapter->fwd_bitmask, adapter->num_rx_pools, 1)) { adapter->flags &=3D ~IXGBE_FLAG_VMDQ_ENABLED; adapter->flags &=3D ~IXGBE_FLAG_SRIOV_ENABLED; rss =3D min_t(int, ixgbe_max_rss_indices(adapter), --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49573C433EF for ; Fri, 11 Feb 2022 00:00:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345983AbiBKAAR (ORCPT ); Thu, 10 Feb 2022 19:00:17 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344855AbiBKAAQ (ORCPT ); Thu, 10 Feb 2022 19:00:16 -0500 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41E2DB43; Thu, 10 Feb 2022 16:00:17 -0800 (PST) Received: by mail-io1-xd36.google.com with SMTP id c188so9484478iof.6; Thu, 10 Feb 2022 16:00:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=1VzDs/UF8yNYolinMWkkLgNxpJN0NuoP4WS4+Lqu0sA=; b=m35rj5AcGg4ZoO/CaQ6n0yBhN80NZMhAZaAYPc5oQ5QLdbRk6Sl/E8joLQn53J4ff3 2Q4sVyUWGAiW9X/8aoIfgolVHBX39NTLvrHb/NT1sL9Ckw7tjAj0TA2/Mf+TMPFdlKhe E/D2qMjz7iKjdcFKzXN01mzzHTOMC7ys6tQ7P5WAjTgXg7NNG67Tn7WARC/UTrpPNLu/ p53LCn/B4zYErDdyOIsWeNVIQlH5nblQtYEZAqvmI6fWAjalLCk1MiS0Wix4HmyL1m/7 /fcQYKq/1C0EpHDZ+djamC1YqlAZ5ps0Tw7cMdqna9BtQRZ1tlLH8EZAZlG8OgZ/vokz YQJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1VzDs/UF8yNYolinMWkkLgNxpJN0NuoP4WS4+Lqu0sA=; b=Zju7Ck6xu/Agr/t93XDt/4p8c391UDeERVDtbVb1tJjcGC7sgrXgMDveebI62ab3FP /uxWwEZbHK225FEIMli81Er4Tb5NViHt2o2iwqVJ7i0eac2n3WsOkyVjeWtv5jcBBmEy TBBDNVA6ZR/w4CyGTESsBaxdhRU3kxU4C8/lhFIldDI51TqTY5xLgM/CzExItbfWt8vT G8t1fYe6wVMurzAr0+v7muJcFHebKIYutWIxSQUVXBx6lvwtgTqnhntnwAJeCEm1ucbz YbwCTV9Yq8k+QGpEw/JlQ9TPYGgswfwlkJ1y4wC9QgqnVkrLHQznUAJHD5xNQtaPHAW0 dubA== X-Gm-Message-State: AOAM5339rAB14H7Dix/65hY4Ud1PKg2/L08m6wwnTyGFRGYC7gRMVMh7 VC1TgxGF7m8fTKwn/pCewcw= X-Google-Smtp-Source: ABdhPJxIsukjl91lmQIP9KGBjssEZgccEFXHxU6BJidUIyqZB50gNcturaZWfIbyxXDkBQagwZ6erQ== X-Received: by 2002:a05:6602:148c:: with SMTP id a12mr5156955iow.139.1644537616646; Thu, 10 Feb 2022 16:00:16 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id x1sm11412699ilc.34.2022.02.10.16.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:00:16 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Sunil Goutham , Geetha sowjanya , Subbaraya Sundeep , hariprasad , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Subject: [PATCH 31/49] octeontx2-pf: replace bitmap_weight with bitmap_weight_{eq,gt} Date: Thu, 10 Feb 2022 14:49:15 -0800 Message-Id: <20220210224933.379149-32-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" OcteonTX2 code calls bitmap_weight() to compare the weight of bitmap with a given number. We can do it more efficiently with bitmap_weight_{eq,gt} because conditional bitmap_weight may stop traversing the bitmap earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 2 +- drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c b/dr= ivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c index abe5267210ef..152890066c2a 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c @@ -287,7 +287,7 @@ static int otx2_set_channels(struct net_device *dev, if (!channel->rx_count || !channel->tx_count) return -EINVAL; =20 - if (bitmap_weight(&pfvf->rq_bmap, pfvf->hw.rx_queues) > 1) { + if (bitmap_weight_gt(&pfvf->rq_bmap, pfvf->hw.rx_queues, 1)) { netdev_err(dev, "Receive queues are in use by TC police action\n"); return -EINVAL; diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c b/driv= ers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c index 80b2d64b4136..55c899a6fcdd 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c @@ -1170,8 +1170,8 @@ int otx2_remove_flow(struct otx2_nic *pfvf, u32 locat= ion) * interface mac address and configure CGX/RPM block in * promiscuous mode */ - if (bitmap_weight(&flow_cfg->dmacflt_bmap, - flow_cfg->dmacflt_max_flows) =3D=3D 1) + if (bitmap_weight_eq(&flow_cfg->dmacflt_bmap, + flow_cfg->dmacflt_max_flows, 1)) otx2_update_rem_pfmac(pfvf, DMAC_ADDR_DEL); } else { err =3D otx2_remove_flow_msg(pfvf, flow->entry, false); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96220C433FE for ; Fri, 11 Feb 2022 00:02:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346008AbiBKACb (ORCPT ); Thu, 10 Feb 2022 19:02:31 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345998AbiBKAC3 (ORCPT ); Thu, 10 Feb 2022 19:02:29 -0500 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08AE6B49; Thu, 10 Feb 2022 16:02:29 -0800 (PST) Received: by mail-qk1-x736.google.com with SMTP id b35so6675716qkp.6; Thu, 10 Feb 2022 16:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=cn+lM1AC6Wl058uCalgabTDXoS6RKyQ5ezmTj8hWjqc=; b=U6qybxVNUPg6wMb4Z1IQgNBqT6xW3REYN2Sr/6brQlQsYt6MN0rdzndRhY1bqgcIWj OZEYlaAmP8rhkhwL1v4h50e+w6DKaqK9b4jaDwjxi5J36Nc8nm2KlHJLlSZwqQqN+5AF /GvIdafVgN6DI7iM+8CdPZkYFoz5OtGlCZVRLCCtDwlWHbgPn+wRceAoy1u8/10XPAzW wvwf5sEWsyipP+Co2Us5jJL2qnVCGyhvB+ZAO/LNGkYi16RuhSY5ggC/sSl6UXWNLU5Z eihuxa2wdkytxpqfsQb/fee3IDvquaqQLoOT1wwVQDnXPrO2W4G3b2ti2V7k65li737J woHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cn+lM1AC6Wl058uCalgabTDXoS6RKyQ5ezmTj8hWjqc=; b=SOE4InXr0B3zXPEu0BO79aJYHaK2IPeykdVUW/aZ+jsB7jmdONl/ZmkJvKxCtJXKwv pmK4Bei2IJw5oBTKrd950eYK8bpOkocDq5N4RbOwtDJPpNPQUNZM4HPwtUTPWWIf4Ufd dwqDuyT68h4P2ADEkb7P+clmBC/0F16mcfiDNrZzkMCpVTI5EFrRKWNH1QBlzQa6OyYi fa80CV+TMelQukb4z/BJfF/sIqCgPPGFHz8cbGlMPIDjn08liA2ecdFvTevklUBISf8x ZHYTL2U0ascm+XG+vtlpELBgJZNmi3ghaXaXl0LCodoD6FnE2hf46WGYbNHrvQJm1uDd KxXg== X-Gm-Message-State: AOAM530dLb+2hZBKtiul7XPWewLhJrWLHUojayNrJUMbS8yOUrHXE4bd zYonHBSl22tsKtWaYuVrJbc= X-Google-Smtp-Source: ABdhPJz6x7E7rMj/rklw9RICLxkRDsShVMv05ry/VIWiG39qkYPi6XHc0xmgoCevif80B9SyBk8Vpw== X-Received: by 2002:a05:620a:11ad:: with SMTP id c13mr5210841qkk.541.1644537748044; Thu, 10 Feb 2022 16:02:28 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id r2sm12006233qta.15.2022.02.10.16.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:02:27 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Sunil Goutham , Geetha sowjanya , Subbaraya Sundeep , hariprasad , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Subject: [PATCH 32/49] mlx4: replace bitmap_weight with bitmap_weight_{eq,gt,ge,lt,le} Date: Thu, 10 Feb 2022 14:49:16 -0800 Message-Id: <20220210224933.379149-33-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Mellanox code uses bitmap_weight() to compare the weight of bitmap with a given number. We can do it more efficiently with bitmap_weight_{eq, ...} because conditional bitmap_weight may stop traversing the bitmap earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- drivers/net/ethernet/mellanox/mlx4/cmd.c | 10 +++------- drivers/net/ethernet/mellanox/mlx4/eq.c | 4 ++-- drivers/net/ethernet/mellanox/mlx4/fw.c | 4 ++-- drivers/net/ethernet/mellanox/mlx4/main.c | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/etherne= t/mellanox/mlx4/cmd.c index c56d2194cbfc..5bca0c68f00a 100644 --- a/drivers/net/ethernet/mellanox/mlx4/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c @@ -2792,9 +2792,8 @@ int mlx4_slave_convert_port(struct mlx4_dev *dev, int= slave, int port) { unsigned n; struct mlx4_active_ports actv_ports =3D mlx4_get_active_ports(dev, slave); - unsigned m =3D bitmap_weight(actv_ports.ports, dev->caps.num_ports); =20 - if (port <=3D 0 || port > m) + if (port <=3D 0 || bitmap_weight_lt(actv_ports.ports, dev->caps.num_ports= , port)) return -EINVAL; =20 n =3D find_first_bit(actv_ports.ports, dev->caps.num_ports); @@ -3404,10 +3403,6 @@ int mlx4_vf_set_enable_smi_admin(struct mlx4_dev *de= v, int slave, int port, struct mlx4_priv *priv =3D mlx4_priv(dev); struct mlx4_active_ports actv_ports =3D mlx4_get_active_ports( &priv->dev, slave); - int min_port =3D find_first_bit(actv_ports.ports, - priv->dev.caps.num_ports) + 1; - int max_port =3D min_port - 1 + - bitmap_weight(actv_ports.ports, priv->dev.caps.num_ports); =20 if (slave =3D=3D mlx4_master_func_num(dev)) return 0; @@ -3417,7 +3412,8 @@ int mlx4_vf_set_enable_smi_admin(struct mlx4_dev *dev= , int slave, int port, enabled < 0 || enabled > 1) return -EINVAL; =20 - if (min_port =3D=3D max_port && dev->caps.num_ports > 1) { + if (dev->caps.num_ports > 1 && + bitmap_weight_eq(actv_ports.ports, priv->dev.caps.num_ports, 1)) { mlx4_info(dev, "SMI access disallowed for single ported VFs\n"); return -EPROTONOSUPPORT; } diff --git a/drivers/net/ethernet/mellanox/mlx4/eq.c b/drivers/net/ethernet= /mellanox/mlx4/eq.c index 414e390e6b48..0c09432ff389 100644 --- a/drivers/net/ethernet/mellanox/mlx4/eq.c +++ b/drivers/net/ethernet/mellanox/mlx4/eq.c @@ -1435,8 +1435,8 @@ int mlx4_is_eq_shared(struct mlx4_dev *dev, int vecto= r) if (vector <=3D 0 || (vector >=3D dev->caps.num_comp_vectors + 1)) return -EINVAL; =20 - return !!(bitmap_weight(priv->eq_table.eq[vector].actv_ports.ports, - dev->caps.num_ports) > 1); + return bitmap_weight_gt(priv->eq_table.eq[vector].actv_ports.ports, + dev->caps.num_ports, 1); } EXPORT_SYMBOL(mlx4_is_eq_shared); =20 diff --git a/drivers/net/ethernet/mellanox/mlx4/fw.c b/drivers/net/ethernet= /mellanox/mlx4/fw.c index 42c96c9d7fb1..855aae326ccb 100644 --- a/drivers/net/ethernet/mellanox/mlx4/fw.c +++ b/drivers/net/ethernet/mellanox/mlx4/fw.c @@ -1300,8 +1300,8 @@ int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, = int slave, actv_ports =3D mlx4_get_active_ports(dev, slave); first_port =3D find_first_bit(actv_ports.ports, dev->caps.num_ports); for (slave_port =3D 0, real_port =3D first_port; - real_port < first_port + - bitmap_weight(actv_ports.ports, dev->caps.num_ports); + bitmap_weight_gt(actv_ports.ports, dev->caps.num_ports, + real_port - first_port); ++real_port, ++slave_port) { if (flags & (MLX4_DEV_CAP_FLAG_WOL_PORT1 << real_port)) flags |=3D MLX4_DEV_CAP_FLAG_WOL_PORT1 << slave_port; diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethern= et/mellanox/mlx4/main.c index b187c210d4d6..cfbaa7ac712f 100644 --- a/drivers/net/ethernet/mellanox/mlx4/main.c +++ b/drivers/net/ethernet/mellanox/mlx4/main.c @@ -1383,7 +1383,7 @@ static int mlx4_mf_bond(struct mlx4_dev *dev) dev->persist->num_vfs + 1); =20 /* only single port vfs are allowed */ - if (bitmap_weight(slaves_port_1_2, dev->persist->num_vfs + 1) > 1) { + if (bitmap_weight_gt(slaves_port_1_2, dev->persist->num_vfs + 1, 1)) { mlx4_warn(dev, "HA mode unsupported for dual ported VFs\n"); return -EINVAL; } --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07AB5C433EF for ; Fri, 11 Feb 2022 00:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346036AbiBKAEp (ORCPT ); Thu, 10 Feb 2022 19:04:45 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:35270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242517AbiBKAEl (ORCPT ); Thu, 10 Feb 2022 19:04:41 -0500 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 F0A6F26CD for ; Thu, 10 Feb 2022 16:04:41 -0800 (PST) Received: by mail-qv1-xf2f.google.com with SMTP id n6so6797750qvk.13 for ; Thu, 10 Feb 2022 16:04:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4Pnr1geQeZZNYUvmzTdrAcaSDDBHcWYiYOpV2+IuXsY=; b=igNyfPN7wFlEB1yG0Q94kr/PxThWMFSj7uV6Xa4lsNO8Eodt/gd8/VSAkzJPPNNLqD qQwMyH8ytBWbsWit97TH9K8POhN09okti3ZyrqvzyHsbekkA+9K/sE9UpcWfflBJ6IX+ rhewR0hrCY8scmAiE3GTbwcTImsKu8PHITWAJ8KcJjCbRrQVFfaIPsg5CJBI+XMVT1T2 Mpfbx/rAP4rZXHBa7IM2cBBntYJ+Tq2sImYYlI9cqsl2/gWObSkvu8rlLJoLDx7IJcj1 jCx2oUFhq59q3xZWxiZBd6OlaPcAu9p4kvX0V3N74k5jHjhmq4ZfoiAb7ipvUDuOUeOL 9MJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4Pnr1geQeZZNYUvmzTdrAcaSDDBHcWYiYOpV2+IuXsY=; b=UU6GMNB0fsGJrG3DfVheY67iM57aasdZCTqsTCSs5wrXVFYICw/TLQLnD9tN8YnGS6 gI76ub3oSZ1shTs4MUftCP/ZyU8pv96I1mltbJNexVTgogFQCHDDXjIqffeKDhHAuXGc MNHY4d1nYp243k8Vp5iEYL5A2rCh04kUXN3AAEn2rfUWNLi/EN+lt6/RGJRQFWxfnmDS nG9RI/fBHDagAY4+vFETd7PBAWMyVB8934dRIBRPM5WzSFXSETKf6cNDbz5nqQ8UTUVY SqZJDFj+R8LXa9mOSXt/OR1qSIXrjUHU8uraOlX0fLUpmqGEl3KgVg9HDcNawpr7+IiT x8dQ== X-Gm-Message-State: AOAM533wGaB+ZxL0iXl4l6FPXwCKDM0J0CbF35eSwO7p+RhU+kCvIN9w QAJHsxwxcuVH5cYPPWzJN9ljTBMJryNVeQ== X-Google-Smtp-Source: ABdhPJyfV3TF5HzHznBEsBWEauR+HTDxani3jRA7hek8YabMaXIpvx3P8mEI1Y1Wy7MVJOQjILfz9w== X-Received: by 2002:a05:6214:2306:: with SMTP id gc6mr6804104qvb.45.1644537881043; Thu, 10 Feb 2022 16:04:41 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id 195sm10710640qkf.30.2022.02.10.16.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:04:40 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org Subject: [PATCH 33/49] perf: replace bitmap_weight with bitmap_weight_eq for ThunderX2 Date: Thu, 10 Feb 2022 14:49:17 -0800 Message-Id: <20220210224933.379149-34-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" tx2_uncore_event_start() calls bitmap_weight() to compare the weight of bitmap with a given number. We can do it more efficiently with bitmap_weight_eq because conditional bitmap_weight may stop traversing the bitmap earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- drivers/perf/thunderx2_pmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/perf/thunderx2_pmu.c b/drivers/perf/thunderx2_pmu.c index 1edb9c03704f..97d5b39778fa 100644 --- a/drivers/perf/thunderx2_pmu.c +++ b/drivers/perf/thunderx2_pmu.c @@ -623,8 +623,8 @@ static void tx2_uncore_event_start(struct perf_event *e= vent, int flags) return; =20 /* Start timer for first event */ - if (bitmap_weight(tx2_pmu->active_counters, - tx2_pmu->max_counters) =3D=3D 1) { + if (bitmap_weight_eq(tx2_pmu->active_counters, + tx2_pmu->max_counters, 1)) { hrtimer_start(&tx2_pmu->hrtimer, ns_to_ktime(tx2_pmu->hrtimer_interval), HRTIMER_MODE_REL_PINNED); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8886C433F5 for ; Fri, 11 Feb 2022 00:06:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346050AbiBKAG5 (ORCPT ); Thu, 10 Feb 2022 19:06:57 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:36308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235345AbiBKAGz (ORCPT ); Thu, 10 Feb 2022 19:06:55 -0500 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45DAE26DF; Thu, 10 Feb 2022 16:06:55 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id bs32so6716113qkb.1; Thu, 10 Feb 2022 16:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=kIxNsx5t66aCekxGiYnzItzLDmvgCurjGzLHlKM8kmo=; b=kUPI1caTAiBqAVK3q8DnKRacUz2Uib6Hme9P7gr7i8kQ+e8TDEJqGlFb9zgPToD7X4 N+9XO0XYP2mYbZz74uZ8ryyWvq1dnX9hrT17tCXcrSr4PANCJ/G0mRpk/gSmP6hwaIA4 tSW8lv3cVv4eh0Fc3r/J6QFoUcItqKb2tIQyxE/nf7iYijX6DS2RQXFJKqGgFPMhUCS9 Dqf5xuMhdzQRvnaBkiEGdwqac4utkIFoMdIFFiXveNwGxaUBDmRdbQNyiyVPpzaVTcFz igRbWOfbP9PGIw7H/TiCmFN2ibo8AOWyYEUvfZNJ2d6hoCz97qFC1FNpcapXfbvgCC0D Dc2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kIxNsx5t66aCekxGiYnzItzLDmvgCurjGzLHlKM8kmo=; b=dZFBvUyx6I6yu5x9KI7cykgRPP61BtCZRsR3c72lrQqqd+vAXXKoPSXWqH2eRXrwxF bZZYjQQk1Fe1jxukTgyoWiPlBNvdVijIzhiCro4Wl5AHAbhxvaHsRYUv1ljd1w+DAJ4O HgWCTyYLBp+AlQZkfUpA4pHSJI/XXHi9RGWeXqkkGsBKdP4GCgqw4wkowqqO+H3SSiii kEqxsTKBnfR8MokBcSQaY5/Akp5xc80KFbhWmVcMiH/wF8v6ZRQ16pgVtgZGuC2YWdTq MYXSLXND5qqDrrJKGKibQPD2qqOMweDCvDtMmBDJFZJW0EczRbjJRrhdM7xQHss8zjuj T8Dg== X-Gm-Message-State: AOAM531HrHekkONxkoVwTEqPrMDcw05AbZB0UDkV+KncAouDGc/dWoWc 1yOxuJwSIH+Ypqd7fBB8DSY= X-Google-Smtp-Source: ABdhPJwXNB8AH9WzcydC3nOV4kHShzA6P4syYry2xqBz+Iro1F4pn0IXPMbEY20Ct9c0HLCgx/xhIg== X-Received: by 2002:a37:851:: with SMTP id 78mr5100598qki.617.1644538014344; Thu, 10 Feb 2022 16:06:54 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id v5sm11133965qkp.70.2022.02.10.16.06.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:06:53 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Thierry Reding , Jonathan Hunter , Sowjanya Komatineni , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 34/49] media: tegra-video: replace bitmap_weight with bitmap_weight_le Date: Thu, 10 Feb 2022 14:49:18 -0800 Message-Id: <20220210224933.379149-35-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" tegra_channel_enum_format() calls bitmap_weight() to compare the weight of bitmap with a given number. We can do it more efficiently with bitmap_weight_le() because conditional bitmap_weight may stop traversing the bitmap earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- drivers/staging/media/tegra-video/vi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media= /tegra-video/vi.c index d1f43f465c22..4e79a80e9307 100644 --- a/drivers/staging/media/tegra-video/vi.c +++ b/drivers/staging/media/tegra-video/vi.c @@ -436,7 +436,7 @@ static int tegra_channel_enum_format(struct file *file,= void *fh, if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG)) fmts_bitmap =3D chan->fmts_bitmap; =20 - if (f->index >=3D bitmap_weight(fmts_bitmap, MAX_FORMAT_NUM)) + if (bitmap_weight_le(fmts_bitmap, MAX_FORMAT_NUM, f->index)) return -EINVAL; =20 for (i =3D 0; i < f->index + 1; i++, index++) --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C120FC433FE for ; Fri, 11 Feb 2022 00:09:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346163AbiBKAJL (ORCPT ); Thu, 10 Feb 2022 19:09:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:45140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346149AbiBKAJH (ORCPT ); Thu, 10 Feb 2022 19:09:07 -0500 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA9C82734 for ; Thu, 10 Feb 2022 16:09:07 -0800 (PST) Received: by mail-io1-xd34.google.com with SMTP id s18so9475391ioa.12 for ; Thu, 10 Feb 2022 16:09:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4opLWPM2zNGxYK/Q3wpGKFEipyHS9bpsKAz2hDFfcuU=; b=Wc1DpM2btDFmtN2luf7HF0t4hU44TIGq/0YL0bpQa6g+iE8hZBeyWR92RUacj652vT xTeWUzCzvTHlJzr3SFJuRLsV9NQaWHOLGUB9F8QWcCEv36Iz7c7sVdetuTXYoqfu2Xo2 2bLumF+y0+7NHCuNnuvWraBPfeGbS2BODGTmwgjbZdGEZV7P3V4faUYlSK5hlqIOQ9SL OOWmkUgaoa892REhSeotBEng3Rz/QPBMv0BGWqzsAdVEHT/kGDjwr43k+E7DXLkjcWXB ijOPcoOAyAU22WMkLEB0E3iCCK6HFjZUcR6/2zVmaKNY3u07dpAQUstPDRGeps8VWJjX eftw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4opLWPM2zNGxYK/Q3wpGKFEipyHS9bpsKAz2hDFfcuU=; b=h2OXAva7WB4xinFY3uYLRZ3CrdUQxHr4SOHqzhyCI1yoKjiTe5OioMuF7u1S8znFm1 vUD6NKMPo0MEqhhs9wtpPTLIqxrcb2mJeVOzZ1OhSUAaZaP7bmTj7gKBj1wdNr2LeaqL XBo+KIKKn7XXqPoBUguG4qYTLKruEh0rkZIXdLjlmAaunI4NnwZMgbgDiqu+dRYrR7t4 byJzz9M4DjzNgnWaPujqATpS4x5eysC05dNdL2tTCQYdIBX6EtT4Ua0aeBYbXPDhH0um XPrpT45PFG1hXSJZySwU5I4fkjqeMRCw5RzdDysNPTRpcH5U9ZIyFuafrgC1kHcOvipj D4Ow== X-Gm-Message-State: AOAM5335gd8e0kUIk4YrrftLMiSumpWuaEeAP+4ut5HI6xz2VXvvg6LJ TRTkigd0/9AhgHKtL3o4SBI= X-Google-Smtp-Source: ABdhPJzOtCPYAM7lNC3ivI+eGe1Vm96G5CP/MEuWyQgdhttuG5n0Y7IOVFiufLeO2bodUS0FCAeGyA== X-Received: by 2002:a05:6602:1407:: with SMTP id t7mr5040293iov.82.1644538147202; Thu, 10 Feb 2022 16:09:07 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id t2sm7942285ilp.49.2022.02.10.16.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:09:06 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org Subject: [PATCH 35/49] cpumask: add cpumask_weight_{eq,gt,ge,lt,le} Date: Thu, 10 Feb 2022 14:49:19 -0800 Message-Id: <20220210224933.379149-36-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In many cases people use cpumask_weight() to compare the result against some number or expression: if (cpumask_weight(...) > 1) do_something(); It may be significantly improved for large cpumasks: if first few words count set bits to a number greater than given, we can stop counting and immediately return. The same idea would work in other direction: if we know that the number of set bits that we counted so far is small enough, so that it would be smaller than required number even if all bits of the rest of the cpumask are set, we can stop counting earlier. This patch adds cpumask_weight_{eq, gt, ge, lt, le} helpers based on corresponding bitmap functions. The following patches apply new functions where appropriate. Signed-off-by: Yury Norov --- include/linux/cpumask.h | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 6b06c698cd2a..0037297c542a 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -575,6 +575,56 @@ static inline unsigned int cpumask_weight(const struct= cpumask *srcp) return bitmap_weight(cpumask_bits(srcp), nr_cpumask_bits); } =20 +/** + * cpumask_weight_eq - Check if # of bits in *srcp is equal to a given num= ber + * @srcp: the cpumask to count bits (< nr_cpu_ids) in. + * @num: the number to check. + */ +static inline bool cpumask_weight_eq(const struct cpumask *srcp, unsigned = int num) +{ + return bitmap_weight_eq(cpumask_bits(srcp), nr_cpumask_bits, num); +} + +/** + * cpumask_weight_gt - Check if # of bits in *srcp is greater than a given= number + * @srcp: the cpumask to count bits (< nr_cpu_ids) in. + * @num: the number to check. + */ +static inline bool cpumask_weight_gt(const struct cpumask *srcp, int num) +{ + return bitmap_weight_gt(cpumask_bits(srcp), nr_cpumask_bits, num); +} + +/** + * cpumask_weight_ge - Check if # of bits in *srcp is greater than or equa= l to a given number + * @srcp: the cpumask to count bits (< nr_cpu_ids) in. + * @num: the number to check. + */ +static inline bool cpumask_weight_ge(const struct cpumask *srcp, int num) +{ + return bitmap_weight_ge(cpumask_bits(srcp), nr_cpumask_bits, num); +} + +/** + * cpumask_weight_lt - Check if # of bits in *srcp is less than a given nu= mber + * @srcp: the cpumask to count bits (< nr_cpu_ids) in. + * @num: the number to check. + */ +static inline bool cpumask_weight_lt(const struct cpumask *srcp, int num) +{ + return bitmap_weight_lt(cpumask_bits(srcp), nr_cpumask_bits, num); +} + +/** + * cpumask_weight_le - Check if # of bits in *srcp is less than or equal t= o a given number + * @srcp: the cpumask to count bits (< nr_cpu_ids) in. + * @num: the number to check. + */ +static inline bool cpumask_weight_le(const struct cpumask *srcp, int num) +{ + return bitmap_weight_le(cpumask_bits(srcp), nr_cpumask_bits, num); +} + /** * cpumask_shift_right - *dstp =3D *srcp >> n * @dstp: the cpumask result --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7396FC433EF for ; Fri, 11 Feb 2022 00:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346182AbiBKALZ (ORCPT ); Thu, 10 Feb 2022 19:11:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:47548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243963AbiBKALU (ORCPT ); Thu, 10 Feb 2022 19:11:20 -0500 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2584926FC; Thu, 10 Feb 2022 16:11:21 -0800 (PST) Received: by mail-il1-x12a.google.com with SMTP id c12so5089696ilm.8; Thu, 10 Feb 2022 16:11:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4h1t/bTC+qDJEJPFRFVcOK5rGe+GH/iRxYkyQH+GgIE=; b=ZbhAJACxr48oNEwePgKFllHTK19fvAQq+syugIWiNbjTIbpMhXabd524NdFk43VC0r B2hb9BmF99mJk9SLhcktegNw7uf/aZput7dd0Caq9kW8BhlfTyrh9FLvqip34hJAYxU3 yJu6/fI770DnT1KmaXY2hB6gXMtWmcQIO+/NoeGJqB+FEUOjjrueHwo997wTI6Qa+u1e dsTSd8IexTLJdmTz03InYWBbE5FetCdiNbfdUBuMl6uoDH/GyCJ9Qhd/tIcnOq5AYY+d H0vKrvtzn6zHqEpnQBzqdN7cZHZ8BYNcBACZth46mq4/qK0PuxkQEQPP7ihi6PQFbdbL B9mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4h1t/bTC+qDJEJPFRFVcOK5rGe+GH/iRxYkyQH+GgIE=; b=KGBeVlX0Ps418O1UhTg9XwpVhFXaXMYTHLm7eGZsi0IhLSvsScgB7GTB9akiTXe9IF 8QIODYg7L4RR1fghX6Mo3jINoCAjxEXamiufs8nrse0zvxfAjzV4Touq5q4wrsNayu2M R6pW+uLV0nB5Ln2k4Cpy578iAhplWc8szXNQhv8nALb5wZ7GSkeyMzj1TMihzLjw6NfE R7RoCPgxJmUxYwZUImpkrgGULuY/h6bCOoqwmvq/YyTvPfdKxnMDOQPK8/VbvgZqTFuf hQ75AqSQQGj9gXrwR7W57bMAXiQsIH2nj8Qusn+W/I8dkrr0FWjo2K7B3+QUo0XijjPs MayQ== X-Gm-Message-State: AOAM531FqPf0sWkrSmimMtl7NTB5BRH0RbreHSFCPgZ/7G2O6a+Vrg6P NyWxYdWeHSNCI/kxVlRa/tM= X-Google-Smtp-Source: ABdhPJxnKGWWX+h3tns0z9BdoPa/Tdtk5KLlu3v4Oxuh6/KxSgi5Su/RU6jC7/E8reyvrJ26b1xJ6Q== X-Received: by 2002:a05:6e02:1e08:: with SMTP id g8mr5702300ila.22.1644538280448; Thu, 10 Feb 2022 16:11:20 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id u26sm12191990ior.52.2022.02.10.16.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:11:20 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org Subject: [PATCH 36/49] arch/ia64: replace cpumask_weight with cpumask_weight_eq in mm/tlb.c Date: Thu, 10 Feb 2022 14:49:20 -0800 Message-Id: <20220210224933.379149-37-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" __flush_tlb_range() code calls cpumask_weight() to compare the weight of cpumask with a given number. We can do it more efficiently with cpumask_weight_eq because conditional cpumask_weight may stop traversing the cpumask earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- arch/ia64/mm/tlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/ia64/mm/tlb.c b/arch/ia64/mm/tlb.c index 135b5135cace..a5bce13ab047 100644 --- a/arch/ia64/mm/tlb.c +++ b/arch/ia64/mm/tlb.c @@ -332,7 +332,7 @@ __flush_tlb_range (struct vm_area_struct *vma, unsigned= long start, =20 preempt_disable(); #ifdef CONFIG_SMP - if (mm !=3D current->active_mm || cpumask_weight(mm_cpumask(mm)) !=3D 1) { + if (mm !=3D current->active_mm || !cpumask_weight_eq(mm_cpumask(mm), 1)) { ia64_global_tlb_purge(mm, start, end, nbits); preempt_enable(); return; --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04EB8C433EF for ; Fri, 11 Feb 2022 00:13:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346190AbiBKANg (ORCPT ); Thu, 10 Feb 2022 19:13:36 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243610AbiBKANf (ORCPT ); Thu, 10 Feb 2022 19:13:35 -0500 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DFE426DA; Thu, 10 Feb 2022 16:13:34 -0800 (PST) Received: by mail-il1-x12f.google.com with SMTP id h11so5699490ilq.9; Thu, 10 Feb 2022 16:13:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=P9CQld7JqGJfJXS61tcHY1+Q0rrT2ByYuWx5h8QfDxg=; b=Si1YTbH4uVu7arrxfMdWslaIjgTMOegSVuC2K771A/Gpc/h4LY+Ug2RAq06koXGaGB 19raDUJ4IbyL5UxNmkSlCjq8yC0/MQs7ny+ceRdiPJgWKRUH/g18HGx76TR+d4u5aMzn wHojbv8airUCDg2dFG2TbYE125EbBMUIDn3GuuP1WbW788400zH6+9vtkV/0b0LEQHXH hSz7xK8WHhKcCHAo+/a9VIqRueI+LX7YZgdAseKgEsfWPcC9ycBltcYUnix/qjFGgExK TIgNvHH3qNwC7XplpKn5TZgIeG+RXXAOipR9U+RCHjmeX2WVTrja7/7RtroVmHPwzzgT KOGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P9CQld7JqGJfJXS61tcHY1+Q0rrT2ByYuWx5h8QfDxg=; b=DQmyz7j565RKn7ovZ2VBATROAmt1KOcPfCnTt0W0fxdNzgD1ATBFregAi8sP4SLYg1 G5tRJ0caFLFzl/Bav3COONZkY07bp5fLuNKHiCQ/HcKgvq1k0Xi+Cx6YEDBvBh+Ci0SQ kZnYvqh2picx9PxGFBQCK2nOMt3oGyB+h+/Wz/4WcDyuvcyJ762yCBAi7imVWiA1AHaV Po2Xe/g1zyi4FjZx2WnPlfDQDdCuH3WsiqKjuZcczchTJ2Zad2a2EhZSZEEDIuPBMUUC cLlzIllWz7nJLkHf7cKTPmLYpGC929apoDoehtYdD5kDnJpeH9w1ucxcWO6LP1btULpq fGrQ== X-Gm-Message-State: AOAM532EeUtBAr+BGqXc49rR9h8jDqOYjpMuOj4yH04esSRN74gtSceP Dj7+AQldqYJcj/3EoiFBwvU= X-Google-Smtp-Source: ABdhPJxfWUlPP3bz5Kd/ubQZOjy0O9kW3lT//YIrBrMf5tL4x2+m9mGFhShROfdFB+0MnnI9PBIWKg== X-Received: by 2002:a92:d944:: with SMTP id l4mr4723853ilq.2.1644538413618; Thu, 10 Feb 2022 16:13:33 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id c11sm7148530iln.56.2022.02.10.16.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:13:33 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Thomas Bogendoerfer , Mark Rutland , Marc Zyngier , linux-mips@vger.kernel.org Subject: [PATCH 37/49] arch/mips: replace cpumask_weight with cpumask_weight_{eq, ...} where appropriate Date: Thu, 10 Feb 2022 14:49:21 -0800 Message-Id: <20220210224933.379149-38-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Mips code uses calls cpumask_weight() to compare the weight of cpumask with a given number. We can do it more efficiently with cpumask_weight_{eq, ...} because conditional cpumask_weight may stop traversing the cpumask earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov Acked-by: Thomas Bogendoerfer --- arch/mips/cavium-octeon/octeon-irq.c | 4 ++-- arch/mips/kernel/crash.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/mips/cavium-octeon/octeon-irq.c b/arch/mips/cavium-octeon= /octeon-irq.c index 844f882096e6..914871f15fb7 100644 --- a/arch/mips/cavium-octeon/octeon-irq.c +++ b/arch/mips/cavium-octeon/octeon-irq.c @@ -763,7 +763,7 @@ static void octeon_irq_cpu_offline_ciu(struct irq_data = *data) if (!cpumask_test_cpu(cpu, mask)) return; =20 - if (cpumask_weight(mask) > 1) { + if (cpumask_weight_gt(mask, 1)) { /* * It has multi CPU affinity, just remove this CPU * from the affinity set. @@ -795,7 +795,7 @@ static int octeon_irq_ciu_set_affinity(struct irq_data = *data, * This removes the need to do locking in the .ack/.eoi * functions. */ - if (cpumask_weight(dest) !=3D 1) + if (!cpumask_weight_eq(dest, 1)) return -EINVAL; =20 if (!enable_one) diff --git a/arch/mips/kernel/crash.c b/arch/mips/kernel/crash.c index 81845ba04835..5b690d52491f 100644 --- a/arch/mips/kernel/crash.c +++ b/arch/mips/kernel/crash.c @@ -72,7 +72,7 @@ static void crash_kexec_prepare_cpus(void) */ pr_emerg("Sending IPI to other cpus...\n"); msecs =3D 10000; - while ((cpumask_weight(&cpus_in_crash) < ncpus) && (--msecs > 0)) { + while (cpumask_weight_lt(&cpus_in_crash, ncpus) && (--msecs > 0)) { cpu_relax(); mdelay(1); } --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DDFEC433F5 for ; Fri, 11 Feb 2022 00:15:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346239AbiBKAPs (ORCPT ); Thu, 10 Feb 2022 19:15:48 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346226AbiBKAPr (ORCPT ); Thu, 10 Feb 2022 19:15:47 -0500 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69100558A for ; Thu, 10 Feb 2022 16:15:47 -0800 (PST) Received: by mail-io1-xd36.google.com with SMTP id m185so9505727iof.10 for ; Thu, 10 Feb 2022 16:15:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=PIovVUUoTXrNkGptnZalq8qTG6elYmmkmcndd2InBI8=; b=pcjmfLwAiS/XGbn7H5lJSwo1VmJtz/MoynS0X5Dcg+dWgAtP50rspk13S0E5pJvDty S6taB1oBu2sz0cRmYD0OrRjqt2eHBVSewuL1cld2PkhQsvFtl9InCW6guWZsBAakxHMk QeAHrP+IGJZPPsIbTyETpTaKJMX41JIs46ZQl2s+qGfwWzoybsFUJSxmhqN/EcMYGjqu aLAgKKOq45uiO1viWnPybbeWGhqL5zctU9mMIOJebmWir+BUuJeDQnU4GPsD0okN+NS4 pJvRQWhfbiVaTp3GfeFPrI0rEQUVFFs+HDyaa7lPxlLEpozQBg6i1VzRnx8jLoMxeYZM MW4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PIovVUUoTXrNkGptnZalq8qTG6elYmmkmcndd2InBI8=; b=3vjumhYVGVtilNlI4+zJxUPjYiRsBlKN96h4xGO6ppEU1RzI+rRZHfphT/+avqYkrl xIqMjopNy1qmA12IVoY5nZv4JHG0VyqAZCfQsNWxe7i50ONM3AqZdepINVgSM4Vfev6P KiIsp/qbSu9PR5NNiggAFm7QxpPphPcgLxB9y1dlxWUQVRvfqQO2YzsPNpDoKF56YOns SzyCHRyL70dq4z8ByIU8qaOcEdSNEL76gfE1UzH0Uvblo/CppY6CNpZJ8qrtm37ZFOwi qd/mKLzZWF/+oeBIWfOwQZBi4TRW+BIOT1j8MiUBbnqYVVR3ZKUm/c/tB4nibIk9i7UK SEWA== X-Gm-Message-State: AOAM530Y03xfWyagsvEuP4Id80ip+3t8/WC+1tLNs8/0CPS6WCUSrxOI rYBsVDYpTkO/YmSqcSAc9Ig= X-Google-Smtp-Source: ABdhPJxRcsurSAFIVa51O5zD9bcY1kB5OJeXxGfVrQ9MyMfVmVSnWSLVAohEIbusFvdw1qpbmH+QRA== X-Received: by 2002:a05:6638:d0c:: with SMTP id q12mr5411794jaj.310.1644538546802; Thu, 10 Feb 2022 16:15:46 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id h3sm12329728ioe.19.2022.02.10.16.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:15:46 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Srikar Dronamraju , "Gautham R. Shenoy" , Valentin Schneider , Parth Shah , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Hari Bathini , Rob Herring , Laurent Dufour , Petr Mladek , John Ogness , Sudeep Holla , Christophe Leroy , "Naveen N. Rao" , Xiongwei Song , Arnd Bergmann , linuxppc-dev@lists.ozlabs.org Subject: [PATCH 38/49] arch/powerpc: replace cpumask_weight with cpumask_weight_{eq, ...} where appropriate Date: Thu, 10 Feb 2022 14:49:22 -0800 Message-Id: <20220210224933.379149-39-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" PowerPC code uses cpumask_weight() to compare the weight of cpumask with a given number. We can do it more efficiently with cpumask_weight_{eq, ...} because conditional cpumask_weight may stop traversing the cpumask earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- arch/powerpc/kernel/smp.c | 2 +- arch/powerpc/kernel/watchdog.c | 2 +- arch/powerpc/xmon/xmon.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index b7fd6a72aa76..8bff748df402 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -1656,7 +1656,7 @@ void start_secondary(void *unused) if (has_big_cores) sibling_mask =3D cpu_smallcore_mask; =20 - if (cpumask_weight(mask) > cpumask_weight(sibling_mask(cpu))) + if (cpumask_weight_gt(mask, cpumask_weight(sibling_mask(cpu)))) shared_caches =3D true; } =20 diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c index bfc27496fe7e..62937a077de7 100644 --- a/arch/powerpc/kernel/watchdog.c +++ b/arch/powerpc/kernel/watchdog.c @@ -483,7 +483,7 @@ static void start_watchdog(void *arg) =20 wd_smp_lock(&flags); cpumask_set_cpu(cpu, &wd_cpus_enabled); - if (cpumask_weight(&wd_cpus_enabled) =3D=3D 1) { + if (cpumask_weight_eq(&wd_cpus_enabled, 1)) { cpumask_set_cpu(cpu, &wd_smp_cpus_pending); wd_smp_last_reset_tb =3D get_tb(); } diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c index fd72753e8ad5..b423812e94e0 100644 --- a/arch/powerpc/xmon/xmon.c +++ b/arch/powerpc/xmon/xmon.c @@ -469,7 +469,7 @@ static bool wait_for_other_cpus(int ncpus) =20 /* We wait for 2s, which is a metric "little while" */ for (timeout =3D 20000; timeout !=3D 0; --timeout) { - if (cpumask_weight(&cpus_in_xmon) >=3D ncpus) + if (cpumask_weight_ge(&cpus_in_xmon, ncpus)) return true; udelay(100); barrier(); @@ -1338,7 +1338,7 @@ static int cpu_cmd(void) case 'S': case 't': cpumask_copy(&xmon_batch_cpus, &cpus_in_xmon); - if (cpumask_weight(&xmon_batch_cpus) <=3D 1) { + if (cpumask_weight_le(&xmon_batch_cpus, 1)) { printf("There are no other cpus in xmon\n"); break; } --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61A66C433F5 for ; Fri, 11 Feb 2022 00:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346272AbiBKASB (ORCPT ); Thu, 10 Feb 2022 19:18:01 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346262AbiBKAR7 (ORCPT ); Thu, 10 Feb 2022 19:17:59 -0500 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 608AF105; Thu, 10 Feb 2022 16:18:00 -0800 (PST) Received: by mail-il1-x12e.google.com with SMTP id d3so5708865ilr.10; Thu, 10 Feb 2022 16:18:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=7yoyMsL7SyevN/y4cH9y7HBy5JcN4ZPi5dkNOU9qEgE=; b=cjSHDomLYdafXDclCfXftX/KeP7y/uJEw/qtk1hqGp3MaWFhiinNwkVAsrB7zXZXCw UVpHjhSNynzmJ61ExawDF3np2A97Q0Qk9+NS7JQ1RHeNCc98/fX5RgP2h74m9/niOGwz B61BqZAjfNBdF5xjhtIPK4DCq7HoJ70gA4gvTK5G9H6BdJ9QDEMId+UXZVzrTgpFvta5 7/W1oUpxy8YRdTXbKeWTowVYdpiYUmb5uj2hA2xc0McmxJjnR+QcHrVajxS9eeQAKZt5 B2aDKNlfCGJWkf4SSI+yqbkb6Wro/HcRN4rSQ9nt5esXZW/ooo18jiA9RogOaF/Ry2Om nGCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7yoyMsL7SyevN/y4cH9y7HBy5JcN4ZPi5dkNOU9qEgE=; b=HGl/nkrauDdjCXX8twYSM9xCN+csOmanps7dI5wHm6FYktQlxSs8VFW4/+h+JU9R8L SPlDu1VuuDa0jyPsFNiGm2zOkNByW+hcNny4z4qKa67VoYBvcp5HeVGP9ld2GBO1YcSs y0ABZ+8QXR2s+djRGqqDfOB2LoRCBQCaNT+xv11RCet8oIYoKfDUNLIFkoKEG34K51CP rUryvp5eJoaf55LIwTHcrogryWdiyNs0EK+xHFmiEnbLFFtxmUv3QxBHV1kgWXyQkeTT t5jFX7bcPtcedr7dc6/TXDr9fvEONVApVl8otUYuzBlo5tppOJvjjVColZoA9N/1LXTC HMDg== X-Gm-Message-State: AOAM531EKtfl0fPMTOoUoO4PDy8EInGMk1gU98o4Y+VgnEgqHqxHOp69 rSMmm6xtq62JuzQLKC+nWkM= X-Google-Smtp-Source: ABdhPJxcPsfzEQtc8co4G0V78MxZQ0H3JjCQJHCLjHTl1WrVlCNlJ/iGZcNVR1Vxlyc4FGh8gOvSfA== X-Received: by 2002:a05:6e02:180b:: with SMTP id a11mr5307358ilv.196.1644538679746; Thu, 10 Feb 2022 16:17:59 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id q16sm11837074ion.27.2022.02.10.16.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:17:59 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Sven Schnelle , Thomas Richter , Sumanth Korikkar , Sebastian Andrzej Siewior , Jiapeng Chong , kernel test robot , linux-s390@vger.kernel.org Subject: [PATCH 39/49] arch/s390: replace cpumask_weight with cpumask_weight_eq where appropriate Date: Thu, 10 Feb 2022 14:49:23 -0800 Message-Id: <20220210224933.379149-40-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" cfset_all_start() calls cpumask_weight() to compare the weight of cpumask with a given number. We can do it more efficiently with cpumask_weight_{eq, ...} because conditional cpumask_weight may stop traversing the cpumask earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- arch/s390/kernel/perf_cpum_cf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/s390/kernel/perf_cpum_cf.c b/arch/s390/kernel/perf_cpum_c= f.c index ee8707abdb6a..4d217f7f5ccf 100644 --- a/arch/s390/kernel/perf_cpum_cf.c +++ b/arch/s390/kernel/perf_cpum_cf.c @@ -975,7 +975,7 @@ static int cfset_all_start(struct cfset_request *req) return -ENOMEM; cpumask_and(mask, &req->mask, cpu_online_mask); on_each_cpu_mask(mask, cfset_ioctl_on, &p, 1); - if (atomic_read(&p.cpus_ack) !=3D cpumask_weight(mask)) { + if (!cpumask_weight_eq(mask, atomic_read(&p.cpus_ack))) { on_each_cpu_mask(mask, cfset_ioctl_off, &p, 1); rc =3D -EIO; debug_sprintf_event(cf_dbg, 4, "%s CPUs missing", __func__); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17C08C433EF for ; Fri, 11 Feb 2022 00:20:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346301AbiBKAUQ (ORCPT ); Thu, 10 Feb 2022 19:20:16 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346272AbiBKAUN (ORCPT ); Thu, 10 Feb 2022 19:20:13 -0500 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E8EFC7 for ; Thu, 10 Feb 2022 16:20:13 -0800 (PST) Received: by mail-io1-xd2b.google.com with SMTP id c188so9527067iof.6 for ; Thu, 10 Feb 2022 16:20:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=hLEL9851jabrdDhcxhGMVE1OmCduEAH/N0L9wmwcIjg=; b=Ddx6yjYcPE8CmX5hCgpAe3NuBPN+UEnDWxaj/S4nyidlsNp29Qi4nO6yKxahYSYWze 60wBTMk/1n3Bf0Dn3Qa+ISIEaGAIbwgzWu13tuLljBfaY2PsnoHzOrV4sBzxPCb9gaGE obvUhv9/uBtVaE78ha7HcUXUC1VXhfiFzo2TuxG/D3nExuOMPflFJuzfwDMEkVz4obqJ U4tJPN3VkTmPOMPDDmKLp4mU6KISHK1gSlamntZK/Ny7CNDDZI5eMEHdTAG8rnsFssRc k94GWNgNxamMatkGjEVqYabjh/Rr7UGcEqRtK2QKFls+yc5KuvRZaVEOKnKvt6NXX9jZ 3Thw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hLEL9851jabrdDhcxhGMVE1OmCduEAH/N0L9wmwcIjg=; b=cXJpWoIZBbcONy8B2Eczqxruovs5zoYUw3lJeExo0OcrCZ02rqfSjEDKH0tcRfyxMY zsFDMnBJzl+w1TkBC4p93GrzjK0FefD5mktb8l2ZH7T/LEn28VF7amGVHC6IAk011nak zU8PB9OGXaA6HlLFlWhSbna5K67Qi+In3K9Z6qLv8PiaJpGJJzuAyLY/9XuQb3ZtOoZ1 NSY2l4hk3nX02gSjGH57hwpGc9ZvXlRAeTqToQm2F7kNPZ3O+DI/a5zuU1+GFmrlcymR DaZL1t/Bg5Uxk70Kfo8R5+U2jsdfv6p7F05Ezcu3hAQARNiIhx6LGtGp8LF7zL7EV34n 60mQ== X-Gm-Message-State: AOAM5338q/Xbd5i/sHjvVa8pmQkIkyE5UJPBSBHBSd68m4+2Fus0hOXN gr2jQc7pYF0B7OhRcm19KmA= X-Google-Smtp-Source: ABdhPJw7qdPMYUQVvRvWAT1whw8GJ3WVabvUcKINgiQx0zHMbH9lOyy7aRlH2DJYa0qShCIMVimymQ== X-Received: by 2002:a6b:7316:: with SMTP id e22mr5135069ioh.125.1644538812801; Thu, 10 Feb 2022 16:20:12 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id d12sm11665467ilv.42.2022.02.10.16.20.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:20:12 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Mark Rutland , Lorenzo Pieralisi , linux-arm-kernel@lists.infradead.org Subject: [PATCH 40/49] firmware: pcsi: replace cpumask_weight with cpumask_weight_eq Date: Thu, 10 Feb 2022 14:49:24 -0800 Message-Id: <20220210224933.379149-41-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" down_and_up_cpus() calls cpumask_weight() to compare the weight of cpumask with a given number. We can do it more efficiently with cpumask_weight_{eq, ...} because conditional cpumask_weight may stop traversing the cpumask earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- drivers/firmware/psci/psci_checker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/psci/psci_checker.c b/drivers/firmware/psci/p= sci_checker.c index 116eb465cdb4..90c9473832a9 100644 --- a/drivers/firmware/psci/psci_checker.c +++ b/drivers/firmware/psci/psci_checker.c @@ -90,7 +90,7 @@ static unsigned int down_and_up_cpus(const struct cpumask= *cpus, * cpu_down() checks the number of online CPUs before the TOS * resident CPU. */ - if (cpumask_weight(offlined_cpus) + 1 =3D=3D nb_available_cpus) { + if (cpumask_weight_eq(offlined_cpus, nb_available_cpus - 1)) { if (ret !=3D -EBUSY) { pr_err("Unexpected return code %d while trying " "to power down last online CPU %d\n", --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0832DC433EF for ; Fri, 11 Feb 2022 00:22:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346253AbiBKAW1 (ORCPT ); Thu, 10 Feb 2022 19:22:27 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235311AbiBKAW0 (ORCPT ); Thu, 10 Feb 2022 19:22:26 -0500 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 879E4E5C; Thu, 10 Feb 2022 16:22:26 -0800 (PST) Received: by mail-io1-xd2f.google.com with SMTP id p63so9488313iod.11; Thu, 10 Feb 2022 16:22:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=r+2Lxrqd+/2P51TipH+bP8eiwgKfuynFq8H8rT90BTo=; b=O0EsFj+PK5aIQhKNiYkuOp8pqc92sDAN2/x3yJmEPRLbP1QWwij1piX3OhbpRMP7Dn zvBAKgRCW7S4vtdIdFtO6h0HlIJ0xyT3Dx3wBGWanFtfISRLHpuR/+aeOrzyOwhAjtW3 sC7Id1ezVuG2bIafzzAhUTZM1O/p4cAj+g7Dzoxeza1lFPPiy2nN+SAUZEWBhYylw/c6 mp7diWtiWVmMLMo5OtmfD8saDNbBcUDtYLvynvdRaGzh5O+QbN8do6aWL5I4OSjlD1So I+a9hiJlmLU9BKl53nAQmdQhaPM7mkLekABzMmfZ9OrNNuprEKK6XzNz/7FNRqEKADQe Bn+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r+2Lxrqd+/2P51TipH+bP8eiwgKfuynFq8H8rT90BTo=; b=P4Wzp9U7Ya0ItxFaKx+DL+ruimLeGJn/9pw1+QL7OycllASwlg9lmUXm25WPo+iH66 FploEZ1D8IGNmHoNsVN8GJihHZaA9ImqM+2PLmbR8YeDRPcnEhWtddLs8Rv9SzOWkGxA R/Snis6bRHCj5+LBwA7MNApd0MnBTLHtytX7fmJ5EsgF9zNg9kmG7GbaH2NKCUnlUsu8 wcaNv2NQJlhgBgPYjtPAqHKgQMI3Gck74rYmEY51CzR7OiTAMpe6HxFiviPXvIJcyvNm RRAcKsadeRc1PJXtXKf+J50CJFjneWM8ZQuOcXNZv6clBcKcQz3Mp+fJK+/ONII/Mkgv v/tQ== X-Gm-Message-State: AOAM532w4uwV/EBE9pda9xIo/9hSPamo/Tlesp0IwE+fmuMK9wWZilti laW1ICRtflGWF44mzDUQ83I= X-Google-Smtp-Source: ABdhPJwhX5j3SHuGJVMlF9z+AvEbLjcuC5tdzf4YVYtzgTeP+dHG6E9oAedcHzacHNV+YT4aqz1byA== X-Received: by 2002:a05:6638:389c:: with SMTP id b28mr5326203jav.176.1644538945854; Thu, 10 Feb 2022 16:22:25 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id i9sm2610693ilm.74.2022.02.10.16.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:22:25 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Mike Marciniszyn , Dennis Dalessandro , Jason Gunthorpe , linux-rdma@vger.kernel.org Subject: [PATCH 41/49] RDMA/hfi1: replace cpumask_weight with cpumask_weight_{eq, ...} where appropriate Date: Thu, 10 Feb 2022 14:49:25 -0800 Message-Id: <20220210224933.379149-42-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Infiniband code uses cpumask_weight() to compare the weight of cpumask with a given number. We can do it more efficiently with cpumask_weight_{eq, ...} because conditional cpumask_weight may stop traversing the cpumask earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- drivers/infiniband/hw/hfi1/affinity.c | 9 ++++----- drivers/infiniband/hw/qib/qib_file_ops.c | 2 +- drivers/infiniband/hw/qib/qib_iba7322.c | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/= hfi1/affinity.c index 877f8e84a672..a9ad07808dea 100644 --- a/drivers/infiniband/hw/hfi1/affinity.c +++ b/drivers/infiniband/hw/hfi1/affinity.c @@ -506,7 +506,7 @@ static int _dev_comp_vect_cpu_mask_init(struct hfi1_dev= data *dd, * available CPUs divide it by the number of devices in the * local NUMA node. */ - if (cpumask_weight(&entry->comp_vect_mask) =3D=3D 1) { + if (cpumask_weight_eq(&entry->comp_vect_mask, 1)) { possible_cpus_comp_vect =3D 1; dd_dev_warn(dd, "Number of kernel receive queues is too large for completion vector= affinity to be effective\n"); @@ -592,7 +592,7 @@ int hfi1_dev_affinity_init(struct hfi1_devdata *dd) { struct hfi1_affinity_node *entry; const struct cpumask *local_mask; - int curr_cpu, possible, i, ret; + int curr_cpu, i, ret; bool new_entry =3D false; =20 local_mask =3D cpumask_of_node(dd->node); @@ -625,10 +625,9 @@ int hfi1_dev_affinity_init(struct hfi1_devdata *dd) local_mask); =20 /* fill in the receive list */ - possible =3D cpumask_weight(&entry->def_intr.mask); curr_cpu =3D cpumask_first(&entry->def_intr.mask); =20 - if (possible =3D=3D 1) { + if (cpumask_weight_eq(&entry->def_intr.mask, 1)) { /* only one CPU, everyone will use it */ cpumask_set_cpu(curr_cpu, &entry->rcv_intr.mask); cpumask_set_cpu(curr_cpu, &entry->general_intr_mask); @@ -1016,7 +1015,7 @@ int hfi1_get_proc_affinity(int node) cpu =3D cpumask_first(proc_mask); cpumask_set_cpu(cpu, &set->used); goto done; - } else if (current->nr_cpus_allowed < cpumask_weight(&set->mask)) { + } else if (cpumask_weight_gt(&set->mask, current->nr_cpus_allowed)) { hfi1_cdbg(PROC, "PID %u %s affinity set to CPU set(s) %*pbl", current->pid, current->comm, cpumask_pr_args(proc_mask)); diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/= hw/qib/qib_file_ops.c index aa290928cf96..add89bc21b0a 100644 --- a/drivers/infiniband/hw/qib/qib_file_ops.c +++ b/drivers/infiniband/hw/qib/qib_file_ops.c @@ -1151,7 +1151,7 @@ static void assign_ctxt_affinity(struct file *fp, str= uct qib_devdata *dd) * reserve a processor for it on the local NUMA node. */ if ((weight >=3D qib_cpulist_count) && - (cpumask_weight(local_mask) <=3D qib_cpulist_count)) { + (cpumask_weight_le(local_mask, qib_cpulist_count))) { for_each_cpu(local_cpu, local_mask) if (!test_and_set_bit(local_cpu, qib_cpulist)) { fd->rec_cpu_num =3D local_cpu; diff --git a/drivers/infiniband/hw/qib/qib_iba7322.c b/drivers/infiniband/h= w/qib/qib_iba7322.c index ceed302cf6a0..b17f96509d2c 100644 --- a/drivers/infiniband/hw/qib/qib_iba7322.c +++ b/drivers/infiniband/hw/qib/qib_iba7322.c @@ -3405,7 +3405,7 @@ static void qib_setup_7322_interrupt(struct qib_devda= ta *dd, int clearpend) local_mask =3D cpumask_of_pcibus(dd->pcidev->bus); firstcpu =3D cpumask_first(local_mask); if (firstcpu >=3D nr_cpu_ids || - cpumask_weight(local_mask) =3D=3D num_online_cpus()) { + cpumask_weight_eq(local_mask, num_online_cpus())) { local_mask =3D topology_core_cpumask(0); firstcpu =3D cpumask_first(local_mask); } --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3317C433FE for ; Fri, 11 Feb 2022 00:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346310AbiBKAYl (ORCPT ); Thu, 10 Feb 2022 19:24:41 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346239AbiBKAYj (ORCPT ); Thu, 10 Feb 2022 19:24:39 -0500 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE7462735; Thu, 10 Feb 2022 16:24:39 -0800 (PST) Received: by mail-io1-xd36.google.com with SMTP id d188so9541410iof.7; Thu, 10 Feb 2022 16:24:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=QAzv4ww8wIlL+as7782AHbg1vH8P76wooakjw6i+3Lc=; b=eXLLwoHPmmMGbzE7v0/eoXuOPxdUXwkX/S1PRH7+XaWXBdBlZ2LApOHE3iMbfl1Kr1 4GwEpbo6DXk12uqn0CKDnMRhKWqc5E3xyz9NlalC6BgjOF5wKrnvMhCPW9SSAhlLLl6m SJ7sEazoSG1wTfj/t9S8PKfHMcLUmvpTj5Pc0aeefCRDO6tqtR1xpZoio2/j0k8YYyxX zEBfNvS1zpcUSSWrMuGVBIRyH8o5iTxni7dpOaIzvLu25KQaD405JzCGbLLWDXy3I+2R RrwzKsgeq5+sh8lMKFvhc8G58okPUNcmv6K7HmZ88pG7t1Y1PPc1VwW9SLPBecuQ6xwT /6zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QAzv4ww8wIlL+as7782AHbg1vH8P76wooakjw6i+3Lc=; b=hTsQWyDyKSbu3ZwsEqV2Lzfe8WDWkNt0zcrOhzoUd/fBQGfNHGuJBM+0ezQFO1d8Vw JiJkQor5dpMBA28s2VCM6IETHnXcBobFa2WgdXi9SYoF52ZOi7CLmV1/R7xChSTSgIBk 2vIW1WItHEmbEACEi7K6cMoCzdApArl0lABv0RwuQXlYiPbgaX4ptBXDaXCmzn9BN/iH b56qic+7F/HGQ9Q1uvGmbzmQ/k3Cc21qdMQQclMZD/HAGlfn65Lup4hlmJB2/UjssJYm srlWKE1ZeMliouUCh0LXo2Q551VVmkzL8kjChTXs4+xLscfuflTJv+xOgDWtSd7I12f4 G0nQ== X-Gm-Message-State: AOAM530PwIyTAlaANtjaQJSyBWmEiboBl4iYqctO07BibVncQK6WLvfl 1VlMk/tXepdhJS0eAS7TQ94= X-Google-Smtp-Source: ABdhPJzat5BMCPgkejoDjmOJcB5P48ExVxXh+fEyDvvDxqoIGAU7OXeWm93caqoE2/ZSItwt5e3CXA== X-Received: by 2002:a6b:ed06:: with SMTP id n6mr5210030iog.88.1644539079119; Thu, 10 Feb 2022 16:24:39 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id b5sm6780043ilr.0.2022.02.10.16.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:24:38 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, James Smart , Dick Kennedy , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [PATCH 42/49] scsi: lpfc: replace cpumask_weight with cpumask_weight_gt Date: Thu, 10 Feb 2022 14:49:26 -0800 Message-Id: <20220210224933.379149-43-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" lpfc_cpuhp_get_eq() calls cpumask_weight() to compare the weight of cpumask with a given number. We can do it more efficiently with cpumask_weight_gt because conditional cpumask_weight may stop traversing the cpumask earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- drivers/scsi/lpfc/lpfc_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index f5c363f663f6..35688427cb7f 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -12642,7 +12642,7 @@ lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned i= nt cpu, * gone offline yet, we need >1. */ cpumask_and(tmp, maskp, cpu_online_mask); - if (cpumask_weight(tmp) > 1) + if (cpumask_weight_gt(tmp, 1)) continue; =20 /* Now that we have an irq to shutdown, get the eq --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 626B1C433EF for ; Fri, 11 Feb 2022 00:26:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346333AbiBKA0x (ORCPT ); Thu, 10 Feb 2022 19:26:53 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346261AbiBKA0w (ORCPT ); Thu, 10 Feb 2022 19:26:52 -0500 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD7915594 for ; Thu, 10 Feb 2022 16:26:52 -0800 (PST) Received: by mail-il1-x132.google.com with SMTP id c12so5109451ilm.8 for ; Thu, 10 Feb 2022 16:26:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=1MJU8h6aqi1lREanFgpSWWzF65VdO9IwfkWhBgqaH3Y=; b=mvi1bzuGc+ZCDBoKyIvPuu57FjwX/ZNRRmbHLZvq28NxvswbVJpCtL+TPmWTVqyuNq zHOVncwF2tsmDVT250gY7kLq+jhckLGi7PlKEqS4kMkEFP1KTu7Z7xjiQlYjB2792Sy0 y79LwuSrYF42p6Ksm7buY7+zkijxS7uB/hHR9ElJmFJeaWgz2GF8WWh/oKXQxLhRyRAL sBCNNuvExT46DRyy/8TIoNJF5PD3spUAqOHHh9NO3ZMs/icV5NIDHPE+azUqsowaetzV 7cpHrDo+EZ7zUtQ5l6ZDe3klqtAXMvArBpa4JNsPnSEGr2ueqLcJfFXWmveEcH8M/UrG z/9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1MJU8h6aqi1lREanFgpSWWzF65VdO9IwfkWhBgqaH3Y=; b=kjQ/uIH3jWFE9HMBpCZUS59BdbEMlgUUsSdOVC4SnK4i2ebN5bYPHvY3N8c9mMZk/o m5H/DVMDioKvyWiSPmL1IKnkN1BglyR9GXfIKu1o9j4xSG2g5mdK4CzTKrwULnC7svc5 Kvez5gATQriISEdkQaZb52CQIeLKAmtTR3ioVt69WPe9bV5zomF5sktsU4ou302a224b apZuo24XMf9TfHzSqb48cbQ48w34hBCSYnBKq3hUBK/Uj7CDpUxssDVa6D8sEDQNwnRA Me5NCqoQP0o+qg8bTpzp6lVThao14c3+t+O5pdbyKS3cLE011/vNUIVWNhSYpnJoww+6 3ljA== X-Gm-Message-State: AOAM531eR9XqDCJP5E2j9gwx6P1eYV2tVUpZPbp7Ykj+uGT1oRv2leak sCPa9NVCkF8H9axy+Yzq+Ms= X-Google-Smtp-Source: ABdhPJw4HRWGUzFWRINnqDSvHJhe4t426yscU51lkh9YSM6/oOmml5+22RpllautY9urs7QLFyNzJQ== X-Received: by 2002:a92:ab01:: with SMTP id v1mr5297485ilh.149.1644539212078; Thu, 10 Feb 2022 16:26:52 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id y22sm12896727iow.2.2022.02.10.16.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:26:51 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Li Yang , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 43/49] soc/qman: replace cpumask_weight with cpumask_weight_lt Date: Thu, 10 Feb 2022 14:49:27 -0800 Message-Id: <20220210224933.379149-44-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" qman_test_stash() calls cpumask_weight() to compare the weight of cpumask with a given number. We can do it more efficiently with cpumask_weight_lt because conditional cpumask_weight may stop traversing the cpumask earlier, as soon as condition is (or can't be) met. Signed-off-by: Yury Norov --- drivers/soc/fsl/qbman/qman_test_stash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/soc/fsl/qbman/qman_test_stash.c b/drivers/soc/fsl/qbma= n/qman_test_stash.c index b7e8e5ec884c..28b08568a349 100644 --- a/drivers/soc/fsl/qbman/qman_test_stash.c +++ b/drivers/soc/fsl/qbman/qman_test_stash.c @@ -561,7 +561,7 @@ int qman_test_stash(void) { int err; =20 - if (cpumask_weight(cpu_online_mask) < 2) { + if (cpumask_weight_lt(cpu_online_mask, 2)) { pr_info("%s(): skip - only 1 CPU\n", __func__); return 0; } --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DB3FC433F5 for ; Fri, 11 Feb 2022 00:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346333AbiBKA3I (ORCPT ); Thu, 10 Feb 2022 19:29:08 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345570AbiBKA3F (ORCPT ); Thu, 10 Feb 2022 19:29:05 -0500 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA6B6E1E for ; Thu, 10 Feb 2022 16:29:05 -0800 (PST) Received: by mail-io1-xd34.google.com with SMTP id p63so9500344iod.11 for ; Thu, 10 Feb 2022 16:29:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZDTlgBeWU01PBOzjEa5E75U6QWQseHc5+WCVq5kwy3w=; b=HM8kw4tWsOdALdKvtiwg2yy9eOvpQP+q0yOYC3qOjgrpR8fI4vo/sNinxN+PB+x/Ol jByaLF6SaOUOAP39+R0hdd76DXy4YmvFOlSGW6WvBQuLHJhLwD9LtChUJ0kIsq1VgDpt 9zckiYssOWPzRn1v/clJUdveiACOLwgOPwPmzgTEXdvK0beN6ZNDn9AYQI6fFMTgnM38 wm9a4sIxFBKuY0LyCYAB26zyZCuFv/y2XI02KUyo7gtVdClkz+WUvOihIGw2V5OsAtQJ Wifm0YtgNEUu29R3DbtPrD2hbVucPDQkBrf9ZGTr8wkNeEu0FKXVsUdOusf28EPD3pz9 b5SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZDTlgBeWU01PBOzjEa5E75U6QWQseHc5+WCVq5kwy3w=; b=DhCan/V1CsBzAh0hXkPQyhS6EFI46o7pi20dlmA0ueO8vsrSCpoxjS97jyB0EvdyhS jaSmtk88cbptYEKlvuWl7xaSMaRqwOSl803EflpuDAjbyXB7L+t+vaeKbPxWzJkT7FxJ Qnz7iVRPBjwrjRi1+q55we4vlkgogpsgN5xaDnOQtWEUR3qM9jUUO2HYgAjiHIK21CtB gs9eCyWYjbMkyVm2CvLRcKXqiIPDzXWxMDrHDP/lUkbTopX5DnnL+mcVgeUxRh9iHsjd Z68wNa6qRqkr8/YsECBjbogrhf0S8zKUsYEFtQwC1Kye9eyEWpZrNbQcrlHNPhUL7JZB yLvw== X-Gm-Message-State: AOAM533fHsWoDkCnJdAKhbFjNMt5NBmMlsOgAUnlrZzIGLrZbrFr0KUt mJWXrZGfwvfMqBQ2wJX6j1o= X-Google-Smtp-Source: ABdhPJwy0yG0d3qlBtG2SbAr160MBRvEPBQfXpQbtOrFB7KYpu61+Ou5PiEWocR3zTMOS1zHZBe0nA== X-Received: by 2002:a02:852e:: with SMTP id g43mr5671744jai.40.1644539345325; Thu, 10 Feb 2022 16:29:05 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id c12sm10343849ilo.70.2022.02.10.16.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:29:04 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org Subject: [PATCH 44/49] nodemask: add nodemask_weight_{eq,gt,ge,lt,le} Date: Thu, 10 Feb 2022 14:49:28 -0800 Message-Id: <20220210224933.379149-45-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In many cases kernel code uses nodemask_weight() to compare the result against some number or expression: if (nodes_weight(...) > 1) do_something(); It may be significantly improved for large nodemasks: if first few words count set bits to a number greater than given, we can stop counting and immediately return. The same idea would work in other direction: if we know that the number of set bits that we counted so far is small enough, so that it would be smaller than required number even if all bits of the rest of the nodemask are set, we can stop counting earlier. This patch adds nodes_weight{eq, gt, ge, lt, le} helpers based on corresponding bitmap functions. The following patches apply new functions where appropriate. Signed-off-by: Yury Norov --- include/linux/nodemask.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index 567c3ddba2c4..197598e075e9 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h @@ -38,6 +38,11 @@ * int nodes_empty(mask) Is mask empty (no bits sets)? * int nodes_full(mask) Is mask full (all bits sets)? * int nodes_weight(mask) Hamming weight - number of set bits + * bool nodes_weight_eq(src, nbits, num) Hamming Weight is equal to num + * bool nodes_weight_gt(src, nbits, num) Hamming Weight is greater than num + * bool nodes_weight_ge(src, nbits, num) Hamming Weight is greater than or= equal to num + * bool nodes_weight_lt(src, nbits, num) Hamming Weight is less than num + * bool nodes_weight_le(src, nbits, num) Hamming Weight is less than or eq= ual to num * * void nodes_shift_right(dst, src, n) Shift right * void nodes_shift_left(dst, src, n) Shift left @@ -240,6 +245,36 @@ static inline int __nodes_weight(const nodemask_t *src= p, unsigned int nbits) return bitmap_weight(srcp->bits, nbits); } =20 +#define nodes_weight_eq(nodemask, num) __nodes_weight_eq(&(nodemask), MAX_= NUMNODES, (num)) +static inline int __nodes_weight_eq(const nodemask_t *srcp, unsigned int n= bits, int num) +{ + return bitmap_weight_eq(srcp->bits, nbits, num); +} + +#define nodes_weight_gt(nodemask, num) __nodes_weight_gt(&(nodemask), MAX_= NUMNODES, (num)) +static inline int __nodes_weight_gt(const nodemask_t *srcp, unsigned int n= bits, int num) +{ + return bitmap_weight_gt(srcp->bits, nbits, num); +} + +#define nodes_weight_ge(nodemask, num) __nodes_weight_ge(&(nodemask), MAX_= NUMNODES, (num)) +static inline int __nodes_weight_ge(const nodemask_t *srcp, unsigned int n= bits, int num) +{ + return bitmap_weight_ge(srcp->bits, nbits, num); +} + +#define nodes_weight_lt(nodemask, num) __nodes_weight_lt(&(nodemask), MAX_= NUMNODES, (num)) +static inline int __nodes_weight_lt(const nodemask_t *srcp, unsigned int n= bits, int num) +{ + return bitmap_weight_lt(srcp->bits, nbits, num); +} + +#define nodes_weight_le(nodemask, num) __nodes_weight_le(&(nodemask), MAX_= NUMNODES, (num)) +static inline int __nodes_weight_le(const nodemask_t *srcp, unsigned int n= bits, int num) +{ + return bitmap_weight_le(srcp->bits, nbits, num); +} + #define nodes_shift_right(dst, src, n) \ __nodes_shift_right(&(dst), &(src), (n), MAX_NUMNODES) static inline void __nodes_shift_right(nodemask_t *dstp, --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16306C433F5 for ; Fri, 11 Feb 2022 00:31:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346352AbiBKAbU (ORCPT ); Thu, 10 Feb 2022 19:31:20 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245157AbiBKAbT (ORCPT ); Thu, 10 Feb 2022 19:31:19 -0500 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FE3A559A; Thu, 10 Feb 2022 16:31:19 -0800 (PST) Received: by mail-io1-xd2e.google.com with SMTP id n17so9561351iod.4; Thu, 10 Feb 2022 16:31:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WY+F15RwKoXSBs81n7QT8FqeoZ2/vRqemIDQ19p9hAY=; b=UhDGPTTGkCv7nd2i/RxSPH4PnVPZlxYLGSFCnJ4+jnU1zbj0n8l7wVAyCdZZNe4xg1 RVezAL9rFr1cDpujwWZ19coQQzwOQ8jqEuPUM3RTAzcJoTLbeUwPZxQnnTk2s9EjgDdM bqVuyPRCfRizMtazcb6ZHcm0of8H+1Zpq3KZTY7y9b1Vd/FvIUupHM5PwEvYk6iZsPa0 a48amFL3lBebCekA448n7zpKvMPr2J4GBSKGH1TkLOozoIK4f04NbEsPJFzZsffvrz5n jMJwjmBLyd8kN79M7JlB19hF4boCL26IuZBs/TGBiu1lOedGjl0eKRMxhP7Dz44nOEaU hgVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WY+F15RwKoXSBs81n7QT8FqeoZ2/vRqemIDQ19p9hAY=; b=7VjKq2vZENiURrW8qW0FOxjZavzg9aYsvFJg2Utla7K0OYpKwOb2HYpbM1XUbmGsSA vZcDtBgeuL/d5SF/2PxrJ68rcXwUafmwPh9F+NJNtmH3hT79mw3PVqJtt8kEsACY1hvO V3+tn4wswC+dRxXtxQdwIR8Wt2kZCEwHMTO9+qsigXnW724aZdcdSiuz5ShqEXkJBs0I y1YU40zrG+wOK0wh1Jsn93LOb90hN8d5DWBLTqny+qAbRilUJsj0S4Qs4iEflHE+DWsi lECQ+isgmgESsjeCi5oQCOILGtPkaLyHXyyNWhh3W5iKxvI8k3v5iSbWkM1trZYFe7uo 07RA== X-Gm-Message-State: AOAM533aB6ECqKOCq1/+rXkkjGRQqrG/raeFRKiKg8sqnxMDoKnXjfYS t5Gr5DWTVicDwAaFjufSXbM= X-Google-Smtp-Source: ABdhPJyJf8DICiugARTyGxQTO41WkKOMQOz8THqG4YLlZKUdSd+jbMzkeB9uqKFDGytPzQQRKnntPQ== X-Received: by 2002:a05:6602:26ce:: with SMTP id g14mr5175279ioo.137.1644539478920; Thu, 10 Feb 2022 16:31:18 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id w19sm13031570iov.16.2022.02.10.16.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:31:18 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Len Brown , Dan Williams , Huacai Chen , Vitaly Kuznetsov , Alison Schofield , linux-acpi@vger.kernel.org Subject: [PATCH 45/49] ACPI: replace nodes__weight with nodes_weight_ge for numa Date: Thu, 10 Feb 2022 14:49:29 -0800 Message-Id: <20220210224933.379149-46-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" acpi_map_pxm_to_node() calls nodes_weight() to compare the weight of nodemask with a given number. We can do it more efficiently with nodes_weight_eq() because conditional nodes_weight may stop traversing the nodemask earlier, as soon as condition is (or is not) met. Signed-off-by: Yury Norov --- drivers/acpi/numa/srat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c index 3b818ab186be..fe7a7996f553 100644 --- a/drivers/acpi/numa/srat.c +++ b/drivers/acpi/numa/srat.c @@ -67,7 +67,7 @@ int acpi_map_pxm_to_node(int pxm) node =3D pxm_to_node_map[pxm]; =20 if (node =3D=3D NUMA_NO_NODE) { - if (nodes_weight(nodes_found_map) >=3D MAX_NUMNODES) + if (nodes_weight_ge(nodes_found_map, MAX_NUMNODES)) return NUMA_NO_NODE; node =3D first_unset_node(nodes_found_map); __acpi_map_pxm_to_node(pxm, node); --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2AEBC433F5 for ; Fri, 11 Feb 2022 00:33:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245008AbiBKAdf (ORCPT ); Thu, 10 Feb 2022 19:33:35 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242517AbiBKAdb (ORCPT ); Thu, 10 Feb 2022 19:33:31 -0500 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF0AC5F66 for ; Thu, 10 Feb 2022 16:33:31 -0800 (PST) Received: by mail-io1-xd33.google.com with SMTP id y84so9661062iof.0 for ; Thu, 10 Feb 2022 16:33:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=r/11QztAgc7p887H2JROAx8muQu/2OLTeRvuBg6maFg=; b=ok4tnMvC7LNlEY46BePrt8wMU+Xygc1lZ1J4h61Xtojbzh341QW8CBnitkhh5WqB3/ XQn5p4hMW9VVGbkJ9OqMDwRUWIdHv5YGA1+MudlaHItROlN0ZWP+huOqrDwFHv9Z8QR6 kAQBAsudTSUpOAzB8WSpovQie3Y9Oejz4Ny6jolkns7yygmDKtkLzivE4oMh3a2eFa0Q blKT0mttPX3VUmJXZcZg9AeE3k4/82VYbeWrmKV+2djpYxOF+Z8FLRVT7aZJzk3HNEyf zId6ynUThngQhyEuB4bOApoKZZXjGDOOJNdj8JSWbzBBA7Maj1PC2m2E0xgnM+DZdPL7 xKnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r/11QztAgc7p887H2JROAx8muQu/2OLTeRvuBg6maFg=; b=b1M2xL5LsNNBu0N7g2/nGI0bQDHXua6lhm19sRHWftvLYWxFpRQQRHs2ySDHkLdUxr zOtnEfFxwEmUWv3I55v3YHQ4kcgQSdMABIbU95lmIdwOHPoLOI9jN0bt4PL5pgibAzS4 2PBWVQZl8nX9jl5F8neQ6iCAtzrdAbSseB4JXYMmaoUw9rDj4zlrIaOApd5W/yiPVc4o lYdEnkwsOFlwM8wu5Wo4ItYq8MpkNJZRw4uF24Ua9t6Q4jC7o7iqGJguTX3vL5ApqpmX ayfIKgsK8wKdTq3S8Gt9bf1rHgl7hFkcx18htmZ1MaLEdUA2S//54ox/5+a/WryzrAok 5vUQ== X-Gm-Message-State: AOAM530Ep/13JvtDF+TJWG2/vfZeGROSEXqMdQ/HoAMTb4yS4bABDqQg V7dCvwWG/nSi9Rj4h3XnWBo= X-Google-Smtp-Source: ABdhPJyzos5XlKp1kunYx0r5VshfNF8Q0FlI8L2FzcjJPMYDnSfr0hH9Cw5PSnXX0u86MmWYjJr03Q== X-Received: by 2002:a02:3f2f:: with SMTP id d47mr5568535jaa.228.1644539611330; Thu, 10 Feb 2022 16:33:31 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id 193sm3856876iob.17.2022.02.10.16.33.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:33:31 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 46/49] mm/mempolicy: replace nodes_weight with nodes_weight_eq Date: Thu, 10 Feb 2022 14:49:30 -0800 Message-Id: <20220210224933.379149-47-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" do_migrate_pages() calls nodes_weight() to compare the weight of nodemask with a given number. We can do it more efficiently with nodes_weight_eq() because conditional nodes_weight() may stop traversing the nodemask earlier, as soon as condition is (or is not) met. Signed-off-by: Yury Norov --- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 7c852793d9e8..56efd00b1b6e 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1154,7 +1154,7 @@ int do_migrate_pages(struct mm_struct *mm, const node= mask_t *from, * [0-7] - > [3,4,5] moves only 0,1,2,6,7. */ =20 - if ((nodes_weight(*from) !=3D nodes_weight(*to)) && + if (!nodes_weight_eq(*from, nodes_weight(*to)) && (node_isset(s, *to))) continue; =20 --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93F66C433F5 for ; Fri, 11 Feb 2022 00:35:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346396AbiBKAfr (ORCPT ); Thu, 10 Feb 2022 19:35:47 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245125AbiBKAfn (ORCPT ); Thu, 10 Feb 2022 19:35:43 -0500 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2D685F66 for ; Thu, 10 Feb 2022 16:35:43 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id o3so7353855qtm.12 for ; Thu, 10 Feb 2022 16:35:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OWAdmxyB++0+PrjBMyb2j1q4M+ZTDvPBI87BwMKOTA4=; b=px25tVfseTRg17nKrinckLpm5Os6T2EDwYc8LKgshVBbe8wsdoAH40zqblIKerCD/M 9FOLPx46bt7sHkinZB7cbxFBdikM66T7mIE2f+XeWCQEEWgZ6+Fj8c60iMtssJ2j4Ax5 ywQwibJ3q+gTnIvO+B0epbOGU2k7wcFwtAmB2Ekl9ZcADK2LwleSSxyJRs3DD/O5DZ2q 3TtJYkbVmKfY7d2ve4Ep5xreuUGke1oZrOtsnTBOvbkyt9qrnwapvEabYRk+An2u5fDB srQ7MLPu2N9T8Fk0fsc3+eu95bT6srOmeEd1PY3YKp7ljCULaG+YIorAkRi025pE/HtS At7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OWAdmxyB++0+PrjBMyb2j1q4M+ZTDvPBI87BwMKOTA4=; b=Nqair/vDeS2BUuKINeYHkwBe78SI351hrXzh/AMoNbldp6hcS9CA8MWJ3vOOe0Tegp rrUk0+sWHcPXBmCaWv1VrQnLaz1sE9Bqes5TT8gug6T4GGSnq0D3M4WakkHIEpIEDTmz jawHYWnCQF0c+ZuqCBOwjxx1gSLa37Q7ZIOuWtI9daXZqD7GbBHgHHQuQFBSkUDaNKOV zDWMwMXtcpxaOrd3qTaQWZChzEW2qtRfoqF9FooSqy9AuwxWkuQB6QDZ76HDVYOl/whZ ZCJWOMe3no0XTQZGaNlnpAIcgLn0hXBFloQEAIt3z1Tsv4NOilhpg0pufYSmu7YaTmLL mfNQ== X-Gm-Message-State: AOAM533zG5zuN1evAY5B2mKOsLNkeaT/1CfjbK4NV05k46qH7zAf1OUW Blq0NAv1vKoz6myCjSVeko4= X-Google-Smtp-Source: ABdhPJwKE/7L+78ImyHSzKItwQ+7D0kCNRZ6HRgstwY/P0UGJdT1+mnItTy7cbAEdrMnsxIjkAmO9Q== X-Received: by 2002:ac8:5747:: with SMTP id 7mr6794649qtx.95.1644539742833; Thu, 10 Feb 2022 16:35:42 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id k13sm11581386qko.45.2022.02.10.16.35.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:35:42 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 47/49] nodemask: add num_node_state_eq() Date: Thu, 10 Feb 2022 14:49:31 -0800 Message-Id: <20220210224933.379149-48-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Page allocator uses num_node_state() to compare number of nodes with a given number. The underlying code calls bitmap_weight(), and we can do it more efficiently with num_node_state_eq because conditional nodes_weight may stop traversing the nodemask earlier, as soon as condition is (or is not) met. Signed-off-by: Yury Norov --- include/linux/nodemask.h | 5 +++++ mm/page_alloc.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index 197598e075e9..c5014dbf3cce 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h @@ -466,6 +466,11 @@ static inline int num_node_state(enum node_states stat= e) return nodes_weight(node_states[state]); } =20 +static inline int num_node_state_eq(enum node_states state, int num) +{ + return nodes_weight_eq(node_states[state], num); +} + #define for_each_node_state(__node, __state) \ for_each_node_mask((__node), node_states[__state]) =20 diff --git a/mm/page_alloc.c b/mm/page_alloc.c index cface1d38093..897e64b66ca4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8434,7 +8434,7 @@ void __init page_alloc_init(void) int ret; =20 #ifdef CONFIG_NUMA - if (num_node_state(N_MEMORY) =3D=3D 1) + if (num_node_state_eq(N_MEMORY, 1)) hashdist =3D 0; #endif =20 --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 140B2C433FE for ; Fri, 11 Feb 2022 00:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346416AbiBKAh6 (ORCPT ); Thu, 10 Feb 2022 19:37:58 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242949AbiBKAh4 (ORCPT ); Thu, 10 Feb 2022 19:37:56 -0500 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BFF15F7C; Thu, 10 Feb 2022 16:37:56 -0800 (PST) Received: by mail-io1-xd35.google.com with SMTP id s18so9531390ioa.12; Thu, 10 Feb 2022 16:37:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=YsSFVcBAVgAnh1p0qtI8V/Jpa4hlZLllbwLcaFPQgA0=; b=cW/5wKGiWXoUhwkDkZDHsCqrs3nultWGlDM8mzcIOR/k2uTAprKe5yszATQTNPCSCJ 1m7THR5JF2seGAiygdS0fr24QyEZT0sgAQ9wB5PCP4TWpuejgB2a01Q0MvyEJuc1shdA 8CJ4yWoIsRObMajqGrLb7XTjEVviIfaKIgFnmab7Rbb4qJmhUzcNdYqczakRU0Ci90pn HqP+vbPkC+SeNc5JD+FFLVP2GkIQ8WDQIRlDpIQzZo52mMn00OCewffUksZ8Aol+2Bi+ OejfdElRAWRhWleKV+UcqqDm0Zc49ACLla4SRERHQMkPyydvud7vDMi/NBzJxhFT+wlg 2qjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YsSFVcBAVgAnh1p0qtI8V/Jpa4hlZLllbwLcaFPQgA0=; b=2ZjnqgCD3j0TMjvn6h8UpEim5/VZECiOdeXMUy5SO7D+BRAeklrVmpMSxZxaEF6WOa UhbsHMa301YRH9W2lgs2Gkb/VSTP5ft5zwnnIoAJIVOj4Km4B0eXCPpJRTGSSt02g1eD CL0DpRETnK3Td4zHyxCAhLsJDrGSeze5aFjNb5WuLgnAvGlnA1noShbVW21zXPJSP5YX wK/Qwhq01XmsdGwP9+Lnd1b2ugUUdE7bS7Dh/ZAl/RyD7sEyVMeZY8V9Tahpu5Y/DGXt m4Z+/JD8f6F6l/SAwhPp9FI71RYBu62NXBvJ0MMd8CVSlT19mTE/8CC/hBLrfJS5N5Z1 yQ0w== X-Gm-Message-State: AOAM530SkE1r4qzasOEXBvdAJEN5FVpyC9ke9Lh5dttACyK2KfTuwrXj +2hDICgxkWTDz3BTZQoBUqg= X-Google-Smtp-Source: ABdhPJw313nFWHa7NqEf6BSTSrIQf9t0LekjW6QyePAevB7Ed9CZMq3DGQ+dll3RTz0cTf9zJfAbpA== X-Received: by 2002:a6b:d80c:: with SMTP id y12mr4955845iob.31.1644539875809; Thu, 10 Feb 2022 16:37:55 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id w11sm11664522ill.46.2022.02.10.16.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:37:55 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Jin Yao , John Garry , Ian Rogers , Kan Liang , linux-perf-users@vger.kernel.org Subject: [PATCH 48/49] tools: bitmap: sync bitmap_weight Date: Thu, 10 Feb 2022 14:49:32 -0800 Message-Id: <20220210224933.379149-49-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Pull bitmap_weight_{cmp,eq,gt,ge,lt,le} from mother kernel and use where applicable. Signed-off-by: Yury Norov --- tools/include/linux/bitmap.h | 44 ++++++++++++++++++++++++++++++++++++ tools/lib/bitmap.c | 20 ++++++++++++++++ tools/perf/util/pmu.c | 2 +- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index ea97804d04d4..29bf54996a84 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -12,6 +12,8 @@ unsigned long name[BITS_TO_LONGS(bits)] =20 int __bitmap_weight(const unsigned long *bitmap, int bits); +int __bitmap_weight_cmp(const unsigned long *bitmap, unsigned int bits, + unsigned int num); void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, const unsigned long *bitmap2, int bits); int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, @@ -68,6 +70,48 @@ static inline int bitmap_weight(const unsigned long *src= , unsigned int nbits) return __bitmap_weight(src, nbits); } =20 +static __always_inline +int bitmap_weight_cmp(const unsigned long *src, unsigned int nbits, int nu= m) +{ + if ((unsigned int)num > nbits) + return -num; + + if (small_const_nbits(nbits)) + return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)) - num; + + return __bitmap_weight_cmp(src, nbits, num); +} + +static __always_inline +bool bitmap_weight_eq(const unsigned long *src, unsigned int nbits, int nu= m) +{ + return bitmap_weight_cmp(src, nbits, num) =3D=3D 0; +} + +static __always_inline +bool bitmap_weight_gt(const unsigned long *src, unsigned int nbits, int nu= m) +{ + return bitmap_weight_cmp(src, nbits, num) > 0; +} + +static __always_inline +bool bitmap_weight_ge(const unsigned long *src, unsigned int nbits, int nu= m) +{ + return bitmap_weight_cmp(src, nbits, num - 1) > 0; +} + +static __always_inline +bool bitmap_weight_lt(const unsigned long *src, unsigned int nbits, int nu= m) +{ + return bitmap_weight_cmp(src, nbits, num - 1) <=3D 0; +} + +static __always_inline +bool bitmap_weight_le(const unsigned long *src, unsigned int nbits, int nu= m) +{ + return bitmap_weight_cmp(src, nbits, num) <=3D 0; +} + static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c index db466ef7be9d..06e58fee8523 100644 --- a/tools/lib/bitmap.c +++ b/tools/lib/bitmap.c @@ -18,6 +18,26 @@ int __bitmap_weight(const unsigned long *bitmap, int bit= s) return w; } =20 +int __bitmap_weight_cmp(const unsigned long *bitmap, unsigned int bits, in= t num) +{ + unsigned int k, w, lim =3D bits / BITS_PER_LONG; + + for (k =3D 0, w =3D 0; k < lim; k++) { + if (w + bits - k * BITS_PER_LONG < num) + goto out; + + w +=3D hweight_long(bitmap[k]); + + if (w > num) + goto out; + } + + if (bits % BITS_PER_LONG) + w +=3D hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); +out: + return w - num; +} + void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, const unsigned long *bitmap2, int bits) { diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 8dfbba15aeb8..2c26cdd7f9b0 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1314,7 +1314,7 @@ static int pmu_config_term(const char *pmu_name, */ if (term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM) { if (term->no_value && - bitmap_weight(format->bits, PERF_PMU_FORMAT_BITS) > 1) { + bitmap_weight_gt(format->bits, PERF_PMU_FORMAT_BITS, 1)) { if (err) { parse_events_error__handle(err, term->err_val, strdup("no value assigned for term"), --=20 2.32.0 From nobody Mon Jun 29 11:19:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4104CC433F5 for ; Fri, 11 Feb 2022 00:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346445AbiBKAkK (ORCPT ); Thu, 10 Feb 2022 19:40:10 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:34934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343924AbiBKAkJ (ORCPT ); Thu, 10 Feb 2022 19:40:09 -0500 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8962F5F6E for ; Thu, 10 Feb 2022 16:40:09 -0800 (PST) Received: by mail-io1-xd32.google.com with SMTP id p63so9520899iod.11 for ; Thu, 10 Feb 2022 16:40:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=vmCRi5YEMF1V/cao58AWdP9eCW6N73MpNoaksw6efrg=; b=kOleynCii1sTUECOg708u4XojrBU9aS21lN3USq2R+X5/ZO33qGfpqSNvnne6+Tbb7 w1a5Q82784qwC6s2+tfAJ08cVm+lekZz2Ht7m8pT16vUPtp9HbSuprSDBx8z1Z82vSp6 Lg3sLP3tU5/bASf45WQF9dsmCstphPdp2diEHkM1mHagQsCK1/DuYY/mlwKWTclZubrA UHaoSXaZZ+qrSb8fTEnXC8HD+988Lag0y2tBy/61FrGOBdUeNpOgKYdud9iIuAtqxZuz oSTg9go8Mp2nmp2P4xSC2IaULA7ZdycJf2oeREtRb1akdVemUo6v0PMgDbnpi83Lg4Vi /SpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vmCRi5YEMF1V/cao58AWdP9eCW6N73MpNoaksw6efrg=; b=xdUuIeMyxTXyU6SQ1Kfvlw/83TNb0bkALETzaSGSJ5q5QpEy7LXygdnEhCrRk8Y7Hu 1WWVHxSqP5jRF8xDDR6FS3teqNTbkDcgaiSJiBfCU2D0o/MTep0V7YtF408cZVQgzhvR EH24MW7XlqxmVSNhWirIHW9MI5x1yfSPm1WAar9HsxDRORT3dB45EBSVA7K2IvG+1ABQ s2x0D7oN9Ic3bsW9oQ5rdGa3mrEC+ajB2pVCbnOoA/lSVPPo9wTn4zqOX69UY+B7Aana LdI3oM+3yk2Qnzd3Vx5mDiOV6xO6WW8IcHB9WtBMS4Kne6WbDRnFww6wkRug9zSZI2s8 cSiQ== X-Gm-Message-State: AOAM530Lbsot5VWNb7eYt1UCNOUq+Wp7wjSeH/BFAvCI82c39Ripba4I cUgGWjo5cln0bg7GNGeN88Q= X-Google-Smtp-Source: ABdhPJxoFCWN5x2mN0KD5UIrwsWX5nqLJ2PSiQsS/yLSfalb2eKudKYngjMmUEcyHIIzios3XdvRdQ== X-Received: by 2002:a05:6638:13d1:: with SMTP id i17mr5558325jaj.182.1644540008959; Thu, 10 Feb 2022 16:40:08 -0800 (PST) Received: from localhost ([12.28.44.171]) by smtp.gmail.com with ESMTPSA id c9sm668312ile.38.2022.02.10.16.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:40:08 -0800 (PST) From: Yury Norov To: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org Subject: [PATCH 49/49] MAINTAINERS: add cpumask and nodemask files to BITMAP_API Date: Thu, 10 Feb 2022 14:49:33 -0800 Message-Id: <20220210224933.379149-50-yury.norov@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220210224933.379149-1-yury.norov@gmail.com> References: <20220210224933.379149-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" cpumask and nodemask APIs are thin wrappers around basic bitmap API, and corresponding files are not formally maintained. This patch adds them to BITMAP_API section, so that bitmap folks would have closer look at it. Signed-off-by: Yury Norov --- MAINTAINERS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index bc32519e5c02..718ed3b81c8e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3434,10 +3434,14 @@ R: Andy Shevchenko R: Rasmus Villemoes S: Maintained F: include/linux/bitmap.h +F: include/linux/cpumask.h F: include/linux/find.h +F: include/linux/nodemask.h 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 --=20 2.32.0