Fix assertion failure in NullEvent::setCompute with small G values#17
Open
Fix assertion failure in NullEvent::setCompute with small G values#17
Conversation
When getGlobalTimeNs() truncates picoseconds to nanoseconds via integer division (now()/1000), converting back to picoseconds (×1000) can produce a value smaller than the actual eventlist().now(). This caused an unsigned underflow in NullEvent::setCompute, scheduling events in the past and triggering 'assert(when >= now())' in EventList::sourceIsPending. The bug surfaces when the LogGOPSim G parameter is small (e.g., 0.0001), because bandwidth_cost2 truncates to 0 for most message sizes, so can_simulate_until stays at the truncated current time rather than advancing into the future. Fixes: 1. null_event.cpp: Guard against underflow by clamping the relative offset to 0 when the target time is at or before now. 2. logsim-interface.cpp (htsim_simulate_until): Clamp the 'until' parameter to at least the current HTSIM time before scheduling. 3. logsim-interface.cpp (OP_SEND): Use std::ceil + std::max(1,...) for bandwidth_cost2 so it never truncates to 0, preventing send pileups that also cause extreme simulation slowdowns. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Problem
When the LogGOPSim
Gparameter is set to a small value (e.g., 0.0001), the simulation:Assertion 'when >= now()' failedinEventList::sourceIsPending()Root Cause
getGlobalTimeNs()returnseventlist().now() / 1000, integer division that truncates sub-nanosecond precision. When this truncated value flows back throughNullEvent::setCompute(ns_value)which doesns_value * 1000, the round-tripped picosecond value is smaller thaneventlist().now(), causing an unsigned underflow that schedules events in the past.Fixes
null_event.cpp: Guard against unsigned underflow by clamping the relative offset to 0 when target time ≤ nowlogsim-interface.cpp(htsim_simulate_until): Clampuntilto at least current HTSIM time before schedulinglogsim-interface.cpp(OP_SEND): Usestd::ceil+std::max(1,...)forbandwidth_cost2so it never truncates to 0