Skip to content

Commit

Permalink
arch/risc-v: inline up_cpu_index if RISCV_PERCPU_SCRATCH is not enabled
Browse files Browse the repository at this point in the history
Inline the short function to provide better performance.

Signed-off-by: Huang Qi <[email protected]>
  • Loading branch information
no1wudi authored and acassis committed Dec 31, 2024
1 parent cd92e2d commit 6eb2f33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions arch/risc-v/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,27 @@ irqstate_t up_irq_enable(void);
* Description:
* Return the real core number regardless CONFIG_SMP setting
*
* When CONFIG_RISCV_PERCPU_SCRATCH is enabled, this uses the percpu
* scratch area to store the hart ID. This is needed when the CSR_MHARTID
* register may not contain the actual hart ID.
*
* When CONFIG_RISCV_PERCPU_SCRATCH is not enabled, this directly reads
* the CSR_MHARTID register. Use this version when you can guarantee
* CSR_MHARTID contains the actual hart ID. This is the default behavior
* that can be achieved by single instruction to provide better
* performance.
*
****************************************************************************/

#ifdef CONFIG_ARCH_HAVE_MULTICPU
#ifdef CONFIG_RISCV_PERCPU_SCRATCH
int up_cpu_index(void) noinstrument_function;
#else
noinstrument_function static inline int up_cpu_index(void)
{
return READ_CSR(CSR_MHARTID);
}
#endif
#endif /* CONFIG_ARCH_HAVE_MULTICPU */

/****************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions arch/risc-v/src/common/riscv_cpuindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
*
****************************************************************************/

#ifdef CONFIG_RISCV_PERCPU_SCRATCH
int up_cpu_index(void)
{
return (int)riscv_mhartid();
}
#endif

/****************************************************************************
* Name: up_this_cpu
Expand Down

0 comments on commit 6eb2f33

Please sign in to comment.