PhysicalCoreID: Use sched_getcpu on aarch64 with glibc >= 2.35#14224
PhysicalCoreID: Use sched_getcpu on aarch64 with glibc >= 2.35#14224evanj wants to merge 1 commit into
Conversation
e875d5d to
97ca3b1
Compare
b2cc26a to
c91ef6c
Compare
|
Rebased on top of main commit 6ff9638 from 2026-04-18. This change is still relevant for arm64 Linux. |
c91ef6c to
2d2ad78
Compare
✅ clang-tidy: No findings on changed linesCompleted in 182.9s. |
2d2ad78 to
1b15aec
Compare
🟡 Codex Code ReviewAuto-triggered after CI passed — reviewing commit 1b15aec ❌ Codex review failed before producing findings. ℹ️ About this responseGenerated by Codex CLI. Limitations:
Commands:
|
✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 1b15aec SummaryThe PR extends High-severity findings (2):
Full review (click to expand)Findings🔴 HIGHH1. Incomplete macro fix:
|
| Context | Behavior | Issue? |
|---|---|---|
| x86_64 glibc >= 2.35 | Works (via non-x86 branch, H2 masks H1) | No |
| x86_64 glibc 2.22-2.34 | Fragile (H1 bug, accidentally works) | Yes |
| aarch64 glibc >= 2.35 | Works (new, correct) | No |
| musl Linux | Falls back to -1 despite having sched_getcpu |
M3 |
Positive Observations
- Correctly targets a real perf win: rseq-based
sched_getcpu()on aarch64 is fast. - Build detection (
ROCKSDB_SCHED_GETCPU_PRESENT) is already architecture-independent. - Error handling (
sched_getcpu() < 0 → return -1) is preserved correctly.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/code_review.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
The Linux sched_getcpu function was changed to use glibc "restartable sequences" since glibc 2.35 in in 2022. As of 2026, all 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. Simplify the macro to just check for >= 2.35, since it is many years old and the major LTS distributions have picked this up a long time ago. 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
1b15aec to
b0bb9fb
Compare
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