Skip to content

Commit 7f52fc4

Browse files
nashifcarlescufi
authored andcommitted
arch: custom cpu_idle and cpu_atomic harmonization
custom arch_cpu_idle and arch_cpu_atomic_idle implementation was done differently on different architectures. riscv implemented those as weak symbols, xtensa used a kconfig and all other architectures did not really care, but this was a global kconfig that should apply to all architectures. Signed-off-by: Anas Nashif <[email protected]>
1 parent e6235f4 commit 7f52fc4

File tree

12 files changed

+49
-3
lines changed

12 files changed

+49
-3
lines changed

arch/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,3 +1084,10 @@ config ARCH_CPU_IDLE_CUSTOM
10841084
help
10851085
This options allows applications to override the default arch idle implementation with
10861086
a custom one.
1087+
1088+
config ARCH_CPU_ATOMIC_IDLE_CUSTOM
1089+
bool "Custom arch_cpu_atomic_idle implementation"
1090+
default n
1091+
help
1092+
This options allows applications to override the default arch idle implementation with
1093+
a custom one.

arch/arc/core/cpu_idle.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SECTION_VAR(BSS, z_arc_cpu_sleep_mode)
2626
.align 4
2727
.word 0
2828

29+
#ifndef CONFIG_ARCH_CPU_IDLE_CUSTOM
2930
/*
3031
* @brief Put the CPU in low-power mode
3132
*
@@ -48,14 +49,17 @@ SECTION_FUNC(TEXT, arch_cpu_idle)
4849
sleep r1
4950
j_s [blink]
5051
nop
52+
#endif
5153

54+
#ifndef CONFIG_ARCH_CPU_ATOMIC_IDLE_CUSTOM
5255
/*
5356
* @brief Put the CPU in low-power mode, entered with IRQs locked
5457
*
5558
* This function exits with interrupts restored to <key>.
5659
*
5760
* void arch_cpu_atomic_idle(unsigned int key)
5861
*/
62+
5963
SECTION_FUNC(TEXT, arch_cpu_atomic_idle)
6064

6165
#ifdef CONFIG_TRACING
@@ -70,3 +74,4 @@ SECTION_FUNC(TEXT, arch_cpu_atomic_idle)
7074
sleep r1
7175
j_s.d [blink]
7276
seti r0
77+
#endif

arch/arm/core/cortex_a_r/cpu_idle.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ _skip_\@:
4949
#endif /* CONFIG_ARM_ON_ENTER_CPU_IDLE_HOOK */
5050
.endm
5151

52+
#ifndef CONFIG_ARCH_CPU_IDLE_CUSTOM
5253
SECTION_FUNC(TEXT, arch_cpu_idle)
5354
#ifdef CONFIG_TRACING
5455
push {r0, lr}
@@ -68,6 +69,9 @@ SECTION_FUNC(TEXT, arch_cpu_idle)
6869

6970
bx lr
7071

72+
#endif
73+
74+
#ifndef CONFIG_ARCH_CPU_ATOMIC_IDLE_CUSTOM
7175
SECTION_FUNC(TEXT, arch_cpu_atomic_idle)
7276
#ifdef CONFIG_TRACING
7377
push {r0, lr}
@@ -93,3 +97,4 @@ SECTION_FUNC(TEXT, arch_cpu_atomic_idle)
9397
_irq_disabled:
9498

9599
bx lr
100+
#endif

arch/arm/core/cortex_m/cpu_idle.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void z_arm_cpu_idle_init(void)
5353
} while (false)
5454
#endif
5555

56+
#ifndef CONFIG_ARCH_CPU_IDLE_CUSTOM
5657
void arch_cpu_idle(void)
5758
{
5859
#if defined(CONFIG_TRACING)
@@ -96,7 +97,9 @@ void arch_cpu_idle(void)
9697
__enable_irq();
9798
__ISB();
9899
}
100+
#endif
99101

102+
#ifndef CONFIG_ARCH_CPU_ATOMIC_IDLE_CUSTOM
100103
void arch_cpu_atomic_idle(unsigned int key)
101104
{
102105
#if defined(CONFIG_TRACING)
@@ -135,3 +138,4 @@ void arch_cpu_atomic_idle(unsigned int key)
135138
__enable_irq();
136139
#endif
137140
}
141+
#endif

arch/arm64/core/cpu_idle.S

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <zephyr/arch/cpu.h>
1414

1515
_ASM_FILE_PROLOGUE
16-
16+
#ifndef CONFIG_ARCH_CPU_IDLE_CUSTOM
1717
GTEXT(arch_cpu_idle)
1818
SECTION_FUNC(TEXT, arch_cpu_idle)
1919
#ifdef CONFIG_TRACING
@@ -25,7 +25,9 @@ SECTION_FUNC(TEXT, arch_cpu_idle)
2525
wfi
2626
msr daifclr, #(DAIFCLR_IRQ_BIT)
2727
ret
28+
#endif
2829

30+
#ifndef CONFIG_ARCH_CPU_ATOMIC_IDLE_CUSTOM
2931
GTEXT(arch_cpu_atomic_idle)
3032
SECTION_FUNC(TEXT, arch_cpu_atomic_idle)
3133
#ifdef CONFIG_TRACING
@@ -41,3 +43,5 @@ SECTION_FUNC(TEXT, arch_cpu_atomic_idle)
4143
msr daifclr, #(DAIFCLR_IRQ_BIT)
4244
_irq_disabled:
4345
ret
46+
47+
#endif

arch/mips/core/cpu_idle.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ static ALWAYS_INLINE void mips_idle(unsigned int key)
1919
__asm__ volatile("wait");
2020
}
2121

22+
#ifndef CONFIG_ARCH_CPU_IDLE_CUSTOM
2223
void arch_cpu_idle(void)
2324
{
2425
mips_idle(1);
2526
}
27+
#endif
2628

29+
#ifndef CONFIG_ARCH_CPU_ATOMIC_IDLE_CUSTOM
2730
void arch_cpu_atomic_idle(unsigned int key)
2831
{
2932
mips_idle(key);
3033
}
34+
#endif

arch/nios2/core/cpu_idle.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/kernel_structs.h>
99

10+
#ifndef CONFIG_ARCH_CPU_IDLE_CUSTOM
1011
void arch_cpu_idle(void)
1112
{
1213
/* Do nothing but unconditionally unlock interrupts and return to the
1314
* caller. This CPU does not have any kind of power saving instruction.
1415
*/
1516
irq_unlock(NIOS2_STATUS_PIE_MSK);
1617
}
18+
#endif
1719

20+
#ifndef CONFIG_ARCH_CPU_ATOMIC_IDLE_CUSTOM
1821
void arch_cpu_atomic_idle(unsigned int key)
1922
{
2023
/* Do nothing but restore IRQ state. This CPU does not have any
2124
* kind of power saving instruction.
2225
*/
2326
irq_unlock(key);
2427
}
28+
#endif

arch/riscv/core/cpu_idle.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@
77
#include <zephyr/irq.h>
88
#include <zephyr/tracing/tracing.h>
99

10-
void __weak arch_cpu_idle(void)
10+
#ifndef CONFIG_ARCH_CPU_IDLE_CUSTOM
11+
void arch_cpu_idle(void)
1112
{
1213
sys_trace_idle();
1314
__asm__ volatile("wfi");
1415
irq_unlock(MSTATUS_IEN);
1516
}
17+
#endif
1618

17-
void __weak arch_cpu_atomic_idle(unsigned int key)
19+
#ifndef CONFIG_ARCH_CPU_ATOMIC_IDLE_CUSTOM
20+
void arch_cpu_atomic_idle(unsigned int key)
1821
{
1922
sys_trace_idle();
2023
__asm__ volatile("wfi");
2124
irq_unlock(key);
2225
}
26+
#endif

arch/x86/core/cpuhalt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <zephyr/tracing/tracing.h>
88
#include <zephyr/arch/cpu.h>
99

10+
#ifndef CONFIG_ARCH_CPU_IDLE_CUSTOM
1011
__pinned_func
1112
void arch_cpu_idle(void)
1213
{
@@ -15,7 +16,9 @@ void arch_cpu_idle(void)
1516
"sti\n\t"
1617
"hlt\n\t");
1718
}
19+
#endif
1820

21+
#ifndef CONFIG_ARCH_CPU_ATOMIC_IDLE_CUSTOM
1922
__pinned_func
2023
void arch_cpu_atomic_idle(unsigned int key)
2124
{
@@ -42,3 +45,4 @@ void arch_cpu_atomic_idle(unsigned int key)
4245
__asm__ volatile("cli");
4346
}
4447
}
48+
#endif

arch/xtensa/core/cpu_idle.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ void arch_cpu_idle(void)
1414
}
1515
#endif
1616

17+
#ifndef CONFIG_ARCH_CPU_ATOMIC_IDLE_CUSTOM
1718
void arch_cpu_atomic_idle(unsigned int key)
1819
{
1920
sys_trace_idle();
2021
__asm__ volatile ("waiti 0\n\t"
2122
"wsr.ps %0\n\t"
2223
"rsync" :: "a"(key));
2324
}
25+
#endif

0 commit comments

Comments
 (0)