From 8c874692636a63f8d58f9a0d5f68cdeb771837a2 Mon Sep 17 00:00:00 2001 From: schilkp Date: Thu, 6 Jun 2024 12:31:02 +0200 Subject: [PATCH] Split traceTASK_NOTIFY_WAIT into _EXT and _FAILED hooks. The old traceTASK_NOTIFY_WAIT hook was always called (no matter the success or failure of the action) and did not hygienically expose enough information for the tracer to determine the state of the task notification after it has been taken. The new traceTASK_NOTIFY_WAIT_EXT hook is called only if the notification was taken successfully and hygienically expose ulBitsToClearOnExit. The new traceTASK_NOTIFY_WAIT_FAILED hook is called if the notification could not be taken. This matches how the tracing hooks for all other APIs that attempt to receive/take a resource and my block function: First, if the task blocks, a BLOCK or BLOCKING trace hook is called. Then, either a normal or FAILED trace hook is called, indicating if the operation timed out or succeeded. Both hooks fall back on the old traceTASK_NOTIFY_WAIT, preserving its functionality for backwards compatibility. Not that there is a very slight breaking change in this commit: traceTASK_NOTIFY_WAIT is now called after the out-var pulNotificationValue is set. Because this pointer was in an unknown/user-set state when the tracing hook was previously called, it is highly unlikely that there are any tracers that rely on this. --- include/FreeRTOS.h | 19 +++++++++++++++++++ tasks.c | 6 ++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index eba66a879..702f25fb7 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -1017,6 +1017,25 @@ #define traceTASK_NOTIFY_WAIT( uxIndexToWait ) #endif +#ifndef traceTASK_NOTIFY_WAIT_EXT + +/* Extended version of traceTASK_NOTIFY_WAIT that also exposes value of + * ulBitsToClearOnExit, informing the tracer of the state of this task + * notification after it has been taken. Note that this hook, unlike + * traceTASK_NOTIFY_WAIT, is only called if the notification was successfully + * taken. */ + #define traceTASK_NOTIFY_WAIT_EXT( uxIndexToWait, ulBitsToClearOnExit ) traceTASK_NOTIFY_WAIT( uxIndexToWait ) +#endif + +#ifndef traceTASK_NOTIFY_WAIT_FAILED + +/* Task notification wait failed. For backwards-compatability, this macro falls + * back on traceTASK_NOTIFY_WAIT which was always called, no matter if + * successfull or not. */ + #define traceTASK_NOTIFY_WAIT_FAILED( uxIndexToWait ) traceTASK_NOTIFY_WAIT( uxIndexToWait ) +#endif + + #ifndef traceTASK_NOTIFY #define traceTASK_NOTIFY( uxIndexToNotify ) #endif diff --git a/tasks.c b/tasks.c index e8387be94..c407bf8e9 100644 --- a/tasks.c +++ b/tasks.c @@ -7741,6 +7741,8 @@ TickType_t uxTaskResetEventItemValue( void ) /* Only block if a notification is not already pending. */ if( pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] != taskNOTIFICATION_RECEIVED ) { + traceTASK_NOTIFY_VALUE_CLEAR( pxCurrentTCB, uxIndexToWaitOn, ulBitsToClearOnEntry ); + /* Clear bits in the task's notification value as bits may get * set by the notifying task or interrupt. This can be used * to clear the value to zero. */ @@ -7792,8 +7794,6 @@ TickType_t uxTaskResetEventItemValue( void ) taskENTER_CRITICAL(); { - traceTASK_NOTIFY_WAIT( uxIndexToWaitOn ); - if( pulNotificationValue != NULL ) { /* Output the current notification value, which may or may not @@ -7808,12 +7808,14 @@ TickType_t uxTaskResetEventItemValue( void ) if( pxCurrentTCB->ucNotifyState[ uxIndexToWaitOn ] != taskNOTIFICATION_RECEIVED ) { /* A notification was not received. */ + traceTASK_NOTIFY_WAIT_FAILED( uxIndexToWaitOn ); xReturn = pdFALSE; } else { /* A notification was already pending or a notification was * received while the task was waiting. */ + traceTASK_NOTIFY_WAIT_EXT( uxIndexToWaitOn, ulBitsToClearOnExit ); pxCurrentTCB->ulNotifiedValue[ uxIndexToWaitOn ] &= ~ulBitsToClearOnExit; xReturn = pdTRUE; }