From af2637256e080a5ce8bd5dda6e5f7ceed9c4aeef Mon Sep 17 00:00:00 2001 From: Sid Manning Date: Wed, 24 Jun 2026 15:08:54 -0700 Subject: [PATCH] Fix hang at startup. Return a minimal non-zero value (1 ps) when the CPU is exactly AT the quantum boundary (not past it). This allows sync() to exit immediately, letting the CPU proceed to its next execution cycle. The timehandler mechanism still correctly paces the kernel advancement via tick scheduling. Change-Id: I35adcca21f515a7cb7f6ea52668732c4b241240f Signed-off-by: Sid Manning --- systemc-components/common/include/qkmulti-quantum.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/systemc-components/common/include/qkmulti-quantum.h b/systemc-components/common/include/qkmulti-quantum.h index 521994d1..4eca03d0 100644 --- a/systemc-components/common/include/qkmulti-quantum.h +++ b/systemc-components/common/include/qkmulti-quantum.h @@ -20,8 +20,15 @@ class tlm_quantumkeeper_multi_quantum : public tlm_quantumkeeper_multithread sc_core::sc_time quantum = tlm_utils::tlm_quantumkeeper::get_global_quantum(); sc_core::sc_time next_quantum_boundary = sc_core::sc_time_stamp() + quantum; sc_core::sc_time now = get_current_time(); - if (next_quantum_boundary >= now) { + if (now < next_quantum_boundary) { return next_quantum_boundary - now; + } else if (now == next_quantum_boundary) { + // At the exact boundary: the CPU has used its quantum but hasn't + // exceeded it. Return a minimal non-zero value so sync() doesn't + // block. The timehandler will advance the kernel on the next delta + // cycle; blocking here risks a deadlock when sc_suspend_all() + // prevents next_time() from seeing the scheduled tick event. + return sc_core::sc_time(1, sc_core::SC_PS); } else { return sc_core::SC_ZERO_TIME; }