sim: runtime debug flags toggle via SIGRTMIN+1#3181
Open
polpetras wants to merge 1 commit into
Open
Conversation
Add support for toggling gem5 debug flags in a running simulation without restarting. A SIGRTMIN+1 handler (debugCmdHandler) sets async_debug_cmd; doSimLoop() dispatches processDebugCmd() which reads /tmp/gem5_debug_<pid>.cmd and applies the commands. Command format (one per line, # comments supported): +FLAG enable flag (stays on until disabled) +FLAG:Nt enable flag, auto-disable after N ticks -FLAG disable flag immediately trace:on global trace master enable trace:off global trace master disable SIGRTMIN is reserved for KVM (KVM_KICK_SIGNAL in cpu/kvm/base.hh), so SIGRTMIN+1 is used to avoid conflicts. Auto-disable is implemented via DebugFlagOffEvent, a self-deleting Event scheduled on the main event queue. Unknown flag names produce a warning but do not abort processing of remaining commands. util/gem5_debug_ctl.sh is a companion shell script that writes the command file and sends SIGRTMIN+1 (kill -RTMIN+1) to the target pid. base/debug.hh: Flag::_tracing is made std::atomic<bool> with memory_order_relaxed to eliminate the data race between the main thread calling changeFlag() and subordinate threads reading _tracing in DPRINTFs. On x86/ARM64 relaxed atomics compile to plain loads/stores so there is no performance overhead.
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.
Follows up on discussion #1598.
Summary
This patch adds the ability to enable and disable gem5 debug flags in a
running simulation without restarting it.
gem5 installs a handler on
SIGRTMIN+1at simulation start. A companionshell script (
util/gem5_debug_ctl.sh) writes commands to a temporary fileand sends the signal. Commands are processed on the main event loop at the
next sim tick after delivery — no mid-instruction races.
Supported commands:
+FLAG+FLAG:Nt-FLAGtrace:ontrace:offExample usage:
Confirmation lines (
gem5_debug_ctl: ...) appear in the sim's stdout/log.Design notes
SIGRTMIN+1is used to avoidSIGRTMINwhich is reserved for KVM(
KVM_KICK_SIGNAL).async_event+async_debug_cmd, wakes the primary event queue, returnsimmediately. All file I/O and flag changes happen on the main thread.
Flag::_tracingis changed frombooltostd::atomic<bool>(relaxedordering) to eliminate the data race that arises when
changeFlag()iscalled while other host threads are executing
DPRINTF.Event(AutoDelete)scheduled at
curTick() + duration.This implementation was developed with AI assistance.