Browse Source

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>
pull/74918/merge
Rubin Gerritsen 11 months ago committed by Anas Nashif
parent
commit
fb745f610f
  1. 1
      arch/Kconfig
  2. 5
      arch/posix/core/posix_core_nsi.c
  3. 35
      arch/posix/core/thread.c
  4. 1
      arch/posix/include/posix_core.h
  5. 1
      scripts/native_simulator/common/src/include/nct_if.h
  6. 10
      scripts/native_simulator/common/src/nct.c

1
arch/Kconfig

@ -146,6 +146,7 @@ config ARCH_POSIX @@ -146,6 +146,7 @@ config ARCH_POSIX
select ARCH_HAS_CUSTOM_SWAP_TO_MAIN
select ARCH_HAS_CUSTOM_BUSY_WAIT
select ARCH_HAS_THREAD_ABORT
select ARCH_HAS_THREAD_NAME_HOOK
select NATIVE_BUILD
select HAS_COVERAGE_SUPPORT
select BARRIER_OPERATIONS_BUILTIN

5
arch/posix/core/posix_core_nsi.c

@ -57,3 +57,8 @@ int posix_arch_get_unique_thread_id(int thread_idx) @@ -57,3 +57,8 @@ int posix_arch_get_unique_thread_id(int 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);
}

35
arch/posix/core/thread.c

@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
* architecture
*/
#include <stdio.h>
#include <zephyr/toolchain.h>
#include <zephyr/kernel_structs.h>
#include <ksched.h>
@ -54,6 +55,40 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack, @@ -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);
}
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)
{
posix_thread_status_t *ptr = pa_thread_status;

1
arch/posix/include/posix_core.h

@ -47,6 +47,7 @@ void posix_main_thread_start(int next_allowed_thread_nbr); @@ -47,6 +47,7 @@ void posix_main_thread_start(int next_allowed_thread_nbr);
int posix_new_thread(void *payload);
void posix_abort_thread(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
#define POSIX_ARCH_DEBUG_PRINTS 0

1
scripts/native_simulator/common/src/include/nct_if.h

@ -25,6 +25,7 @@ void nct_first_thread_start(void *this, int next_allowed_thread_nbr); @@ -25,6 +25,7 @@ void nct_first_thread_start(void *this, int next_allowed_thread_nbr);
int nct_new_thread(void *this, void *payload);
void nct_abort_thread(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
}

10
scripts/native_simulator/common/src/nct.c

@ -60,6 +60,8 @@ @@ -60,6 +60,8 @@
#define NCT_DEBUG_PRINTS 0
/* For pthread_setname_np() */
#define _GNU_SOURCE
#include <pthread.h>
#include <stdbool.h>
#include <stdlib.h>
@ -647,6 +649,14 @@ int nct_get_unique_thread_id(void *this_arg, int thread_idx) @@ -647,6 +649,14 @@ int nct_get_unique_thread_id(void *this_arg, int thread_idx)
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:
*

Loading…
Cancel
Save