Repository navigation
fix: idle-refresh cycle skew, drive(batch=0) hang, cancel accounting - #3
Merged
Merged
Conversation
…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
marked this pull request as ready for review
August 27, 2026 12:23
4 of 5 tasks
6 tasks done
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.
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, andSimulator.cancel()of the running event corruptedpending.Changes
_start_idle_tickingrestarts_current_idle_batchat_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, sodram.cyclesjumped ahead ofsim.now(refresh no longer tracks wall clock).drive()/drive_range(): reject non-positivebatchorqueue_depth. Withbatch=0and 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 decrementpendingtwice (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)
tests/test_extreme.py. Fixed in the next commit (20ae651). Not a live flake.Dram.flush()nestedsim.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 afterpending==0— same as “queue empty, then fire deltas”; write callbacks already ran on acceptance.dram.pendingstill counts the write queue, soflush()waits for service.now + k*periodis strictly beforenext_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/passesruff format --check pyramulator/ tests/ benchmarks/ examples/passesmypy pyramulator/passespytestpasses (195 tests, 97% coverage)pip install -e ".[dev]"from a clean checkout worksNew tests: idle-refresh backoff vs wall clock after busy,
drive(batch=0)/queue_depth=0rejected, cancel of the running event,split_read_writeis not a tail split.Changelog
Yes —
[Unreleased]inCHANGELOG.md.