Implement tick() for aarch64 on non-Apple platforms#854
Merged
Conversation
The aarch64 tick() implementation was previously gated on __APPLE__, leaving Linux (and other non-Apple aarch64 platforms) with no cycle counter. On those platforms the generic AAL fell through to __builtin_readcyclecounter(), which on aarch64 emits `mrs PMCCNTR_EL0`; that register is not accessible from EL0 on Linux and would SIGILL. CNTVCT_EL0 is readable from EL0 on Linux, FreeBSD, and other mainstream aarch64 OSes (the kernel sets CNTKCTL_EL1.EL0VCTEN), so the same implementation Apple uses works everywhere on aarch64. - aal_arm.h: extend tick() to all SNMALLOC_VA_BITS_64 targets and add an MSVC path using _ReadStatusReg(ARM64_CNTVCT). Drop NoCpuCycleCounters for 64-bit ARM (it remains for 32-bit ARM). - aal.h: exclude aarch64 from the __builtin_readcyclecounter() path so it always routes through Arch::tick(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ARM64_CNTVCT is not always available as a predefined macro. Use the explicit ARM64_SYSREG(3, 3, 14, 0, 2) encoding for CNTVCT_EL0 instead, and include <intrin.h> so _ReadStatusReg and ARM64_SYSREG are declared. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
The aarch64 tick() implementation was previously gated on APPLE, leaving Linux (and other non-Apple aarch64 platforms) with no cycle counter. On those platforms the generic AAL fell through to __builtin_readcyclecounter(), which on aarch64 emits
mrs PMCCNTR_EL0; that register is not accessible from EL0 on Linux and would SIGILL.CNTVCT_EL0 is readable from EL0 on Linux, FreeBSD, and other mainstream aarch64 OSes (the kernel sets CNTKCTL_EL1.EL0VCTEN), so the same implementation Apple uses works everywhere on aarch64.