mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 23:28:29 +08:00
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 <huangqi3@xiaomi.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user