Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmarking embedded rust code #669

Closed
KRACK-BIT opened this issue Apr 5, 2023 · 3 comments
Closed

Benchmarking embedded rust code #669

KRACK-BIT opened this issue Apr 5, 2023 · 3 comments

Comments

@KRACK-BIT
Copy link

I've been working on my own embedded rust project (a no_std KYBER implementation), and have been trying to run time consistency tests on my micro-controller. As such, I'm currently trying to validate that the number of clock cycles are constant for each of my critical functions, and I can measure the clock cycle time directly through cortex_m::Peripherals

However, I can't find any bench-marking framework which supports measuring this, or even any projects that take measurements (be they clock or real-world time) of a micro-controller's runtime.

As such, are there any good libraries/examples on profiling execution time on a micro-controller, and if not, are there any examples on how to write your own bench-marking framework for an embedded system?

@ryan-summers
Copy link

ryan-summers commented Apr 5, 2023

For cortex-m devices, the ITM can be used to do this if your microcontroller can support it. probe-rs supports this functionality via the CLI or via your own custom code.

Probe-rs's CLI has a trace command that will use the ITM to capture the cycle counts of all ISRs in your system, but it doesn't support bench marking arbitrary functions or sections (although I've been looking at adding such functionality).

Take a look at rtic-scope if you're using RTIC

@therealprof
Copy link
Contributor

An approach has been mentioned in https://blog.japaric.io/rtfm-overhead/. I've been also using the external method using a GPIO quite successfully to do A/B comparisons of code and optimize it, though it won't yield exact measurements.

There have been some experiments with https://github.com/orbcode/orbuculum a long time ago but I can't find any reference. Using that software with ITM/ETM has the potential of yielding professional level results and details at the expense of a non-trivial setup and potentially research work.

@jamesmunns
Copy link
Member

Closing this as part of the 2024 triage. I'd definitely recommend following up with probe-rs trace, and the other options mentioned above.

If anyone discovers this in the future or has a better solution - please feel free to submit it to the https://github.com/rust-embedded/awesome-embedded-rust list!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants