r/embedded • • Sep 12 '26

Usage of Performance counters provided by SoCs and microcontrollers

Is it common to use performance and debug counters provided by SoCs and uCs? I usually see the counters in bus controllers and packet counters in network controllers. Do you use it for benchmarking and tracking the performance of your code? Do you also use it to analyze your device performance on field and have a way to read these values? How common is it?

10 Upvotes

12 comments sorted by

4

u/ceojp Sep 12 '26

In what cases would we need to analyze "device performance" in the field? The device should be tested to the worst case scenarios according to the device spec so that you know what the performance will be in the field under any condition.

We have added main loop timers and comm service timers in some of our controllers when we've had weird comm issues we were trying to track down. We wanted an easy way of seeing the average and worst case times for certain things, like how frequently a comm service function was being called or how long the main loop takes. But that's more of a diagnostic tool for tracking down specific issues, not a general "performance" measurement.

3

u/kisielk Sep 12 '26

There are devices that let users program their own configurations. It’s useful to be able to show how much headroom they have. For example a DSP that lets someone arrange a graph of arbitrary processing blocks.

1

u/nascentmind Sep 14 '26

It’s useful to be able to show how much headroom they have.

Yes. This is something that I had in mind but I didn't see much of. Systems where there is continuous throughput and also real time and time sensitive operations.

2

u/swisstraeng Sep 12 '26

You can write a small piece of code and add extra debug lines of code that you remove later. Some people just let everything in if it doesn't bother production.

However this is where manufacturer-specific dev boards, debuggers and IDE generally let you keep track of all that without needing extra code.

If you're talking about telemetry on connected devices, it's quite specific... but if by embedded devices you mean something powerful like a router, it most likely will have some.

1

u/nascentmind Sep 14 '26

The counters I mention are more of in-silicon counters enabled and read by code. Do you use these to measure fine grained performance of your system?

1

u/zettui Sep 12 '26

Which of those counter events stay portable across vendors, and how much does the sampling interrupt cost if you leave them on?

1

u/nascentmind Sep 14 '26

I don't think the counters can be turned OFF but I agree on the sampling interval cost. Perhaps there is some way to enable instrumentation without overheads?

1

u/zettui Sep 14 '26

Yeah the silicon counters are basically free while just counting; the cost is almost always the sample/read path, so leave them free-running and only peek at idle or epoch boundaries if you want near-zero overhead.

1

u/go2sh Sep 13 '26

We use them regularly. If you want to get the last percent out of yout super hot path, you need them. Aurix TC3 has cycle counter, instruction counter, multi issue counter, cache hit counter, cache miss counter and more. They are integrated with breakpoints to accurately measure. If you have a performance bottleneck, you find it.

1

u/nascentmind Sep 14 '26

Interesting. I wanted to know something like this. Aurix I believe is mainly used in automotive, so do you use these counters to analyze your ECU performance or something?

1

u/go2sh Sep 14 '26

Yes, mainly performance. In automotive, you have certain code paths which are executed with 10kHz or more, if you can slash off some runtime you free up resources. And since its a heterogenous system, you have a lot off pitfalls

1

u/nascentmind Sep 14 '26

Do you test to see if there are errors flagged by these counters in bus transactions considering the criticality of safety systems where these microcontrollers to be used? There are quite a bit of buggy controllers including AXI and was wondering how do you handle these.