]> git.sur5r.net Git - freertos/commitdiff
Exercise the new vPortGetHeapStats() function from the Win32 demo projects.
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 5 Jul 2019 20:21:59 +0000 (20:21 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 5 Jul 2019 20:21:59 +0000 (20:21 +0000)
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
FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h
FreeRTOS/Demo/WIN32-MSVC/WIN32.vcxproj
FreeRTOS/Demo/WIN32-MSVC/WIN32.vcxproj.filters
FreeRTOS/Demo/WIN32-MSVC/main_full.c
FreeRTOS/Demo/WIN32-MingW/main.c
FreeRTOS/Demo/WIN32-MingW/main_full.c

index 7f5848df53f7fad54b9402d24e9b1955ffc3aab4..324972876a6280982943ae5aea8be03b1acfcf91 100644 (file)
Binary files a/FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo and b/FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo differ
index cc08b5f3f59a7681c618cb7f0b4958f312917ce1..6b98922ee5d2e5b6fa92915cac0de94a6da764eb 100644 (file)
@@ -62,7 +62,8 @@
 #define configUSE_ALTERNATIVE_API                              0\r
 #define configUSE_QUEUE_SETS                                   1\r
 #define configUSE_TASK_NOTIFICATIONS                   1\r
-#define configSUPPORT_STATIC_ALLOCATION                        1\r
+#define configSUPPORT_STATIC_ALLOCATION                        0\r
+#define configSUPPORT_DYNAMIC_ALLOCATION               1\r
 \r
 /* Software timer related configuration options. */\r
 #define configUSE_TIMERS                                               1\r
index 87c034b6e40733bfbfd5e00f41fd9ffacc941dc3..d3531b4667b6e82be12290faf72d41707ed2657a 100644 (file)
@@ -81,6 +81,7 @@
     <ClCompile Include="..\..\Source\event_groups.c" />\r
     <ClCompile Include="..\..\Source\portable\MemMang\heap_5.c" />\r
     <ClCompile Include="..\..\Source\stream_buffer.c" />\r
+    <ClCompile Include="..\..\Source\task_pool.c" />\r
     <ClCompile Include="..\..\Source\timers.c" />\r
     <ClCompile Include="..\Common\Minimal\AbortDelay.c" />\r
     <ClCompile Include="..\Common\Minimal\BlockQ.c" />\r
index ae43ea75080ad22eb06a73ec5ae32bc7c9f6080f..0fcb7b74043716f83c2c9d69cd6ac48ba99ba6ff 100644 (file)
     <ClCompile Include="..\Common\Minimal\MessageBufferAMP.c">\r
       <Filter>Demo App Source\Full_Demo\Common Demo Tasks</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\Source\task_pool.c">\r
+      <Filter>FreeRTOS Source\Source</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="FreeRTOSConfig.h">\r
index 3f19db32e89f18b5d905a58152d28d7f6d821670..81d84750c58cd35b77bc4f83938ebc2c577365e3 100644 (file)
@@ -245,6 +245,7 @@ static void prvCheckTask( void *pvParameters )
 {\r
 TickType_t xNextWakeTime;\r
 const TickType_t xCycleFrequency = pdMS_TO_TICKS( 4000UL );\r
+HeapStats_t xHeapStats;\r
 \r
        /* Just to remove compiler warning. */\r
        ( void ) pvParameters;\r
@@ -370,10 +371,17 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 4000UL );
 \r
                /* This is the only task that uses stdout so its ok to call printf()\r
                directly. */\r
-               printf( "%s - tick count %zu - free heap %zu - min free heap %zu\r\n", pcStatusMessage,\r
-                                                                                                                                                          xTaskGetTickCount(),\r
-                                                                                                                                                          xPortGetFreeHeapSize(),\r
-                                                                                                                                                          xPortGetMinimumEverFreeHeapSize() );\r
+               vPortGetHeapStats( &xHeapStats );\r
+\r
+               configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == xPortGetFreeHeapSize() );\r
+               configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xPortGetMinimumEverFreeHeapSize() );\r
+\r
+               printf( "%s - tick count %zu - free heap %zu - min free heap %zu - largest free block %zu \r\n",\r
+                       pcStatusMessage,\r
+                       xTaskGetTickCount(),\r
+                       xHeapStats.xAvailableHeapSpaceInBytes,\r
+                       xHeapStats.xMinimumEverFreeBytesRemaining,\r
+                       xHeapStats.xSizeOfLargestFreeBlockInBytes );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
index 2f3b36bfdcb261afadad900001e680590ff5c31a..2ccf29ac715c111a7c5bead7c69b0e7675df8973 100644 (file)
@@ -103,6 +103,12 @@ void vFullDemoIdleFunction( void );
  */\r
 static void  prvInitialiseHeap( void );\r
 \r
+/*\r
+ * Performs a few sanity checks on the behaviour of the vPortGetHeapStats()\r
+ * function.\r
+ */\r
+static void prvExerciseHeapStats( void );\r
+\r
 /*\r
  * Prototypes for the standard FreeRTOS application hook (callback) functions\r
  * implemented within this file.  See http://www.freertos.org/a00016.html .\r
@@ -344,6 +350,8 @@ offsets into the array - with gaps in between and messy alignment just for test
 purposes. */\r
 static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];\r
 volatile uint32_t ulAdditionalOffset = 19; /* Just to prevent 'condition is always true' warnings in configASSERT(). */\r
+HeapStats_t xHeapStats;\r
+const HeapStats_t xZeroHeapStats = { 0 };\r
 const HeapRegion_t xHeapRegions[] =\r
 {\r
        /* Start address with dummy offsets                                             Size */\r
@@ -360,7 +368,80 @@ const HeapRegion_t xHeapRegions[] =
        /* Prevent compiler warnings when configASSERT() is not defined. */\r
        ( void ) ulAdditionalOffset;\r
 \r
+       /* The heap has not been initialised yet so expect stats to all be zero. */\r
+       vPortGetHeapStats( &xHeapStats );\r
+       configASSERT( memcmp( &xHeapStats, &xZeroHeapStats, sizeof( HeapStats_t ) ) == 0 );\r
+\r
        vPortDefineHeapRegions( xHeapRegions );\r
+\r
+       /* Sanity check vTaskGetHeapStats(). */\r
+       prvExerciseHeapStats();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvExerciseHeapStats( void )\r
+{\r
+HeapStats_t xHeapStats;\r
+size_t xInitialFreeSpace = xPortGetFreeHeapSize(), xMinimumFreeBytes;\r
+size_t xMetaDataOverhead, i;\r
+void *pvAllocatedBlock;\r
+const size_t xArraySize = 5, xBlockSize = 1000UL;\r
+void *pvAllocatedBlocks[ xArraySize ];\r
+\r
+       /* Check heap stats are as expected after initialisation but before any\r
+       allocations. */\r
+       vPortGetHeapStats( &xHeapStats );\r
+\r
+       /* Minimum ever free bytes remaining should be the same as the total number\r
+       of bytes as nothing has been allocated yet. */\r
+       configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xHeapStats.xAvailableHeapSpaceInBytes );\r
+       configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xInitialFreeSpace );\r
+\r
+       /* Nothing has been allocated or freed yet. */\r
+       configASSERT( xHeapStats.xNumberOfSuccessfulAllocations == 0 );\r
+       configASSERT( xHeapStats.xNumberOfSuccessfulFrees == 0 );\r
+\r
+       /* Allocate a 1000 byte block then measure what the overhead of the\r
+       allocation in regards to how many bytes more than 1000 were actually\r
+       removed from the heap in order to store metadata about the allocation. */\r
+       pvAllocatedBlock = pvPortMalloc( xBlockSize );\r
+       configASSERT( pvAllocatedBlock );\r
+       xMetaDataOverhead = ( xInitialFreeSpace - xPortGetFreeHeapSize() ) - xBlockSize;\r
+\r
+       /* Free the block again to get back to where we started. */\r
+       vPortFree( pvAllocatedBlock );\r
+       vPortGetHeapStats( &xHeapStats );\r
+       configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == xInitialFreeSpace );\r
+       configASSERT( xHeapStats.xNumberOfSuccessfulAllocations == 1 );\r
+       configASSERT( xHeapStats.xNumberOfSuccessfulFrees == 1 );\r
+\r
+       /* Allocate blocks checking some stats value on each allocation. */\r
+       for( i = 0; i < xArraySize; i++ )\r
+       {\r
+               pvAllocatedBlocks[ i ] = pvPortMalloc( xBlockSize );\r
+               configASSERT( pvAllocatedBlocks[ i ] );\r
+               vPortGetHeapStats( &xHeapStats );\r
+               configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == ( xInitialFreeSpace - ( ( i + 1 ) * ( xBlockSize + xMetaDataOverhead ) ) ) );\r
+               configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xHeapStats.xAvailableHeapSpaceInBytes );\r
+               configASSERT( xHeapStats.xNumberOfSuccessfulAllocations == ( 2Ul + i ) );\r
+               configASSERT( xHeapStats.xNumberOfSuccessfulFrees == 1 ); /* Does not increase during allocations. */\r
+       }\r
+\r
+       configASSERT( xPortGetFreeHeapSize() == xPortGetMinimumEverFreeHeapSize() );\r
+       xMinimumFreeBytes = xPortGetFreeHeapSize();\r
+\r
+       /* Free the blocks again. */\r
+       for( i = 0; i < xArraySize; i++ )\r
+       {\r
+               vPortFree( pvAllocatedBlocks[ i ] );\r
+               vPortGetHeapStats( &xHeapStats );\r
+               configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == ( xInitialFreeSpace - ( ( ( xArraySize - i - 1 ) * ( xBlockSize + xMetaDataOverhead ) ) ) ) );\r
+               configASSERT( xHeapStats.xNumberOfSuccessfulAllocations == ( xArraySize + 1 ) ); /* Does not increase during frees. */\r
+               configASSERT( xHeapStats.xNumberOfSuccessfulFrees == ( 2UL + i ) );\r
+       }\r
+\r
+       /* The minimum ever free heap size should not change as blocks are freed. */\r
+       configASSERT( xMinimumFreeBytes == xPortGetMinimumEverFreeHeapSize() );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
index 13a66910a30269516a68e37389a7315ba3d88a96..84ae4074e3c7711e7400dc532527a1d3f7a82887 100644 (file)
@@ -260,6 +260,7 @@ static void prvCheckTask( void *pvParameters )
 {\r
 TickType_t xNextWakeTime;\r
 const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL );\r
+HeapStats_t xHeapStats;\r
 \r
        /* Just to remove compiler warning. */\r
        ( void ) pvParameters;\r
@@ -385,10 +386,19 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL );
 \r
                /* This is the only task that uses stdout so its ok to call printf()\r
                directly. */\r
-               printf( "%s - tick count %u - free heap %u - min free heap %u\r\n", pcStatusMessage,\r
-                                                                                                                                                          xTaskGetTickCount(),\r
-                                                                                                                                                          xPortGetFreeHeapSize(),\r
-                                                                                                                                                          xPortGetMinimumEverFreeHeapSize() );\r
+               vPortGetHeapStats( &xHeapStats );\r
+\r
+               configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == xPortGetFreeHeapSize() );\r
+               configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xPortGetMinimumEverFreeHeapSize() );\r
+\r
+               printf( "%s - tick count %u - free heap %u - min free heap %u - largest free block %u - number of free blocks %u\r\n",\r
+                                       pcStatusMessage,\r
+                                       xTaskGetTickCount(),\r
+                                       xHeapStats.xAvailableHeapSpaceInBytes,\r
+                                       xHeapStats.xMinimumEverFreeBytesRemaining,\r
+                                       xHeapStats.xSizeOfLargestFreeBlockInBytes,\r
+                                       xHeapStats.xNumberOfFreeBlocks );\r
+\r
                fflush( stdout );\r
        }\r
 }\r