Processor profiling - how to see how much processor utilization we have (in percent)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RiTa_288331
Level 2
Level 2
10 replies posted 10 questions asked 5 replies posted

Greetings All!

We are using the PSOC 6 in a motor control application.  The M4 core is being used for the motor control loops (torque and velocity loops), and we want to use the M0 as an interface to a desktop computer app using BLE.

--> The motor control laws themselves will use interrupts, while we want to use an RTOS for communication/background tasks.

Is there an example on PSOC, or maybe one in general, that shows how we can profile the processor utilization?  For instance, if we run our motor control loop at 20kHz (50usec), we want to know how much time we are using doing the control law, and therefore how much time we have left to do "other things".

We have done this in the past with a simple GPIO pin (raise the pin at the start of the 50usec interrupt, then lower it when the calculations are done, and view this pin on an oscilloscope).  I'm not sure if this method can be used when we are using both interrupts and an RTOS scheduler.

0 Likes
1 Solution

Attached is a code snipped that does calculate the CPU usage based on the Energy Profiler.

- WDT is generating an interrupt every 1s to wakeup from sleep.

- cpu load is generated with a cyDelay function.

- Brakepoint in line 83 is needed to read out the variables. I did not add a UART to the code.

cpu_free and cpu_load are both calculated as 10th percentile values.

In the example there is an error involved in the result, as the WDT and MCU (CyDelay) use different clock sources and the ILO can have an error of +-10%.

This should not be an issue when used in your RTOS!

Achim

View solution in original post

0 Likes
2 Replies
AchimE_41
Employee
Employee
10 sign-ins 5 sign-ins First comment on KBA

Hi,

this is just a theoretical idea as I haven't done it yet, but PSoC6 has an energy profiler built in. These are a bunch of 32bit timers that can count events and duration of events. Two of those events are the active time of each core.

- count the cores active cycles

- put the core into sleep mode during the idle task

- let another count the constant 1 duration

- both timers have to use the same clock source

you should now get the cpu load by dividing both values.

pastedImage_2.png

kind regards,

Achim

0 Likes

Attached is a code snipped that does calculate the CPU usage based on the Energy Profiler.

- WDT is generating an interrupt every 1s to wakeup from sleep.

- cpu load is generated with a cyDelay function.

- Brakepoint in line 83 is needed to read out the variables. I did not add a UART to the code.

cpu_free and cpu_load are both calculated as 10th percentile values.

In the example there is an error involved in the result, as the WDT and MCU (CyDelay) use different clock sources and the ILO can have an error of +-10%.

This should not be an issue when used in your RTOS!

Achim

0 Likes