0
\$\begingroup\$

I'm using a Cortex M3 processor on an LPC1769 board. For this particular situation, all processes occur within interrupts. Therefore, within the main "loop" there isn't actually anything to be processed. I want to calculate the processor utilisation however I'm not entirely sure of the best method to do this.

My original idea was to have a variable that is incremented every clock cycle where an interrupt isn't run. I can then use the equation below once a second.

$$ processorUtilisation = \frac{totalExpectedTickets - countedTicks}{totalExpectedTickets} * 100 $$

However, I'm not entirely sure whether that is a suitable solution mainly because I can't see a way to have a variable increment on every clock cycle.

Any other suggestions?

\$\endgroup\$
0
\$\begingroup\$

The tick counter doesn't have to increment on every cycle, you just have to know how many cycles are taken by each tick. You can then multiply countedTicks by cyclesPerTick to get the number of cycles.

Calculating the number of cycles per tick may be tricky, as it depends on what instructions the compiler generates. One way could be to single step through the machine code in a debugger or simulator, noting the number of cycles used per loop. However if caching or wait states are involved then this might not be accurate.

To get a run-time value you could temporarily disable process interrupts and count the number of ticks that occur in 1 second to get totalExpectedTicks, then divide it into the processor clock frequency to get cyclesPerTick (or, since the answer you want is only a ratio, you could just work in ticks and not worry about how many cycles they represent).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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