Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/zephyr/kernel_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@
*/
bool z_smp_cpu_mobile(void);

#define _current_cpu ({ __ASSERT_NO_MSG(!z_smp_cpu_mobile()); \
arch_curr_cpu(); })
#define _current_cpu \
({ \
IF_ENABLED(CONFIG_CURRENT_CPU_VALIDATE, (__ASSERT_NO_MSG(!z_smp_cpu_mobile()))); \
arch_curr_cpu(); \

Check notice on line 264 in include/zephyr/kernel_structs.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/kernel_structs.h:264 - IF_ENABLED(CONFIG_CURRENT_CPU_VALIDATE, (__ASSERT_NO_MSG(!z_smp_cpu_mobile()))); \ + IF_ENABLED(CONFIG_CURRENT_CPU_VALIDATE, (__ASSERT_NO_MSG(!z_smp_cpu_mobile()))); \
})
#define _current k_sched_current_thread_query()

#else
Expand Down
8 changes: 8 additions & 0 deletions kernel/Kconfig.smp
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,12 @@ config TICKET_SPINLOCKS
which resolves such unfairness issue at the cost of slightly
increased memory footprint.

config CURRENT_CPU_VALIDATE
bool "Validate usage of _current_cpu"
depends on SMP && ASSERT
default y if MP_MAX_NUM_CPUS > 1
help
The `_current_cpu` pointer should only ever be used in non-preemptible
contexts. When assertions are enabled in SMP systems, this option guarantees
correct `_current_cpu` usage with runtime checks.
endmenu
Loading