Skip to content

Commit

Permalink
Add traceQUEUE_SEND{_FROM_ISR,}_EXT and traceQUEUE_RESET hooks.
Browse files Browse the repository at this point in the history
The current hooks were not effective at allowing a tracer to track the
number of items in a queue, since it could not differentiate between a
queueOVERWRITE, queueSEND_TO_BACK, and queueSEND_TO_FRONT send, and
could not (efficiently) trace a queue reset.

For sends, this adds extended tracing macros that, if not implemented,
fall back on the original tracing macros for backwards compatibility,
and introduces a new traceQUEUE_RESET hook.

Discussed here: https://forums.freertos.org/t/queue-tracing/20054/4
  • Loading branch information
schilkp committed May 17, 2024
1 parent 0801c91 commit 4dc217d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 16 additions & 0 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,12 @@
#define traceQUEUE_SET_SEND traceQUEUE_SEND
#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
#define traceQUEUE_SEND( pxQueue )
#endif
Expand Down Expand Up @@ -793,6 +799,12 @@
#define traceQUEUE_RECEIVE_FAILED( 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
#define traceQUEUE_SEND_FROM_ISR( pxQueue )
#endif
Expand All @@ -813,6 +825,10 @@
#define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue )
#endif

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

#ifndef traceQUEUE_DELETE
#define traceQUEUE_DELETE( pxQueue )
#endif
Expand Down
9 changes: 6 additions & 3 deletions queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
/* Check for multiplication overflow. */
( ( SIZE_MAX / pxQueue->uxLength ) >= pxQueue->uxItemSize ) )
{

traceQUEUE_RESET( pxQueue, xNewQueue );

taskENTER_CRITICAL();
{
pxQueue->u.xQueue.pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize );
Expand Down Expand Up @@ -966,7 +969,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 @@ -1200,7 +1203,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 @@ -1382,7 +1385,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

0 comments on commit 4dc217d

Please sign in to comment.