Skip to content

Fix SITL system load metric permanently pinned at 100%, blocking arming#11720

Open
sensei-hacker wants to merge 2 commits into
iNavFlight:release/9.1from
sensei-hacker:fix-sitl-scheduler-load-pins-100-percent
Open

Fix SITL system load metric permanently pinned at 100%, blocking arming#11720
sensei-hacker wants to merge 2 commits into
iNavFlight:release/9.1from
sensei-hacker:fix-sitl-scheduler-load-pins-100-percent

Conversation

@sensei-hacker

Copy link
Copy Markdown
Member

Summary

A freshly-defaulted SITL build on 9.1 cannot arm: the Configurator's Status
tab shows CPU load pinned at/above 100%, tripping
ARMING_DISABLED_SYSTEM_OVERLOADED on an idle, correctly functioning
instance.

averageSystemLoadPercent (src/main/scheduler/scheduler.c) is a duty-cycle
estimator that counts how many scheduler() samples found a task already
overdue. That only produces a sane result if scheduler() runs far more
often than tasks become due — true on real hardware, which busy-polls. PR
#11436 made SITL's scheduler() sleep until just before the next task is
due instead of busy-polling (a real, worthwhile CPU-usage improvement on the
host). That eliminated the zero-load samples the old estimator relied on, so
every sample now finds >=1 task due and the average is permanently >=100.

Changes

  • Cherry-picked 5e47ffd356 ("Fix SITL system load accounting") by
    @xznhj8129, originally authored against maintenance-10.x as part of
    SITL & X-Plane simulation fixes #11712. Full credit for the fix
    design and implementation goes to that commit's author — this PR ports it
    to release/9.1, where the same regression (8a475617c4, "SITL Tweaks")
    is also present.
    • Adds a SITL_BUILD-gated busy-time/elapsed-time duty-cycle calculation:
      scheduler() measures wall-clock time spent per iteration (excluding
      the intentional sleep), and taskSystem() converts that into a percentage
      over a rolling window, capped at 100.
    • Hardware (non-SITL_BUILD) load accounting is untouched.
    • docs/SITL/SITL.md: one-line note on how SITL load is now calculated.
  • Follow-up commit (mine): moved a stale UNUSED(currentTimeUs) call into
    the branch where it's actually still unused, and added a short comment
    explaining why SITL needs a different calculation than hardware — raised
    by code review, no behavior change.

Testing

  • Built SITL from this branch; froze a synthetic stress test into taskGyro()
    temporarily (reverted before commit) to drive genuine load:
    • Idle: cpuLoad (MSP2_INAV_STATUS) steady at 3-4%, no
      ARMING_DISABLED_SYSTEM_OVERLOADED.
    • 3,000 busy-loop iterations/call: cpuLoad 10-12%.
    • 20,000 busy-loop iterations/call: cpuLoad stable 58-59%, metric tracks
      added load, still armable, no overload flag.
  • Host CPU usage of the idle SITL.elf process measured two ways (ps pcpu and /proc/[pid]/stat tick deltas): steady 7.4-8% of one core,
    confirming PR [SITL] Maintenance and Improvements #11436's sleep-based scheduling is untouched (no
    busy-polling reintroduced).
  • Compiled a hardware target (MATEKF722, F7) cleanly with no warnings —
    confirms the non-SITL_BUILD path is unaffected (all changes are inside
    #if defined(SITL_BUILD) blocks).

Code Review

Reviewed with the inav-code-review agent: approved, no critical or
important issues blocking merge. Two minor suggestions (explanatory comment,
misplaced UNUSED()) were addressed in the follow-up commit.

Fixes #11710

xznhj8129 and others added 2 commits July 12, 2026 19:40
taskSystem() used the sample-based load estimator's UNUSED(currentTimeUs)
placement even though SITL_BUILD now uses the parameter, and lacked any
note on why SITL needs a different calculation than hardware targets.
@sensei-hacker sensei-hacker added this to the 9.1 milestone Jul 13, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@github-actions

Copy link
Copy Markdown

Test firmware build ready — commit ca26d31

Download firmware for PR #11720

243 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants