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:
parent
fce4f2b3ee
commit
de5151c64b
1 changed files with 4 additions and 4 deletions
|
@ -222,14 +222,14 @@ void riscv_percpu_set_kstack(uintptr_t ksp)
|
||||||
|
|
||||||
/* This must be done with interrupts disabled */
|
/* This must be done with interrupts disabled */
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = up_irq_save();
|
||||||
scratch = READ_CSR(CSR_SCRATCH);
|
scratch = READ_CSR(CSR_SCRATCH);
|
||||||
|
|
||||||
DEBUGASSERT(scratch >= (uintptr_t) &g_percpu &&
|
DEBUGASSERT(scratch >= (uintptr_t) &g_percpu &&
|
||||||
scratch < (uintptr_t) &g_percpu + sizeof(g_percpu));
|
scratch < (uintptr_t) &g_percpu + sizeof(g_percpu));
|
||||||
|
|
||||||
((riscv_percpu_t *)scratch)->ksp = ksp;
|
((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 */
|
/* This must be done with interrupts disabled */
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = up_irq_save();
|
||||||
scratch = READ_CSR(CSR_SCRATCH);
|
scratch = READ_CSR(CSR_SCRATCH);
|
||||||
|
|
||||||
DEBUGASSERT(scratch >= (uintptr_t) &g_percpu &&
|
DEBUGASSERT(scratch >= (uintptr_t) &g_percpu &&
|
||||||
scratch < (uintptr_t) &g_percpu + sizeof(g_percpu));
|
scratch < (uintptr_t) &g_percpu + sizeof(g_percpu));
|
||||||
|
|
||||||
((riscv_percpu_t *)scratch)->tcb = tcb;
|
((riscv_percpu_t *)scratch)->tcb = tcb;
|
||||||
leave_critical_section(flags);
|
up_irq_restore(flags);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue