kernel: Define optional arch_thread_name_set()

The intention of this API is to allow setting the posix thread
name equal to the zephyr thread name.
By defining it as an arch interface, the implementation becomes
generic.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
This commit is contained in:
Rubin Gerritsen 2024-08-07 23:03:18 +02:00 committed by Anas Nashif
parent 8a4b3a4b61
commit 98a16b424a
3 changed files with 29 additions and 0 deletions

View file

@ -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

View file

@ -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
*

View file

@ -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';
}