简体   繁体   English

手臂裸机系统的CPU使用率测量

[英]CPU usage measurment on arm bare metal system

I am working on a ARM cortex M4 evaluation board, its a bare metal application without any operating system running on it. 我正在研究ARM cortex M4评估板,它是一个bare metal应用,没有运行任何操作系统。

Now I want to measure CPU usage of a given process/algorithm , what would be the best way to do so? 现在我想测量给定进程/算法的CPU使用率,这样做的最佳方法是什么?

Should i implement an operating system to measure the CPU usage that have the functionality for such demand? 我应该实现一个操作系统来衡量具有此类需求功能的CPU使用率吗?

The question almost answers itself. 这个问题几乎可以解决。 What is your bare metal application doing when it is not in that process/algorithm? 当您的裸机应用程序不在该流程/算法中时,它的作用是什么? Measure one or the other or both. 测量一个或另一个或两者。 If you have a bare metal application that is not completely consuming the cpu in this algorithm, then you already have an operating system to the extent that you are managing this application/function's time. 如果你的裸机应用程序没有完全消耗这个算法中的cpu,那么你已经拥有了一个操作系统,只要你管理这个应用程序/函数的时间。 You can use a number of methods from a simple counter in a loop relative to a timer to see how many counts per loop when the algorithm is getting time slices vs not. 您可以使用循环中相对于计时器的简单计数器中的多种方法来查看算法获取时间片与否时每个循环计数的数量。 You can simply time the algorithm itself, etc. 您可以简单地计算算法本身等。

I assume when you say CPU you mean the whole system as your performance is heavily dependent both on your code and what it is talking to. 我假设你说CPU意味着整个系统,因为你的性能严重依赖于你的代码和它所说的内容。 If running from flash on a cortex-m4 depending on the clock rate you may be burning processor cycles just waiting for instructions or data (and can very easily get the wrong notion of processor performance for an algorithm when it isnt the algorithm burning clocks). 如果根据时钟速率从cortex-m4上的闪存运行,您可能正在等待处理器周期等待指令或数据(并且当算法不燃烧时钟时,很容易得到错误的处理器性能概念)。 The caches mask/manipulate that performance and can easily greatly affect the performance if you are not careful and aware of what they are doing. 缓存掩盖/操纵该性能,如果您不小心并意识到它们正在做什么,它们很容易对性能产生很大影响。 Being a C++ question your compiler plays a large role in performance as well as your code of course, can very easily make the code run several times faster or slower with minimal changes to the command line or code. 作为一个C ++问题,您的编译器在性能和代码中扮演着重要角色,可以非常轻松地使代码运行速度或速度快几倍,而对命令行或代码的更改最少。

If the algorithm is part of an isr then the processor goes to sleep otherwise, you can use the gpio pin and scope techinique to get a feel for the running vs sleeping ratio. 如果算法是isr的一部分,则处理器进入休眠状态,否则,您可以使用gpio引脚和范围techinique来了解运行与睡眠比率。

Implementing an OS to measure idle time of a CPU seems a bit overengineered for me. 实现一个操作系统来测量CPU的空闲时间对我来说似乎有点过分。 From my knowledge the Cortex-M4 includes a Debug unit (DWT) that allows you to snapshot a cycle counter . 据我所知,Cortex-M4包含一个调试单元(DWT),允许您对循环计数器进行快照。 But the easiest thing would be to hook a pin to an oscilloscope and toggle it on enter and on exit of your algorithm. 但最简单的方法是将一个引脚连接到示波器,并在算法的输入和退出时切换它。

First, of all implementing an operating system will not be practical or even possible for the purpose of only measuring the performance.So one possible approach is to keep a count variable which will record the number of tick occurred till that duration. 首先,所有实施操作系统都不实用,甚至不可能仅用于测量性能。因此,一种可能的方法是保留一个计数变量,该变量将记录在该持续时间内发生的滴答数。 And increment that variable in a interrupt of the Timer. 并在Timer的中断中递增该变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM