From 5ae12c4ef87c8e3b50df79ff6e7e27d13ac70218 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 23 Oct 2020 17:57:41 -0400 Subject: [PATCH 1/5] Fix #199, set kernel task name for OSAL tasks Use event callback mechanism to invoke pthread_setname_np() such that the OS kernel is informed of the OSAL task name. --- fsw/pc-linux/CMakeLists.txt | 6 +++++ fsw/pc-linux/src/cfe_psp_start.c | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/fsw/pc-linux/CMakeLists.txt b/fsw/pc-linux/CMakeLists.txt index c89361a7..0a5aed0a 100644 --- a/fsw/pc-linux/CMakeLists.txt +++ b/fsw/pc-linux/CMakeLists.txt @@ -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 +) \ No newline at end of file diff --git a/fsw/pc-linux/src/cfe_psp_start.c b/fsw/pc-linux/src/cfe_psp_start.c index 6338b411..4166ca8d 100644 --- a/fsw/pc-linux/src/cfe_psp_start.c +++ b/fsw/pc-linux/src/cfe_psp_start.c @@ -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() @@ -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 */ From 99740d1fc34a1dc8e85d2bfac100ac79b04c0b00 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 28 Oct 2020 11:58:27 -0400 Subject: [PATCH 2/5] Update #199, limit kernel name length --- fsw/pc-linux/src/cfe_psp_start.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fsw/pc-linux/src/cfe_psp_start.c b/fsw/pc-linux/src/cfe_psp_start.c index 4166ca8d..f6330d46 100644 --- a/fsw/pc-linux/src/cfe_psp_start.c +++ b/fsw/pc-linux/src/cfe_psp_start.c @@ -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 */ @@ -170,6 +176,16 @@ int32 CFE_PSP_OS_EventHandler(OS_Event_t event, osal_id_t object_id, void *data) /* 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; From b975264efa014b0580f442407d511338ef8e6931 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 3 Nov 2020 12:02:57 -0500 Subject: [PATCH 3/5] HOTFIX IC 2020-10-28, move variable declaration --- fsw/pc-linux/src/cfe_psp_start.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fsw/pc-linux/src/cfe_psp_start.c b/fsw/pc-linux/src/cfe_psp_start.c index f6330d46..3e512ba6 100644 --- a/fsw/pc-linux/src/cfe_psp_start.c +++ b/fsw/pc-linux/src/cfe_psp_start.c @@ -157,6 +157,8 @@ static const struct option longOpts[] = { */ int32 CFE_PSP_OS_EventHandler(OS_Event_t event, osal_id_t object_id, void *data) { + char taskname[OS_MAX_API_NAME]; + switch(event) { case OS_EVENT_RESOURCE_ALLOCATED: @@ -170,8 +172,6 @@ int32 CFE_PSP_OS_EventHandler(OS_Event_t event, osal_id_t object_id, void *data) 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) From 7a7fadebb37a3dd63951b6c383b73fd485b0fcde Mon Sep 17 00:00:00 2001 From: astrogeco <59618057+astrogeco@users.noreply.github.com> Date: Tue, 3 Nov 2020 20:00:09 -0500 Subject: [PATCH 4/5] Set REVISION to "99" to indicate development version Indicate unreleased development version by setting revision number to 99 to match cfe and osal. See nasa/cfe#853 --- fsw/mcp750-vxworks/inc/psp_version.h | 2 +- fsw/pc-linux/inc/psp_version.h | 2 +- fsw/pc-rtems/inc/psp_version.h | 33 ++++++++++++++-------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/fsw/mcp750-vxworks/inc/psp_version.h b/fsw/mcp750-vxworks/inc/psp_version.h index c46deb7e..77637df6 100644 --- a/fsw/mcp750-vxworks/inc/psp_version.h +++ b/fsw/mcp750-vxworks/inc/psp_version.h @@ -38,7 +38,7 @@ #define CFE_PSP_IMPL_MAJOR_VERSION 1 /*!< @brief ONLY APPLY for OFFICIAL releases. Major version number. */ #define CFE_PSP_IMPL_MINOR_VERSION 4 /*!< @brief ONLY APPLY for OFFICIAL releases. Minor version number. */ #define CFE_PSP_IMPL_REVISION 0 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision number. */ -#define CFE_PSP_IMPL_MISSION_REV 0 /*!< @brief ONLY USED by MISSION Implementations. Mission revision */ +#define CFE_PSP_IMPL_MISSION_REV 99 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision version number. A value of "99" indicates an unreleased development version. */ /* * Tools to construct version string diff --git a/fsw/pc-linux/inc/psp_version.h b/fsw/pc-linux/inc/psp_version.h index e4e195c5..19ca98bc 100644 --- a/fsw/pc-linux/inc/psp_version.h +++ b/fsw/pc-linux/inc/psp_version.h @@ -38,7 +38,7 @@ #define CFE_PSP_IMPL_MAJOR_VERSION 1 /*!< @brief ONLY APPLY for OFFICIAL releases. Major version number. */ #define CFE_PSP_IMPL_MINOR_VERSION 4 /*!< @brief ONLY APPLY for OFFICIAL releases. Minor version number. */ #define CFE_PSP_IMPL_REVISION 0 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision number. */ -#define CFE_PSP_IMPL_MISSION_REV 0 /*!< @brief ONLY USED by MISSION Implementations. Mission revision */ +#define CFE_PSP_IMPL_MISSION_REV 99 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision version number. A value of "99" indicates an unreleased development version. */ /* * Tools to construct version string diff --git a/fsw/pc-rtems/inc/psp_version.h b/fsw/pc-rtems/inc/psp_version.h index 79c2a709..c0fd7e69 100644 --- a/fsw/pc-rtems/inc/psp_version.h +++ b/fsw/pc-rtems/inc/psp_version.h @@ -19,17 +19,17 @@ */ /*! @file pc-rtems/inc/psp_version.h - * @brief Purpose: - * @details Provide version identifiers for the cFE Platform Support Packages (PSP). + * @brief Purpose: + * @details Provide version identifiers for the cFE Platform Support Packages (PSP). * See @ref cfsversions for version and build number and description */ #ifndef _psp_version_ #define _psp_version_ /* - * Development Build Macro Definitions + * Development Build Macro Definitions */ -#define CFE_PSP_IMPL_BUILD_NUMBER 24 +#define CFE_PSP_IMPL_BUILD_NUMBER 24 #define CFE_PSP_IMPL_BUILD_BASELINE "v1.5.0-rc1" /* @@ -38,26 +38,27 @@ #define CFE_PSP_IMPL_MAJOR_VERSION 1 /*!< @brief ONLY APPLY for OFFICIAL releases. Major version number. */ #define CFE_PSP_IMPL_MINOR_VERSION 4 /*!< @brief ONLY APPLY for OFFICIAL releases. Minor version number. */ #define CFE_PSP_IMPL_REVISION 0 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision number. */ -#define CFE_PSP_IMPL_MISSION_REV 0 /*!< @brief ONLY USED by MISSION Implementations. Mission revision */ +#define CFE_PSP_IMPL_MISSION_REV 99 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision version number. A value of "99" indicates an unreleased development version. */ /* * Tools to construct version string - */ -#define CFE_PSP_IMPL_STR_HELPER(x) #x /*!< @brief Helper function to concatenate strings from integer */ -#define CFE_PSP_IMPL_STR(x) CFE_PSP_IMPL_STR_HELPER(x) /*!< @brief Helper function to concatenate strings from integer */ + */ +#define CFE_PSP_IMPL_STR_HELPER(x) #x /*!< @brief Helper function to concatenate strings from integer */ +#define CFE_PSP_IMPL_STR(x) \ + CFE_PSP_IMPL_STR_HELPER(x) /*!< @brief Helper function to concatenate strings from integer */ -/*! @brief Development Build Version Number. +/*! @brief Development Build Version Number. * @details Baseline git tag + Number of commits since baseline. @n * See @ref cfsversions for format differences between development and release versions. */ #define CFE_PSP_IMPL_VERSION CFE_PSP_IMPL_BUILD_BASELINE CFE_PSP_IMPL_STR(CFE_PSP_IMPL_BUILD_NUMBER) /*! @brief Development Build Version String. - * @details Reports the current development build's baseline, number, and name. Also includes a note about the latest official version. @n - * See @ref cfsversions for format differences between development and release versions. - */ -#define CFE_PSP_IMPL_VERSION_STRING \ - " PSP DEVELOPMENT BUILD " CFE_PSP_IMPL_VERSION /* Codename for current development */ \ - ", Last Official Release: psp v1.4.0" /* For full support please use this version */ + * @details Reports the current development build's baseline, number, and name. Also includes a note about the latest + * official version. @n See @ref cfsversions for format differences between development and release versions. + */ +#define CFE_PSP_IMPL_VERSION_STRING \ + " PSP DEVELOPMENT BUILD " CFE_PSP_IMPL_VERSION /* Codename for current development */ \ + ", Last Official Release: psp v1.4.0" /* For full support please use this version */ -#endif /* _psp_version_ */ +#endif /* _psp_version_ */ From a3c9fc656cf4d2159824a92a0556aa6c733341b3 Mon Sep 17 00:00:00 2001 From: astrogeco <59618057+astrogeco@users.noreply.github.com> Date: Tue, 3 Nov 2020 20:08:30 -0500 Subject: [PATCH 5/5] Bump to v1.5.0-rc1+dev30 and update ReadMe --- README.md | 6 ++++++ fsw/mcp750-vxworks/inc/psp_version.h | 2 +- fsw/pc-linux/inc/psp_version.h | 2 +- fsw/pc-rtems/inc/psp_version.h | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 25df34ca..0aaf49e6 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,12 @@ This is a collection of APIs abstracting platform specific functionality to be l ## Version History +### Development Build: 1.5.0-rc1+dev30 + +- PR #212 - Use event callback mechanism to invoke pthread_setname_np() such that the OS kernel is informed of the OSAL task name. `/proc` filesystem on Linux now has actual task name, instead of all being core-cpu1. The `pthread_setname_np` API requires `_GNU_SOURCE` to be defined when compiling - this can be local to PSP. +- Set REVISION to "99" to indicate development version +- See + ### Development Build: 1.5.0-rc1+dev24 - Improves the module ID lookup when getting the CFE core text segment info. VxWorks PSP should use the real module name, not assume cfe-core.o when getting text segment info diff --git a/fsw/mcp750-vxworks/inc/psp_version.h b/fsw/mcp750-vxworks/inc/psp_version.h index 77637df6..5db350e3 100644 --- a/fsw/mcp750-vxworks/inc/psp_version.h +++ b/fsw/mcp750-vxworks/inc/psp_version.h @@ -29,7 +29,7 @@ /* * Development Build Macro Definitions */ -#define CFE_PSP_IMPL_BUILD_NUMBER 24 +#define CFE_PSP_IMPL_BUILD_NUMBER 30 #define CFE_PSP_IMPL_BUILD_BASELINE "v1.5.0-rc1" /* diff --git a/fsw/pc-linux/inc/psp_version.h b/fsw/pc-linux/inc/psp_version.h index 19ca98bc..7ff37df0 100644 --- a/fsw/pc-linux/inc/psp_version.h +++ b/fsw/pc-linux/inc/psp_version.h @@ -29,7 +29,7 @@ /* * Development Build Macro Definitions */ -#define CFE_PSP_IMPL_BUILD_NUMBER 24 +#define CFE_PSP_IMPL_BUILD_NUMBER 30 #define CFE_PSP_IMPL_BUILD_BASELINE "v1.5.0-rc1" /* diff --git a/fsw/pc-rtems/inc/psp_version.h b/fsw/pc-rtems/inc/psp_version.h index c0fd7e69..535e4fe9 100644 --- a/fsw/pc-rtems/inc/psp_version.h +++ b/fsw/pc-rtems/inc/psp_version.h @@ -29,7 +29,7 @@ /* * Development Build Macro Definitions */ -#define CFE_PSP_IMPL_BUILD_NUMBER 24 +#define CFE_PSP_IMPL_BUILD_NUMBER 30 #define CFE_PSP_IMPL_BUILD_BASELINE "v1.5.0-rc1" /*