From 59ce4f401beb56ad6257fa96d8e4e3aec14d3a6c Mon Sep 17 00:00:00 2001 From: rtel Date: Fri, 5 Jul 2019 20:21:59 +0000 Subject: [PATCH] Exercise the new vPortGetHeapStats() function from the Win32 demo projects. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2673 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo | Bin 73728 -> 77312 bytes FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h | 3 +- FreeRTOS/Demo/WIN32-MSVC/WIN32.vcxproj | 1 + .../Demo/WIN32-MSVC/WIN32.vcxproj.filters | 3 + FreeRTOS/Demo/WIN32-MSVC/main_full.c | 16 +++- FreeRTOS/Demo/WIN32-MingW/main.c | 81 ++++++++++++++++++ FreeRTOS/Demo/WIN32-MingW/main_full.c | 18 +++- 7 files changed, 113 insertions(+), 9 deletions(-) diff --git a/FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo b/FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo index 7f5848df53f7fad54b9402d24e9b1955ffc3aab4..324972876a6280982943ae5aea8be03b1acfcf91 100644 GIT binary patch delta 5128 zcmc&&4OCRe6`pzQgSY&-D}Sr$Ec00wREL$gFjk!q0jO+PT{22q1bXQkh2+5vr#A z5V-<{R76%&{xG;HOAMNf3i~V<%ONm|AE9^-r6R;E#B2l@cw^8~6x=QL)xfTRkS4Pr zv!c<)8Rh0hHC}u*c=1)|&6nqU0YCHfhOxt=?qQKJ$m%f`v0?Q9h1vBDxXB5bT57 zVo*Sc&pkn~R}TA2vYCC%7I9XRvm($Nqb9WP8o-{al>`9>7pgql!{+EBo^pw{8) zLrekx25N^PUq2a6=!?a;;kT)%9{v%vB`3mZP=Pb@r6?n*Ad86wgE0{3+g=pc`r;pF z_vEknDy`g~1rty~7GRu4Qbp=nS8w|uB~s2G45d>!OmAzqBAF(+OpN4ej-u! zl)IB)nR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FDHi%m!7^~PEqhOJn8))_~a3<<6>3iQug&E)E@_q*g`b0TS5Dl$;LQ@oD zH-~!HtA}{kiwpek8+xzSm1J1hF~-Uz9SToo@(`34?lNdQkP=t1E94_YpPD+{$v?=_HS9Gh3?bI1Frcc>)1V(-C@vm zqi5g{0ql1?+_^Xg&tU2JI+!(kpcB{fO_Rb|UDMeZ)+Th_s9+tN$Fr@x_-vu4iyK + diff --git a/FreeRTOS/Demo/WIN32-MSVC/WIN32.vcxproj.filters b/FreeRTOS/Demo/WIN32-MSVC/WIN32.vcxproj.filters index ae43ea750..0fcb7b740 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/WIN32.vcxproj.filters +++ b/FreeRTOS/Demo/WIN32-MSVC/WIN32.vcxproj.filters @@ -160,6 +160,9 @@ Demo App Source\Full_Demo\Common Demo Tasks + + FreeRTOS Source\Source + diff --git a/FreeRTOS/Demo/WIN32-MSVC/main_full.c b/FreeRTOS/Demo/WIN32-MSVC/main_full.c index 3f19db32e..81d84750c 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/main_full.c +++ b/FreeRTOS/Demo/WIN32-MSVC/main_full.c @@ -245,6 +245,7 @@ static void prvCheckTask( void *pvParameters ) { TickType_t xNextWakeTime; const TickType_t xCycleFrequency = pdMS_TO_TICKS( 4000UL ); +HeapStats_t xHeapStats; /* Just to remove compiler warning. */ ( void ) pvParameters; @@ -370,10 +371,17 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 4000UL ); /* This is the only task that uses stdout so its ok to call printf() directly. */ - printf( "%s - tick count %zu - free heap %zu - min free heap %zu\r\n", pcStatusMessage, - xTaskGetTickCount(), - xPortGetFreeHeapSize(), - xPortGetMinimumEverFreeHeapSize() ); + vPortGetHeapStats( &xHeapStats ); + + configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == xPortGetFreeHeapSize() ); + configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xPortGetMinimumEverFreeHeapSize() ); + + printf( "%s - tick count %zu - free heap %zu - min free heap %zu - largest free block %zu \r\n", + pcStatusMessage, + xTaskGetTickCount(), + xHeapStats.xAvailableHeapSpaceInBytes, + xHeapStats.xMinimumEverFreeBytesRemaining, + xHeapStats.xSizeOfLargestFreeBlockInBytes ); } } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Demo/WIN32-MingW/main.c b/FreeRTOS/Demo/WIN32-MingW/main.c index 2f3b36bfd..2ccf29ac7 100644 --- a/FreeRTOS/Demo/WIN32-MingW/main.c +++ b/FreeRTOS/Demo/WIN32-MingW/main.c @@ -103,6 +103,12 @@ void vFullDemoIdleFunction( void ); */ static void prvInitialiseHeap( void ); +/* + * Performs a few sanity checks on the behaviour of the vPortGetHeapStats() + * function. + */ +static void prvExerciseHeapStats( void ); + /* * Prototypes for the standard FreeRTOS application hook (callback) functions * implemented within this file. See http://www.freertos.org/a00016.html . @@ -344,6 +350,8 @@ offsets into the array - with gaps in between and messy alignment just for test purposes. */ static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; volatile uint32_t ulAdditionalOffset = 19; /* Just to prevent 'condition is always true' warnings in configASSERT(). */ +HeapStats_t xHeapStats; +const HeapStats_t xZeroHeapStats = { 0 }; const HeapRegion_t xHeapRegions[] = { /* Start address with dummy offsets Size */ @@ -360,7 +368,80 @@ const HeapRegion_t xHeapRegions[] = /* Prevent compiler warnings when configASSERT() is not defined. */ ( void ) ulAdditionalOffset; + /* The heap has not been initialised yet so expect stats to all be zero. */ + vPortGetHeapStats( &xHeapStats ); + configASSERT( memcmp( &xHeapStats, &xZeroHeapStats, sizeof( HeapStats_t ) ) == 0 ); + vPortDefineHeapRegions( xHeapRegions ); + + /* Sanity check vTaskGetHeapStats(). */ + prvExerciseHeapStats(); +} +/*-----------------------------------------------------------*/ + +static void prvExerciseHeapStats( void ) +{ +HeapStats_t xHeapStats; +size_t xInitialFreeSpace = xPortGetFreeHeapSize(), xMinimumFreeBytes; +size_t xMetaDataOverhead, i; +void *pvAllocatedBlock; +const size_t xArraySize = 5, xBlockSize = 1000UL; +void *pvAllocatedBlocks[ xArraySize ]; + + /* Check heap stats are as expected after initialisation but before any + allocations. */ + vPortGetHeapStats( &xHeapStats ); + + /* Minimum ever free bytes remaining should be the same as the total number + of bytes as nothing has been allocated yet. */ + configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xHeapStats.xAvailableHeapSpaceInBytes ); + configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xInitialFreeSpace ); + + /* Nothing has been allocated or freed yet. */ + configASSERT( xHeapStats.xNumberOfSuccessfulAllocations == 0 ); + configASSERT( xHeapStats.xNumberOfSuccessfulFrees == 0 ); + + /* Allocate a 1000 byte block then measure what the overhead of the + allocation in regards to how many bytes more than 1000 were actually + removed from the heap in order to store metadata about the allocation. */ + pvAllocatedBlock = pvPortMalloc( xBlockSize ); + configASSERT( pvAllocatedBlock ); + xMetaDataOverhead = ( xInitialFreeSpace - xPortGetFreeHeapSize() ) - xBlockSize; + + /* Free the block again to get back to where we started. */ + vPortFree( pvAllocatedBlock ); + vPortGetHeapStats( &xHeapStats ); + configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == xInitialFreeSpace ); + configASSERT( xHeapStats.xNumberOfSuccessfulAllocations == 1 ); + configASSERT( xHeapStats.xNumberOfSuccessfulFrees == 1 ); + + /* Allocate blocks checking some stats value on each allocation. */ + for( i = 0; i < xArraySize; i++ ) + { + pvAllocatedBlocks[ i ] = pvPortMalloc( xBlockSize ); + configASSERT( pvAllocatedBlocks[ i ] ); + vPortGetHeapStats( &xHeapStats ); + configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == ( xInitialFreeSpace - ( ( i + 1 ) * ( xBlockSize + xMetaDataOverhead ) ) ) ); + configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xHeapStats.xAvailableHeapSpaceInBytes ); + configASSERT( xHeapStats.xNumberOfSuccessfulAllocations == ( 2Ul + i ) ); + configASSERT( xHeapStats.xNumberOfSuccessfulFrees == 1 ); /* Does not increase during allocations. */ + } + + configASSERT( xPortGetFreeHeapSize() == xPortGetMinimumEverFreeHeapSize() ); + xMinimumFreeBytes = xPortGetFreeHeapSize(); + + /* Free the blocks again. */ + for( i = 0; i < xArraySize; i++ ) + { + vPortFree( pvAllocatedBlocks[ i ] ); + vPortGetHeapStats( &xHeapStats ); + configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == ( xInitialFreeSpace - ( ( ( xArraySize - i - 1 ) * ( xBlockSize + xMetaDataOverhead ) ) ) ) ); + configASSERT( xHeapStats.xNumberOfSuccessfulAllocations == ( xArraySize + 1 ) ); /* Does not increase during frees. */ + configASSERT( xHeapStats.xNumberOfSuccessfulFrees == ( 2UL + i ) ); + } + + /* The minimum ever free heap size should not change as blocks are freed. */ + configASSERT( xMinimumFreeBytes == xPortGetMinimumEverFreeHeapSize() ); } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Demo/WIN32-MingW/main_full.c b/FreeRTOS/Demo/WIN32-MingW/main_full.c index 13a66910a..84ae4074e 100644 --- a/FreeRTOS/Demo/WIN32-MingW/main_full.c +++ b/FreeRTOS/Demo/WIN32-MingW/main_full.c @@ -260,6 +260,7 @@ static void prvCheckTask( void *pvParameters ) { TickType_t xNextWakeTime; const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL ); +HeapStats_t xHeapStats; /* Just to remove compiler warning. */ ( void ) pvParameters; @@ -385,10 +386,19 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL ); /* This is the only task that uses stdout so its ok to call printf() directly. */ - printf( "%s - tick count %u - free heap %u - min free heap %u\r\n", pcStatusMessage, - xTaskGetTickCount(), - xPortGetFreeHeapSize(), - xPortGetMinimumEverFreeHeapSize() ); + vPortGetHeapStats( &xHeapStats ); + + configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == xPortGetFreeHeapSize() ); + configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xPortGetMinimumEverFreeHeapSize() ); + + printf( "%s - tick count %u - free heap %u - min free heap %u - largest free block %u - number of free blocks %u\r\n", + pcStatusMessage, + xTaskGetTickCount(), + xHeapStats.xAvailableHeapSpaceInBytes, + xHeapStats.xMinimumEverFreeBytesRemaining, + xHeapStats.xSizeOfLargestFreeBlockInBytes, + xHeapStats.xNumberOfFreeBlocks ); + fflush( stdout ); } } -- 2.39.5