diff options
| author | ShengYi Hung <aokblast@FreeBSD.org> | 2026-01-03 16:32:50 +0000 |
|---|---|---|
| committer | ShengYi Hung <aokblast@FreeBSD.org> | 2026-02-18 09:40:54 +0000 |
| commit | e387d9438ba0258b88ebe03ef139bc6fd70b5a46 (patch) | |
| tree | 85a775f18a620211e337e57678dfdc76af3f669a | |
| parent | efcfba9b31ad11ec901085c38b79e40289b9e7bc (diff) | |
smp: Use bitwise operation to count cpu number
Previously, we iterated over all CPUs using CPU_FOREACH and checked
individual bits to count valid CPUs. Refactor this to use a bitwise AND
and popcount to count the number of enabled bits directly.
Approved by: markj (mentor)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D54474
| -rw-r--r-- | sys/kern/subr_smp.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/sys/kern/subr_smp.c b/sys/kern/subr_smp.c index 2256ba648e4d..148b366e7435 100644 --- a/sys/kern/subr_smp.c +++ b/sys/kern/subr_smp.c @@ -588,7 +588,7 @@ smp_rendezvous_cpus(cpuset_t map, void (* teardown_func)(void *), void *arg) { - int curcpumap, i, ncpus = 0; + int curcpumap, ncpus = 0; /* See comments in the !SMP case. */ if (!smp_started) { @@ -609,10 +609,8 @@ smp_rendezvous_cpus(cpuset_t map, */ MPASS(curthread->td_md.md_spinlock_count == 0); - CPU_FOREACH(i) { - if (CPU_ISSET(i, &map)) - ncpus++; - } + CPU_AND(&map, &map, &all_cpus); + ncpus = CPU_COUNT(&map); if (ncpus == 0) panic("ncpus is 0 with non-zero map"); |
