Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream fix for OpenBSD cpuid stats #1622

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rfht
Copy link
Contributor

@rfht rfht commented Jul 27, 2024

Use HW_NCPUONLINE for OpenBSD CPU count and implement cpu_clock_by_os. HW_NCPUONLINE is the preferred count on OpenBSD; HW_NCPU would count virtual hyperthreading cores that might be deactivated.

#ifdef __OpenBSD__
// HW_NCPUONLINE accounts for hyperthreading off/on
int mib[2] = { CTL_HW, HW_NCPUONLINE };
#else
int mib[2] = { CTL_HW, HW_NCPU };
Copy link
Collaborator

@sprunk sprunk Jul 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps regular linux could use the new constant as well? is it available and kosher?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux seems to use something similar judging from the variable name _SC_NPROCESSORS_ONLN, see https://github.com/beyond-all-reason/spring/blob/BAR105/rts/lib/libcpuid/libcpuid/cpuid_main.c#L253. This segment with HW_NCPU is for various *BSD OS, QNX. Just looking at FreeBSD's sysctl(3) man page, they don't seem to have this kind of MIB entry yet.

Copy link
Collaborator

@sprunk sprunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks decent. There's a merge freeze though.

@@ -290,7 +290,12 @@ static bool set_cpu_affinity(logical_cpu_t logical_cpu)

static int get_total_cpus(void)
{
#ifdef __OpenBSD__
// HW_NCPUONLINE accounts for hyperthreading off/on
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// HW_NCPUONLINE accounts for hyperthreading off/on
// HW_NCPUONLINE accounts for hyperthreading off/on,
// not available on regular linux

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't related to linux. It looks like linux uses sysconf as I linked above, with different header definitions. This code section is inside:

#if defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __bsdi__ || defined __QNX__

In my opinion the HW_NCPUONLINE is clearly enough expressed as OpenBSD-only by the #ifdef __OpenBSD__ right before it, but if you feel strongly that this needs stating, then it should be something like:

// not available on FreeBSD/NetBSD/bsdi/QNX

or

// only available on OpenBSD

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, in that case it's fine as-is IMO.

@lostsquirrel1
Copy link
Collaborator

These changes are for libcpuid. Shouldn't these changes be submitted to that project? If we update to a later version we'd need to re-apply these changes?

@rfht
Copy link
Contributor Author

rfht commented Sep 26, 2024

I will see about approaching upstream libcpuid...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants