Skip to content

Commit 4aec74b

Browse files
committed
arch/x86: replace cpumask_weight with cpumask_empty where appropriate
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 <[email protected]> Reviewed-by: Steve Wahl <[email protected]>
1 parent b6dad11 commit 4aec74b

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,14 @@ static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
341341

342342
/* Check whether cpus belong to parent ctrl group */
343343
cpumask_andnot(tmpmask, newmask, &prgrp->cpu_mask);
344-
if (cpumask_weight(tmpmask)) {
344+
if (!cpumask_empty(tmpmask)) {
345345
rdt_last_cmd_puts("Can only add CPUs to mongroup that belong to parent\n");
346346
return -EINVAL;
347347
}
348348

349349
/* Check whether cpus are dropped from this group */
350350
cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
351-
if (cpumask_weight(tmpmask)) {
351+
if (!cpumask_empty(tmpmask)) {
352352
/* Give any dropped cpus to parent rdtgroup */
353353
cpumask_or(&prgrp->cpu_mask, &prgrp->cpu_mask, tmpmask);
354354
update_closid_rmid(tmpmask, prgrp);
@@ -359,7 +359,7 @@ static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
359359
* and update per-cpu rmid
360360
*/
361361
cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
362-
if (cpumask_weight(tmpmask)) {
362+
if (!cpumask_empty(tmpmask)) {
363363
head = &prgrp->mon.crdtgrp_list;
364364
list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
365365
if (crgrp == rdtgrp)
@@ -394,7 +394,7 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
394394

395395
/* Check whether cpus are dropped from this group */
396396
cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
397-
if (cpumask_weight(tmpmask)) {
397+
if (!cpumask_empty(tmpmask)) {
398398
/* Can't drop from default group */
399399
if (rdtgrp == &rdtgroup_default) {
400400
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,
413413
* and update per-cpu closid/rmid.
414414
*/
415415
cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
416-
if (cpumask_weight(tmpmask)) {
416+
if (!cpumask_empty(tmpmask)) {
417417
list_for_each_entry(r, &rdt_all_groups, rdtgroup_list) {
418418
if (r == rdtgrp)
419419
continue;
420420
cpumask_and(tmpmask1, &r->cpu_mask, tmpmask);
421-
if (cpumask_weight(tmpmask1))
421+
if (!cpumask_empty(tmpmask1))
422422
cpumask_rdtgrp_clear(r, tmpmask1);
423423
}
424424
update_closid_rmid(tmpmask, rdtgrp);
@@ -488,7 +488,7 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
488488

489489
/* check that user didn't specify any offline cpus */
490490
cpumask_andnot(tmpmask, newmask, cpu_online_mask);
491-
if (cpumask_weight(tmpmask)) {
491+
if (!cpumask_empty(tmpmask)) {
492492
ret = -EINVAL;
493493
rdt_last_cmd_puts("Can only assign online CPUs\n");
494494
goto unlock;

arch/x86/mm/mmio-mod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static void leave_uniprocessor(void)
400400
int cpu;
401401
int err;
402402

403-
if (!cpumask_available(downed_cpus) || cpumask_weight(downed_cpus) == 0)
403+
if (!cpumask_available(downed_cpus) || cpumask_empty(downed_cpus))
404404
return;
405405
pr_notice("Re-enabling CPUs...\n");
406406
for_each_cpu(cpu, downed_cpus) {

arch/x86/platform/uv/uv_nmi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ static int uv_handle_nmi(unsigned int reason, struct pt_regs *regs)
985985

986986
/* Clear global flags */
987987
if (master) {
988-
if (cpumask_weight(uv_nmi_cpu_mask))
988+
if (!cpumask_empty(uv_nmi_cpu_mask))
989989
uv_nmi_cleanup_mask();
990990
atomic_set(&uv_nmi_cpus_in_nmi, -1);
991991
atomic_set(&uv_nmi_cpu, -1);

0 commit comments

Comments
 (0)