当前位置:网站首页>【Autosar RTM】
【Autosar RTM】
2022-08-02 23:27:00 【民谣唱给爱人听丶】
Autosar RTM
本文主要介绍MISCOSAR AMD 模块中的RTM 用来计算CPU Loading
1. RTM介绍
- Runtime Measurement (RTM) allows the user to determine runtimes and CPU load of BSW modules and user code sections.
运行时测量 (RTM) 允许用户确定 BSW 模块和用户代码段的运行时和 CPU 负载。 - RTM provides a set of macros, which are used to instrument the source code to be measured.
RTM 提供了一组宏,用于检测要测量的源代码。 - Such an instrumented code section is called measurement point (MP).
这样的插桩代码段称为测量点 (MP)。 - Measurement is controlled- and evaluated in CANoe by RTM’s frontend or a self-written RTM application.
通过 RTM 的前端或自行编写的 RTM 应用程序在 CANoe 中控制和评估测量。 - Data exchange between CANoe and the ECU is done by the XCP protocol(e.g. using CAN, FlexRay or Ethernet network communication)
CANoe 和 ECU 之间的数据交换通过 XCP 协议完成(例如使用 CAN、FlexRay 或以太网网络通信)。
1.1 AUTOSAR 4.x Architecture Overview 层级结构
MICROSAR AMD (AUTOSAR Monitoringaad Debugging)模块包含了三个子模块,
提供了错误报告、当前CPU负载及软件执行时间测量等功能,能够大大简化ECU软件的开发和测试过程。
- DBG(DeBuGging)
- DLT (DiagnosticLogandTrace)
- RTM(RunTimeMeasurement)

1.2 RTM 如何工作

How Does Measurement Work At a start point the measurement is started, at a stop point, it is stopped. In your code you can define as many start-stop couples as you want. You can also use the predefined measurements of the BSW modules.
在开始点开始测量,在停止点停止测量。在您的代码中你想定义多少(开始-停止)测量点对都可以。你也可以使用预定义的BSW模块测量。
Define the complete duration of a measurement and get the following results:
定义度量的完整持续时间并获得以下结果:
- Count: Counts how often the defined start-stop sections had been passed.
- Max: Shows the absolute longest runtime of each start-stop section.
- Min: Shows the absolute shortest runtime of each start-stop section.
- Average: Shows the average runtime of each start-stop section.
- Average CPU load: Shows the average CPU load caused by each start-stop section.
1.3 Interfaces to adjacent modules of the RTM 临近接口

2. 如何计算CpuLoading
Cpu负载率: 用来衡量在一段时间内CPU被占用情况.
Cpu负载率的计算方法: 可以用CPU一段工作时间与该时间段内被占用时间的比值来计算.
可以得之:
CPU负载率 = 占用时间(忙碌时间) / 运行总时间 (1)
由于CPU被占用 主要是用来执行任务代码 中断服务代码和系统调度功能代码
CPU负载率 = (总的任务运行时间 + 中断服务代码运行时间 + 系统调度功能代码运行时间) / 运行总时间 (2)
由于中断处理和静态系统的调度所需时间开销都较小,一般情况下将 中断服务代码运行时间 和 系统调度功能代码运行时间 忽略不计
所以一般来说,可以将CPU负载率近似看作:
CPU负载率 ≈ 总的任务运行时间 / 运行总时间 (3)
我们将所有任务的周期的最小公倍数称作:任务的超周期.那么可以得之 CPU负载率近似为操作系统中所有周期性任务的运行时间之和与这些任务的超周期的比值:
CPU负载率 ≈ i任务的周期 / 所有周期性任务的超周期 (4)
但是这4这种计算方法中,并没有考虑到中断请求的周期性和操作系统调度的频繁度.如果我们需要更精确的去测量CPU负载率.
按照(1)公式来推导出
CPU负载率 = 占用时间(忙碌时间) / 运行总时间
= (运行总时间 - 空闲时间) / 运行总时间 (5)
从(5)中 我们可知我们需要计算CPU loading的有效方法是, 得到一段时间内CPU空闲时间计数值. 从而更精确的计算CPU loading.
RTOS任务调度策略
- 时间片轮转式
- 优先级抢占式
在AUTOSAR 规范中,规定了一种没有任何具体功能的特殊任务(空闲任务).规范中 规定操作系统中的空闲任务没有固定周期,优先级最低,可以不执行任何功能,当系统中没有其他任务要运行或中断请求时,系统会自动跳转到空闲任务中,并一直执行空闲任务.
这样就为我们获得空闲时间提供了可能.
在空闲任务中,我们可以一直循环读取时间值, Interval (后一次的时间值减去前一次的时间值) 则能知道是空闲任务运行的时间,但是由于空闲任务优先级最低,OS产生调度的时候,也就是发生中断服务或者任务抢占的 之时,这个值就变成了CPU的占用时间,这个时间差值不仅包含任务调度产生的时间消耗,任务代码运行产生的消耗和中断服务产生的消耗.
如何来判断 Interval 值是空闲时间值 还是 忙碌时间值呢?
我们在这里假设操作系统从空闲任务跳转到其他高优先级任务或中断,在跳回空闲任务的时间为 T(s) ,那么得之所有大于T(s)间隔的时间段都是忙碌时间.

3. RTM 集成
3.1 导入RTM模块




3.2 RtmCoreDefinitions

| Short Name | |
| Bsw Core | BSW运行的core |
| Backgound Task Name | 实现空闲任务的任务名称 |
| Core | 定义应用程序正在运行的核心。对于交叉核心测量,请将此字段保留为空。 |
| Core Definition id | 符号名称该容器的值。 |
| Number Of Task Response Time Percentiles | |
| NvM Cpu Load Persistency Block | |
| Nvm Task Response Time Persistency Block |
3.3 RtmMeasurementPionts

| Short Name | 测量点 |
| Assigned To Core | 定义测量点在哪个核心上运行。 |
| Autostart Enabled | 自动启动可用于初始化函数,该函数只在启动阶段被调用,通信栈、XCP和RTM模块被激活。 |
| Disable Interrupts | 如果启用,RTM在测量期间使用临界段RTM_EXCLUSIVE_AREA_0锁定中断。 |
| Measurement Enabled | 此参数定义预编译期间测量部分的可用性。如果禁用,该部分的测量点将生成空宏。 |
| Measurement Group | 测量对象组 |
| Measurement Id | 测量对象的ID |
| Measurement Point Type | |
| Measurement Type | |
| Runtime Threshold[ms] | 阈值报警时间 如果该测量段的当前运行时间超过指定的时间,将调用一个回调函数。如果该参数未定义或设置为0,则该阈值告警是不活动的。 |
| Target Runtime[us] |
This parameter defines whether the measurement point measures:
Runtime: Regular runtime measurement point.
Task: Task response time measurement point.
CPU_Load: Core specific CPU load measurement point.
The measurement type defines the measurement behavior of this measurement point.
If set to GrossExecutionTime:
- Measures the absolute time between measurement start and stop.
If set to NetExecutionTime: - Measures like GrossExecutionTime minus interruptions by task or ISR.
If set to FlatExecutionTime: - Measures like NetExecutionTime minus the execution time of nested measurement points.
3.4 RtmGeneral

| Short Name | |
| 32 Bit Timer | 指定是否使用32位定时器。如果设置为true:使用32位定时器如果设置为false:使用16位定时器 |
| Control | 它允许在运行时禁用和启用RTM功能。 |
| Ctr Direction | 硬件计数器的计数方向 RTM_UP: 向上计数 RTM_DOWN: 向下计数 |
| Dev Error Detect | 错误检测和通知开关 打开或关闭 |
| Ecu Name | CANoe的XCP设置中的ECU名称。 |
| Get Measurement Timestamp Fct | 使用获取硬件计数器的当前值。必须由应用程序提供。 |
| Mainfunction Cycle Time[s] | 建议设置为0.01 [s]。 |
| Measurement Ctr Frequency [Ticks / ms] | 硬件计时器提供的每[毫秒]滴答数。 |
| NvM Task Stack Usage | |
| Safe Bsw Checks | 是否使用安全检查 |
| Timer Overrun Support | 定时器溢出支持开关 |
| Use Nesting Counter | |
| Use Core Mask | 此参数不能修改! |
| User Config File | 可以指定用户自定义配置文件的路径。 |
3.5 RtmCpuLoadMeasurement

| Short Name | |
| Cpu Load Control Mode | 定义如何测量Cpu负载和测量控制。 |
| Hyperperiod[s] | |
| Number Of Cpu Load Percentiles |
边栏推荐
猜你喜欢

IDEA 重复代码的黄色波浪线取消设置

Jmeter二次开发实现rsa加密

CAS:474922-22-0,DSPE-PEG-MAL,磷脂-聚乙二醇-马来酰亚胺科研试剂供应

redis的学习笔记

js基础知识整理之 —— 全局作用域

精心整理16条MySQL使用规范,减少80%问题,推荐分享给团队

别再到处乱放配置文件了!我司使用 7 年的这套解决方案,稳的一秕

令人心动的AI综述(1)

js基础知识整理之 —— 五种输出方式

What is the matter that programmers often say "the left hand is knuckled and the right hand is hot"?
随机推荐
解决错误:Optional int parameter ‘pageSize‘ is present but cannot be translated into a null value due to
Swift中的类型相关内容
2022中国眼博会,山东眼健康展,视力矫正仪器展,护眼产品展
Speech Synthesis Model Cheat Sheet (1)
科研用Cholesterol-PEG-NHS,NHS-PEG-CLS,胆固醇-聚乙二醇-活性酯
华为设备配置BFD与接口联动(触发与BFD联动的接口物理状态变为Down)
No-code development platform form styling steps introductory course
21天学习挑战赛(1)设备树的由来
d合并json
用了这么多年的LinkedList,作者说自己从来不用它?为什么?
2022第十一届财经峰会:优炫软件斩获双项大奖
秒懂网络拓扑中的下一跳地址
Controller层代码这么写,简洁又优雅!
程序员如何优雅地解决线上问题?
flutter空安全问题,平时用到的数据一定要注意
漫画:怎么证明sleep不释放锁,而wait释放锁?
2022 China Eye Expo, Shandong Eye Health Exhibition, Vision Correction Instrument Exhibition, Eye Care Products Exhibition
C# 异步编程(async和await)
几种常见的跨域解决方法
vant-swipe adaptive picture height + picture preview