The branch stable/15 has been updated by aokblast: URL: https://cgit.FreeBSD.org/src/commit/?id=beccc030b4fbd411276858ba771b4228f3885568
commit beccc030b4fbd411276858ba771b4228f3885568 Author: ShengYi Hung <[email protected]> AuthorDate: 2026-01-03 16:32:50 +0000 Commit: ShengYi Hung <[email protected]> CommitDate: 2026-03-04 13:58:23 +0000 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 (cherry picked from commit e387d9438ba0258b88ebe03ef139bc6fd70b5a46) --- sys/kern/subr_smp.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sys/kern/subr_smp.c b/sys/kern/subr_smp.c index d80048f961bd..bd4e5c4b5aeb 100644 --- a/sys/kern/subr_smp.c +++ b/sys/kern/subr_smp.c @@ -581,7 +581,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) { @@ -602,10 +602,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");
