explorer/{cpu_cores,cpu_sockets,memory}: Misc. fixes for NetBSD#155
Merged
4nd3r merged 4 commits intoskonfig:mainfrom Sep 1, 2025
Merged
Conversation
…ault and fix for empty /proc/cpuinfo Assume that multiple processors are cores instead of sockets. For most architectures sockets are not reported using "physical id" in /proc/cpuinfo, making this explorer report all cores as separate sockets. This does not make much sense. For most systems assuming one socket and N cores is more correct. On NetBSD /proc/cpuinfo is only implemented for a few architectures. For all the others /proc/cpuinfo is an empty file (which makes grep -c exit 1). On NetBSD also currently no architecture reports "physical id", so socket detection using /proc/cpuinfo will never work. It is thus disabled on NetBSD until somebody finds another way.
…enBSD NetBSD also has hw.ncpuonline like OpenBSD (in fact, OpenBSD imported the code for it from NetBSD). Let's merge the code for NetBSD and OpenBSD instead of FreeBSD. On OpenBSD sysctl(8) never returns a non-zero exit status, so `grep .' is used to detect success and fall back to hw.ncpu. https://marc.info/?l=openbsd-cvs&m=153135863131342&w=2
OpenBSD exports HW_PHYSMEM64 as hw.physmem. NetBSD exports HW_PHYSMEM as hw.physmem and HW_PHYSMEM64 as hw.physmem64 (since NetBSD 2.0).
In the unlikely (or impossible?) case that there are no online memory blocks, fall back to /proc/meminfo.
7f7ad16 to
57ab6e7
Compare
4nd3r
approved these changes
Sep 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
explorer/{cpu_cores,cpu_sockets}:Assume that multiple processors are cores instead of sockets.
For most architectures sockets are not reported using "physical id" in
/proc/cpuinfo, making this explorer report all cores as separate sockets.This does not make much sense. For most systems assuming one socket and N cores seems to be more correct to me.
On NetBSD
/proc/cpuinfois only implemented for a few architectures.For all the others
/proc/cpuinfois an empty file (which makesgrep -cexit 1).On NetBSD also currently no architecture reports "physical id", so socket detection using
/proc/cpuinfowill never work.It is thus disabled on NetBSD until somebody finds another way.
NetBSD also has
hw.ncpuonlinelike OpenBSD (in fact, OpenBSD imported the code for it from NetBSD).So it makes more sense to merge the code for NetBSD and OpenBSD instead of NetBSD and FreeBSD.
explorer/memory:OpenBSD exports
HW_PHYSMEM64ashw.physmem.NetBSD exports
HW_PHYSMEMashw.physmemandHW_PHYSMEM64ashw.physmem64(since NetBSD 2.0).NetBSD < 2.0 is not supported by this code. For these versions
hw.physmemcould be used as a fall back, but I haven't implemented it because there are numerous other problems with its outdated/bin/sh(switching to/bin/kshwould fix those, though).In the unlikely (or impossible?) case that there are no online memory blocks, fall back to
/proc/meminfo. (grep -cproblem cf. above).