History

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.

Yury Norov committed 4 years ago

Commit 4aec74b1 parent b6dad113 files · +9 −9Browse files

Unified · Split

3 files
  1. arch/x86/kernel/cpu/resctrl/rdtgroup.c +7 −7
  2. arch/x86/mm/mmio-mod.c +1 −1
  3. arch/x86/platform/uv/uv_nmi.c +1 −1
arch/x86/kernel/cpu/resctrl/rdtgroup.c+7−7
@@ -341,14 +341,14 @@ static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask, · 340 unmodified lines
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, · 4 unmodified lines
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, · 28 unmodified lines
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, · 12 unmodified lines
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, · 63 unmodified lines
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+1−1
@@ -400,7 +400,7 @@ static void leave_uniprocessor(void) · 399 unmodified lines
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+1−1
@@ -985,7 +985,7 @@ static int uv_handle_nmi(unsigned int reason, struct pt_regs *regs) · 984 unmodified lines
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);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t