Repository navigation
Defer RISC-V callee-saved registers on no-switch timer interrupts - #1482
mingshun-zhou wants to merge 3 commits into
Conversation
Signed-off-by: zhouzhou_code <2031145985@qq.com>
Signed-off-by: zhouzhou_code <2031145985@qq.com>
|
|
Hi maintainers, just a gentle follow-up on this focused RISC-V timer-path optimization. The change has been validated on both QEMU and JH7110 hardware, and I am happy to rebase or adjust the approach if needed. Would someone be available to take a look? |
|
@aggarg, thank you again for offering to take a look in the FreeRTOS forum. I wanted to follow up here in case this PR needs to be routed to another RISC-V reviewer. Please let me know if you would like me to rebase, add any tests, or adjust the approach. |
|
@mingshun-zhou Apologies for missing it. I will do it soon and get back if I need anything from you. Apologies again! |
|
|
No worries at all — thanks for taking a look and updating the branch! I’ll keep an eye out for any feedback. |



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.