Skip to content

Fix assertion failure in NullEvent::setCompute with small G values#17

Open
tommasobo wants to merge 1 commit intomainfrom
fix/null-event-time-underflow
Open

Fix assertion failure in NullEvent::setCompute with small G values#17
tommasobo wants to merge 1 commit intomainfrom
fix/null-event-time-underflow

Conversation

@tommasobo
Copy link
Contributor

@tommasobo tommasobo commented Mar 18, 2026

Problem

When the LogGOPSim G parameter is set to a small value (e.g., 0.0001), the simulation:

  1. Crashes with Assertion 'when >= now()' failed in EventList::sourceIsPending()
  2. Runs extremely slowly due to send pileups

Root Cause

getGlobalTimeNs() returns eventlist().now() / 1000, integer division that truncates sub-nanosecond precision. When this truncated value flows back through NullEvent::setCompute(ns_value) which does ns_value * 1000, the round-tripped picosecond value is smaller than eventlist().now(), causing an unsigned underflow that schedules events in the past.

Fixes

  1. null_event.cpp: Guard against unsigned underflow by clamping the relative offset to 0 when target time ≤ now
  2. logsim-interface.cpp (htsim_simulate_until): Clamp until to at least 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

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>
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.

1 participant