PhysicalCoreID: Use sched_getcpu on aarch64 with glibc >= 2.35 #14224
+26
−5
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.
The Linux sched_getcpu function was changed to use the glibc "restartable sequences" since glibc 2.35 in in 2022. At this point, most recent Linux distributions have picked this up. The preprocessor macro will conditionally enable it based on the version of glibc, so this should make this faster on newer aarch64 builds, without impacting old ones. I have tested with a microbenchmark that the performance with new glibc is the same as x86-64 (a few ns/call).
I added a test to try to check this. It was useful for me in testing this, but it is probably "wrong": without duplicating the check exactly, it is hard to test the support. It is possible we should remove the test.
Correct the macro: it should be testing
__GLIBC__and__GLIBC_MINOR__for the glibc version, rather than__GNUC__and__GNUC_MINOR__for the gcc/clang version.Linux distribution support for this feature:
RHEL 9 glibc glibc 2.34 released 2022-05-17 (TOO OLD)
RHEL 9.1 glibc 2.35 released 2022-11-15 [1]
RHEL 10 glibc 2.39 released 2025-05-20
Ubuntu LTS 20.04 glibc 2.31 released 2020-04-23 (TOO OLD)
Ubuntu LTS 22.04 glibc 2.35 released 2022-04-21
Ubuntu LTS 24.04 glibc 2.39 released 2024-04-25
Debian 11 glibc 2.31 released 2021-08-14 (TOO OLD)
Debian 12 glibc 2.36 released 2023-06-14
Debian 13 glibc 2.41 released 2025-08-09
[1] https://developers.redhat.com/articles/2022/12/22/restartable-sequences-support-glibc-rhel-9