Skip to content

fix: idle-refresh cycle skew, drive(batch=0) hang, cancel accounting - #3

Merged
chenshih1 merged 1 commit into
masterfrom
cursor/fix-idle-refresh-drive-a8b9
Aug 27, 2026
Merged

chenshih1 merged 1 commit into
masterfrom
cursor/fix-idle-refresh-drive-a8b9

Conversation

@chenshih1

Copy link
Copy Markdown
Owner

Summary

Three high-confidence correctness bugs on master after PR #1: idle-refresh could desynchronize DRAM cycles from wall-clock time, MemorySystem.drive(batch=0) could spin forever, and Simulator.cancel() of the running event corrupted pending.

Changes

  • Idle-refresh backoff reset: _start_idle_ticking restarts _current_idle_batch at _idle_batch_cycles. After backoff had grown, a busy stretch cancelled the long idle event and rescheduled a short delay while still ticking the long batch, so dram.cycles jumped ahead of sim.now (refresh no longer tracks wall clock).
  • drive() / drive_range(): reject non-positive batch or queue_depth. With batch=0 and more requests than the queue depth, the C++ loop issued a burst then ticked zero cycles, never made progress, and hung.
  • Simulator.cancel(): drop the event id before invoking the callback so cancel of the running event returns False and does not decrement pending twice (it went negative).
  • split_read_write() docstring: describe the independent random split the code actually performs (it claimed writes were taken from the tail).

Investigation (not bugs)

  • Old CI on 7f0895e (run 33034354201): ruff W292 missing newline in tests/test_extreme.py. Fixed in the next commit (20ae651). Not a live flake.
  • Dram.flush() nested sim.step() loop: documented barrier that advances the whole simulator. Can nest/reorder other components if called from a callback (the accel example does this). Not silent wrong DRAM timing; changing it would be an API semantics change. Completions for the last read batch stay queued at current time after pending==0 — same as “queue empty, then fire deltas”; write callbacks already ran on acceptance.
  • FIFO has no wakeup: combinational buffer; documented. User code must pump it (PR docs: add Pipe+FIFO+Dram architecture composition example #2 shows the composition).
  • Writes complete on acceptance: documented Ramulator constraint; dram.pending still counts the write queue, so flush() waits for service.
  • PR perf: coalesce empty DRAM ticks and fix drive() drain accounting #1 coalescing: now + k*period is strictly before next_time; host event at the completion cycle still runs first; sim.now == depart_cycle * period_ps. No off-by-one found.

Testing

  • ruff check pyramulator/ tests/ benchmarks/ examples/ passes
  • ruff format --check pyramulator/ tests/ benchmarks/ examples/ passes
  • mypy pyramulator/ passes
  • pytest passes (195 tests, 97% coverage)
  • If the build changed: pip install -e ".[dev]" from a clean checkout works

New tests: idle-refresh backoff vs wall clock after busy, drive(batch=0) / queue_depth=0 rejected, cancel of the running event, split_read_write is not a tail split.

Changelog

Yes — [Unreleased] in CHANGELOG.md.

Open in Web Open in Cursor 

…ting

Idle-refresh left a grown tick batch in place after busy traffic, so the
next idle event ran far more DRAM cycles than the scheduled delay.
drive() with batch=0 never ticked between issue bursts and could spin
forever. cancel() of the running event double-decremented pending.

Co-authored-by: chenshih <chenshih1@users.noreply.github.com>
@chenshih1
chenshih1 marked this pull request as ready for review August 27, 2026 12:23
@chenshih1
chenshih1 merged commit 56cbafb into master Aug 27, 2026
6 checks passed
@chenshih1 chenshih1 mentioned this pull request Aug 27, 2026
6 tasks done
@chenshih1
chenshih1 deleted the cursor/fix-idle-refresh-drive-a8b9 branch August 27, 2026 13:48
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

Successfully merging this pull request may close these issues.

2 participants