From 49337973e02006432b76caa97d43aebe36224971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Fri, 4 Apr 2025 13:47:00 +0200 Subject: [PATCH] kernel_structs: Add macro CPU_ID for getting current CPU ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case of a single core it resolves to 0. In many cases it reduces code size and execution time compared to reading id in runtime. Signed-off-by: Krzysztof Chruściński --- include/zephyr/kernel_structs.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/zephyr/kernel_structs.h b/include/zephyr/kernel_structs.h index 3306c5f2768..5bf9ae6df1c 100644 --- a/include/zephyr/kernel_structs.h +++ b/include/zephyr/kernel_structs.h @@ -257,6 +257,8 @@ __attribute_const__ struct k_thread *z_smp_current_get(void); #define _current _kernel.cpus[0].current #endif +#define CPU_ID ((CONFIG_MP_MAX_NUM_CPUS == 1) ? 0 : _current_cpu->id) + /* This is always invoked from a context where preemption is disabled */ #define z_current_thread_set(thread) ({ _current_cpu->current = (thread); })