⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

MIPS: Loongson: Salvage the full count from the constant timer#20

Closed
Rongronggg9 wants to merge 2 commits intoAOSC-Tracking:aosc/v6.18.7from
Rongronggg9:aosc/v6.18.7-ls64-timer
Closed

MIPS: Loongson: Salvage the full count from the constant timer#20
Rongronggg9 wants to merge 2 commits intoAOSC-Tracking:aosc/v6.18.7from
Rongronggg9:aosc/v6.18.7-ls64-timer

Conversation

@Rongronggg9
Copy link

@Rongronggg9 Rongronggg9 commented Jan 24, 2026

HWR $30 (Loongson64 constant timer) is 64 bits wide. However, vDSO uses `unsigned long' to read the timer count, which leads to frozen time (delta ~= 3s) when O32/N32 userspace programs request HRES time.

For N32, using `u64' instead of `unsigned long' fixes the issue.

The issue becomes trickier on O32. RDHWR never sign-extends the timer count before copying it into a GPR, as the kernel always sets Status.UX=1 even in O32 userspace. Aside from the frozen time, the "shadow" on the upper half also breaks subsequent logical/branch instructions relying on
the GPR.

Thankfully, Status.UX==1 also means that we have the full timer count available and can use 64-bit instructions to salvage it into a pair of GPR to comply with O32 ABI.

Utilize (abuse?) this fact to salvage the full timer count in O32 vDSO.

HWR $30 (Loongson64 constant timer) is 64 bits wide. However, vDSO uses
`unsigned long' to read the timer count, which leads to frozen time
(delta ~= 3s) when O32/N32 userspace programs request HRES time.

For N32, using `u64' instead of `unsigned long' fixes the issue.

The issue becomes trickier on O32. RDHWR never sign-extends the timer
count before copying it into a GPR, as the kernel always sets
Status.UX=1 even in O32 userspace. Aside from the frozen time, the
"shadow" on the upper half also breaks subsequent logical/branch
instructions relying on the GPR.

Thankfully, Status.UX==1 also means that we have the full timer count
available and can use 64-bit instructions to salvage it into a pair of
GPR to comply with O32 ABI.

Utilize (abuse?) this fact to salvage the full timer count in O32 vDSO.

Fixes: "AOSCOS: MIPS: Loongson: Add constant timer support"
Signed-off-by: Rong Zhang <i@rong.moe>
…timer"

This reverts commit 1e094a6.

With the full timer count salvaged, we can safely use RDHWR to read
the timer count from Loongson64 constant timer in O32 vDSO.

Signed-off-by: Rong Zhang <i@rong.moe>
@MingcongBai MingcongBai changed the base branch from aosc/v6.18.7 to aosc/v6.18.8 February 1, 2026 04:20
@MingcongBai MingcongBai changed the base branch from aosc/v6.18.8 to aosc/v6.18.7 February 1, 2026 04:20
@MingcongBai
Copy link

Picked to aosc/v6.18.8, thanks!

@MingcongBai MingcongBai closed this Feb 1, 2026
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.

2 participants