From bc6eded597d074fe5b987e68686635105387ac2e Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 8 Jan 2025 12:36:37 -0500 Subject: [PATCH] kernel: mark z_smp_current_get() with the const attribute Repeated references to _current won't produce a different result as the executing thread instance is always the same. Use the const attribute to let the compiler know it may reuse a previously obtained value. This offset the penalty for moving z_smp_current_get() out of line and provides yet more binary size reduction. This change is isolated in its own commit to ease bisecting in case some unexpected misbehavior is eventually observed. Signed-off-by: Nicolas Pitre --- include/zephyr/kernel_structs.h | 2 +- kernel/smp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/zephyr/kernel_structs.h b/include/zephyr/kernel_structs.h index 5cea718f0b4c38..56df49dcb23dbb 100644 --- a/include/zephyr/kernel_structs.h +++ b/include/zephyr/kernel_structs.h @@ -263,7 +263,7 @@ bool z_smp_cpu_mobile(void); #define _current_cpu ({ __ASSERT_NO_MSG(!z_smp_cpu_mobile()); \ arch_curr_cpu(); }) -struct k_thread *z_smp_current_get(void); +__attribute_const__ struct k_thread *z_smp_current_get(void); #define _current z_smp_current_get() #else diff --git a/kernel/smp.c b/kernel/smp.c index f97f1b2a17e3ac..63ac7bc8975e7b 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -249,7 +249,7 @@ bool z_smp_cpu_mobile(void) return !pinned; } -struct k_thread *z_smp_current_get(void) +__attribute_const__ struct k_thread *z_smp_current_get(void) { /* * _current is a field read from _current_cpu, which can race