Hi,
I’ve been testing FreeRTOS on the RP2350’s Hazard3 RISC-V cores and came across an issue with the tick interrupt handler in the RP2350 RISC-V port.
It appears that the return value from xTaskIncrementTick() is overwritten before it is checked, which prevents the scheduler from switching tasks when a tick makes a higher-priority task ready.
The relevant code is in freertos_risc_v_mtimer_interrupt_handler in GCC/RP2350_RISC-V/portASM.S:
call callTaskEnterCriticalFromISR
mv s1, a0
call xTaskIncrementTick
mv a0, s1
call callTaskExitCriticalFromISR
beqz a0, exit_without_context_switch
xTaskIncrementTick() returns whether a context switch is required in a0. However, this value is overwritten with the saved interrupt status before callTaskExitCriticalFromISR() is called.
Since callTaskExitCriticalFromISR() returns void, the subsequent beqz checks whatever value happens to remain in a0, rather than the result from xTaskIncrementTick().
With configNUMBER_OF_CORES == 1, the body of callTaskExitCriticalFromISR() is empty, leaving a0 at zero. The handler therefore skips vTaskSwitchContext() entirely.
In practice, this means a higher-priority task that becomes ready when its vTaskDelay() expires will not run until the currently running task yields or blocks.
Reproduction
-
RP2350 using the Hazard3 RISC-V cores.
-
configNUMBER_OF_CORES == 1 -
configUSE_PREEMPTION == 1 -
A low-priority task continuously loops without blocking or yielding.
-
A higher-priority task calls
vTaskDelay(1000).
When the delay expires, the higher-priority task never runs again while the lower-priority task continues running.
I’ve also seen this in Thread-Metric’s basic, message and synchronisation tests, where the report thread stops printing.
Affected versions
I’ve found the same code in both repositories:
-
raspberrypi/FreeRTOS-Kernel, commit4f7299d6e -
FreeRTOS/FreeRTOS-Kernel-Community-Supported-Ports, commitbae4c7a
Possible fix
I tested a change that saves the return value from xTaskIncrementTick() on the stack across the call to callTaskExitCriticalFromISR(), then restores it before checking whether a context switch is required.
With this change, the single-core tests run as expected.
I’d be interested to know whether this is already a known issue, and whether the maintainers would prefer a pull request against one of these repositories or both.
Thanks!