3
\$\begingroup\$

To fulfill customer expentations and fill out customer reports about the device, is there also one section about CPU Utilization. Because I have never done such task before I have overview some "Google Search" articles. A lot of the articles are in direct connection with Linux programming, a lot of them speak generally about CPU Utilization (just theoretical) and I didnt found no article about the method how can be this done .. okay there are some: embedded.com.

I am interested how YOU have done such task timing job before? I am intereseted in method and also whit which tool was done? With some direct measuring on the osciloscope (or logic analyser) or capturing data from osciloscope and post processing them? Which time frame to take for CPU Utilization to calculate - most "busy moment" when all interrupts are present, because in this case CPU utilization is much bigger then maybe 1 milisecond or 1 microsecond later, when only the background loop is executing?

Maybe for reference how I have made my first CPU Utilization approach (I don't know if is the right approach): Every interrupt when start executing have dedicated PIN which goes high when interrupt begin and gets low when interrupt ends. There is also same propagation delays involed. I export this signals over the osciloscope into one file and post-process with octave. There is still an issue which timeframe to take.

In case of any question please write in the comment section

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Which MCU platform are you using? What kind of debugging interface does it have? Some microcontrollers support advanced tracing mechanisms where you can profile the utilization of the MCU through the debugging interface. Example for STM32 \$\endgroup\$
    – Bora
    Commented May 23, 2019 at 12:15
  • \$\begingroup\$ It is a MSP430 MCU. We are using IAR version 5.40.3. So I belive there is no such tool included, maybe in the new versions? \$\endgroup\$
    – Pukaai
    Commented May 23, 2019 at 12:24
  • \$\begingroup\$ There are many possible methods, use whatever gives your design team and/or the customer confidence that your software will always work. They are often divided into two categories, high priority tasks that must be executed in a given time frame (I have used a GPIO, like your interrupt example for this); and lower priority tasks that just must never get too far behind. I have often had a "spare throughput" requirement for the latter, the software can easily calculate this itself tracking timer counts when it goes idle. \$\endgroup\$
    – Mattman944
    Commented May 23, 2019 at 12:34
  • \$\begingroup\$ @Pukaai I don't know about v5 but apparently IAR v7 has function profiling under the EnergyTrace function. User guide \$\endgroup\$
    – Bora
    Commented May 23, 2019 at 12:42
  • \$\begingroup\$ Thanks Bora! I didn't know about EnergyTrace, I must take a look if I can use it (some examples and ask boss about updating the IAR). On this video link I have also notice (44:15) that "EnergyTrace++ is not a high speed digital trace. Typical speed is 1kHz to 4kHz...". One of my interrupt muss execute in maximum 100 us - so probaly will not fit my needs. Thanks Bora! \$\endgroup\$
    – Pukaai
    Commented May 23, 2019 at 13:12

1 Answer 1

5
\$\begingroup\$

CPU utilization is really only a crude measurement of the overall resiliency of a real-time system. Therefore, the answer to your question is that it is generally a long-term average value.

The real criterion is whether all of the software tasks meet their completion deadlines. Note that this includes both tasks triggered by interrupts and tasks triggered by other kinds of events. When CPU utilization begins to approach 100%, then the completion time of lower-priority tasks tends to become arbitrarily large.

Using GPIO pins to indicate the run time of individual tasks is one good way to check whether those deadlines are ever exceeded.

Another approach is to instrument the code itself. If you have access to a free-running counter (a spare hardware counter/timer module, perhaps), then you can take a snapshot of its value at the beginning of each task, and then at the end of the task, take another snapshot and compute the difference. If this ever exceeds the required value for that task, indicate an error.


A slightly different question would be to compute the expected CPU utilization of a system, before it is implemented.

In this case, you consider each task individually, coming up with estimates of how long it runs when triggered and how often it is triggered. The run time divided by the trigger period gives the CPU utilization for that task by itself.

If you add up all of the individual utilization values and get a value that approaches or exceeds 100%, then you need to think about ways to redistribute the work — faster CPU, more CPUs, dedicated hardware for some tasks, etc.

\$\endgroup\$
7
  • \$\begingroup\$ Thanks Dave! I have counters already implemented for each task - problem is that task 3 is longer because task 2 have priority over task 3, and task 2 is longer because task 1 have higher priority over task 2 and task 3 ... so in short: T1 (highest priority) > T2 > T3 (lowest priority). So what I get are the maximum times of the each task and I didnt find the solution how to cancel timer when new task with the higher priority kick in. In second part you have talking about "Real Time Scheduling -> Rate Monotonic Approach"? I need real timmings results (lower priority times are not real). \$\endgroup\$
    – Pukaai
    Commented May 24, 2019 at 8:44
  • \$\begingroup\$ So maybe the easiest way is on oscilloscope to trigger the longest for example "Task 2" and minus interrupts of the "Task 1" and I will get the "real number", only that by measuring can be some deviations. So I will get the time numbers and I can calculate "Real Time Scheduling" \$\endgroup\$
    – Pukaai
    Commented May 24, 2019 at 10:25
  • \$\begingroup\$ But you don't want to "cancel the timer" when a higher-priority task runs -- the whole point is that the higher-priority task contributes directly to the completion time of the tasks that it interrupts. So if the completion deadline for T2 is not greater than the actual run time of T2 PLUS that of T1, then you're in trouble! \$\endgroup\$
    – Dave Tweed
    Commented May 24, 2019 at 10:46
  • \$\begingroup\$ I think that I uderstand you :) Thanks! One question ... can I even use "Real Time Scheduling -> Rate Monotonic Approach" in this case (I am using MSP430), or is this just for E.g. Linux Embedded system? Because in my case there are three tasks: Task 1 (higher priority) > Task 2 > background (lowest priority) \$\endgroup\$
    – Pukaai
    Commented May 24, 2019 at 11:21
  • \$\begingroup\$ I'm not sure what you're referring to, since I don't see any such heading in the article you linked. But assuming it's something similar to the Wikipedia description, you haven't provided enough information about the tasks in your system to know whether they meet the criteria described there. I can say that it is not just for Linux-based systems. \$\endgroup\$
    – Dave Tweed
    Commented May 24, 2019 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.