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 9, 2024
1 parent 846cb7d commit c96e54f
Show file tree
Hide file tree
Showing 56 changed files with 206 additions and 487 deletions.
24 changes: 11 additions & 13 deletions arch/arm/include/arm/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,34 +231,32 @@ static inline irqstate_t up_irq_enable(void)
* Name: up_cpu_index
*
* Description:
* Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
*
* Input Parameters:
* None
*
* Returned Value:
* An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
* Return the real core number regardless CONFIG_SMP setting
*
****************************************************************************/

#ifdef CONFIG_SMP
#ifdef CONFIG_ARCH_HAVE_MULTICPU
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_ARCH_HAVE_MULTICPU */

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
24 changes: 11 additions & 13 deletions arch/arm/include/armv6-m/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,23 +342,13 @@ static inline void setcontrol(uint32_t control)
* Name: up_cpu_index
*
* Description:
* Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
*
* Input Parameters:
* None
*
* Returned Value:
* An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
* Return the real core number regardless CONFIG_SMP setting
*
****************************************************************************/

#ifdef CONFIG_SMP
#ifdef CONFIG_ARCH_HAVE_MULTICPU
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_ARCH_HAVE_MULTICPU */

static inline_function uint32_t up_getsp(void)
{
Expand All @@ -376,13 +366,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
16 changes: 3 additions & 13 deletions arch/arm/include/armv7-a/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,19 +433,11 @@ noinstrument_function static inline void up_irq_restore(irqstate_t flags)
* Name: up_cpu_index
*
* Description:
* Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
*
* Input Parameters:
* None
*
* Returned Value:
* An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
* Return the real core number regardless CONFIG_SMP setting
*
****************************************************************************/

#ifdef CONFIG_SMP
#ifdef CONFIG_ARCH_HAVE_MULTICPU
noinstrument_function
static inline_function int up_cpu_index(void)
{
Expand All @@ -459,9 +451,7 @@ static inline_function int up_cpu_index(void)

return (mpidr & MPIDR_CPUID_MASK) >> MPIDR_CPUID_SHIFT;
}
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_ARCH_HAVE_MULTICPU */

static inline_function uint32_t up_getsp(void)
{
Expand Down
24 changes: 11 additions & 13 deletions arch/arm/include/armv7-m/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,23 +547,13 @@ static inline void setcontrol(uint32_t control)
* Name: up_cpu_index
*
* Description:
* Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
*
* Input Parameters:
* None
*
* Returned Value:
* An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
* Return the real core number regardless CONFIG_SMP setting
*
****************************************************************************/

#ifdef CONFIG_SMP
#ifdef CONFIG_ARCH_HAVE_MULTICPU
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_ARCH_HAVE_MULTICPU */

static inline_function uint32_t up_getsp(void)
{
Expand All @@ -581,13 +571,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
16 changes: 3 additions & 13 deletions arch/arm/include/armv7-r/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,19 +428,11 @@ noinstrument_function static inline void up_irq_restore(irqstate_t flags)
* Name: up_cpu_index
*
* Description:
* Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
*
* Input Parameters:
* None
*
* Returned Value:
* An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
* Return the real core number regardless CONFIG_SMP setting
*
****************************************************************************/

#ifdef CONFIG_SMP
#ifdef CONFIG_ARCH_HAVE_MULTICPU
noinstrument_function
static inline_function int up_cpu_index(void)
{
Expand All @@ -454,9 +446,7 @@ static inline_function int up_cpu_index(void)

return (mpidr & MPIDR_CPUID_MASK) >> MPIDR_CPUID_SHIFT;
}
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_ARCH_HAVE_MULTICPU */

static inline_function uint32_t up_getsp(void)
{
Expand Down
24 changes: 11 additions & 13 deletions arch/arm/include/armv8-m/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,23 +520,13 @@ static inline void setcontrol(uint32_t control)
* Name: up_cpu_index
*
* Description:
* Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
*
* Input Parameters:
* None
*
* Returned Value:
* An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
* Return the real core number regardless CONFIG_SMP setting
*
****************************************************************************/

#ifdef CONFIG_SMP
#ifdef CONFIG_ARCH_HAVE_MULTICPU
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_ARCH_HAVE_MULTICPU */

static inline_function uint32_t up_getsp(void)
{
Expand All @@ -554,13 +544,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
16 changes: 3 additions & 13 deletions arch/arm/include/armv8-r/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,19 +428,11 @@ noinstrument_function static inline void up_irq_restore(irqstate_t flags)
* Name: up_cpu_index
*
* Description:
* Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
*
* Input Parameters:
* None
*
* Returned Value:
* An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
* Return the real core number regardless CONFIG_SMP setting
*
****************************************************************************/

#ifdef CONFIG_SMP
#ifdef CONFIG_ARCH_HAVE_MULTICPU
noinstrument_function
static inline_function int up_cpu_index(void)
{
Expand All @@ -454,9 +446,7 @@ static inline_function int up_cpu_index(void)

return (mpidr & MPIDR_CPUID_MASK) >> MPIDR_CPUID_SHIFT;
}
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_ARCH_HAVE_MULTICPU */

static inline_function uint32_t up_getsp(void)
{
Expand Down
24 changes: 11 additions & 13 deletions arch/arm/include/tlsr82/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,23 +247,13 @@ static inline uint32_t getcontrol(void)
* Name: up_cpu_index
*
* Description:
* Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
*
* Input Parameters:
* None
*
* Returned Value:
* An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
* corresponds to the currently executing CPU.
* Return the real core number regardless CONFIG_SMP setting
*
****************************************************************************/

#ifdef CONFIG_SMP
#ifdef CONFIG_ARCH_HAVE_MULTICPU
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() 0
#endif /* CONFIG_SMP */
#endif /* CONFIG_ARCH_HAVE_MULTICPU */

static inline_function uint32_t up_getsp(void)
{
Expand All @@ -281,13 +271,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
2 changes: 1 addition & 1 deletion arch/arm/src/armv7-a/arm_gicv2.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void arm_gic_init_done(void)
irqstate_t flags;

flags = spin_lock_irqsave(NULL);
CPU_SET(up_cpu_index(), &g_gic_init_done);
CPU_SET(this_cpu(), &g_gic_init_done);
spin_unlock_irqrestore(NULL, flags);
}

Expand Down
5 changes: 2 additions & 3 deletions arch/arm/src/armv8-r/arm_gicv3.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void arm_gic_irq_enable(unsigned int intid)

if (GIC_IS_SPI(intid))
{
arm_gic_write_irouter(up_cpu_index(), intid);
arm_gic_write_irouter(this_cpu(), intid);
}

putreg32(mask, ISENABLER(GET_DIST_BASE(intid), idx));
Expand Down Expand Up @@ -797,8 +797,7 @@ static void arm_gic_init(void)
int err;

cpu = this_cpu();
g_gic_rdists[cpu] = CONFIG_GICR_BASE +
up_cpu_index() * CONFIG_GICR_OFFSET;
g_gic_rdists[cpu] = CONFIG_GICR_BASE + cpu * CONFIG_GICR_OFFSET;

err = gic_validate_redist_version();
if (err)
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/cxd56xx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ set(SRCS
cxd56_farapi.c
cxd56_sysctl.c)

if(CONFIG_SMP)
if(CONFIG_ARCH_HAVE_MULTICPU)
list(APPEND SRCS cxd56_cpuidlestack.c)
list(APPEND SRCS cxd56_cpuindex.c)
list(APPEND SRCS cxd56_smpcall.c)
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/cxd56xx/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CHIP_CSRCS += cxd56_powermgr.c
CHIP_CSRCS += cxd56_farapi.c
CHIP_CSRCS += cxd56_sysctl.c

ifeq ($(CONFIG_SMP), y)
ifeq ($(CONFIG_ARCH_HAVE_MULTICPU), y)
CHIP_CSRCS += cxd56_cpuidlestack.c
CHIP_CSRCS += cxd56_cpuindex.c
CHIP_CSRCS += cxd56_smpcall.c
Expand Down
Loading

0 comments on commit c96e54f

Please sign in to comment.