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

FreeRTOS: add mutex hold count to task status info (IDFGH-3762) #5682

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dexterbg
Copy link

@dexterbg dexterbg commented Aug 2, 2020

This change enables applications to track down and debug stuck mutex priority inheritance and missing mutex release issues.

If uxCurrentPriority != uxBasePriority and uxMutexesHeld > 0, the task has taken a mutex which was then required by a higher priority task. That's normal FreeRTOS mutex priority inheritance, but should only occur temporarily. If uxMutexesHeld continues rising, the application has a bug in mutex management.

@CLAassistant
Copy link

CLAassistant commented Aug 2, 2020

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot changed the title FreeRTOS: add mutex hold count to task status info FreeRTOS: add mutex hold count to task status info (IDFGH-3762) Aug 2, 2020
@Alvin1Zhang
Copy link
Collaborator

Thanks for your contribution.

Copy link

@uLipe uLipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dexterbg , thanks for your contribution, Mutex debug utilities are always welcome :)

I just left a small minor comment, otherwise, LGTM.

@@ -181,6 +181,7 @@ typedef struct xTASK_STATUS
eTaskState eCurrentState; /*!< The state in which the task existed when the structure was populated. */
UBaseType_t uxCurrentPriority; /*!< The priority at which the task was running (may be inherited) when the structure was populated. */
UBaseType_t uxBasePriority; /*!< The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
UBaseType_t uxMutexesHeld; /*!< The number of mutexes currently held by the task. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dexterbg , could you please put this field around a configUSE_MUTEXES ifdef? Since this is more a debug feature, release applications may not use it, and it could be good to save more memory as possible on the TCBs.

@dexterbg
Copy link
Author

dexterbg commented Aug 7, 2020

@uLipe I would already have done so, if uxBasePriority was conditional. Why isn't it? Shall I include it in the ifdef?

@uLipe
Copy link

uLipe commented Aug 10, 2020

@dexterbg , the uxBasePriority were used to stuff related to the SMP and priority changing functions besides the mutex priority inheritance algorithm. So even if mutexes are not actually being used, these functions needs of this TCB field if I'm not missing something.

@dexterbg
Copy link
Author

@uLipe Take a look at the TCB definition:
https://github.com/espressif/esp-idf/blob/master/components/freertos/tasks.c#L192

There is no uxBasePriority even in the TCB without configUSE_MUTEXES. My assumption would be, this condition has been forgotten on the initial inclusion of uxBasePriority into struct xTASK_STATUS.

@uLipe
Copy link

uLipe commented Aug 11, 2020

@dexterbg , I was also afraid this was left behind to its usage by espcoredump component (which currently has very strict rules about data structure size and depends on freertos tasks).

After looking better, the implementation, leaving both fields without #ifdef will keep the freertos code close of the upstream version, so please just ignore my suggestion.

Thanks again for your contribution

@espressif-bot espressif-bot added the Status: Opened Issue is new label Mar 9, 2022
@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development and removed Status: Opened Issue is new labels Mar 1, 2023
@espressif-bot espressif-bot added Status: Opened Issue is new and removed Status: Selected for Development Issue is selected for development labels Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants