Browse Source

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>
pull/81536/head
Nicolas Pitre 6 months ago committed by Benjamin Cabé
parent
commit
bc6eded597
  1. 2
      include/zephyr/kernel_structs.h
  2. 2
      kernel/smp.c

2
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()); \ #define _current_cpu ({ __ASSERT_NO_MSG(!z_smp_cpu_mobile()); \
arch_curr_cpu(); }) 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() #define _current z_smp_current_get()
#else #else

2
kernel/smp.c

@ -249,7 +249,7 @@ bool z_smp_cpu_mobile(void)
return !pinned; 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 * _current is a field read from _current_cpu, which can race

Loading…
Cancel
Save