Getting more information on task status

I am using FreeRTOS 10.3.1 but happy to upgrade to a later version if it helps. For diagnostic purposes, my application includes a facility to list all the running tasks with their states, and list all mutexes and their owners. However, the information provided by vTaskGetInfo isn’t adequate. In particular, if a task is not running or ready, it is always reported as “blocked”. What I need to know is whether it is waiting to be notified, or waiting on a mutex, or delaying; and if it is waiting on a mutex, the address of that mutex (from which I can get its identity, because we derive our own C++ Mutex class from StaticSemaphore_t).

Before I add an additional API function to FreeRTOS, are there any existing API functions I have missed that can provide some or all of this information?

One simple improvement that I think could be made is for vTaskGetInfo to return a new status value instead of “blocked” if the ucNotifyState field of the task being queried is taskWAITING_NOTIFICATION.

Some kernel aware plug-ins will give you the address of an object on which a task is blocked, but there is no way of knowing what that object is without having a registry of each created object - and that is exactly what is done for queues and semaphores. It is a little crude but the queue registry (semaphores are basically the same so can also be added to the registry) allows users to assign a human readable text name to each queue and semaphore - and then one a debugger has worked out which object the task is blocked on it looks that object up in the registry and displays the text name. There is no equivalent for task notifications, event groups or stream/message buffers though. https://www.freertos.org/vQueueAddToRegistry.html

That also leaves you to work out which object a task is blocked on, and that requires you to travers pointers, so it is not something you can do outside of tasks.c as the data structures are deliberately private to that file. There is however a mechanism for users to add their own code into tasks.c as can be seen here: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/V10.4.3/tasks.c#L5384 Let me know if you want to have a go at that and I can talk you through it here - although maybe this is something we should add as a standard feature?

Hi Richard, thanks for your reply.

We already have a “registry” of all mutexes. We derive our own C++ Mutex class from StaticSemaphore_t so that we can add ‘name’ and ‘next’ fields. When creating them, we provide the name and add them to a linked list. This allows us to traverse the list and display the mutex owners in our diagnostics. It also means that if we can get a pointer to the StaticSemaphore_t that a task is waiting on, we will be able to retrieve the name. The code is at RRFLibraries/src/RTOSIface at 3.3-dev · Duet3D/RRFLibraries · GitHub.

Thanks for the info about the “freertos_tasks_c_additions.h” file. I will use that to add the functionality that we need.

Just a note that we have now implemented this. We added our own version of vTaskGetInfo to return different status values for waiting for task notification, waiting for a resource (in which case we also pass back a pointer to the resource), and just delaying. Then we added a version of xTaskGetState that also returns this additional information. The code is at FreeRTOS/freertos_tasks_c_additions.h at 3.3-dev · Duet3D/FreeRTOS · GitHub. Thanks again to Richard for making it so easy to add!