Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #532, Set pthread names to match CFE tasks names #533

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/bsp/pc-linux/config/osconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,10 @@
*/
#define OSAL_DEBUG_PERMISSIVE_MODE

/*
* If OS_HAVE_PTHREAD_SETNAME_NP is defined, this will allow underlying pthread names
* to match CFE task names
*/
#define OS_HAVE_PTHREAD_SETNAME_NP

#endif
5 changes: 1 addition & 4 deletions src/os/posix/os-posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,4 @@ int32 OS_Posix_StreamAPI_Impl_Init(void);
int32 OS_Posix_DirAPI_Impl_Init(void);
int32 OS_Posix_FileSysAPI_Impl_Init(void);

int32 OS_Posix_InternalTaskCreate_Impl (pthread_t *thr, uint32 priority, size_t stacksz, PthreadFuncPtr_t Entry, void *entry_arg);



int32 OS_Posix_InternalTaskCreate_Impl (pthread_t *thr, const char *thread_name, uint32 priority, size_t stacksz, PthreadFuncPtr_t Entry, void *entry_arg);
36 changes: 33 additions & 3 deletions src/os/posix/osapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = { { 0, NULL } };
static void OS_CompAbsDelayTime( uint32 milli_second , struct timespec * tm);
static int OS_PriorityRemap(uint32 InputPri);

#ifdef OS_HAVE_PTHREAD_SETNAME_NP
extern int pthread_setname_np(pthread_t thread, const char *name);
#endif


/*----------------------------------------------------------------
*
Expand Down Expand Up @@ -734,7 +738,9 @@ int32 OS_Posix_TaskAPI_Impl_Init(void)
* Purpose: Local helper routine, not part of OSAL API.
*
*-----------------------------------------------------------------*/
int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t stacksz, PthreadFuncPtr_t entry, void *entry_arg)
int32 OS_Posix_InternalTaskCreate_Impl(
pthread_t *pthr, const char* thread_name, uint32 priority, size_t stacksz,
PthreadFuncPtr_t entry, void *entry_arg)
{
int return_code = 0;
pthread_attr_t custom_attr;
Expand Down Expand Up @@ -830,6 +836,20 @@ int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t
return(OS_ERROR);
}

/*
** Set the thread name through the POSIX API to allow for visibility in OS
** utilities
*/

#ifdef OS_HAVE_PTHREAD_SETNAME_NP
return_code = pthread_setname_np(*pthr, thread_name);

if (return_code != 0)
{
OS_DEBUG("pthread_setname_np error in OS_TaskCreate: %s\n",strerror(return_code));
}
#endif

/*
** Free the resources that are no longer needed
** Since the task is now running - pthread_create() was successful -
Expand Down Expand Up @@ -870,6 +890,7 @@ int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags)

return_code = OS_Posix_InternalTaskCreate_Impl(
&OS_impl_task_table[task_id].id,
OS_task_table[task_id].task_name,
OS_task_table[task_id].priority,
OS_task_table[task_id].stack_size,
OS_PthreadTaskEntry,
Expand Down Expand Up @@ -2470,6 +2491,8 @@ int32 OS_ConsoleCreate_Impl(uint32 local_id)
OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id];
pthread_t consoletask;
int32 return_code;
char console_name[OS_MAX_API_NAME];

OS_U32ValueWrapper_t local_arg = { 0 };

if (local_id == 0)
Expand All @@ -2487,8 +2510,15 @@ int32 OS_ConsoleCreate_Impl(uint32 local_id)
else
{
local_arg.value = local_id;
return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, 0,
OS_ConsoleTask_Entry, local_arg.opaque_arg);

/*
** Construct the console task name:
** The name will consist of "console.{console local id}"
*/
snprintf(console_name, sizeof(console_name), "console.%d", local_id);

return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, console_name,
OS_CONSOLE_TASK_PRIORITY, 0, OS_ConsoleTask_Entry, local_arg.opaque_arg);

if (return_code != OS_SUCCESS)
{
Expand Down
11 changes: 9 additions & 2 deletions src/os/posix/ostimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id)
OS_impl_timebase_internal_record_t *local;
OS_common_record_t *global;
OS_U32ValueWrapper_t arg;

char timer_name[OS_MAX_API_NAME];

local = &OS_impl_timebase_table[timer_id];
global = &OS_global_timebase_table[timer_id];
Expand All @@ -368,7 +368,14 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id)
*/
arg.opaque_arg = NULL;
arg.value = global->active_id;
return_code = OS_Posix_InternalTaskCreate_Impl(&local->handler_thread, 0, 0, OS_TimeBasePthreadEntry, arg.opaque_arg);

/*
** Construct the timer thread name:
** The name will consist of "timer.{timer id}"
*/
snprintf(timer_name, sizeof(timer_name), "timer.%d", timer_id);

return_code = OS_Posix_InternalTaskCreate_Impl(&local->handler_thread, timer_name, 0, 0, OS_TimeBasePthreadEntry, arg.opaque_arg);
if (return_code != OS_SUCCESS)
{
return return_code;
Expand Down