From 535fc38fe7017f55e0e562cdbae311c0cab2edb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Rei=C3=9Fnegger?= Date: Mon, 24 May 2021 14:36:28 -0700 Subject: [PATCH] riscv: Don't reschedule on back-to-back interrupts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some cases the 'reschedule' code path is executed when the current thread is the same as the next thread in the ready Q. If this happens, the swap_return_value of the thread is ifalsely being reset to -EAGAIN. This commit prevents the rescheduling code to run if the current thread is the same as the thread in the ready Q. Signed-off-by: Wolfgang Reißnegger --- arch/riscv/core/isr.S | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/riscv/core/isr.S b/arch/riscv/core/isr.S index b21ea7a7490..edf4b008b41 100644 --- a/arch/riscv/core/isr.S +++ b/arch/riscv/core/isr.S @@ -811,6 +811,18 @@ skip_fp_move_irq: #endif /* CONFIG_USERSPACE */ reschedule: + /* + * Check if the current thread is the same as the thread on the ready Q. If + * so, do not reschedule. + * Note: + * Sometimes this code is execute back-to-back before the target thread + * has a chance to run. If this happens, the current thread and the + * target thread will be the same. + */ + la t0, _kernel + RV_OP_LOADREG t2, _kernel_offset_to_current(t0) + RV_OP_LOADREG t3, _kernel_offset_to_ready_q_cache(t0) + beq t2, t3, no_reschedule #if CONFIG_INSTRUMENT_THREAD_SWITCHING call z_thread_mark_switched_out