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
Yes Tamir. I was re-reading your comment twice. How do i proceed with this? Any idea?
If you have included the example way of implementing the RTX and TCP stack then it is 100% ready all the time. So Tamir is right, it would never get to the idle task. I have a os_dly_wait in the main thread of my TCP task so that it gives up some time.
Stuart
this measurement is actually meaningless in RTX. in Linux systems, the scheduler has window of a predetermined size in which tasks are executed; if there is time left in it, the idle task is run. but RTX does not work like that. what you can do it use the __weak function void rt_post_taskswitch(U32 new_task) to log the timestamp at which a context switch has occured (use a free running hardware timer for that). it is called when a context switch happens. maybe you can compute how much of its time slice each task has consumed every period of something similar.
Hi Vivek,
As suggested in this thread, I am also trying to measure the idle time , etc and arrive at CPU util using the logic analyzer.
However, I am curious to know ("Without an RTOS, i can measure the idle time to come to some conclusion"), how / which method did you use for this?
Regards Padma
"RTX's idle task is only invoked if there are no really to run tasks"
Assuming that should be "ready to run".
If something is ready to run, then the CPU cannot be idle. It is therefore sensible to assume that you should not expect the idle task to run at this time.
Hi Padma,
I used Stuart's method. Inside the while (1) loop, i keep incrementing a counter variable. I reset the variable periodically. The period is something that i defined. (say 10 ms). I used to store these data in an array to make an iterative measurement.
Iam equally curious about your method using a logic analyzer. (though i dont have one to ake use of)
hope this helps.
BR/ Vivek
Thanks Stuart.
I was really blind. I found os_tsk_pass() in the routine. I changed it to os_dly_wait(). Now iam getting some meaningful numbers. Thanks again
Hello Tamir,
Why do you think, this approach wont work in RTX?
Even if RTX is preemptive and doesn't have a fixed window size to execute tasks, I believe, then also this approach could give a measure of CPU idle time. Isnt it?
If i use context switching to save a timer value, then also i need to check for idle task's id etc...and then its just a matter of using a time difference right away instead of using variables.
Am I missing something?
Thanks & Best Regards, Vivek
Vivek,
the fact that the idle task is not executed does not mean the processor is 100% loaded. proof? you can probably add a task that needs to wait for a predetermined period before waking up (even quite often) and it will probably never miss its deadline.
"the fact that the idle task is not executed does not mean the processor is 100% loaded. proof? you can probably add a task that needs to wait for a predetermined period before waking up (even quite often) and it will probably never miss its deadline."
Is that proof?
You can always add a task and have it run without it missing it's deadline so long as the priorities are suitable. (i.e., higher priority than others that are ready to run.)
Those lower priority tasks will still be consuming CPU cycles if they're ready to run.
ok, it's not "proof" - I just wanted to demonstrate that one cannot conclude anything based on idle task.
Hello All,
When i make repeated measurements, i observe that sometimes, i get values that are twice or thrice the value i get most of the times.
For ex i get CPU_idle_time_counter = 0x00057E34 most of the times, but i also get 0x000AFC68 and 0x00107A9D.
I couldnt think of any reason why this could happen. Idle task is not executed. That is clear. But is it OK to ignore such values.
Vivek
interrupts during measurement?
i dont have any interrupts enabled in my program. After i set up the clock, initialize a timer, enable it and go into a while(1) loop with a variable (counter) to make idle time measurement. With this simple code, i didnt even attach my application.
If the task that reads out the sample and clears the counter misses one run, then the counter may measure during two time slices.