From 27ff0cd3cf32e4b84525e67215adad41cb1e393c Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Tue, 10 Dec 2024 14:09:37 +0800 Subject: [PATCH] riscv_percpu: Replace critical section with irqsave/irqrestore Since the SCRATCH register is used to store the percpu pointer, which should not be accessed by other CPUs, we can replace the critical section with irqsave/irqrestore. Signed-off-by: Huang Qi --- arch/risc-v/src/common/riscv_percpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/risc-v/src/common/riscv_percpu.c b/arch/risc-v/src/common/riscv_percpu.c index 5c704e4c86443..94d88f4da5d27 100644 --- a/arch/risc-v/src/common/riscv_percpu.c +++ b/arch/risc-v/src/common/riscv_percpu.c @@ -222,14 +222,14 @@ void riscv_percpu_set_kstack(uintptr_t ksp) /* This must be done with interrupts disabled */ - flags = enter_critical_section(); + flags = up_irq_save(); scratch = READ_CSR(CSR_SCRATCH); DEBUGASSERT(scratch >= (uintptr_t) &g_percpu && scratch < (uintptr_t) &g_percpu + sizeof(g_percpu)); ((riscv_percpu_t *)scratch)->ksp = ksp; - leave_critical_section(flags); + up_irq_restore(flags); } /**************************************************************************** @@ -254,12 +254,12 @@ void riscv_percpu_set_thread(struct tcb_s *tcb) /* This must be done with interrupts disabled */ - flags = enter_critical_section(); + flags = up_irq_save(); scratch = READ_CSR(CSR_SCRATCH); DEBUGASSERT(scratch >= (uintptr_t) &g_percpu && scratch < (uintptr_t) &g_percpu + sizeof(g_percpu)); ((riscv_percpu_t *)scratch)->tcb = tcb; - leave_critical_section(flags); + up_irq_restore(flags); }