Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3174558pxb; Mon, 24 Jan 2022 04:13:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpMEwbwej4dAz58efvf5rBHLmhYNgjStVFtLVUGgl6+oByD1+hEe6WThbwKZAA7NdZ0XvV X-Received: by 2002:a17:90b:38ca:: with SMTP id nn10mr1608003pjb.205.1643026428320; Mon, 24 Jan 2022 04:13:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643026428; cv=none; d=google.com; s=arc-20160816; b=G3cE0xy55ZPZMZ65bP+9c/PPHeEbxnhYfcHhzApXFJ6GOzCB3BEuep6ki+nP1ttOBH YTx+HHaZkD453XSSQCgARRmo1FlShTNFY59Aa7ciqZvxdDW5xKsz2y42tdqxlY/cxed9 Yfw+tccCP70n+9ewbA86pnZ0BMpP4gC4kW7kZbnjvezOgWxBSAJLaB5VnxjZ3L8Gh9Ir Aq58P+H6RzCXpca6nrqKQH/a/UKCfslfR4/GODQa2lvBtigK7HmhypRtahpuPvrbVrWU EbH6U7qovzBfpRUf3MivkBb/28pmpyqlbEekh0EKF8lYpX3Qdxgq4+jXaP0rsO8KHcST ykoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=QGbXvpGX2v4Ey2LzEKSSlIal0vlI7iYMGBrpPZxtbCI=; b=yLPw3EnXOLPttbs3sJcF6RkiXqZfY5GeSM9AB6ZTtmEctjdIF2YSYNybDbvF1RbKzw u+fWGxPOflbwhb4YcmgwbTNtnypiHZvlW+VgzEV58+b9ntw+ayoQNZmR5RFwrc9dvQn4 Sa43iTYTEujhJO4LHSAo2vXEfhoDVBBIdgpPlk9LRc3hMmjNWZDTsxAuUZ5Zq8SKOFaS tZnJfyB6sneU6FVaadMjsEe2uuyLa1S/9AitiJ0TovPUXiuE9YUSkbCww+ien7MYVaSu Ls2Pe7hQum97Bcjk84sLP917Wg5aWmoTy0nbXQudo8n+wTzsd68wK0v1qIhGYpGiXdLg h9rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WDp7M2gj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z11si12875964pgh.786.2022.01.24.04.13.36; Mon, 24 Jan 2022 04:13:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WDp7M2gj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239840AbiAWSk7 (ORCPT + 99 others); Sun, 23 Jan 2022 13:40:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239673AbiAWSkn (ORCPT ); Sun, 23 Jan 2022 13:40:43 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1427DC06173D; Sun, 23 Jan 2022 10:40:36 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id pf13so14152333pjb.0; Sun, 23 Jan 2022 10:40:36 -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=QGbXvpGX2v4Ey2LzEKSSlIal0vlI7iYMGBrpPZxtbCI=; b=WDp7M2gjbxgNLuGpYm8aNkWuCH3uLDBFVX5FbgY+MiojtTvY8hzIZDZaDHvjikmt2W Iq6iXMvmCiKcT9KRr6bh0cz3x1yye0VWg64m7jFtFzX8DBqzKmf59SCJq5nT3uBXanWW N8X/Gnlq6wA3k1Jbo9hVJKnwZRGdnZfOvRVAubkwSPjFbGuqi6s2bSwqOSbAVB3HCFQO +GLitOBWcHfwg5XWigt/EC0FrOocZLnZNM99jzmQ3NFBxnY1b58cKstaTpkVSMQyLjLA q+k26qTBO1IzuK5NIYv4DYVJ8L3HgHD2KsaRkb7Rwpi42Dl3INgZa68SrvKvGO1nKF8m 1Drg== 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=QGbXvpGX2v4Ey2LzEKSSlIal0vlI7iYMGBrpPZxtbCI=; b=cpLhqgpb/uFMUzsQhd4gPpFDRxlDy9PlxsTBAUqevMpBhhFzgB/zccuoT2scOkY/Lx bIZZBhM0vqciJrdvRE+TSNGuLubnMZXkz1hkEJ677GfzPZx/Al0fHCq8q3+EGGAzNROt lHPeDaUmOc/2zVdwCKTyENMkeOZ8YnZbOHFc9zRMUb1XFaMSiJoyuGCp3UVOpk1Jf4NU szyeE15ksesC1mrVTAjyut4FDyuhBYntO8cnRwjebf03vonJl5QnHYEAmQUDrIkpaF90 EfUyVH/6cH1hSXNeI8m6FgViuZVNz7rRlR2KSGlnbJgvsOdHBgwlkoKkcE7M8URQ5vB5 zb1g== X-Gm-Message-State: AOAM531TeMdaPtO2hK0HBavdPKgP6mXLHbpoNVYcB8Eh24pa2nYLsN2b GqeauFAZXt28NffOt2woDME= X-Received: by 2002:a17:90b:1b0e:: with SMTP id nu14mr9711815pjb.39.1642963235490; Sun, 23 Jan 2022 10:40:35 -0800 (PST) Received: from localhost (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id c8sm14350579pfl.122.2022.01.23.10.40.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jan 2022 10:40:35 -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 15/54] arch/x86: replace cpumask_weight with cpumask_empty where appropriate Date: Sun, 23 Jan 2022 10:38:46 -0800 Message-Id: <20220123183925.1052919-16-yury.norov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220123183925.1052919-1-yury.norov@gmail.com> References: <20220123183925.1052919-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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/resctrl/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, cpumask_var_t newmask, /* 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; } /* 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, cpumask_var_t newmask, * and update per-cpu rmid */ cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask); - if (cpumask_weight(tmpmask)) { + if (!cpumask_empty(tmpmask)) { head = &prgrp->mon.crdtgrp_list; list_for_each_entry(crgrp, head, mon.crdtgrp_list) { if (crgrp == rdtgrp) @@ -394,7 +394,7 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask, /* 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 == &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, cpumask_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 == 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_file *of, /* 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 = -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; - if (!cpumask_available(downed_cpus) || cpumask_weight(downed_cpus) == 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) /* 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); -- 2.30.2