Defer RISC-V callee-saved registers on no-switch timer interrupts - #1482
Open
zhouzhou-code wants to merge 2 commits into
Open
Defer RISC-V callee-saved registers on no-switch timer interrupts#1482zhouzhou-code wants to merge 2 commits into
zhouzhou-code wants to merge 2 commits into
Conversation
Signed-off-by: zhouzhou_code <2031145985@qq.com>
Signed-off-by: zhouzhou_code <2031145985@qq.com>
|
zhouzhou-code
marked this pull request as ready for review
August 26, 2026 06:38
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.



Description
The dedicated RISC-V machine-timer handler currently saves and restores the
complete integer context even when
xTaskIncrementTick()returnspdFALSE.The called C code must preserve
s0-s11according to the RISC-V ABI, so thoseregisters do not need to be written to the task stack when execution returns to
the interrupted task.
This change keeps the existing task-frame layout and optional-context behavior,
but splits integer context handling into caller-saved and callee-saved parts:
s0-s11into their reserved frameslots before calling
vTaskSwitchContext().FPU, VPU, and chip-specific additional contexts retain their existing save and
restore semantics. Other interrupt, exception, unified-trap, and yield paths
continue to save the complete context.
For RV64, the no-switch path avoids 12 stores and 12 loads, reducing stack
traffic by 192 bytes per tick.
Test Steps
A standalone QEMU
virtM-mode test uses different sentinel values ins0-s11for two equal-priority tasks and checks them after 2,000 timer ticks.The following configurations passed against the current
mainbranch:The modified
portASM.Swas also assembled successfully for RV32 (ilp32)and RV64 (
lp64d). Disassembly confirms that thepdFALSEpath contains nos0-s11stores or loads and that thepdTRUEpath stores all twelve registersbefore
vTaskSwitchContext().The same implementation was previously validated on a JH7110/U74 in M-mode:
144.746 cycles
Checklist:
Related Issue
Closes #1464
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.