Skip to main content

cortex-cycle-budget

CI PyPI Python License

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.

Metadata

Release files for cortex-cycle-budget 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cortex-cycle-budget 0.2.0
File Size Uploaded Provenance Actions
cortex_cycle_budget-0.2.0.tar.gz 57.4 kB With provenance Details for cortex_cycle_budget-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cortex-cycle-budget 0.2.0
File Interpreter ABI Platform Actions
cortex_cycle_budget-0.2.0-py3-none-any.whl Python 3 none any Details for cortex_cycle_budget-0.2.0-py3-none-any.whl

Total release size: 87.1 kB

Release files / cortex_cycle_budget-0.2.0.tar.gz

Download URL cortex_cycle_budget-0.2.0.tar.gz
Size 57.4 kB
Tags Source
SHA-256 checksum
How to use checksums
eac88ca29d21c98dde749a172334a8b925f6ea90ddbcce664b5ff65ce7208913
BLAKE2b-256 checksum
How to use checksums
4dc90043436a0fa76fcfa9436775cc8ab1ab32b871d92125c6bd4c5eecfac04f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 23, 2026.

Transparency log

Release files / cortex_cycle_budget-0.2.0-py3-none-any.whl

Download URL cortex_cycle_budget-0.2.0-py3-none-any.whl
Size 29.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c01a5ebed8efe0850299859811387c89ab7e93368d6c1da8bd2120c7ded8f39
BLAKE2b-256 checksum
How to use checksums
fd6af5e9c7e1fa442f8c2a142014a178b37978ef1a75e3b2aa6205fe19235a9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 23, 2026.

Transparency log

Security for cortex-cycle-budget 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cortex_cycle_budget-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page