Hello,
I wish to measure the CPU utlization for a cortex processor running an RTOS (keil RTX). Without an RTOS, i can measure the idle time to come to some conclusion. But with RTOS, can someone guide me how to measure CPU utlization?
Thanks & Best Regards Vivek
I learn much from the discussion. But I still don't really understand the meaning. What's the meaning of the "CPU"? Is it the computer CPU? I haven't used the Keil RTX? I had used SComAssistant.exe V2.2 to transmit the data from the IC to computer. I used the software of Delphi7 to program a UART transmission software which could control the LEDs on a board which had the IC of RS232,AT89S52 and so on. I think that if the computer is good enough. We don't need to care about the CPU utilization. My comprehension is limited. The above is my mind.
I do something similar in that I have a counter in the idle task. I Let this run for a set period when I know no tasks are running. Then when tasks are running the difference in this counter can be used to calculate/estimate the cpu used.
It is surprising how useful this can be, and its quite simple with no external hardware.
Stuart.
wow. you guys are so smart.
Ok. I get the point. Thanks for the discussion, Per and Tamir.
Yes, if no work tasks are running (they don't exist, or they are waiting for some event), the idle task (potentially just a normal low-priority user task) will run and will toggle an output pin at full speed.
When tasks or interrupts are serviced, the toggling task will not get any CPU time, so the toggling will stop.
No toggling means that the processor don't have any spare time for such a low-priority task.
The number of toggles/second correlates to the number of loops/second this idle task performs, and hence informs about spare processor time. No pin toggles - no spare time.
I meant: "ready to run tasks", of course.
the principle is correct, but there is problem with what Per suggested: RTX's idle task is only invoked if there are no really to run tasks, yielding a constant 100% processor utilization...
A cheap trick. Let the idle task busy-loop constantly toggling a pin. Check what frequency it manages to toggle the pin. Use a counter to check the number of toggles you get during normal operation. If you get 10% toggles then you spend about 10% of the time in the idle task. With an intelligent scope/logic analyzer, you could also pick up the longest interval without any toggling - that could potentially indicate starvation of your lowest-priority non-idle task.
View all questions in Keil forum