diff options
author | Steve 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 |
---|---|---|
committer | Steve 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 |
commit | de366a16f11b7e27a5b5e064a2a773052568428e (patch) | |
tree | 9bed0ebc9801c118e0f17702a979a659a59a67df /src/sim/eventq.cc | |
parent | 8a53da22c2f07aed924a45ab296f7468d842d7f6 (diff) | |
download | gem5-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/eventq.cc')
-rw-r--r-- | src/sim/eventq.cc | 67 |
1 files changed, 59 insertions, 8 deletions
diff --git a/src/sim/eventq.cc b/src/sim/eventq.cc index d81937a86..0735a011b 100644 --- a/src/sim/eventq.cc +++ b/src/sim/eventq.cc @@ -1,6 +1,7 @@ /* * Copyright (c) 2000-2005 The Regents of The University of Michigan * Copyright (c) 2008 The Hewlett-Packard Development Company + * Copyright (c) 2013 Advanced Micro Devices, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,13 +47,30 @@ using namespace std; +Tick simQuantum = 0; + // -// Main Event Queue +// Main Event Queues // -// Events on this queue are processed at the *beginning* of each +// Events on these queues are processed at the *beginning* of each // cycle, before the pipeline simulation is performed. // -EventQueue mainEventQueue("Main Event Queue"); +uint32_t numMainEventQueues = 0; +vector<EventQueue *> mainEventQueue; +__thread EventQueue *_curEventQueue = NULL; +bool inParallelMode = false; + +EventQueue * +getEventQueue(uint32_t index) +{ + while (numMainEventQueues <= index) { + numMainEventQueues++; + mainEventQueue.push_back( + new EventQueue(csprintf("MainEventQueue-%d", index))); + } + + return mainEventQueue[index]; +} #ifndef NDEBUG Counter Event::instanceCounter = 0; @@ -156,6 +174,8 @@ EventQueue::remove(Event *event) if (head == NULL) panic("event not found!"); + assert(event->queue == this); + // deal with an event on the head's 'in bin' list (event has the same // time as the head) if (*head == *event) { @@ -232,8 +252,13 @@ Event::serialize(std::ostream &os) void Event::unserialize(Checkpoint *cp, const string §ion) { +} + +void +Event::unserialize(Checkpoint *cp, const string §ion, EventQueue *eventq) +{ if (scheduled()) - mainEventQueue.deschedule(this); + eventq->deschedule(this); UNSERIALIZE_SCALAR(_when); UNSERIALIZE_SCALAR(_priority); @@ -259,7 +284,7 @@ Event::unserialize(Checkpoint *cp, const string §ion) if (wasScheduled) { DPRINTF(Config, "rescheduling at %d\n", _when); - mainEventQueue.schedule(this, _when); + eventq->schedule(this, _when); } } @@ -388,7 +413,9 @@ EventQueue::replaceHead(Event* s) void dumpMainQueue() { - mainEventQueue.dump(); + for (uint32_t i = 0; i < numMainEventQueues; ++i) { + mainEventQueue[i]->dump(); + } } @@ -432,5 +459,29 @@ Event::dump() const } EventQueue::EventQueue(const string &n) - : objName(n), head(NULL), _curTick(0) -{} + : objName(n), head(NULL), _curTick(0), + async_queue_mutex(new std::mutex()) +{ +} + +void +EventQueue::asyncInsert(Event *event) +{ + async_queue_mutex->lock(); + async_queue.push_back(event); + async_queue_mutex->unlock(); +} + +void +EventQueue::handleAsyncInsertions() +{ + assert(this == curEventQueue()); + async_queue_mutex->lock(); + + while (!async_queue.empty()) { + insert(async_queue.front()); + async_queue.pop_front(); + } + + async_queue_mutex->unlock(); +} |