Skip to content

Commit 088a089

Browse files
committed
arch/risc-v: inline up_cpu_index if RISCV_PERCPU_SCRATCH is not enabled
Inline the short function to provide better performance. Signed-off-by: Huang Qi <[email protected]>
1 parent a393f7f commit 088a089

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

arch/risc-v/include/irq.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,27 @@ irqstate_t up_irq_enable(void);
697697
* Description:
698698
* Return the real core number regardless CONFIG_SMP setting
699699
*
700+
* When CONFIG_RISCV_PERCPU_SCRATCH is enabled, this uses the percpu
701+
* scratch area to store the hart ID. This is needed when the CSR_MHARTID
702+
* register may not contain the actual hart ID.
703+
*
704+
* When CONFIG_RISCV_PERCPU_SCRATCH is not enabled, this directly reads
705+
* the CSR_MHARTID register. Use this version when you can guarantee
706+
* CSR_MHARTID contains the actual hart ID. This is the default behavior
707+
* that can be achieved by single instruction to provide better
708+
* performance.
709+
*
700710
****************************************************************************/
701711

702712
#ifdef CONFIG_ARCH_HAVE_MULTICPU
703-
int up_cpu_index(void) noinstrument_function;
713+
noinstrument_function static inline int up_cpu_index(void)
714+
{
715+
#ifdef CONFIG_RISCV_PERCPU_SCRATCH
716+
return (int)riscv_mhartid();
717+
#else
718+
return READ_CSR(CSR_MHARTID);
719+
#endif
720+
}
704721
#endif /* CONFIG_ARCH_HAVE_MULTICPU */
705722

706723
/****************************************************************************

arch/risc-v/src/common/riscv_cpuindex.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,6 @@
3737
* Public Functions
3838
****************************************************************************/
3939

40-
/****************************************************************************
41-
* Name: up_cpu_index
42-
*
43-
* Description:
44-
* Return the real core number regardless CONFIG_SMP setting
45-
*
46-
****************************************************************************/
47-
48-
int up_cpu_index(void)
49-
{
50-
return (int)riscv_mhartid();
51-
}
52-
5340
/****************************************************************************
5441
* Name: up_this_cpu
5542
*

0 commit comments

Comments
 (0)