diff --git a/kernel/Kconfig b/kernel/Kconfig index e75944761fd..716294a39da 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -764,6 +764,12 @@ config SWAP_NONATOMIC ARM when the PendSV exception priority sits below that of Zephyr-handled interrupts. +config ARCH_HAS_THREAD_NAME_HOOK + bool + help + The architecture provides a hook to handle thread name changes beyond + just storing it in the kernel structure. + config SYS_CLOCK_TICKS_PER_SEC int "System tick frequency (in ticks/second)" default 100 if QEMU_TARGET || SOC_POSIX diff --git a/kernel/include/kernel_arch_interface.h b/kernel/include/kernel_arch_interface.h index 7ff269b69f5..1c080e22475 100644 --- a/kernel/include/kernel_arch_interface.h +++ b/kernel/include/kernel_arch_interface.h @@ -557,6 +557,22 @@ uintptr_t arch_page_info_get(void *addr, uintptr_t *location, */ int arch_printk_char_out(int c); +#ifdef CONFIG_ARCH_HAS_THREAD_NAME_HOOK +/** + * Set thread name hook + * + * If implemented, any invocation of a function setting a thread name + * will invoke this function. + * + * @param thread Pointer to thread object + * @param str The thread name + * + * @retval 0 On success. + * @retval -EAGAIN If the operation could not be performed. + */ +int arch_thread_name_set(struct k_thread *thread, const char *str); +#endif /* CONFIG_ARCH_HAS_THREAD_NAME_HOOK */ + /** * Architecture-specific kernel initialization hook * diff --git a/kernel/thread.c b/kernel/thread.c index 25bf9a9e55d..89972cd9e34 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -145,6 +145,10 @@ int z_impl_k_thread_name_set(k_tid_t thread, const char *str) strncpy(thread->name, str, CONFIG_THREAD_MAX_NAME_LEN - 1); thread->name[CONFIG_THREAD_MAX_NAME_LEN - 1] = '\0'; +#ifdef CONFIG_ARCH_HAS_THREAD_NAME_HOOK + arch_thread_name_set(thread, str); +#endif /* CONFIG_ARCH_HAS_THREAD_NAME_HOOK */ + SYS_PORT_TRACING_OBJ_FUNC(k_thread, name_set, thread, 0); return 0; @@ -608,6 +612,9 @@ char *z_setup_new_thread(struct k_thread *new_thread, CONFIG_THREAD_MAX_NAME_LEN - 1); /* Ensure NULL termination, truncate if longer */ new_thread->name[CONFIG_THREAD_MAX_NAME_LEN - 1] = '\0'; +#ifdef CONFIG_ARCH_HAS_THREAD_NAME_HOOK + arch_thread_name_set(new_thread, name); +#endif /* CONFIG_ARCH_HAS_THREAD_NAME_HOOK */ } else { new_thread->name[0] = '\0'; }