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

Hygenic tracing hooks #1085

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
129 changes: 128 additions & 1 deletion include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,13 @@
#define traceCREATE_COUNTING_SEMAPHORE()
#endif

#ifndef traceCREATE_COUNTING_SEMAPHORE_EXT

/* Extended version of traceCREATE_COUNTING_SEMAPHORE that also exposes the queue
* handle after the initial count has been set */
#define traceCREATE_COUNTING_SEMAPHORE_EXT( xHandle ) traceCREATE_COUNTING_SEMAPHORE()
#endif

#ifndef traceCREATE_COUNTING_SEMAPHORE_FAILED
#define traceCREATE_COUNTING_SEMAPHORE_FAILED()
#endif
Expand All @@ -769,10 +776,24 @@
#define traceQUEUE_SEND( pxQueue )
#endif

#ifndef traceQUEUE_SEND_EXT

/* Extended version of traceQUEUE_SEND that also reports the copy position
* of the sent data. */
#define traceQUEUE_SEND_EXT( pxQueue, xCopyPosition ) traceQUEUE_SEND( pxQueue )
#endif

#ifndef traceQUEUE_SEND_FAILED
#define traceQUEUE_SEND_FAILED( pxQueue )
#endif

#ifndef traceQUEUE_SEND_FAILED_EXT

/* Extended version of traceQUEUE_SEND_FAILED that also reports the requested
* copy position of the sent data. */
#define traceQUEUE_SEND_FAILED_EXT( pxQueue, xCopyPosition ) traceQUEUE_SEND_FAILED( pxQueue )
#endif

#ifndef traceQUEUE_RECEIVE
#define traceQUEUE_RECEIVE( pxQueue )
#endif
Expand All @@ -797,10 +818,24 @@
#define traceQUEUE_SEND_FROM_ISR( pxQueue )
#endif

#ifndef traceQUEUE_SEND_FROM_ISR_EXT

/* Extended version of traceQUEUE_SEND_FROM_ISR that also reports the copy
* position of the sent data. */
#define traceQUEUE_SEND_FROM_ISR_EXT( pxQueue, xCopyPosition ) traceQUEUE_SEND_FROM_ISR( pxQueue )
#endif

#ifndef traceQUEUE_SEND_FROM_ISR_FAILED
#define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue )
#endif

#ifndef traceQUEUE_SEND_FROM_ISR_FAILED_EXT

/* Extended version of traceQUEUE_SEND_FROM_ISR_FAILED that also reports the requested
* copy position of the sent data. */
#define traceQUEUE_SEND_FROM_ISR_FAILED_EXT( pxQueue, xCopyPosition ) traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue )
#endif

#ifndef traceQUEUE_RECEIVE_FROM_ISR
#define traceQUEUE_RECEIVE_FROM_ISR( pxQueue )
#endif
Expand All @@ -813,6 +848,14 @@
#define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue )
#endif

#ifndef traceQUEUE_RESET
#define traceQUEUE_RESET( pxQueue, xNewQueue )
#endif

#ifndef traceQUEUE_RESET_FAILED
#define traceQUEUE_RESET_FAILED( pxQueue, xNewQueue )
#endif

#ifndef traceQUEUE_DELETE
#define traceQUEUE_DELETE( pxQueue )
#endif
Expand All @@ -830,13 +873,20 @@
#endif

#ifndef traceTASK_DELAY_UNTIL
#define traceTASK_DELAY_UNTIL( x )
#define traceTASK_DELAY_UNTIL( xTimeToWake )
#endif

#ifndef traceTASK_DELAY
#define traceTASK_DELAY()
#endif

#ifndef traceTASK_DELAY_EXT

/* Extended version of traceTASK_DELAY that also exposes the number of ticks
* to delay for. */
#define traceTASK_DELAY_EXT( xTicksToDelay ) traceTASK_DELAY()
#endif

#ifndef traceTASK_PRIORITY_SET
#define traceTASK_PRIORITY_SET( pxTask, uxNewPriority )
#endif
Expand Down Expand Up @@ -949,6 +999,23 @@
#define traceTASK_NOTIFY_TAKE( uxIndexToWait )
#endif

#ifndef traceTASK_NOTIFY_TAKE_EXT

/* Extended version of traceTASK_NOTIFY_TAKE that also exposes value of
* xClearCountOnExit, informing the tracer of the state of this task
* notification after it has been taken. Note that this hook, unlike traceTASK_NOTIFY_TAKE,
* is only called if the notification was successfully taken. */
#define traceTASK_NOTIFY_TAKE_EXT( uxIndexToWait, xClearCountOnExit ) traceTASK_NOTIFY_TAKE( uxIndexToWait )
#endif

#ifndef traceTASK_NOTIFY_TAKE_FAILED

/* Task notification take failed. For backwards-compatability, this macro falls
* back on traceTASK_NOTIFY_TAKE which was always called, no matter if
* successfull or not. */
#define traceTASK_NOTIFY_TAKE_FAILED( uxIndexToWait ) traceTASK_NOTIFY_TAKE( uxIndexToWait )
#endif

#ifndef traceTASK_NOTIFY_WAIT_BLOCK
#define traceTASK_NOTIFY_WAIT_BLOCK( uxIndexToWait )
#endif
Expand All @@ -957,18 +1024,66 @@
#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

#ifndef traceTASK_NOTIFY_EXT

/* Extended version of traceTASK_NOTIFY that also exposes the task being
* notified, and if/how the notification value was modified. */
#define traceTASK_NOTIFY_EXT( pxTCB, uxIndexToNotify, eAction, xReturn ) traceTASK_NOTIFY( uxIndexToNotify )
#endif

#ifndef traceTASK_NOTIFY_FROM_ISR
#define traceTASK_NOTIFY_FROM_ISR( uxIndexToNotify )
#endif

#ifndef traceTASK_NOTIFY_FROM_ISR_EXT

/* Extended version of traceTASK_NOTIFY_FROM_ISR that also exposes the task
* being notified, and if/how the notification value was modified. */
#define traceTASK_NOTIFY_FROM_ISR_EXT( pxTCB, uxIndexToNotify, eAction, xReturn ) traceTASK_NOTIFY_FROM_ISR( uxIndexToNotify )
#endif

#ifndef traceTASK_NOTIFY_GIVE_FROM_ISR
#define traceTASK_NOTIFY_GIVE_FROM_ISR( uxIndexToNotify )
#endif

#ifndef traceTASK_NOTIFY_GIVE_FROM_ISR_EXT

/* Extended version of traceTASK_NOTIFY_GIVE_FROM_ISR that also exposes the task
* being notified. */
#define traceTASK_NOTIFY_GIVE_FROM_ISR_EXT( pxTCB, uxIndexToNotify ) traceTASK_NOTIFY_GIVE_FROM_ISR( uxIndexToNotify )
#endif

#ifndef traceTASK_NOTIFY_STATE_CLEAR
#define traceTASK_NOTIFY_STATE_CLEAR( pxTCB, uxIndexToNotify )
#endif

#ifndef traceTASK_NOTIFY_VALUE_CLEAR
#define traceTASK_NOTIFY_VALUE_CLEAR( pxTCB, uxIndexToNotify, ulBitsToClear )
#endif

#ifndef traceISR_EXIT_TO_SCHEDULER
#define traceISR_EXIT_TO_SCHEDULER()
#endif
Expand Down Expand Up @@ -1037,6 +1152,18 @@
#define traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength )
#endif

#ifndef traceSTREAM_BUFFER_SET_TRIGGER_LEVEL
#define traceSTREAM_BUFFER_SET_TRIGGER_LEVEL( xStreamBuffer, xTriggerLevel )
#endif

#ifndef traceSTREAM_BUFFER_SET_TRIGGER_LEVEL_FAILED
#define traceSTREAM_BUFFER_SET_TRIGGER_LEVEL_FAILED( xStreamBuffer )
#endif

#ifndef traceSTREAM_BUFFER_SET_NOTIFICATION_INDEX
#define traceSTREAM_BUFFER_SET_NOTIFICATION_INDEX( xStreamBuffer, uxNotificationIndex )
#endif

#ifndef traceENTER_xEventGroupCreateStatic
#define traceENTER_xEventGroupCreateStatic( pxEventGroupBuffer )
#endif
Expand Down
22 changes: 13 additions & 9 deletions queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,14 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
}
}
taskEXIT_CRITICAL();

traceQUEUE_RESET( pxQueue, xNewQueue );
}
else
{
xReturn = pdFAIL;

traceQUEUE_RESET_FAILED( pxQueue, xNewQueue );
}

configASSERT( xReturn != pdFAIL );
Expand Down Expand Up @@ -876,7 +880,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
{
( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount;

traceCREATE_COUNTING_SEMAPHORE();
traceCREATE_COUNTING_SEMAPHORE_EXT( xHandle );
}
else
{
Expand Down Expand Up @@ -915,7 +919,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
{
( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount;

traceCREATE_COUNTING_SEMAPHORE();
traceCREATE_COUNTING_SEMAPHORE_EXT( xHandle );
}
else
{
Expand Down Expand Up @@ -966,7 +970,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
* queue is full. */
if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
{
traceQUEUE_SEND( pxQueue );
traceQUEUE_SEND_EXT( pxQueue, xCopyPosition );

#if ( configUSE_QUEUE_SETS == 1 )
{
Expand Down Expand Up @@ -1080,7 +1084,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,

/* Return to the original privilege level before exiting
* the function. */
traceQUEUE_SEND_FAILED( pxQueue );
traceQUEUE_SEND_FAILED_EXT( pxQueue, xCopyPosition );
traceRETURN_xQueueGenericSend( errQUEUE_FULL );

return errQUEUE_FULL;
Expand Down Expand Up @@ -1145,7 +1149,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
prvUnlockQueue( pxQueue );
( void ) xTaskResumeAll();

traceQUEUE_SEND_FAILED( pxQueue );
traceQUEUE_SEND_FAILED_EXT( pxQueue, xCopyPosition );
traceRETURN_xQueueGenericSend( errQUEUE_FULL );

return errQUEUE_FULL;
Expand Down Expand Up @@ -1200,7 +1204,7 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
const int8_t cTxLock = pxQueue->cTxLock;
const UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting;

traceQUEUE_SEND_FROM_ISR( pxQueue );
traceQUEUE_SEND_FROM_ISR_EXT( pxQueue, xCopyPosition );

/* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a
* semaphore or mutex. That means prvCopyDataToQueue() cannot result
Expand Down Expand Up @@ -1314,7 +1318,7 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
}
else
{
traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );
traceQUEUE_SEND_FROM_ISR_FAILED_EXT( pxQueue, xCopyPosition );
xReturn = errQUEUE_FULL;
}
}
Expand Down Expand Up @@ -1382,7 +1386,7 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
{
const int8_t cTxLock = pxQueue->cTxLock;

traceQUEUE_SEND_FROM_ISR( pxQueue );
traceQUEUE_SEND_FROM_ISR_EXT( pxQueue, queueSEND_TO_BACK );

/* A task can only have an inherited priority if it is a mutex
* holder - and if there is a mutex holder then the mutex cannot be
Expand Down Expand Up @@ -1487,7 +1491,7 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
}
else
{
traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );
traceQUEUE_SEND_FROM_ISR_FAILED_EXT( pxQueue, xCopyPosition );
xReturn = errQUEUE_FULL;
}
}
Expand Down
4 changes: 4 additions & 0 deletions stream_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,11 +737,13 @@ BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer,
* buffer before a task that is waiting for data is unblocked. */
if( xTriggerLevel < pxStreamBuffer->xLength )
{
traceSTREAM_BUFFER_SET_TRIGGER_LEVEL( xStreamBuffer, xTriggerLevel );
pxStreamBuffer->xTriggerLevelBytes = xTriggerLevel;
xReturn = pdPASS;
}
else
{
traceSTREAM_BUFFER_SET_TRIGGER_LEVEL_FAILED( xStreamBuffer );
xReturn = pdFALSE;
}

Expand Down Expand Up @@ -1662,6 +1664,8 @@ void vStreamBufferSetStreamBufferNotificationIndex( StreamBufferHandle_t xStream
/* Check that the task notification index is valid. */
configASSERT( uxNotificationIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES );

traceSTREAM_BUFFER_SET_NOTIFICATION_INDEX( xStreamBuffer, uxNotificationIndex );

pxStreamBuffer->uxNotificationIndex = uxNotificationIndex;

traceRETURN_vStreamBufferSetStreamBufferNotificationIndex();
Expand Down
Loading
Loading