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
Introduce configTRACK_TASK_MEMORY_ALLOCATIONS to track dynamic allocations per task #353
base: main
Are you sure you want to change the base?
Introduce configTRACK_TASK_MEMORY_ALLOCATIONS to track dynamic allocations per task #353
Conversation
…and either heap_4 or heap_5 is used then the number of dynamic memory allocations, the number of dynamic memory frees, the total amount of heap memory allocated by a task but not yet freed (by any task), and the maximum amount of heap memory a task has ever had allocated at one time are all tracked on a task by task basis. This additional information is returned in the TaskStatus_t structure populated by the vTaskGetInfo() and the uxTaskGetSystemState() API functions. uxBasePriority is now only included in the TaskStatus_t structure if configUSE_MUTEXES is set to 1. ulRunTimeCounter is now only included in the TaskStatus_t structure if configGENERATE_RUN_TIME_STATS is set to 1. Update how the TCB members get initialised. Previously each member was initialised separately. Now, as there are new members, memset() the entire structure to 0 when the structure is allocated, then only explicitly initialise structure members that are not initialised to zero.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #353 +/- ##
=======================================
Coverage 92.15% 92.15%
=======================================
Files 4 4
Lines 1274 1274
Branches 343 343
=======================================
Hits 1174 1174
Misses 53 53
Partials 47 47
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…EMU IAR demos to exercise the function that track memory allocations on a task by task basis as introduced by FreeRTOS/FreeRTOS-Kernel#353.
Spell check is failing because of variable names. Is spell check meant to check the C code, or just the comments? |
Hi @RichardBarry I just checked with team. It looks like the current spell checker checks any line of code with comment. So if a C code line contains a comment it will check the spell of entire line inclduing the code itself. We are look for some more generic spell checker to replace the current one and hopfully can resolve the problem. But I'm going to unblock this PR by adding exclusion of those words for now. |
/bot run checks |
|
||
TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, | ||
const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ | ||
const uint32_t ulSt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like ulTaskGetIdleRunTimePercent() is missing here.
#endif | ||
|
||
#if ( configGENERATE_RUN_TIME_STATS == 1 ) | ||
uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See https://www.FreeRTOS.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ulRunTimeCounter should now have type configRUN_TIME_COUNTER_TYPE so users can use a 64-bit counter if they wish.
|
||
TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, | ||
const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ | ||
const uint32_t ulSt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[edit] This comment should be in xTaskUpdateHeapAllocationStats() where the total heap held gets incremented. I don't think there is a risk to the value overflowing (which the comment says should be impossible under normal control flows anyway), but it might be beneficial to cap to 0xffffffff if that does occur. [/edit]
|
||
TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, | ||
const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ | ||
const uint32_t ulSt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preference is to use "!= pdFALSE", rather than "== pdTRUE" as it can generate more efficient code, especially on devices with a register that is always zero.
|
||
TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, | ||
const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ | ||
const uint32_t ulSt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think there is a risk from underflow of this variable, but perhaps set xHeapBytesCurrentlyAllocated 0 if that occurs.
|
||
TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, | ||
const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ | ||
const uint32_t ulSt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inconsistent and brings in a dependency on limits.h. The previous function defined const uint32_t ulMaxUint32 = 0xffffffffUL; which is preferable to using UINT32_MAX.
I think this work has been done at this point? |
42257f9
to
2d6724e
Compare
Quality Gate failedFailed conditions D Reliability Rating on New Code (required ≥ A) See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
…reeRTOS#353) To avoid silent errors, configNETWORK_INTERFACE_TO_USE should be defaulted to 0L.
Description
Introduce configTRACK_TASK_MEMORY_ALLOCATIONS. When this is set to 1 and either heap_4 or heap_5 is used then the number of dynamic memory allocations, the number of dynamic memory frees, the total amount of heap memory allocated by a task but not yet freed (by any task), and the maximum amount of heap memory a task has ever had allocated at one time are all tracked on a task by task basis. This additional information is returned in the TaskStatus_t structure populated by the vTaskGetInfo() and the uxTaskGetSystemState() API functions.
uxBasePriority is now only included in the TaskStatus_t structure if configUSE_MUTEXES is set to 1. ulRunTimeCounter is now only included in the TaskStatus_t structure if configGENERATE_RUN_TIME_STATS is set to 1.
Update how the TCB members get initialised. Previously each member was initialised separately. Now, as there are new members, memset() the entire structure to 0 when the structure is allocated, then only explicitly initialise structure members that are not initialised to zero.
Test Steps
Add prvExerciseTaskHeapAllocationStats() to the MSVC Win32 and MPS2 QEMU IAR demos - upstreamed to the FreeRTOS/FreeRTOS repo in a separate PR.
Related Issue
The PR that adds prvExerciseTaskHeapAllocationStats() to the FreeRTOS/FreeRTOS repo.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.