git: e387d9438ba0 - main - smp: Use bitwise operation to count cpu number
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 18 Feb 2026 09:41:08 UTC
The branch main has been updated by aokblast:
URL: https://cgit.FreeBSD.org/src/commit/?id=e387d9438ba0258b88ebe03ef139bc6fd70b5a46
commit e387d9438ba0258b88ebe03ef139bc6fd70b5a46
Author: ShengYi Hung <aokblast@FreeBSD.org>
AuthorDate: 2026-01-03 16:32:50 +0000
Commit: ShengYi Hung <aokblast@FreeBSD.org>
CommitDate: 2026-02-18 09:40:54 +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
---
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 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");