设为首页 加入收藏

TOP

在Amazon FreeRTOS V10中使用运行时统计信息(一)
2019-08-29 23:53:01 】 浏览:92
Tags:Amazon FreeRTOS V10 使用 行时 统计 信息

  在MCU on Eclipse网站上看到Erich Styger在8月2日发的博文,一篇关于在Amazon FreeRTOS V10中使用运行时统计信息的文章,本人觉得很有启发,特将其翻译过来以备参考。原文网址:https://mcuoneclipse.com/2018/08/02/tutorial-using-runtime-statistics-with-amazon-freertos-v10/

 

  FreeRTOS包含一个很好的功能,可以向我提供有关每个任务在系统上运行的时间的信息:

 

FreeRTOS运行时信息

  本教程解释了FreeRTOS运行时统计功能以及如何打开和使用它。

?软件和工具

  在本文中,我使用以下内容:

  • MCUXpresso IDE 10.2.1
  • FRDM-K64F板
  • 来自MCUXpresso SDK 2.4.0的Amazon FreeRTOS V10.0.1

  但是当然可以使用任何其他工具/ IDE或FreeRTOS版本(FreeRTOS至少应该是9.0.0或更高版本)。

  使用以下步骤,还可以使用FreeRTOS任务运行时信息收集来更新现有项目。

?怎么运行的

  FreeRTOS使用用户/应用程序特定的计时器来测量任务执行时间。为此,RTOS中的每个任务描述符都有一个累积计数器,用于添加为该任务花费的计时器滴答。当任务获得CPU时间时,当前计时器滴答计数被记忆,当RTOS切换出该任务时,则记忆当前计时器滴答计数。然后将对应于任务执行时间的增量时间添加到任务执行时间计数器。

  我需要配置FreeRTOS,并将以下宏设置为1以执行运行时分析:

1 #define configGENERATE_RUN_TIME_STATS 1

另外,需要提供以下两个宏:

1 portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
2 portGET_RUN_TIME_COUNTER_VALUE()

  RTOS使用它来配置运行时计数器计时器并获取计时器值。

  运行时计数器在每个任务描述符中存储为32位值,这意味着对于每个任务,我对系统的RAM要求将增加4个字节:

 

FreeRTOS TCB中的ulRunTimeCounter

   假设计数器周期为10 kHz(0.1 ms),这意味着变量将在大约5天后溢出。

  此外,RTOS在task.c中维护额外的全局变量:

1 #if ( configGENERATE_RUN_TIME_STATS == 1 )
2 
3     PRIVILEGED_DATA static uint32_t ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */
4 
5     PRIVILEGED_DATA static uint32_t ulTotalRunTime = 0UL;       /*< Holds the total amount of execution time as defined by the run time counter clock. */
6 
7 #endif

  第一个变量用于记住任务切换的时间,第二个变量是系统的总运行时间。这是在任务切换时发生的事情(内核函数vTaskSwitchContext):

 1 /* Add the amount of time the task has been running to theaccumulated time so far.  The time the task started running wasstored in ulTaskSwitchedInTime.  Note that there is no overflowprotection here so count values are only valid until the timeroverflows.  The guard against negative values is to protectagainst suspect run time stat counter implementations - whichare provided by the application, not the kernel. */
 2 
 3 if( ulTotalRunTime > ulTaskSwitchedInTime )
 4 
 5 {
 6 
 7     pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );
 8 
 9 }
10 
11 else
12 
13 {
14 
15     mtCOVERAGE_TEST_MARKER();
16 
17 }
18 
19 ulTaskSwitchedInTime = ulTotalRunTime;

  通常,周期性定时器中断用于计算执行时间,并且定时器频率应该是嘀嗒中断频率的大约10倍(比如说“Hello”到“奈奎斯特 - 香农”采样定理)。这意味着如果我的滴答中断是1 kHz,我的运行时分析定时器频率应该是10 kHz。

  运行时统计信息通常带有两个数字:

  • 绝对(时间)数字
  • 百分比

  下面是一个文本任务列表,其中包含右侧的运行时信息:

TCB Static Handle     Name         State    Prio    Stack Beg  Stack End  Size    Stack Top            Unused  Runtime         

1   no (0) 0x20000450 Shell        Running  (1,1)   0x20000440 0x20000060  1000 B 0x200001EC (  600 B)   392 B 0x00000000 ( <1%)

7   no (0) 0x20001E68 IDLE         Ready    (0,0)   0x20001E58 0x20001CD0   400 B 0x20001DFC (   96 B)   312 B 0x00007C35 ( 91%)

2   no (0) 0x20000740 Refl         Blocked  (

首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇痞子衡嵌入式:PCM编码与Waveform.. 下一篇OpenWrt-Git依赖报错

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目