summaryrefslogtreecommitdiff
path: root/src/sim/sim_events.cc
diff options
context:
space:
mode:
authorSteve Reinhardt ext:(%2C%20Nilay%20Vaish%20%3Cnilay%40cs.wisc.edu%3E%2C%20Ali%20Saidi%20%3CAli.Saidi%40ARM.com%3E) <stever@gmail.com>2013-11-25 11:21:00 -0600
committerSteve Reinhardt ext:(%2C%20Nilay%20Vaish%20%3Cnilay%40cs.wisc.edu%3E%2C%20Ali%20Saidi%20%3CAli.Saidi%40ARM.com%3E) <stever@gmail.com>2013-11-25 11:21:00 -0600
commitde366a16f11b7e27a5b5e064a2a773052568428e (patch)
tree9bed0ebc9801c118e0f17702a979a659a59a67df /src/sim/sim_events.cc
parent8a53da22c2f07aed924a45ab296f7468d842d7f6 (diff)
downloadgem5-de366a16f11b7e27a5b5e064a2a773052568428e.tar.xz
sim: simulate with multiple threads and event queues
This patch adds support for simulating with multiple threads, each of which operates on an event queue. Each sim object specifies which eventq is would like to be on. A custom barrier implementation is being added using which eventqs synchronize. The patch was tested in two different configurations: 1. ruby_network_test.py: in this simulation L1 cache controllers receive requests from the cpu. The requests are replied to immediately without any communication taking place with any other level. 2. twosys-tsunami-simple-atomic: this configuration simulates a client-server system which are connected by an ethernet link. We still lack the ability to communicate using message buffers or ports. But other things like simulation start and end, synchronizing after every quantum are working. Committed by: Nilay Vaish
Diffstat (limited to 'src/sim/sim_events.cc')
-rw-r--r--src/sim/sim_events.cc92
1 files changed, 58 insertions, 34 deletions
diff --git a/src/sim/sim_events.cc b/src/sim/sim_events.cc
index 5380ddd83..5e47adca1 100644
--- a/src/sim/sim_events.cc
+++ b/src/sim/sim_events.cc
@@ -12,6 +12,8 @@
* modified or unmodified, in source code or in binary form.
*
* Copyright (c) 2002-2005 The Regents of The University of Michigan
+ * Copyright (c) 2013 Advanced Micro Devices, Inc.
+ * Copyright (c) 2013 Mark D. Hill and David A. Wood
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -51,53 +53,71 @@
using namespace std;
-SimLoopExitEvent::SimLoopExitEvent()
+GlobalSimLoopExitEvent::GlobalSimLoopExitEvent(Tick when,
+ const std::string &_cause,
+ int c, Tick r, bool serialize)
+ : GlobalEvent(when, Sim_Exit_Pri,
+ IsExitEvent | (serialize ? AutoSerialize : 0)),
+ cause(_cause), code(c), repeat(r)
+{
+}
+
+const char *
+GlobalSimLoopExitEvent::description() const
+{
+ return "global simulation loop exit";
+}
+
+//
+// handle termination event
+//
+void
+GlobalSimLoopExitEvent::process()
+{
+ if (repeat) {
+ schedule(curTick() + repeat);
+ }
+}
+
+void
+exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
+ bool serialize)
+{
+ new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat,
+ serialize);
+}
+
+LocalSimLoopExitEvent::LocalSimLoopExitEvent()
: Event(Sim_Exit_Pri, IsExitEvent | AutoSerialize),
cause(""), code(0), repeat(0)
{
}
-SimLoopExitEvent::SimLoopExitEvent(const std::string &_cause, int c, Tick r,
- bool serialize)
+LocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c,
+ Tick r, bool serialize)
: Event(Sim_Exit_Pri, IsExitEvent | (serialize ? AutoSerialize : 0)),
cause(_cause), code(c), repeat(r)
{
}
-
//
// handle termination event
//
void
-SimLoopExitEvent::process()
+LocalSimLoopExitEvent::process()
{
- // if this got scheduled on a different queue (e.g. the committed
- // instruction queue) then make a corresponding event on the main
- // queue.
- if (!isFlagSet(IsMainQueue)) {
- exitSimLoop(cause, code);
- setFlags(AutoDelete);
- }
-
- // otherwise do nothing... the IsExitEvent flag takes care of
- // exiting the simulation loop and returning this object to Python
-
- // but if you are doing this on intervals, don't forget to make another
- if (repeat) {
- assert(isFlagSet(IsMainQueue));
- mainEventQueue.schedule(this, curTick() + repeat);
- }
+ exitSimLoop(cause, 0);
}
const char *
-SimLoopExitEvent::description() const
+LocalSimLoopExitEvent::description() const
{
return "simulation loop exit";
}
void
-SimLoopExitEvent::serialize(ostream &os)
+LocalSimLoopExitEvent::serialize(ostream &os)
{
paramOut(os, "type", string("SimLoopExitEvent"));
Event::serialize(os);
@@ -108,7 +128,7 @@ SimLoopExitEvent::serialize(ostream &os)
}
void
-SimLoopExitEvent::unserialize(Checkpoint *cp, const string &section)
+LocalSimLoopExitEvent::unserialize(Checkpoint *cp, const string &section)
{
Event::unserialize(cp, section);
@@ -117,22 +137,26 @@ SimLoopExitEvent::unserialize(Checkpoint *cp, const string &section)
UNSERIALIZE_SCALAR(repeat);
}
-Serializable *
-SimLoopExitEvent::createForUnserialize(Checkpoint *cp, const string &section)
+void
+LocalSimLoopExitEvent::unserialize(Checkpoint *cp, const string &section,
+ EventQueue *eventq)
{
- return new SimLoopExitEvent();
-}
+ Event::unserialize(cp, section, eventq);
-REGISTER_SERIALIZEABLE("SimLoopExitEvent", SimLoopExitEvent)
+ UNSERIALIZE_SCALAR(cause);
+ UNSERIALIZE_SCALAR(code);
+ UNSERIALIZE_SCALAR(repeat);
+}
-void
-exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
- bool serialize)
+Serializable *
+LocalSimLoopExitEvent::createForUnserialize(Checkpoint *cp,
+ const string &section)
{
- Event *event = new SimLoopExitEvent(message, exit_code, repeat, serialize);
- mainEventQueue.schedule(event, when);
+ return new LocalSimLoopExitEvent();
}
+REGISTER_SERIALIZEABLE("LocalSimLoopExitEvent", LocalSimLoopExitEvent)
+
//
// constructor: automatically schedules at specified time
//