Simulator speed and responsiveness overhaul#22
Merged
Conversation
Consolidates the optimizer work into a single change: - Event-driven master clock that skips provably idle ticks. - Per-tick micro-fixes in the hardware simulator hot path: lazy sim_time, early bail in print_steps, timer-enabled bitmask and direct ISR dispatch. - Serial polling syscall diet: one-time raw setup plus non-blocking read. - Yield the host CPU instead of busy-spinning the grbl thread. - Default to -O3 Release builds, with the cross-thread data races that optimization exposed fixed. - Add -v/--version reporting build-time info. - Fix chunky/unresponsive sender realtime view in socket mode. grbl/block output is byte-identical to before; -r sampling drift is bounded.
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The goal was to speed up the simulator, such that local developer on senders (gSender in my case) was better.
The intent was to avoid any functional errors, but I'm NOT using the simulator to test any step timings.
I have ONLY tested on Windows. The result is a much more responsive gSender, useful for testing various gSender improvements I am working on.
If desireable, I can
Throughput: -O0 baseline to event-driven clock
Batch of five optimizations, verified byte-identical against the pre-change
build on the plan workload:
CMAKE_BUILD_TYPE). 1.8x end-to-end, zero code change. Landed with thevolatileshared-state fixes it depends on.sim_loop/mcu_master_clocknow jumpmasterclockstraight to the next event (timer expiry, systick, serialbyte, target) instead of iterating all 16M ticks per simulated second.
Idle periods become free. Benchmark 0.90s to 0.02s; ISR interval trace
verified identical (32,857 firings, 0 mismatches).
sim_time, early bail inprint_steps,timer bitmask +
gpio_irq_pendingflag + direct ISR dispatch.sched_yield()in therealtime hook and delay spin loop.
read()for stdin/socket polling.Interactive latency: chunky/unresponsive sender realtime view
Fixed three independent, compounding problems behind gSender's chunky
DRO/visualizer over
-p <port>:\n-only so eachstatus report goes out as one segment (kills Nagle + delayed-ACK stalls
that quantized the view to the poll rate, up to ~200ms on Windows).
timeBeginPeriod(1)for accurate frame sleeps,QuickEdit disabled so a stray click can no longer freeze the sim,
throttled
_kbhit, and block output no longer written to stdout in socketmode.
Measured
?to status-report latency (Linux, loopback): p50 46ms to 6.8ms,p90 51ms to 9.7ms, max 90ms to 27ms. Windows-only wins (delayed-ACK,
QuickEdit freezes, Sleep granularity) come on top and need eyeball
verification in gSender.
Behavior change
With
-pand no-b, per-block lines are no longer printed to stdout. Pass-b <file>to keep them.Regression
Serial and block output byte-identical pre/post on the plan workload.
-r 0.01step trace differs only by a documented sampling-boundary artifact(last-digit timestamps, +/-1 step at sample boundaries; final position
identical).
-t 1pacing confirmed (5.07s wall for 5.07s simulated).