Static cycle-count estimation for ARM Cortex-M (M0/M4/M7/M33) binaries.
Project description
cortex-cycle-budget
Static cycle-count estimation for ARM Cortex-M binaries — CI-friendly, framework-agnostic, zero runtime dependencies.
cortex-cycle-budget analyzes an ELF binary (via arm-none-eabi-objdump) and
estimates the cycle cost of a user-defined critical path through your
firmware. It supports Cortex-M0, Cortex-M4, Cortex-M7, and
Cortex-M33 with per-variant timing tables sourced from the ARM Technical
Reference Manuals.
It is designed for hard-real-time loops (motor control, signal processing, servo loops) where you must guarantee that a control iteration fits inside a fixed cycle budget.
✨ Features
| Feature | Status |
|---|---|
| Cortex-M0 / M4 / M7 / M33 timing models | ✅ |
FPU costs (vsqrt.f32, vdiv.f32, …) |
✅ |
| Exception entry/exit overhead (per-variant) | ✅ |
| Call-graph walking from an entry function | ✅ |
| Strict & non-strict pattern matching | ✅ |
| CPU-utilization budget table at N kHz | ✅ |
| Annotated disassembly (Markdown) | ✅ |
| Machine-readable JSON metrics | ✅ |
| Multi-mode analyzer (one ELF, many critical paths) | ✅ |
| GitHub composite action + reusable workflow | ✅ |
| PR comment with stable marker (idempotent update) | ✅ |
--fail-over-max-cycles CI gate |
✅ |
| Cortex-M7 dual-issue (limited modelling planned) | 🚧 |
🚀 Quickstart
1. Install
pip install cortex-cycle-budget
Runtime dependencies: none (Python ≥ 3.11 stdlib only). At analysis time
you need arm-none-eabi-objdump (and optionally arm-none-eabi-size) on
PATH, or pass --objdump/--size-tool.
2. Write a config (cycle-analysis.json)
{
"path_name": "FOC Control Loop",
"loop_rates_khz": [20, 40, 100],
"path_stages": [
{"label": "ADC Read", "patterns": ["^adc_read$"]},
{"label": "FOC Math", "entry": "^foc_step$", "patterns": ["^foc_.*$"]},
{"label": "PWM Write", "patterns": ["^pwm_write$"]}
]
}
See docs/config-schema.md for the full schema.
3. Run
cortex-cycle-budget cycle-analysis.json \
--elf build/firmware.elf \
--target nucleo-h743zi \
--build-config Release \
--clock-mhz 480 \
--cortex m7 \
--output-dir reports
Outputs in reports/:
| File | Purpose |
|---|---|
cycle_estimation_report.md |
Full Markdown report |
cpu_budget.md |
CPU utilization at every configured loop rate |
pr_comment.md |
Compact PR comment (with idempotent marker) |
annotated_disassembly.md |
Disassembly annotated with per-instr cycles |
cycle_metrics.json |
Machine-readable summary for downstream tooling |
full_disassembly.txt |
Raw objdump -d output |
size_report.txt |
arm-none-eabi-size output |
4. Use in GitHub Actions
- uses: your-org/cortex-cycle-budget@v0
with:
config-path: cycle-analysis.json
elf-path: build/firmware.elf
target: nucleo-h743zi
build-config: Release
clock-mhz: 480
cortex: m7
fail-over-max-cycles: 20000 # fail the PR if the budget is blown
The action posts an idempotent PR comment, appends a step summary, and uploads all reports as an artifact. See docs/usage.md for the full input/output reference.
📚 Documentation
| Document | What it covers |
|---|---|
| docs/usage.md | CLI flags, action inputs/outputs, examples |
| docs/config-schema.md | Full JSON config schema + reference |
| docs/timing-model.md | How cycle counts are derived (TRM citations) |
| docs/cortex-variants.md | M0 / M4 / M7 / M33 differences & caveats |
| docs/architecture.md | Internal module layout & data flow |
| docs/troubleshooting.md | Common errors & their fixes |
| CONTRIBUTING.md | Dev setup, testing, release process |
| CHANGELOG.md | Version history |
🧪 Examples
Four runnable examples ship in examples/:
| Example | Highlights |
|---|---|
| examples/minimal | 3-stage Cortex-M4 control loop |
| examples/cortex-m7 | FPU-heavy FOC kernel (vsqrt/vdiv) |
| examples/cortex-m33 | ISR with exception_entry / exception_exit |
| examples/multi-mode | One ELF, two distinct critical paths |
⚠️ Scope & limitations
This tool gives static, deterministic estimates. It does not model:
- Cache hits/misses (Cortex-M7 I-cache, D-cache, AXI bus contention).
- Branch prediction accuracy on M7.
- Memory wait states from external flash / SDRAM.
- Interrupt nesting and tail-chaining beyond the documented worst case.
- Cortex-M7 dual-issue at the instruction-pair level (planned).
Estimates are intended as a CI guardrail, not a substitute for cycle-accurate hardware profiling (e.g., DWT/CYCCNT or a logic analyzer).
📄 License
Apache-2.0 — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cortex_cycle_budget-0.2.0.tar.gz.
File metadata
- Download URL: cortex_cycle_budget-0.2.0.tar.gz
- Upload date:
- Size: 57.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eac88ca29d21c98dde749a172334a8b925f6ea90ddbcce664b5ff65ce7208913
|
|
| MD5 |
ab77a353ae0612147f403d0d5f315bbd
|
|
| BLAKE2b-256 |
4dc90043436a0fa76fcfa9436775cc8ab1ab32b871d92125c6bd4c5eecfac04f
|
Provenance
The following attestation bundles were made for cortex_cycle_budget-0.2.0.tar.gz:
Publisher:
release.yml on embedded-pro/cortex-cycle-budget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cortex_cycle_budget-0.2.0.tar.gz -
Subject digest:
eac88ca29d21c98dde749a172334a8b925f6ea90ddbcce664b5ff65ce7208913 - Sigstore transparency entry: 1615899812
- Sigstore integration time:
-
Permalink:
embedded-pro/cortex-cycle-budget@de7fc1f448138bf1ee96f03d46d8a675023b6008 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/embedded-pro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@de7fc1f448138bf1ee96f03d46d8a675023b6008 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cortex_cycle_budget-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cortex_cycle_budget-0.2.0-py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c01a5ebed8efe0850299859811387c89ab7e93368d6c1da8bd2120c7ded8f39
|
|
| MD5 |
9af8a1d4d436f2cada59d482439cfaa1
|
|
| BLAKE2b-256 |
fd6af5e9c7e1fa442f8c2a142014a178b37978ef1a75e3b2aa6205fe19235a9b
|
Provenance
The following attestation bundles were made for cortex_cycle_budget-0.2.0-py3-none-any.whl:
Publisher:
release.yml on embedded-pro/cortex-cycle-budget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cortex_cycle_budget-0.2.0-py3-none-any.whl -
Subject digest:
0c01a5ebed8efe0850299859811387c89ab7e93368d6c1da8bd2120c7ded8f39 - Sigstore transparency entry: 1615899837
- Sigstore integration time:
-
Permalink:
embedded-pro/cortex-cycle-budget@de7fc1f448138bf1ee96f03d46d8a675023b6008 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/embedded-pro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@de7fc1f448138bf1ee96f03d46d8a675023b6008 -
Trigger Event:
push
-
Statement type: