External indication of processor utilization

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

External indication of processor utilization

1,177 Views
davepfaltzgraff
Senior Contributor I

I am using the combination of KDS, KSDK, PE and MQX, but the question may be of more general interest for any OS.

Is there anyway to externally measure the level of processor utilization? In working with MQX, I see that the idle task merely increments a huge number. But, translating this to a meaningful value requires that I have easy access to it as well as knowing the total run time, etc. What I would like is an easy way to measure this without having ti halt my system and access the memory.

For example, if a port is dedicated and the corresponding bit is cleared on entry to the idle task and set when switching away from it, this could be applied to a low pass filter (a simple RC) with the resulting voltage being proportional to the processor utilization.

An added bonus is that looking at the port output with a scope, you could get an idea of how much time the scheduler spends in switching among the various tasks.

If anyone has done this, I'd be interested in their results.

0 Kudos
Reply
4 Replies

956 Views
matthewkendall
Contributor V

_mqx_get_idle_loop_count() will give you the value of the idle lop counter at any time.

The way I calculate idle CPU is to have a task that periodically gets the count at regular intervals, and divides by the maximum possible count in that interval to calculate the proportion of time that the idle task was running.

To determine the maximum possible count per second you can either inspect the compiled assembly code for the idle loop and manually count the cycles for the inner loop, or run a benchmarking test. I use the latter option because then I don't have to worry about things changing if I change optimisation levels, etc. At startup, at a time when only one taks is running and all others have either not been started yet or are known to be idle, I get the idle count, delay 100ms, get it again and calculate the difference. That is my baseline that I use thereafter.

0 Kudos
Reply

956 Views
gpontis
Contributor IV

I agree, this is valuable information. When available, the instrumentation is usually built into the RTOS and goes by the name "profiling". The simplest implementation that can be done after the fact uses a timed interrupt. Each time the interrupt hits, code checks to see what task was executing and logs it. The user can look at the logs to see which ones are getting the most hits, or sometimes a tool is provided to make that easy. There are some obvious ways that this can be tricked, but in practice it is quite useful. Maybe it would not be that difficult to implement this ourselves.

0 Kudos
Reply

956 Views
soledad
NXP Employee
NXP Employee

Hello

TAD provides the Stack usage feature where you can see how much stack is being used. Another available choice is to use klog (source/io/klog.c). Following functions are defined in the code file:

_klog_get_task_stack_usage

_klog_get_interrupt_stack_usage

_klog_show_stack_usage

To use them, an application must enable kernel logging (MQX_KERNEL_LOGGING) and enable monitor stack monitoring (MQX_MONITOR_STACK).

I hope this helps,


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

956 Views
davepfaltzgraff
Senior Contributor I

Hi Sol,

My interest is not in stack utilization but in time utilization. I may have a clean stack, but my system is tied up in performing time intensive tasks. I want to know what percentage of the time my system is running the idle task.

Thanks

0 Kudos
Reply