Skip to content

Commit

Permalink
kernel: mark z_smp_current_get() with the const attribute
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Nicolas Pitre authored and kartben committed Jan 10, 2025
1 parent 7a3124d commit bc6eded
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/zephyr/kernel_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc6eded

Please sign in to comment.