Skip to content

Commit

Permalink
arch: support customized up_cpu_index() in AMP mode
Browse files Browse the repository at this point in the history
Some app with same code runs on different cores in AMP mode,
need the physical core on which the function is called.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
  • Loading branch information
hujun260 committed Oct 8, 2024
1 parent 2d2f405 commit d1c8ddd
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
4 changes: 4 additions & 0 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ config ARCH_HAVE_TESTSET
bool
default n

config ARCH_HAVE_CPU_INDEX
bool
default n

config ARCH_HAVE_THREAD_LOCAL
bool
default n
Expand Down
12 changes: 10 additions & 2 deletions arch/arm/include/arm/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,22 +243,30 @@ static inline irqstate_t up_irq_enable(void)
*
****************************************************************************/

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_ARCH_HAVE_CPU_INDEX)
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_SMP || CONFIG_ARCH_HAVE_CPU_INDEX */

noinstrument_function
static inline_function uint32_t *up_current_regs(void)
{
#ifdef CONFIG_SMP
return (uint32_t *)g_current_regs[up_cpu_index()];
#else
return (uint32_t *)g_current_regs[0];
#endif
}

noinstrument_function
static inline_function void up_set_current_regs(uint32_t *regs)
{
#ifdef CONFIG_SMP
g_current_regs[up_cpu_index()] = regs;
#else
g_current_regs[0] = regs;
#endif
}

noinstrument_function
Expand Down
12 changes: 10 additions & 2 deletions arch/arm/include/armv6-m/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ static inline void setcontrol(uint32_t control)
*
****************************************************************************/

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_ARCH_HAVE_CPU_INDEX)
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_SMP || CONFIG_ARCH_HAVE_CPU_INDEX */

static inline_function uint32_t up_getsp(void)
{
Expand All @@ -376,13 +376,21 @@ static inline_function uint32_t up_getsp(void)
noinstrument_function
static inline_function uint32_t *up_current_regs(void)
{
#ifdef CONFIG_SMP
return (uint32_t *)g_current_regs[up_cpu_index()];
#else
return (uint32_t *)g_current_regs[0];
#endif
}

noinstrument_function
static inline_function void up_set_current_regs(uint32_t *regs)
{
#ifdef CONFIG_SMP
g_current_regs[up_cpu_index()] = regs;
#else
g_current_regs[0] = regs;
#endif
}

noinstrument_function
Expand Down
12 changes: 10 additions & 2 deletions arch/arm/include/armv7-m/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,11 @@ static inline void setcontrol(uint32_t control)
*
****************************************************************************/

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_ARCH_HAVE_CPU_INDEX)
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_SMP || CONFIG_ARCH_HAVE_CPU_INDEX */

static inline_function uint32_t up_getsp(void)
{
Expand All @@ -581,13 +581,21 @@ static inline_function uint32_t up_getsp(void)
noinstrument_function
static inline_function uint32_t *up_current_regs(void)
{
#ifdef CONFIG_SMP
return (uint32_t *)g_current_regs[up_cpu_index()];
#else
return (uint32_t *)g_current_regs[0];
#endif
}

noinstrument_function
static inline_function void up_set_current_regs(uint32_t *regs)
{
#ifdef CONFIG_SMP
g_current_regs[up_cpu_index()] = regs;
#else
g_current_regs[0] = regs;
#endif
}

noinstrument_function
Expand Down
12 changes: 10 additions & 2 deletions arch/arm/include/armv8-m/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,11 @@ static inline void setcontrol(uint32_t control)
*
****************************************************************************/

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_ARCH_HAVE_CPU_INDEX)
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_SMP || CONFIG_ARCH_HAVE_CPU_INDEX */

static inline_function uint32_t up_getsp(void)
{
Expand All @@ -554,13 +554,21 @@ static inline_function uint32_t up_getsp(void)
noinstrument_function
static inline_function uint32_t *up_current_regs(void)
{
#ifdef CONFIG_SMP
return (uint32_t *)g_current_regs[up_cpu_index()];
#else
return (uint32_t *)g_current_regs[0];
#endif
}

noinstrument_function
static inline_function void up_set_current_regs(uint32_t *regs)
{
#ifdef CONFIG_SMP
g_current_regs[up_cpu_index()] = regs;
#else
g_current_regs[0] = regs;
#endif
}

noinstrument_function
Expand Down
12 changes: 10 additions & 2 deletions arch/arm/include/tlsr82/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ static inline uint32_t getcontrol(void)
*
****************************************************************************/

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_ARCH_HAVE_CPU_INDEX)
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_SMP || CONFIG_ARCH_HAVE_CPU_INDEX */

static inline_function uint32_t up_getsp(void)
{
Expand All @@ -281,13 +281,21 @@ static inline_function uint32_t up_getsp(void)
noinstrument_function
static inline_function uint32_t *up_current_regs(void)
{
#ifdef CONFIG_SMP
return (uint32_t *)g_current_regs[up_cpu_index()];
#else
return (uint32_t *)g_current_regs[0];
#endif
}

noinstrument_function
static inline_function void up_set_current_regs(uint32_t *regs)
{
#ifdef CONFIG_SMP
g_current_regs[up_cpu_index()] = regs;
#else
g_current_regs[0] = regs;
#endif
}

noinstrument_function
Expand Down

0 comments on commit d1c8ddd

Please sign in to comment.