Fix calculation of # CPU cores (FreeBSD/DragonFly) #3707
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On both FreeBSD and DragonFly,
sysctl hw.ncpu
returns the number oflogical CPUs, NOT the number of physical CPU cores.
FreeBSD has sysctl
kern.smp.cores
.DragonFly has sysctl's
hw.cpu_topology_core_ids
andhw.cpu_topology_phys_ids
. Both multiplied together results in thenumber of cores.
If
kern.smp.cores
(FreeBSD) orhw.cpu_topology_*
(DragonFly) isnot available, use
hw.ncpu
instead.For example on FreeBSD 12.2p3 running a i7-8565U:
sysctl hw.ncpu # => 8
sysctl kern.smp.cores # => 4
For example on DragonFly 5.9-DEVELOPMENT with Xeon E5-1620:
sysctl hw.ncpu # => 8
sysctl hw.cpu_topology_phys_ids # => 1
sysctl hw.cpu_topology_core_ids # => 4
sysctl hw.cpu_topology_ht_ids # => 2
I found this by running a HTTP benchmark on a FreeBSD system
(i7-8565U, 4 cores / 8 logical CPUs), where setting --ponymaxthreads=4
improved latency significantly over the default value "8" (hw.ncpu).
And I was wondering why I could set --ponymaxthreads to 8, even so the
documentation explicitly states that it cannot be set to anything
above the number of CPU cores.