From 41e8b44619c7dd60ccf91ac642c49e68d14f7ede Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 21 Sep 2023 00:07:28 -0700 Subject: [PATCH] kernel: Make thread 'init_delay' k_timeout_t rather than int msecs Storing this value in milliseconds rather than using k_timeout_t requires the system to perform division at runtime to convert types. This pulls in the 64-bit soft division code on platforms without hardware for this. Perform the conversion at build time instead by using the runtime time directly. The init_delay field was moved within the _static_thread_data structure to avoid introducing a hole for alignment on 32-bit systems when using 64-bit timeouts. Use SYS_TIMEOUT_MS instead of K_MSEC so that the initial delay can be set to forever. Signed-off-by: Keith Packard --- include/zephyr/kernel.h | 4 ++-- kernel/thread.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/zephyr/kernel.h b/include/zephyr/kernel.h index 0ab33e85d42..e3c467f1dbc 100644 --- a/include/zephyr/kernel.h +++ b/include/zephyr/kernel.h @@ -686,8 +686,8 @@ struct _static_thread_data { void *init_p3; int init_prio; uint32_t init_options; - int32_t init_delay; const char *init_name; + k_timeout_t init_delay; }; #define Z_THREAD_INITIALIZER(thread, stack, stack_size, \ @@ -703,7 +703,7 @@ struct _static_thread_data { .init_p3 = (void *)p3, \ .init_prio = (prio), \ .init_options = (options), \ - .init_delay = (delay), \ + .init_delay = SYS_TIMEOUT_MS(delay), \ .init_name = STRINGIFY(tname), \ } diff --git a/kernel/thread.c b/kernel/thread.c index 49b97e6cb4b..2b0b5ce0aac 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -790,9 +790,9 @@ void z_init_static_threads(void) */ k_sched_lock(); _FOREACH_STATIC_THREAD(thread_data) { - if (thread_data->init_delay != K_TICKS_FOREVER) { + if (!K_TIMEOUT_EQ(thread_data->init_delay, K_FOREVER)) { schedule_new_thread(thread_data->init_thread, - K_MSEC(thread_data->init_delay)); + thread_data->init_delay); } } k_sched_unlock();