From f6ee1f27245b95034fe1e82ab0ea17818d8a981e Mon Sep 17 00:00:00 2001 From: Yu-hsin Wang Date: Tue, 7 Mar 2023 16:59:31 +0800 Subject: [PATCH] fastmodel: delay the breakpoint event handle to simulation stop The fastmodel simulation would be paused when it hits a breakpoint. However, the order of stop event happens after the breakpoint event. If we handle the breakpoint logic in the breakpoint event, it may cause somehow status unsynchronized. To make the behavior stable, we delay the breakpoint handle until the simulation stop event called. Change-Id: I0083561f561af71370ccaa066220b72ed7831b78 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/68697 Reviewed-by: Earl Ou Maintainer: Gabe Black Tested-by: kokoro --- src/arch/arm/fastmodel/iris/thread_context.cc | 31 ++++++++++++------- src/arch/arm/fastmodel/iris/thread_context.hh | 2 ++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/arch/arm/fastmodel/iris/thread_context.cc b/src/arch/arm/fastmodel/iris/thread_context.cc index 45e020d832..462995a19a 100644 --- a/src/arch/arm/fastmodel/iris/thread_context.cc +++ b/src/arch/arm/fastmodel/iris/thread_context.cc @@ -269,6 +269,22 @@ ThreadContext::simulationTimeEvent( return iris::E_ok; } + // Handle the breakpoint event at simulation is stopped if needed. + if (bpAddr.has_value()) { + auto it = getOrAllocBp(bpAddr.value()); + + std::shared_ptr events = it->second->events; + auto e_it = events->begin(); + while (e_it != events->end()) { + PCEvent *e = *e_it; + // Advance e_it here since e might remove itself from the list. + e_it++; + e->process(this); + } + + bpAddr.reset(); + } + // If simulation time has stopped for any reason, IRIS helpfully clears // all stepping counters and we need to set them back. We might also need // to service events based on the current number of executed instructions. @@ -286,19 +302,10 @@ ThreadContext::breakpointHit( uint64_t esId, const iris::IrisValueMap &fields, uint64_t time, uint64_t sInstId, bool syncEc, std::string &error_message_out) { + // Handle the breakpoint event later when the fastmodel simulation is + // stopped. Addr pc = fields.at("PC").getU64(); - - auto it = getOrAllocBp(pc); - - std::shared_ptr events = it->second->events; - auto e_it = events->begin(); - while (e_it != events->end()) { - PCEvent *e = *e_it; - // Advance e_it here since e might remove itself from the list. - e_it++; - e->process(this); - } - + bpAddr = pc; return iris::E_ok; } diff --git a/src/arch/arm/fastmodel/iris/thread_context.hh b/src/arch/arm/fastmodel/iris/thread_context.hh index 05209e685e..88c6746037 100644 --- a/src/arch/arm/fastmodel/iris/thread_context.hh +++ b/src/arch/arm/fastmodel/iris/thread_context.hh @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "arch/arm/fastmodel/iris/memory_spaces.hh" @@ -133,6 +134,7 @@ class ThreadContext : public gem5::ThreadContext using BpInfoIt = BpInfoMap::iterator; BpInfoMap bps; + std::optional bpAddr; BpInfoIt getOrAllocBp(Addr pc);