CPU Utilization in Embedded systems

CPU Utilization in Embedded systems

An important metric that give an insight about the system performance is the CPU load or utilization. In the following lines we will know what is CPU load, How does it affect performance of a system, How to measure CPU load and How to minimize your system CPU load if possible.

1-What is CPU Load?

CPU load is the amount of time the CPU spends in processing active code to the amount of time the CPU spends in Idle state without active processing.

This simply means the time the CPU spend in tasks processing to the amount of time CPU spends while it is resting and doing nothing. This could be expressed by the following mathematical formula.

Total CPU load = summation of(Task's Frequency * Task's worst case execution time).

the result of this equation tells us the percentage the CPU spends in processing, but why does it matter to know the CPU load?


2-CPU load Importance

CPU load importance comes from the fact that it is used as a factor to determine the schedulability of our design. for example in Rate monotonic approach CPU utilization is used to test the optimality of the scheduling algorithm and in Time demand analysis technique the CPU utilization is used to test the schedulability of each task by comparing the CPU supply time to the task demand time. So having a high CPU load doesn't mean a bad thing if your design meets all it's deadlines but it means that in the future if you want to add further processes to the system this may lead to overload and so you have a high chance that your design won't be feasible for scheduling. So in safety critical systems there is a margin for the CPU load for delivered products. for example in Automotive the suggested CPU load is to be of 65 to 70%.

3-How to measure CPU load practically ?

There is multiple ways to measure CPU load some requires instrumentation like debuggers and trace boards but the easiest way is to measure it through Code and this approach work as follows.

To measure CPU load we have to measure it in a time window and this window is normally chosen to be equal to the Major frame cycle window of your scheduler. after choosing your window now in every supported tasks read at the task's beginning and end the current timer tick value then subtract both readings and save them in a a global variable, calculate the time executed by every task following the past ways and add the result to the global variable at the end of the time window parse the timer tick values accumulated to the corresponding time unit and divide that by the time window save this value in a variable and view it using the debugger now you have calculated your CPU load!!.

4-How to minimize CPU load.

If you want to minimize the CPU load there is multiple approaches

1-Increase CPU clock Frequency so CPU could executes tasks faster and so have more time capacity for executing other tasks and so lower load.

2-Using a Multi Core processor where tasks could be divided between cores.

3-Divides task's processing to be done in multiple cycles so the execution time of tasks during every cycle decreases and so CPU utilization decreases.

Aravindha Bhat

Technical Specialist at Continental | Embedded Software Developer | Technology Enthusiast

2 年

Informative article! Would love to know how the calculation would be incase of an idle task ( or other scenarios when the periodicity of a particular task in unknown ).

回复

This is about embedded software. The proposed solutions to reduce CPU load are to increase the performance of the hardware. I disagree here. The foremost solution is to increase the efficiency of the software solution. This reduces the energy impact of the system as well. Increasing or wasting hardware resources should be kept as a last resort.

回复

Great article, Thanks for sharing :)

回复
Thierry Bultel

Embedded Systems Consultant at Linatsea

2 年

Hi, Great article ! I would like to emphasize some points, if you don't mind. CPU load also has an immediate impact on power consumption, and that can be a no-go on systems where that point is critical. On such systems, increasing the CPU frequency is just not an option. The other, more long-term effect, is the usability of your hardware, when the application gets more needs (new features, more calculation). In both cases, it has an an ecological impact (more batteries in the first case, more silicon in the other). Saving the CPU load can thus avoid hardware replacement, by 'just' paying attention to applications bottlenecks or unwanted tight loops. That is why , in your "How to minimize CPU load" paragraph, I would add a 4th point: "Optimize the code". From what I have seen in number of projects, some significant gain of performance can often be obtained with minimal efforts. Performance analysis tools can help, of course, and sometimes, benchmarking some other best performing libraries is the key. As usual, it is always easier (and cheaper) during initial design rather than after some years of product life ! Best regards

Helpful! This will

回复

要查看或添加评论,请登录

Omar Ehab的更多文章

  • Introduction to Cache Memory

    Introduction to Cache Memory

    Microcontrollers are the heart of every embedded system and in the last decades we have seen an increase in their…

    3 条评论
  • Flash Memory in Embedded Systems

    Flash Memory in Embedded Systems

    A trivial mistake that lots of beginners in embedded systems do when they get introduced to Flash and EEPROM is they…

    2 条评论
  • Secure Firmware flashing using firmware signing

    Secure Firmware flashing using firmware signing

    The ability to flash a new Firmware to your embedded target using a boot-loader is essential but did you think what if…

    3 条评论
  • Synchronous VS Asynchronous Operations

    Synchronous VS Asynchronous Operations

    One of the concepts that I recognized that lots of people get it wrong is the difference between synchronous and…

    7 条评论
  • Access Synchronization

    Access Synchronization

    Writing Embedded software you will usually encounter the situation where you have to synchronize your tasks either for…

    3 条评论
  • Thread safe and Non-Thread safe Vs Re entrant and Non-Re entrant functions

    Thread safe and Non-Thread safe Vs Re entrant and Non-Re entrant functions

    Multi threading environment could be chaotic if careful design consideration is not taken and one of the most famous…

    4 条评论
  • Interrupt Latency

    Interrupt Latency

    It is known that we use interrupts in embedded software in order to serve asynchronous event almost immediately.so the…

    7 条评论
  • Scheduling analysis and testing using Rate monotonic algorithm with time demand analysis.

    Scheduling analysis and testing using Rate monotonic algorithm with time demand analysis.

    Following up with the article i published before about scheduling and multitasking.In this short tutorial we will see…

  • Functions VS ISR

    Functions VS ISR

    Have you ever thought why interrupt service routines(ISR) in some tool-chains is written in a special format that is…

    2 条评论
  • Introduction to multitasking and scheduling in Embedded systems

    Introduction to multitasking and scheduling in Embedded systems

    This will be a short introduction into multitasking in embedded systems. First what is multitasking? Multitasking is…

    3 条评论

社区洞察

其他会员也浏览了