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 <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2025-01-08 12:36:37 -05:00 committed by Benjamin Cabé
commit bc6eded597
2 changed files with 2 additions and 2 deletions

View file

@ -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

View file

@ -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