Skip to content

Commit

Permalink
Fix nasa#199, set kernel task name for OSAL tasks
Browse files Browse the repository at this point in the history
Use event callback mechanism to invoke pthread_setname_np() such
that the OS kernel is informed of the OSAL task name.
  • Loading branch information
jphickey committed Oct 23, 2020
1 parent 7679b37 commit 5ae12c4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fsw/pc-linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ add_library(psp-${CFE_PSP_TARGETNAME}-impl OBJECT
src/cfe_psp_timer.c
src/cfe_psp_watchdog.c)

# The _GNU_SOURCE directive is required to call non-posix APIs
# that are specific to the Linux/glibc environment.
# Code outside the pc-linux PSP should _not_ depend on this.
target_compile_definitions(psp-${CFE_SYSTEM_PSPNAME}-impl PRIVATE
_GNU_SOURCE
)
42 changes: 42 additions & 0 deletions fsw/pc-linux/src/cfe_psp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,46 @@ static const struct option longOpts[] = {
{ NULL, no_argument, NULL, 0 }
};

/******************************************************************************
** Function: CFE_PSP_OS_EventHandler()
**
** Purpose:
** Linux Task creation event handler.
** Sets the kernel task name using a glibc-specific (non-posix) function.
**
*/
int32 CFE_PSP_OS_EventHandler(OS_Event_t event, osal_id_t object_id, void *data)
{
switch(event)
{
case OS_EVENT_RESOURCE_ALLOCATED:
/* resource/id is newly allocated but not yet created. Invoked within locked region. */
break;
case OS_EVENT_RESOURCE_CREATED:
/* resource/id has been fully created/finalized. Invoked outside locked region. */
break;
case OS_EVENT_RESOURCE_DELETED:
/* resource/id has been deleted. Invoked outside locked region. */
break;
case OS_EVENT_TASK_STARTUP:
{
char taskname[OS_MAX_API_NAME];

/* New task is starting. Invoked from within the task context. */
/* Get the name from OSAL and propagate to the pthread/system layer */
if (OS_GetResourceName(object_id, taskname, sizeof(taskname)) == OS_SUCCESS)
{
pthread_setname_np(pthread_self(), taskname);
}
break;
}

default:
break;
}

return OS_SUCCESS;
}

/******************************************************************************
** Function: main()
Expand Down Expand Up @@ -276,6 +316,8 @@ void OS_Application_Startup(void)
CFE_PSP_Panic(Status);
}

OS_RegisterEventHandler(CFE_PSP_OS_EventHandler);

/*
* Map the PSP shared memory segments
*/
Expand Down

0 comments on commit 5ae12c4

Please sign in to comment.