diff --git a/arch/arm/include/arm/irq.h b/arch/arm/include/arm/irq.h index 246410e47d4..bb369ce9664 100644 --- a/arch/arm/include/arm/irq.h +++ b/arch/arm/include/arm/irq.h @@ -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 diff --git a/arch/arm/include/armv6-m/irq.h b/arch/arm/include/armv6-m/irq.h index 6d142accfa9..e62722c29af 100644 --- a/arch/arm/include/armv6-m/irq.h +++ b/arch/arm/include/armv6-m/irq.h @@ -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) { @@ -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 diff --git a/arch/arm/include/armv7-a/irq.h b/arch/arm/include/armv7-a/irq.h index 803d5807d3e..4393e685b31 100644 --- a/arch/arm/include/armv7-a/irq.h +++ b/arch/arm/include/armv7-a/irq.h @@ -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) { @@ -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) { diff --git a/arch/arm/include/armv7-m/irq.h b/arch/arm/include/armv7-m/irq.h index 87cf6e0acfa..1fd9d48a67d 100644 --- a/arch/arm/include/armv7-m/irq.h +++ b/arch/arm/include/armv7-m/irq.h @@ -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) { @@ -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 diff --git a/arch/arm/include/armv7-r/irq.h b/arch/arm/include/armv7-r/irq.h index 402606a546a..e3563f9f0f0 100644 --- a/arch/arm/include/armv7-r/irq.h +++ b/arch/arm/include/armv7-r/irq.h @@ -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) { @@ -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) { diff --git a/arch/arm/include/armv8-m/irq.h b/arch/arm/include/armv8-m/irq.h index 0860ae960ce..97f8ba97714 100644 --- a/arch/arm/include/armv8-m/irq.h +++ b/arch/arm/include/armv8-m/irq.h @@ -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) { @@ -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 diff --git a/arch/arm/include/armv8-r/irq.h b/arch/arm/include/armv8-r/irq.h index c3be8199f3b..1f26a003d8d 100644 --- a/arch/arm/include/armv8-r/irq.h +++ b/arch/arm/include/armv8-r/irq.h @@ -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) { @@ -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) { diff --git a/arch/arm/include/tlsr82/irq.h b/arch/arm/include/tlsr82/irq.h index 751baa6f61d..fccf441d890 100644 --- a/arch/arm/include/tlsr82/irq.h +++ b/arch/arm/include/tlsr82/irq.h @@ -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) { @@ -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 diff --git a/arch/arm/src/armv7-a/arm_gicv2.c b/arch/arm/src/armv7-a/arm_gicv2.c index 66d9f3547f3..86196789297 100644 --- a/arch/arm/src/armv7-a/arm_gicv2.c +++ b/arch/arm/src/armv7-a/arm_gicv2.c @@ -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); } diff --git a/arch/arm/src/armv8-r/arm_gicv3.c b/arch/arm/src/armv8-r/arm_gicv3.c index 15aac99960e..2fa10dac377 100644 --- a/arch/arm/src/armv8-r/arm_gicv3.c +++ b/arch/arm/src/armv8-r/arm_gicv3.c @@ -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)); @@ -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) diff --git a/arch/arm/src/cxd56xx/CMakeLists.txt b/arch/arm/src/cxd56xx/CMakeLists.txt index cb7315f33b2..31adb76bc83 100644 --- a/arch/arm/src/cxd56xx/CMakeLists.txt +++ b/arch/arm/src/cxd56xx/CMakeLists.txt @@ -41,7 +41,6 @@ set(SRCS if(CONFIG_SMP) list(APPEND SRCS cxd56_cpuidlestack.c) - list(APPEND SRCS cxd56_cpuindex.c) list(APPEND SRCS cxd56_smpcall.c) list(APPEND SRCS cxd56_cpustart.c) if(CONFIG_CXD56_TESTSET) @@ -49,6 +48,10 @@ if(CONFIG_SMP) endif() endif() +if(CONFIG_ARCH_HAVE_MULTICPU) + list(APPEND SRCS cxd56_cpuindex.c) +endif() + if(CONFIG_ARCH_USE_TEXT_HEAP) list(APPEND SRCS cxd56_textheap.c) endif() diff --git a/arch/arm/src/cxd56xx/Make.defs b/arch/arm/src/cxd56xx/Make.defs index ece4ac2b546..eadc9f8332a 100644 --- a/arch/arm/src/cxd56xx/Make.defs +++ b/arch/arm/src/cxd56xx/Make.defs @@ -40,7 +40,6 @@ CHIP_CSRCS += cxd56_sysctl.c ifeq ($(CONFIG_SMP), y) CHIP_CSRCS += cxd56_cpuidlestack.c -CHIP_CSRCS += cxd56_cpuindex.c CHIP_CSRCS += cxd56_smpcall.c CHIP_CSRCS += cxd56_cpustart.c ifeq ($(CONFIG_CXD56_TESTSET),y) @@ -49,6 +48,10 @@ CMN_ASRCS := $(filter-out arm_testset.S,$(CMN_ASRCS)) endif endif +ifeq ($(CONFIG_ARCH_HAVE_MULTICPU), y) +CHIP_CSRCS += cxd56_cpuindex.c +endif + ifeq ($(CONFIG_ARCH_USE_TEXT_HEAP), y) CHIP_CSRCS += cxd56_textheap.c endif diff --git a/arch/arm/src/cxd56xx/cxd56_cpuindex.c b/arch/arm/src/cxd56xx/cxd56_cpuindex.c index dcc6171ee61..e15358efd19 100644 --- a/arch/arm/src/cxd56xx/cxd56_cpuindex.c +++ b/arch/arm/src/cxd56xx/cxd56_cpuindex.c @@ -29,7 +29,7 @@ #include "arm_internal.h" #include "cxd56_cpuindex.h" -#ifdef CONFIG_SMP +#ifdef CONFIG_ARCH_HAVE_MULTICPU /**************************************************************************** * Public Functions @@ -39,15 +39,7 @@ * 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 * ****************************************************************************/ @@ -58,4 +50,4 @@ int up_cpu_index(void) return getreg32(CXD56_ADSP_PID) - 2; } -#endif /* CONFIG_SMP */ +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ diff --git a/arch/arm/src/lc823450/Make.defs b/arch/arm/src/lc823450/Make.defs index 4b3bf6ca428..590e6d02e25 100644 --- a/arch/arm/src/lc823450/Make.defs +++ b/arch/arm/src/lc823450/Make.defs @@ -91,13 +91,16 @@ endif ifeq ($(CONFIG_SMP), y) CHIP_CSRCS += lc823450_cpuidlestack.c -CHIP_CSRCS += lc823450_cpuindex.c CHIP_CSRCS += lc823450_smpcall.c CHIP_CSRCS += lc823450_cpustart.c CHIP_CSRCS += lc823450_testset.c CMN_ASRCS := $(filter-out arm_testset.S,$(CMN_ASRCS)) endif +ifeq ($(CONFIG_ARCH_HAVE_MULTICPU), y) +CHIP_CSRCS += lc823450_cpuindex.c +endif + ifeq ($(CONFIG_LC823450_SDRAM), y) CHIP_CSRCS += lc823450_sdram.c endif diff --git a/arch/arm/src/lc823450/lc823450_cpuindex.c b/arch/arm/src/lc823450/lc823450_cpuindex.c index 61127bdf08d..573b89c142f 100644 --- a/arch/arm/src/lc823450/lc823450_cpuindex.c +++ b/arch/arm/src/lc823450/lc823450_cpuindex.c @@ -44,15 +44,7 @@ * 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 * ****************************************************************************/ diff --git a/arch/arm/src/rp2040/Make.defs b/arch/arm/src/rp2040/Make.defs index 1fbf4b4cd02..857105f11f6 100644 --- a/arch/arm/src/rp2040/Make.defs +++ b/arch/arm/src/rp2040/Make.defs @@ -35,7 +35,6 @@ CHIP_CSRCS += rp2040_xosc.c CHIP_CSRCS += rp2040_pll.c ifeq ($(CONFIG_SMP),y) -CHIP_CSRCS += rp2040_cpuindex.c CHIP_CSRCS += rp2040_cpustart.c CHIP_CSRCS += rp2040_smpcall.c CHIP_CSRCS += rp2040_cpuidlestack.c @@ -43,6 +42,10 @@ CHIP_CSRCS += rp2040_testset.c CMN_ASRCS := $(filter-out arm_testset.S,$(CMN_ASRCS)) endif +ifeq ($(CONFIG_ARCH_HAVE_MULTICPU),y) +CHIP_CSRCS += rp2040_cpuindex.c +endif + ifeq ($(CONFIG_RP2040_DMAC),y) CHIP_CSRCS += rp2040_dmac.c endif diff --git a/arch/arm/src/rp2040/rp2040_cpuindex.c b/arch/arm/src/rp2040/rp2040_cpuindex.c index 245f38bf167..cbeb2d79035 100644 --- a/arch/arm/src/rp2040/rp2040_cpuindex.c +++ b/arch/arm/src/rp2040/rp2040_cpuindex.c @@ -29,7 +29,7 @@ #include "arm_internal.h" #include "hardware/rp2040_sio.h" -#ifdef CONFIG_SMP +#ifdef CONFIG_ARCH_HAVE_MULTICPU /**************************************************************************** * Public Functions @@ -39,15 +39,7 @@ * 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 * ****************************************************************************/ @@ -56,4 +48,4 @@ int up_cpu_index(void) return getreg32(RP2040_SIO_CPUID); } -#endif /* CONFIG_SMP */ +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ diff --git a/arch/arm/src/sam34/Make.defs b/arch/arm/src/sam34/Make.defs index ca7bfb75ed9..ed156e1908b 100644 --- a/arch/arm/src/sam34/Make.defs +++ b/arch/arm/src/sam34/Make.defs @@ -137,11 +137,15 @@ endif # CONFIG_SCHED_TICKLESS endif # CONFIG_SAM34_TC ifeq ($(CONFIG_SMP),y) -CHIP_CSRCS += sam4cm_cpuindex.c sam4cm_cpuidlestack.c +CHIP_CSRCS += sam4cm_cpuidlestack.c CHIP_CSRCS += sam4cm_smpcall.c sam4cm_cpustart.c ifneq ($(CONFIG_ARCH_IDLE_CUSTOM),y) CHIP_CSRCS += sam4cm_idle.c endif endif # CONFIG_SMP +ifeq ($(CONFIG_ARCH_HAVE_MULTICPU),y) +CHIP_CSRCS += sam4cm_cpuindex.c +endif # CONFIG_ARCH_HAVE_MULTICPU + endif # CONFIG_ARCH_CHIP_SAM4CM diff --git a/arch/arm/src/sam34/sam4cm_cpuindex.c b/arch/arm/src/sam34/sam4cm_cpuindex.c index 8b8e7f94607..a8d2bac9885 100644 --- a/arch/arm/src/sam34/sam4cm_cpuindex.c +++ b/arch/arm/src/sam34/sam4cm_cpuindex.c @@ -27,8 +27,9 @@ #include #include "mpu.h" +#include "arm_internal.h" -#ifdef CONFIG_SMP +#ifdef CONFIG_ARCH_HAVE_MULTICPU /**************************************************************************** * Public Functions @@ -38,15 +39,7 @@ * 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 * ****************************************************************************/ @@ -57,4 +50,4 @@ int up_cpu_index(void) return (getreg32(MPU_TYPE) == 0) ? 1 : 0; } -#endif /* CONFIG_SMP */ +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ diff --git a/arch/arm64/include/irq.h b/arch/arm64/include/irq.h index 64ba9a5c65e..65ec6716afa 100644 --- a/arch/arm64/include/irq.h +++ b/arch/arm64/include/irq.h @@ -368,23 +368,13 @@ 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 # define up_cpu_index() ((int)MPID_TO_CORE(GET_MPIDR())) -#else -# define up_cpu_index() (0) -#endif +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ /**************************************************************************** * Name: diff --git a/arch/arm64/src/common/arm64_gicv3.c b/arch/arm64/src/common/arm64_gicv3.c index 9a6c2622e6e..9a8b77b4c6f 100644 --- a/arch/arm64/src/common/arm64_gicv3.c +++ b/arch/arm64/src/common/arm64_gicv3.c @@ -931,8 +931,7 @@ static void arm64_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) diff --git a/arch/arm64/src/zynq-mpsoc/zynq_boot.c b/arch/arm64/src/zynq-mpsoc/zynq_boot.c index 028fe55a3d2..1743908b8be 100644 --- a/arch/arm64/src/zynq-mpsoc/zynq_boot.c +++ b/arch/arm64/src/zynq-mpsoc/zynq_boot.c @@ -101,7 +101,7 @@ void arm64_el_init(void) #endif } -#ifdef CONFIG_SMP +#ifdef CONFIG_ARCH_HAVE_MULTICPU /**************************************************************************** * Public Functions @@ -111,19 +111,7 @@ void arm64_el_init(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. - * - * If TLS is enabled, then the RTOS can get this information from the TLS - * info structure. Otherwise, the MCU-specific logic must provide some - * mechanism to provide the CPU index. - * - * 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 * ****************************************************************************/ @@ -165,7 +153,7 @@ int arm64_get_cpuid(uint64_t mpid) return MPID_TO_CORE(mpid, 0); } -#endif /* CONFIG_SMP */ +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ /**************************************************************************** * Name: arm64_chip_boot diff --git a/arch/avr/include/irq.h b/arch/avr/include/irq.h index 3176366ff3a..5c7aac0497f 100644 --- a/arch/avr/include/irq.h +++ b/arch/avr/include/irq.h @@ -87,24 +87,6 @@ EXTERN volatile uint8_t *g_current_regs; * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * 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. - * - ****************************************************************************/ - -#define up_cpu_index() (0) - /**************************************************************************** * Inline functions ****************************************************************************/ diff --git a/arch/ceva/include/irq.h b/arch/ceva/include/irq.h index 567b9d75baf..e207d55a517 100644 --- a/arch/ceva/include/irq.h +++ b/arch/ceva/include/irq.h @@ -113,23 +113,13 @@ EXTERN uint32_t *volatile g_current_regs[CONFIG_SMP_NCPUS]; * 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 -int up_cpu_index(void); -#else -# define up_cpu_index() (0) -#endif +#ifdef CONFIG_ARCH_HAVE_MULTICPU +int up_cpu_index(void) noinstrument_function; +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ /**************************************************************************** * Inline functions @@ -137,12 +127,20 @@ int up_cpu_index(void); 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 } 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 } /**************************************************************************** diff --git a/arch/hc/include/irq.h b/arch/hc/include/irq.h index 0a588e79cb8..b6698c02afc 100644 --- a/arch/hc/include/irq.h +++ b/arch/hc/include/irq.h @@ -100,24 +100,6 @@ EXTERN volatile uint8_t *g_current_regs; * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * 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. - * - ****************************************************************************/ - -#define up_cpu_index() (0) - /**************************************************************************** * Inline functions ****************************************************************************/ diff --git a/arch/mips/include/irq.h b/arch/mips/include/irq.h index 29681e53391..718cf8a5128 100644 --- a/arch/mips/include/irq.h +++ b/arch/mips/include/irq.h @@ -104,24 +104,6 @@ EXTERN volatile uint32_t *g_current_regs; * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * 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. - * - ****************************************************************************/ - -#define up_cpu_index() (0) - /**************************************************************************** * Inline functions ****************************************************************************/ diff --git a/arch/misoc/include/irq.h b/arch/misoc/include/irq.h index 4ce089ef97a..140665526e1 100644 --- a/arch/misoc/include/irq.h +++ b/arch/misoc/include/irq.h @@ -86,24 +86,6 @@ EXTERN volatile uint32_t *g_current_regs; * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * 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. - * - ****************************************************************************/ - -#define up_cpu_index() (0) - /**************************************************************************** * Inline functions ****************************************************************************/ diff --git a/arch/or1k/include/irq.h b/arch/or1k/include/irq.h index 43d665d01bb..641e5b7f50f 100644 --- a/arch/or1k/include/irq.h +++ b/arch/or1k/include/irq.h @@ -94,23 +94,13 @@ EXTERN volatile uint32_t *g_current_regs[CONFIG_SMP_NCPUS]; * 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 -int up_cpu_index(void); -#else -# define up_cpu_index() (0) -#endif +#ifdef CONFIG_ARCH_HAVE_MULTICPU +int up_cpu_index(void) noinstrument_function; +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ /**************************************************************************** * Inline functions @@ -118,12 +108,20 @@ int up_cpu_index(void); 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 } 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 } /**************************************************************************** diff --git a/arch/renesas/include/irq.h b/arch/renesas/include/irq.h index 3de4630bd48..012c2383302 100644 --- a/arch/renesas/include/irq.h +++ b/arch/renesas/include/irq.h @@ -69,24 +69,6 @@ EXTERN volatile uint32_t *g_current_regs; * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * 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. - * - ****************************************************************************/ - -#define up_cpu_index() (0) - /**************************************************************************** * Inline functions ****************************************************************************/ diff --git a/arch/risc-v/include/irq.h b/arch/risc-v/include/irq.h index a8fc09e5c99..e497f65720b 100644 --- a/arch/risc-v/include/irq.h +++ b/arch/risc-v/include/irq.h @@ -701,23 +701,13 @@ 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 -int up_cpu_index(void); -#else -# define up_cpu_index() (0) -#endif +#ifdef CONFIG_ARCH_HAVE_MULTICPU +int up_cpu_index(void) noinstrument_function; +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ /**************************************************************************** * Inline Functions @@ -725,12 +715,20 @@ int up_cpu_index(void); static inline_function uintreg_t *up_current_regs(void) { +#ifdef CONFIG_SMP return (uintreg_t *)g_current_regs[up_cpu_index()]; +#else + return (uintreg_t *)g_current_regs[0]; +#endif } static inline_function void up_set_current_regs(uintreg_t *regs) { +#ifdef CONFIG_SMP g_current_regs[up_cpu_index()] = regs; +#else + g_current_regs[0] = regs; +#endif } /**************************************************************************** diff --git a/arch/risc-v/src/common/CMakeLists.txt b/arch/risc-v/src/common/CMakeLists.txt index 43e07e91cce..30def6db5e6 100644 --- a/arch/risc-v/src/common/CMakeLists.txt +++ b/arch/risc-v/src/common/CMakeLists.txt @@ -44,7 +44,11 @@ if(NOT CONFIG_ALARM_ARCH) endif() if(CONFIG_SMP) - list(APPEND SRCS riscv_cpuindex.c riscv_smpcall.c riscv_cpustart.c) + list(APPEND SRCS riscv_smpcall.c riscv_cpustart.c) +endif() + +if(CONFIG_ARCH_HAVE_MULTICPU) + list(APPEND SRCS riscv_cpuindex.c) endif() if(CONFIG_RISCV_MISALIGNED_HANDLER) diff --git a/arch/risc-v/src/common/Make.defs b/arch/risc-v/src/common/Make.defs index 343e3ea238b..76970c9b4c6 100644 --- a/arch/risc-v/src/common/Make.defs +++ b/arch/risc-v/src/common/Make.defs @@ -47,7 +47,11 @@ ifneq ($(CONFIG_ALARM_ARCH),y) endif ifeq ($(CONFIG_SMP),y) -CMN_CSRCS += riscv_cpuindex.c riscv_smpcall.c riscv_cpustart.c +CMN_CSRCS += riscv_smpcall.c riscv_cpustart.c +endif + +ifeq ($(CONFIG_ARCH_HAVE_MULTICPU),y) +CMN_CSRCS += riscv_cpuindex.c endif ifeq ($(CONFIG_RISCV_MISALIGNED_HANDLER),y) diff --git a/arch/risc-v/src/common/riscv_cpuindex.c b/arch/risc-v/src/common/riscv_cpuindex.c index d34abc011f5..62bcecd03e5 100644 --- a/arch/risc-v/src/common/riscv_cpuindex.c +++ b/arch/risc-v/src/common/riscv_cpuindex.c @@ -39,15 +39,7 @@ * 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 * ****************************************************************************/ diff --git a/arch/sim/include/irq.h b/arch/sim/include/irq.h index 96686f99bcb..430eb053884 100644 --- a/arch/sim/include/irq.h +++ b/arch/sim/include/irq.h @@ -86,23 +86,13 @@ EXTERN volatile xcpt_reg_t *g_current_regs[CONFIG_SMP_NCPUS]; * 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 -int up_cpu_index(void); -#else -# define up_cpu_index() (0) -#endif +#ifdef CONFIG_ARCH_HAVE_MULTICPU +int up_cpu_index(void) noinstrument_function; +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ /* Name: up_irq_save, up_irq_restore, and friends. * @@ -124,12 +114,20 @@ void up_irq_enable(void); static inline_function xcpt_reg_t *up_current_regs(void) { +#ifdef CONFIG_SMP return (xcpt_reg_t *)g_current_regs[up_cpu_index()]; +#else + return (xcpt_reg_t *)g_current_regs[0]; +#endif } static inline_function void up_set_current_regs(xcpt_reg_t *regs) { +#ifdef CONFIG_SMP g_current_regs[up_cpu_index()] = regs; +#else + g_current_regs[0] = regs; +#endif } /* Return the current value of the stack pointer */ diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index c466dc18c83..1152b041b9d 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -154,6 +154,9 @@ endif ifeq ($(CONFIG_SMP),y) CSRCS += sim_smpsignal.c sim_cpuidlestack.c +endif + +ifeq ($(CONFIG_ARCH_HAVE_MULTICPU),y) HOSTSRCS += sim_hostsmp.c endif diff --git a/arch/sim/src/sim/CMakeLists.txt b/arch/sim/src/sim/CMakeLists.txt index f6fbc724891..ee735edbc44 100644 --- a/arch/sim/src/sim/CMakeLists.txt +++ b/arch/sim/src/sim/CMakeLists.txt @@ -174,6 +174,9 @@ endif() if(CONFIG_SMP) list(APPEND SRCS sim_smpsignal.c sim_cpuidlestack.c) +endif() + +if(CONFIG_ARCH_HAVE_MULTICPU) list(APPEND HOSTSRCS sim_hostsmp.c) endif() diff --git a/arch/sim/src/sim/posix/sim_hostsmp.c b/arch/sim/src/sim/posix/sim_hostsmp.c index beed1dd332c..acdab0e36a9 100644 --- a/arch/sim/src/sim/posix/sim_hostsmp.c +++ b/arch/sim/src/sim/posix/sim_hostsmp.c @@ -49,6 +49,8 @@ struct sim_cpuinfo_s ****************************************************************************/ static pthread_key_t g_cpu_key; + +#ifdef CONFIG_SMP static pthread_t g_cpu_thread[CONFIG_SMP_NCPUS]; /**************************************************************************** @@ -163,28 +165,6 @@ void host_cpu0_start(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. - * - ****************************************************************************/ - -int up_cpu_index(void) -{ - void *value = pthread_getspecific(g_cpu_key); - return (int)((uintptr_t)value); -} - /**************************************************************************** * Name: up_cpu_start * @@ -266,8 +246,6 @@ void host_send_ipi(int cpu) pthread_kill(g_cpu_thread[cpu], SIGUSR1); } -#ifdef CONFIG_SMP - /**************************************************************************** * Name: host_send_func_call_ipi(int cpu) ****************************************************************************/ @@ -277,3 +255,19 @@ void host_send_func_call_ipi(int cpu) pthread_kill(g_cpu_thread[cpu], SIGUSR2); } #endif + +/**************************************************************************** + * Name: up_cpu_index + * + * Description: + * Return the real core number regardless CONFIG_SMP setting + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_HAVE_MULTICPU +int up_cpu_index(void) +{ + void *value = pthread_getspecific(g_cpu_key); + return (int)((uintptr_t)value); +} +#endif \ No newline at end of file diff --git a/arch/sparc/include/irq.h b/arch/sparc/include/irq.h index c37ea5b245c..9316157f3c7 100644 --- a/arch/sparc/include/irq.h +++ b/arch/sparc/include/irq.h @@ -112,23 +112,13 @@ EXTERN volatile uint32_t *g_current_regs[CONFIG_SMP_NCPUS]; * 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 -int up_cpu_index(void); -#else -# define up_cpu_index() (0) -#endif +#ifdef CONFIG_ARCH_HAVE_MULTICPU +int up_cpu_index(void) noinstrument_function; +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ /**************************************************************************** * Inline functions @@ -136,12 +126,20 @@ int up_cpu_index(void); 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 } 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 } /**************************************************************************** diff --git a/arch/sparc/src/s698pm/Make.defs b/arch/sparc/src/s698pm/Make.defs index ff1935e7ad6..55c7bb9058e 100644 --- a/arch/sparc/src/s698pm/Make.defs +++ b/arch/sparc/src/s698pm/Make.defs @@ -54,5 +54,9 @@ endif # Configuration-dependent files ifeq ($(CONFIG_SMP),y) -CHIP_CSRCS += s698pm_cpuindex.c s698pm_cpustart.c s698pm_smpcall.c s698pm_cpuidlestack.c +CHIP_CSRCS += s698pm_cpustart.c s698pm_smpcall.c s698pm_cpuidlestack.c +endif + +ifeq ($(CONFIG_ARCH_HAVE_MULTICPU),y) +CHIP_CSRCS += s698pm_cpuindex.c endif diff --git a/arch/sparc/src/s698pm/s698pm_cpuindex.c b/arch/sparc/src/s698pm/s698pm_cpuindex.c index 25e49f0fee4..93b79ea84e7 100644 --- a/arch/sparc/src/s698pm/s698pm_cpuindex.c +++ b/arch/sparc/src/s698pm/s698pm_cpuindex.c @@ -39,19 +39,11 @@ * 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) { int cpu = 0; diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h index e75d37be77b..350a34b5cdf 100644 --- a/arch/tricore/include/irq.h +++ b/arch/tricore/include/irq.h @@ -80,23 +80,13 @@ EXTERN volatile uintptr_t *g_current_regs[CONFIG_SMP_NCPUS]; * 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 +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ /**************************************************************************** * Name: up_irq_enable @@ -153,12 +143,20 @@ noinstrument_function static inline void up_irq_restore(irqstate_t flags) static inline_function uintptr_t *up_current_regs(void) { +#ifdef CONFIG_SMP return (uintptr_t *)g_current_regs[up_cpu_index()]; +#else + return (uintptr_t *)g_current_regs[0]; +#endif } static inline_function void up_set_current_regs(uintptr_t *regs) { +#ifdef CONFIG_SMP g_current_regs[up_cpu_index()] = regs; +#else + g_current_regs[0] = regs; +#endif } /**************************************************************************** diff --git a/arch/x86/include/irq.h b/arch/x86/include/irq.h index 6de0484f2a4..b6f7d2a999e 100644 --- a/arch/x86/include/irq.h +++ b/arch/x86/include/irq.h @@ -86,24 +86,6 @@ EXTERN volatile uint32_t *g_current_regs; * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * 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. - * - ****************************************************************************/ - -#define up_cpu_index() (0) - /**************************************************************************** * Inline functions ****************************************************************************/ diff --git a/arch/x86_64/include/irq.h b/arch/x86_64/include/irq.h index 834468b84a8..13cd9ead59f 100644 --- a/arch/x86_64/include/irq.h +++ b/arch/x86_64/include/irq.h @@ -83,19 +83,11 @@ extern "C" * 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 static inline_function int up_cpu_index(void) { int cpu; @@ -108,9 +100,7 @@ static inline_function int up_cpu_index(void) return cpu; } -#else -# define up_cpu_index() (0) -#endif +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ /**************************************************************************** * Inline functions diff --git a/arch/xtensa/include/irq.h b/arch/xtensa/include/irq.h index 9a8383aa295..fe93f6dbc6b 100644 --- a/arch/xtensa/include/irq.h +++ b/arch/xtensa/include/irq.h @@ -405,33 +405,31 @@ irqstate_t xtensa_disable_interrupts(irqstate_t mask); * 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 -int up_cpu_index(void); -#else -# define up_cpu_index() (0) -#endif +#ifdef CONFIG_ARCH_HAVE_MULTICPU +int up_cpu_index(void) noinstrument_function; +#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 } /**************************************************************************** diff --git a/arch/xtensa/src/common/espressif/esp_spiflash.c b/arch/xtensa/src/common/espressif/esp_spiflash.c index f174ce8f682..94514527885 100644 --- a/arch/xtensa/src/common/espressif/esp_spiflash.c +++ b/arch/xtensa/src/common/espressif/esp_spiflash.c @@ -189,7 +189,7 @@ IRAM_ATTR void spiflash_start(void) nxmutex_lock(&s_flash_op_mutex); flags = enter_critical_section(); - cpu = up_cpu_index(); + cpu = this_cpu(); s_sched_suspended[cpu] = true; #ifndef CONFIG_ARCH_CHIP_ESP32S2 @@ -225,7 +225,7 @@ IRAM_ATTR void spiflash_end(void) flags = enter_critical_section(); - cpu = up_cpu_index(); + cpu = this_cpu(); cache_invalidate_icache_all(); cache_resume_icache(s_flash_op_cache_state[cpu] >> 16); diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs index 740b9de0335..3e69a2972d9 100644 --- a/arch/xtensa/src/esp32/Make.defs +++ b/arch/xtensa/src/esp32/Make.defs @@ -128,10 +128,13 @@ endif # Configuration-dependent ESP32 files ifeq ($(CONFIG_SMP),y) -CHIP_ASRCS = esp32_cpuindex.S CHIP_CSRCS += esp32_cpuidlestack.c esp32_cpustart.c esp32_intercpu_interrupt.c endif +ifeq ($(CONFIG_ARCH_HAVE_MULTICPU),y) +CHIP_ASRCS = esp32_cpuindex.S +endif + ifeq ($(CONFIG_ESP32_UART),y) CHIP_CSRCS += esp32_serial.c endif diff --git a/arch/xtensa/src/esp32/esp32_cpuindex.S b/arch/xtensa/src/esp32/esp32_cpuindex.S index 6951ba7d692..24f24f0e96f 100644 --- a/arch/xtensa/src/esp32/esp32_cpuindex.S +++ b/arch/xtensa/src/esp32/esp32_cpuindex.S @@ -35,19 +35,7 @@ * 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. - * - * If TLS is enabled, then the RTOS can get this information from the TLS - * info structure. Otherwise, the MCU-specific logic must provide some - * mechanism to provide the CPU index. - * - * 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 * ****************************************************************************/ diff --git a/arch/xtensa/src/esp32s3/Make.defs b/arch/xtensa/src/esp32s3/Make.defs index 6fadf642799..608a985129f 100644 --- a/arch/xtensa/src/esp32s3/Make.defs +++ b/arch/xtensa/src/esp32s3/Make.defs @@ -44,10 +44,13 @@ CHIP_CSRCS += esp32s3_userspace.c endif ifeq ($(CONFIG_SMP),y) -CHIP_ASRCS = esp32s3_cpuindex.S CHIP_CSRCS += esp32s3_cpuidlestack.c esp32s3_cpustart.c esp32s3_intercpu_interrupt.c endif +ifeq ($(CONFIG_ARCH_HAVE_MULTICPU),y) +CHIP_ASRCS = esp32s3_cpuindex.S +endif + ifeq ($(CONFIG_ESP32S3_EFUSE),y) CHIP_CSRCS += esp32s3_efuse.c CHIP_CSRCS += esp32s3_efuse_table.c diff --git a/arch/xtensa/src/esp32s3/esp32s3_cpuindex.S b/arch/xtensa/src/esp32s3/esp32s3_cpuindex.S index d35b5472741..1984996db31 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_cpuindex.S +++ b/arch/xtensa/src/esp32s3/esp32s3_cpuindex.S @@ -35,19 +35,7 @@ * 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. - * - * If TLS is enabled, then the RTOS can get this information from the TLS - * info structure. Otherwise, the MCU-specific logic must provide some - * mechanism to provide the CPU index. - * - * 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 * ****************************************************************************/ diff --git a/arch/z16/include/irq.h b/arch/z16/include/irq.h index ecc611cd699..f4c13d098d5 100644 --- a/arch/z16/include/irq.h +++ b/arch/z16/include/irq.h @@ -73,24 +73,6 @@ EXTERN volatile FAR chipreg_t *g_current_regs; * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * 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. - * - ****************************************************************************/ - -#define up_cpu_index() (0) - /**************************************************************************** * Inline functions ****************************************************************************/ diff --git a/drivers/syslog/vsyslog.c b/drivers/syslog/vsyslog.c index 9ce1ab2fc48..2948ace47e3 100644 --- a/drivers/syslog/vsyslog.c +++ b/drivers/syslog/vsyslog.c @@ -215,7 +215,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) #endif #if defined(CONFIG_SMP) - , up_cpu_index() + , this_cpu() #endif #if defined(CONFIG_SYSLOG_PROCESSID) diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 16994ef7144..3a04da6d1ad 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -99,6 +99,18 @@ #define DEBUGPOINT_BREAKPOINT 0x04 #define DEBUGPOINT_STEPPOINT 0x05 +/**************************************************************************** + * Name: up_cpu_index + * + * Description: + * Return the real core number regardless CONFIG_SMP setting + * + ****************************************************************************/ + +#ifndef CONFIG_ARCH_HAVE_MULTICPU +# define up_cpu_index() 0 +#endif /* CONFIG_ARCH_HAVE_MULTICPU */ + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index f32d3d1e359..bd15818d6a7 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -35,6 +35,7 @@ #include #include +#include #if defined(CONFIG_TICKET_SPINLOCK) || defined(CONFIG_RW_SPINLOCK) # include @@ -531,7 +532,7 @@ irqstate_t spin_lock_irqsave_wo_note(FAR volatile spinlock_t *lock) if (NULL == lock) { - int me = up_cpu_index(); + int me = this_cpu(); if (0 == g_irq_spin_count[me]) { spin_lock_wo_note(&g_irq_spin); @@ -698,7 +699,7 @@ void spin_unlock_irqrestore_wo_note(FAR volatile spinlock_t *lock, { if (NULL == lock) { - int me = up_cpu_index(); + int me = this_cpu(); DEBUGASSERT(0 < g_irq_spin_count[me]); g_irq_spin_count[me]--; diff --git a/net/tcp/tcp_recvfrom.c b/net/tcp/tcp_recvfrom.c index a67c49edbb5..17972a9299b 100644 --- a/net/tcp/tcp_recvfrom.c +++ b/net/tcp/tcp_recvfrom.c @@ -606,7 +606,7 @@ static ssize_t tcp_recvfrom_result(int result, struct tcp_recvfrom_s *pstate) #ifdef CONFIG_NETDEV_RSS static void tcp_notify_recvcpu(FAR struct tcp_conn_s *conn) { - int cpu = up_cpu_index(); + int cpu = this_cpu(); if (cpu != conn->rcvcpu) { diff --git a/net/udp/udp_recvfrom.c b/net/udp/udp_recvfrom.c index 4981e11e95a..0f19c9df205 100644 --- a/net/udp/udp_recvfrom.c +++ b/net/udp/udp_recvfrom.c @@ -628,7 +628,7 @@ static void udp_notify_recvcpu(FAR struct udp_conn_s *conn) return; } - cpu = up_cpu_index(); + cpu = this_cpu(); if (cpu != conn->rcvcpu) { if (conn->domain == PF_INET) diff --git a/sched/irq/irq_spinlock.c b/sched/irq/irq_spinlock.c index c2e756470a7..5b20e77a5a7 100644 --- a/sched/irq/irq_spinlock.c +++ b/sched/irq/irq_spinlock.c @@ -193,7 +193,7 @@ irqstate_t write_lock_irqsave(rwlock_t *lock) if (NULL == lock) { - int me = up_cpu_index(); + int me = this_cpu(); if (0 == g_irq_rwspin_count[me]) { write_lock(&g_irq_rwspin); @@ -243,7 +243,7 @@ void write_unlock_irqrestore(rwlock_t *lock, irqstate_t flags) { if (NULL == lock) { - int me = up_cpu_index(); + int me = this_cpu(); DEBUGASSERT(0 < g_irq_rwspin_count[me]); g_irq_rwspin_count[me]--;