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
341 341
342 /* Check whether cpus belong to parent ctrl group */342 /* Check whether cpus belong to parent ctrl group */
343 cpumask_andnot(tmpmask, newmask, &prgrp->cpu_mask);343 cpumask_andnot(tmpmask, newmask, &prgrp->cpu_mask);
344 if (cpumask_weight(tmpmask)) {344 if (!cpumask_empty(tmpmask)) {
345 rdt_last_cmd_puts("Can only add CPUs to mongroup that belong to parent\n");345 rdt_last_cmd_puts("Can only add CPUs to mongroup that belong to parent\n");
346 return -EINVAL;346 return -EINVAL;
347 }347 }
348 348
349 /* Check whether cpus are dropped from this group */349 /* Check whether cpus are dropped from this group */
350 cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);350 cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
351 if (cpumask_weight(tmpmask)) {351 if (!cpumask_empty(tmpmask)) {
352 /* Give any dropped cpus to parent rdtgroup */352 /* Give any dropped cpus to parent rdtgroup */
353 cpumask_or(&prgrp->cpu_mask, &prgrp->cpu_mask, tmpmask);353 cpumask_or(&prgrp->cpu_mask, &prgrp->cpu_mask, tmpmask);
354 update_closid_rmid(tmpmask, prgrp);354 update_closid_rmid(tmpmask, prgrp);
@@ -359,7 +359,7 @@ static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask, · 4 unmodified lines
359 * and update per-cpu rmid359 * and update per-cpu rmid
360 */360 */
361 cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);361 cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
362 if (cpumask_weight(tmpmask)) {362 if (!cpumask_empty(tmpmask)) {
363 head = &prgrp->mon.crdtgrp_list;363 head = &prgrp->mon.crdtgrp_list;
364 list_for_each_entry(crgrp, head, mon.crdtgrp_list) {364 list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
365 if (crgrp == rdtgrp)365 if (crgrp == rdtgrp)
@@ -394,7 +394,7 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask, · 28 unmodified lines
394 394
395 /* Check whether cpus are dropped from this group */395 /* Check whether cpus are dropped from this group */
396 cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);396 cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
397 if (cpumask_weight(tmpmask)) {397 if (!cpumask_empty(tmpmask)) {
398 /* Can't drop from default group */398 /* Can't drop from default group */
399 if (rdtgrp == &rdtgroup_default) {399 if (rdtgrp == &rdtgroup_default) {
400 rdt_last_cmd_puts("Can't drop CPUs from default group\n");400 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
413 * and update per-cpu closid/rmid.413 * and update per-cpu closid/rmid.
414 */414 */
415 cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);415 cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
416 if (cpumask_weight(tmpmask)) {416 if (!cpumask_empty(tmpmask)) {
417 list_for_each_entry(r, &rdt_all_groups, rdtgroup_list) {417 list_for_each_entry(r, &rdt_all_groups, rdtgroup_list) {
418 if (r == rdtgrp)418 if (r == rdtgrp)
419 continue;419 continue;
420 cpumask_and(tmpmask1, &r->cpu_mask, tmpmask);420 cpumask_and(tmpmask1, &r->cpu_mask, tmpmask);
421 if (cpumask_weight(tmpmask1))421 if (!cpumask_empty(tmpmask1))
422 cpumask_rdtgrp_clear(r, tmpmask1);422 cpumask_rdtgrp_clear(r, tmpmask1);
423 }423 }
424 update_closid_rmid(tmpmask, rdtgrp);424 update_closid_rmid(tmpmask, rdtgrp);
@@ -488,7 +488,7 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of, · 63 unmodified lines
488 488
489 /* check that user didn't specify any offline cpus */489 /* check that user didn't specify any offline cpus */
490 cpumask_andnot(tmpmask, newmask, cpu_online_mask);490 cpumask_andnot(tmpmask, newmask, cpu_online_mask);
491 if (cpumask_weight(tmpmask)) {491 if (!cpumask_empty(tmpmask)) {
492 ret = -EINVAL;492 ret = -EINVAL;
493 rdt_last_cmd_puts("Can only assign online CPUs\n");493 rdt_last_cmd_puts("Can only assign online CPUs\n");
494 goto unlock;494 goto unlock;
arch/x86/mm/mmio-mod.c+1−1
@@ -400,7 +400,7 @@ static void leave_uniprocessor(void) · 399 unmodified lines
400 int cpu;400 int cpu;
401 int err;401 int err;
402 402
403 if (!cpumask_available(downed_cpus) || cpumask_weight(downed_cpus) == 0)403 if (!cpumask_available(downed_cpus) || cpumask_empty(downed_cpus))
404 return;404 return;
405 pr_notice("Re-enabling CPUs...\n");405 pr_notice("Re-enabling CPUs...\n");
406 for_each_cpu(cpu, downed_cpus) {406 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
985 985
986 /* Clear global flags */986 /* Clear global flags */
987 if (master) {987 if (master) {
988 if (cpumask_weight(uv_nmi_cpu_mask))988 if (!cpumask_empty(uv_nmi_cpu_mask))
989 uv_nmi_cleanup_mask();989 uv_nmi_cleanup_mask();
990 atomic_set(&uv_nmi_cpus_in_nmi, -1);990 atomic_set(&uv_nmi_cpus_in_nmi, -1);
991 atomic_set(&uv_nmi_cpu, -1);991 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