Skip to content

Commit

Permalink
Merge pull request #212 from jphickey/fix-199-threadname
Browse files Browse the repository at this point in the history
Fix #199, set kernel task name for OSAL tasks
  • Loading branch information
astrogeco authored Oct 30, 2020
2 parents 7679b37 + 99740d1 commit d381c47
Show file tree
Hide file tree
Showing 2 changed files with 64 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
)
58 changes: 58 additions & 0 deletions fsw/pc-linux/src/cfe_psp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
#define CFE_PSP_CPU_NAME_LENGTH 32
#define CFE_PSP_RESET_NAME_LENGTH 10

/*
* Limits for task name length in kernel (fixed by Linux/glibc)
* For reference see manpage for "pthread_setname_np".
*/
#define CFE_PSP_KERNEL_NAME_LENGTH_MAX 16

/*
** Typedefs for this module
*/
Expand Down Expand Up @@ -141,6 +147,56 @@ 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)
{
/*
* glibc/kernel has an internal limit for this name.
* If the OSAL name is longer, just truncate it.
* Otherwise the name isn't set at all - this assumes the first
* chars of the name is better for debug than none of it.
*/
if (strlen(taskname) >= CFE_PSP_KERNEL_NAME_LENGTH_MAX)
{
taskname[CFE_PSP_KERNEL_NAME_LENGTH_MAX-1] = 0;
}
pthread_setname_np(pthread_self(), taskname);
}
break;
}

default:
break;
}

return OS_SUCCESS;
}

/******************************************************************************
** Function: main()
Expand Down Expand Up @@ -276,6 +332,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 d381c47

Please sign in to comment.