From da36f01a4818fdb42dbb7c80570c3e952f2c1c74 Mon Sep 17 00:00:00 2001 From: rtel Date: Mon, 21 Jan 2019 23:39:48 +0000 Subject: [PATCH] Add xTaskGetIdleRunTimeCounter() API function to return the run time stats counter for the idle task - useful for POSIX time implementations. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2625 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../GCC_Specific/RTOSDemo.uvoptx | 8 ++-- .../Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c | 3 ++ .../.settings/language.settings.xml | 4 +- FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo | Bin 72704 -> 73728 bytes FreeRTOS/Demo/WIN32-MingW/main_full.c | 9 +++++ FreeRTOS/Source/include/mpu_prototypes.h | 1 + FreeRTOS/Source/include/mpu_wrappers.h | 1 + FreeRTOS/Source/include/task.h | 36 +++++++++++++++--- .../Source/portable/Common/mpu_wrappers.c | 13 +++++++ .../Source/portable/GCC/ARM_CM4_MPU/port.c | 2 +- .../Source/portable/GCC/RISC-V-RV32/port.c | 4 ++ 11 files changed, 69 insertions(+), 12 deletions(-) diff --git a/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/GCC_Specific/RTOSDemo.uvoptx b/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/GCC_Specific/RTOSDemo.uvoptx index 85705cfdb..8721f4fd0 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/GCC_Specific/RTOSDemo.uvoptx +++ b/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/GCC_Specific/RTOSDemo.uvoptx @@ -152,7 +152,7 @@ 0 614 1 -
23132
+
23164
0 0 0 @@ -237,7 +237,7 @@ System - 1 + 0 0 0 0 @@ -257,7 +257,7 @@ application_and_config - 1 + 0 0 0 0 @@ -301,7 +301,7 @@ FreeRTOS_Source - 1 + 0 0 0 0 diff --git a/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c b/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c index a1e4ac6d5..bc2ac8b23 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c +++ b/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c @@ -776,6 +776,9 @@ static void prvTaskToDelete( void *pvParameters ) /* For code coverage test purposes it is deleted by the Idle task. */ configASSERT( uxTaskGetStackHighWaterMark( NULL ) > 0 ); configASSERT( uxTaskGetStackHighWaterMark2( NULL ) > 0 ); + /* Run time stats are not being gathered - this is just to exercise + API. */ + configASSERT( xTaskGetIdleRunTimeCounter() == 0 ); vTaskSuspend( NULL ); } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/.settings/language.settings.xml b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/.settings/language.settings.xml index 7ac15d6a2..8ae7de984 100644 --- a/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/.settings/language.settings.xml +++ b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-FreedomStudio/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo b/FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo index 976c93a877d32a153d063b6fe2e182e1dcb79c5a..7f5848df53f7fad54b9402d24e9b1955ffc3aab4 100644 GIT binary patch delta 3131 zcmd6p4NR0}9Khe_y_e%XKIBdgI*|nK5>Frkl@Cdi0Ou_P?gY__3=|C!MB!LQ)4PmW zGd|@080r-Dq~>TWyw?vVYD}`U5b7q=LU9DwytYqo+{~vek%B)C$q|KokW z-sk`PpXasq3DyB&%dD_4j^kv=U6;#+f@6sOfGLs}I|kQ$cHlgl0rk9vy#d3#MP7(6 z&oXF`H3Ywms(L&=uml1VCR#M8VJ9wsl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nTnk-{L=`HCLfn^W;v%Se&cas|3~bx5LPM=hwW9VRQ#WGYs1 zaK|c5ay=r@T^9%U&V=k5ilI9Cm`Gei|4eR*P!|Oqi)O?ccKQ&g$F5&mM>Wx(ZY_O~ zL`QJT8;_3S%`sfa7T#;m7?nj0w#&3bG0tgswiI24 zrTC%RGSb28=p6Lpf=M_{1h7m(%PUjVNf$a*84A?NIi0s5f;9vKT!{42K1LF_8hv~oQ!42;r_8m&bmHX?_zCR8Ro%>2})Vc84 z-X1JHzc%!mgk8NJas2QJ5TAUp8?f%G1rLh~Y}n>gFDsgzb+7N$V^LcUet9WX6qbe| zbWG;#c=PWs6zBi;=s%J^={RsO@%#$D9;tahnd>TBzxkOwtt1!jDce=I!Mk_@27?X^ zI6_H|>bsBKy8rn%o}KdXx6G$gwM#W`x|35XTM>n~FGHwXM&FUw`E|s&Uta@U@$r(B zJnek=VGGZrCx4l^1fDt2h<)!ghfZbUweu;MelY?4zu79v|5ytNTUk3&!YH0Uxn06r zH|yvnt@zoWGVsK;-B5&Qt~yPPRh!mt%3U>SF89Q#>qo#;%wIuVuyY@YYe|yy-^1iqwVd$%JunG9GP8Q2ft%1%f3Gl8c`1*qM{%Dw`KRL?) z^$@zNV8dI^lQ&Y}Jg6nnT;ojI{*JWs?CpAJ{_J3U>Czu$^O1B0tl$hiP6>NQ5&j|H Rj3@FvCridcH5^sI@*S*k)d~Or diff --git a/FreeRTOS/Demo/WIN32-MingW/main_full.c b/FreeRTOS/Demo/WIN32-MingW/main_full.c index 3b27f908e..abd9bf503 100644 --- a/FreeRTOS/Demo/WIN32-MingW/main_full.c +++ b/FreeRTOS/Demo/WIN32-MingW/main_full.c @@ -617,6 +617,8 @@ static portBASE_TYPE xPerformedOneShotTests = pdFALSE; TaskHandle_t xTestTask; TaskStatus_t xTaskInfo; extern StackType_t uxTimerTaskStack[]; +static TickType_t xLastIdleExecutionTime = 0; +TickType_t xIdleExecutionTime; /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and xTaskGetIdleTaskHandle() functions. Also try using the function that sets @@ -715,6 +717,13 @@ extern StackType_t uxTimerTaskStack[]; } } } + + xIdleExecutionTime = xTaskGetIdleRunTimeCounter(); + if( xIdleExecutionTime == xLastIdleExecutionTime ) + { + pcStatusMessage = "Error: Total amount of Idle task execution time did not change"; + } + xLastIdleExecutionTime = xIdleExecutionTime; } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Source/include/mpu_prototypes.h b/FreeRTOS/Source/include/mpu_prototypes.h index b4cc34612..a8fe65574 100644 --- a/FreeRTOS/Source/include/mpu_prototypes.h +++ b/FreeRTOS/Source/include/mpu_prototypes.h @@ -69,6 +69,7 @@ void * MPU_pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseTy BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ); TaskHandle_t MPU_xTaskGetIdleTaskHandle( void ); UBaseType_t MPU_uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ); +TickType_t MPU_xTaskGetIdleRunTimeCounter( void ); void MPU_vTaskList( char * pcWriteBuffer ); void MPU_vTaskGetRunTimeStats( char *pcWriteBuffer ); BaseType_t MPU_xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ); diff --git a/FreeRTOS/Source/include/mpu_wrappers.h b/FreeRTOS/Source/include/mpu_wrappers.h index 66e9a9fd1..220949c0c 100644 --- a/FreeRTOS/Source/include/mpu_wrappers.h +++ b/FreeRTOS/Source/include/mpu_wrappers.h @@ -77,6 +77,7 @@ only for ports that are using the MPU. */ #define uxTaskGetSystemState MPU_uxTaskGetSystemState #define vTaskList MPU_vTaskList #define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats + #define xTaskGetIdleRunTimeCounter MPU_xTaskGetIdleRunTimeCounter #define xTaskGenericNotify MPU_xTaskGenericNotify #define xTaskNotifyWait MPU_xTaskNotifyWait #define ulTaskNotifyTake MPU_ulTaskNotifyTake diff --git a/FreeRTOS/Source/include/task.h b/FreeRTOS/Source/include/task.h index b9c605b54..43fcbee98 100644 --- a/FreeRTOS/Source/include/task.h +++ b/FreeRTOS/Source/include/task.h @@ -1728,6 +1728,36 @@ void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unquali */ void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ +/** +* task. h +*
TickType_t xTaskGetIdleRunTimeCounter( void );
+* +* configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS +* must both be defined as 1 for this function to be available. The application +* must also then provide definitions for +* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE() +* to configure a peripheral timer/counter and return the timers current count +* value respectively. The counter should be at least 10 times the frequency of +* the tick count. +* +* Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total +* accumulated execution time being stored for each task. The resolution +* of the accumulated time value depends on the frequency of the timer +* configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro. +* While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total +* execution time of each task into a buffer, xTaskGetIdleRunTimeCounter() +* returns the total execution time of just the idle task. +* +* @return The total run time of the idle task. This is the amount of time the +* idle task has actually been executing. The unit of time is dependent on the +* frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and +* portGET_RUN_TIME_COUNTER_VALUE() macros. +* +* \defgroup xTaskGetIdleRunTimeCounter xTaskGetIdleRunTimeCounter +* \ingroup TaskUtils +*/ +TickType_t xTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION; + /** * task. h *
BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
@@ -2346,7 +2376,7 @@ void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVIL void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION; /* - * Only avilable when configUSE_TICKLESS_IDLE is set to 1. + * Only available when configUSE_TICKLESS_IDLE is set to 1. * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port * specific sleep function to determine if it is ok to proceed with the sleep, * and if it is ok to proceed, if it is ok to sleep indefinitely. @@ -2367,10 +2397,6 @@ eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION; */ TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION; -#if( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) - TickType_t xTaskGetIdleRunTimeCounter( void ); -#endif - /* * For internal use only. Same as vTaskSetTimeOutState(), but without a critial * section. diff --git a/FreeRTOS/Source/portable/Common/mpu_wrappers.c b/FreeRTOS/Source/portable/Common/mpu_wrappers.c index 0cb79c4c7..d5aa0e930 100644 --- a/FreeRTOS/Source/portable/Common/mpu_wrappers.c +++ b/FreeRTOS/Source/portable/Common/mpu_wrappers.c @@ -333,6 +333,19 @@ BaseType_t xRunningPrivileged = xPortRaisePrivilege(); #endif /*-----------------------------------------------------------*/ +#if( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) + TickType_t MPU_xTaskGetIdleRunTimeCounter( void ) + { + TickType_t xReturn; + BaseType_t xRunningPrivileged = xPortRaisePrivilege(); + + xReturn = xTaskGetIdleRunTimeCounter(); + vPortResetPrivilege( xRunningPrivileged ); + return xReturn; + } +#endif +/*-----------------------------------------------------------*/ + #if ( configUSE_APPLICATION_TASK_TAG == 1 ) void MPU_vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxTagValue ) { diff --git a/FreeRTOS/Source/portable/GCC/ARM_CM4_MPU/port.c b/FreeRTOS/Source/portable/GCC/ARM_CM4_MPU/port.c index 8f7eee555..6f61eee15 100644 --- a/FreeRTOS/Source/portable/GCC/ARM_CM4_MPU/port.c +++ b/FreeRTOS/Source/portable/GCC/ARM_CM4_MPU/port.c @@ -573,7 +573,7 @@ extern uint32_t __privileged_data_end__[]; ( prvGetMPURegionSizeSetting( ( uint32_t ) __FLASH_segment_end__ - ( uint32_t ) __FLASH_segment_start__ ) ) | ( portMPU_REGION_ENABLE ); - /* Setup the first 16K for privileged only access (even though less + /* Setup the first nK for privileged only access (even though less than 10K is actually being used). This is where the kernel code is placed. */ portMPU_REGION_BASE_ADDRESS_REG = ( ( uint32_t ) __FLASH_segment_start__ ) | /* Base address. */ diff --git a/FreeRTOS/Source/portable/GCC/RISC-V-RV32/port.c b/FreeRTOS/Source/portable/GCC/RISC-V-RV32/port.c index a8b492898..8793ee6fc 100644 --- a/FreeRTOS/Source/portable/GCC/RISC-V-RV32/port.c +++ b/FreeRTOS/Source/portable/GCC/RISC-V-RV32/port.c @@ -34,6 +34,10 @@ #include "task.h" #include "portmacro.h" +#ifndef configCLINT_BASE_ADDRESS + #warning configCLINT_BASE_ADDRESS must be defined in FreeRTOSConfig.h. If the target chip includes a Core Local Interrupter (CLINT) then set configCLINT_BASE_ADDRESS to the CLINT's base address. Otherwise set configCLINT_BASE_ADDRESS to 0. +#endif + /* Let the user override the pre-loading of the initial LR with the address of prvTaskExitError() in case it messes up unwinding of the stack in the debugger. */ -- 2.39.5