arch posix: Implement arch_thread_name_set()
This will update the posix thread names to match the zephyr thread names. This will simplify debugging as the debugger will recognize the thread names. Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
This commit is contained in:
parent
98a16b424a
commit
fb745f610f
6 changed files with 53 additions and 0 deletions
|
@ -146,6 +146,7 @@ config ARCH_POSIX
|
||||||
select ARCH_HAS_CUSTOM_SWAP_TO_MAIN
|
select ARCH_HAS_CUSTOM_SWAP_TO_MAIN
|
||||||
select ARCH_HAS_CUSTOM_BUSY_WAIT
|
select ARCH_HAS_CUSTOM_BUSY_WAIT
|
||||||
select ARCH_HAS_THREAD_ABORT
|
select ARCH_HAS_THREAD_ABORT
|
||||||
|
select ARCH_HAS_THREAD_NAME_HOOK
|
||||||
select NATIVE_BUILD
|
select NATIVE_BUILD
|
||||||
select HAS_COVERAGE_SUPPORT
|
select HAS_COVERAGE_SUPPORT
|
||||||
select BARRIER_OPERATIONS_BUILTIN
|
select BARRIER_OPERATIONS_BUILTIN
|
||||||
|
|
|
@ -57,3 +57,8 @@ int posix_arch_get_unique_thread_id(int thread_idx)
|
||||||
{
|
{
|
||||||
return nct_get_unique_thread_id(te_state, thread_idx);
|
return nct_get_unique_thread_id(te_state, thread_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int posix_arch_thread_name_set(int thread_idx, const char *str)
|
||||||
|
{
|
||||||
|
return nct_thread_name_set(te_state, thread_idx, str);
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* architecture
|
* architecture
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <zephyr/toolchain.h>
|
#include <zephyr/toolchain.h>
|
||||||
#include <zephyr/kernel_structs.h>
|
#include <zephyr/kernel_structs.h>
|
||||||
#include <ksched.h>
|
#include <ksched.h>
|
||||||
|
@ -54,6 +55,40 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
||||||
thread_status->thread_idx = posix_new_thread((void *)thread_status);
|
thread_status->thread_idx = posix_new_thread((void *)thread_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int arch_thread_name_set(struct k_thread *thread, const char *str)
|
||||||
|
{
|
||||||
|
#define MAX_HOST_THREAD_NAME 16
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
int thread_index;
|
||||||
|
posix_thread_status_t *thread_status;
|
||||||
|
char th_name[MAX_HOST_THREAD_NAME];
|
||||||
|
|
||||||
|
thread_status = thread->callee_saved.thread_status;
|
||||||
|
if (!thread_status) {
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_index = thread_status->thread_idx;
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(th_name, MAX_HOST_THREAD_NAME,
|
||||||
|
#if (CONFIG_NATIVE_SIMULATOR_NUMBER_MCUS > 1)
|
||||||
|
STRINGIFY(CONFIG_NATIVE_SIMULATOR_MCU_N) ":"
|
||||||
|
#endif
|
||||||
|
"%s", str);
|
||||||
|
|
||||||
|
ret = posix_arch_thread_name_set(thread_index, th_name);
|
||||||
|
if (ret) {
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void posix_arch_thread_entry(void *pa_thread_status)
|
void posix_arch_thread_entry(void *pa_thread_status)
|
||||||
{
|
{
|
||||||
posix_thread_status_t *ptr = pa_thread_status;
|
posix_thread_status_t *ptr = pa_thread_status;
|
||||||
|
|
|
@ -47,6 +47,7 @@ void posix_main_thread_start(int next_allowed_thread_nbr);
|
||||||
int posix_new_thread(void *payload);
|
int posix_new_thread(void *payload);
|
||||||
void posix_abort_thread(int thread_idx);
|
void posix_abort_thread(int thread_idx);
|
||||||
int posix_arch_get_unique_thread_id(int thread_idx);
|
int posix_arch_get_unique_thread_id(int thread_idx);
|
||||||
|
int posix_arch_thread_name_set(int thread_idx, const char *str);
|
||||||
|
|
||||||
#ifndef POSIX_ARCH_DEBUG_PRINTS
|
#ifndef POSIX_ARCH_DEBUG_PRINTS
|
||||||
#define POSIX_ARCH_DEBUG_PRINTS 0
|
#define POSIX_ARCH_DEBUG_PRINTS 0
|
||||||
|
|
|
@ -25,6 +25,7 @@ void nct_first_thread_start(void *this, int next_allowed_thread_nbr);
|
||||||
int nct_new_thread(void *this, void *payload);
|
int nct_new_thread(void *this, void *payload);
|
||||||
void nct_abort_thread(void *this, int thread_idx);
|
void nct_abort_thread(void *this, int thread_idx);
|
||||||
int nct_get_unique_thread_id(void *this, int thread_idx);
|
int nct_get_unique_thread_id(void *this, int thread_idx);
|
||||||
|
int nct_thread_name_set(void *this, int thread_idx, const char *str);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,8 @@
|
||||||
|
|
||||||
#define NCT_DEBUG_PRINTS 0
|
#define NCT_DEBUG_PRINTS 0
|
||||||
|
|
||||||
|
/* For pthread_setname_np() */
|
||||||
|
#define _GNU_SOURCE
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -647,6 +649,14 @@ int nct_get_unique_thread_id(void *this_arg, int thread_idx)
|
||||||
return tt_el->thead_cnt;
|
return tt_el->thead_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int nct_thread_name_set(void *this_arg, int thread_idx, const char *str)
|
||||||
|
{
|
||||||
|
struct te_status_t *this = (struct te_status_t *)this_arg;
|
||||||
|
struct threads_table_el *tt_el = ttable_get_element(this, thread_idx);
|
||||||
|
|
||||||
|
return pthread_setname_np(tt_el->thread, str);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Notes about coverage:
|
* Notes about coverage:
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue