From 86b1c0fd540b57c1e7bba948ad0417f22f90eb41 Mon Sep 17 00:00:00 2001 From: Nilay Vaish Date: Tue, 18 Sep 2012 22:46:34 -0500 Subject: [PATCH] ruby: avoid using g_system_ptr for event scheduling This patch removes the use of g_system_ptr for event scheduling. Each consumer object now needs to specify upfront an EventManager object it would use for scheduling events. This makes the ruby memory system more amenable for a multi-threaded simulation. --- src/mem/ruby/common/Consumer.cc | 14 +------------- src/mem/ruby/common/Consumer.hh | 7 +++---- .../network/garnet/fixed-pipeline/InputUnit_d.cc | 2 +- .../garnet/fixed-pipeline/NetworkInterface_d.cc | 1 + .../network/garnet/fixed-pipeline/NetworkLink_d.cc | 2 +- .../network/garnet/fixed-pipeline/OutputUnit_d.cc | 1 + .../network/garnet/fixed-pipeline/SWallocator_d.cc | 1 + .../ruby/network/garnet/fixed-pipeline/Switch_d.cc | 1 + .../network/garnet/fixed-pipeline/VCallocator_d.cc | 1 + .../garnet/flexible-pipeline/FlexibleConsumer.hh | 1 + .../garnet/flexible-pipeline/NetworkInterface.cc | 1 + .../garnet/flexible-pipeline/NetworkLink.cc | 4 ++-- .../network/garnet/flexible-pipeline/Router.cc | 2 +- .../network/garnet/flexible-pipeline/VCarbiter.cc | 1 + src/mem/ruby/network/simple/PerfectSwitch.cc | 1 + src/mem/ruby/network/simple/Switch.cc | 4 ++-- src/mem/ruby/network/simple/Switch.hh | 2 -- src/mem/ruby/network/simple/Throttle.cc | 8 ++++++-- src/mem/ruby/network/simple/Throttle.hh | 5 +++-- src/mem/ruby/slicc_interface/AbstractController.cc | 3 ++- src/mem/ruby/system/AbstractMemOrCache.hh | 1 - src/mem/ruby/system/MemoryControl.cc | 3 ++- src/mem/ruby/system/System.hh | 1 - src/mem/ruby/system/WireBuffer.cc | 3 --- src/mem/ruby/system/WireBuffer.hh | 3 +-- src/mem/slicc/ast/FuncCallExprAST.py | 4 ++-- src/mem/slicc/symbols/StateMachine.py | 2 +- 27 files changed, 37 insertions(+), 42 deletions(-) diff --git a/src/mem/ruby/common/Consumer.cc b/src/mem/ruby/common/Consumer.cc index 1f7aeebd5..de6a8f448 100644 --- a/src/mem/ruby/common/Consumer.cc +++ b/src/mem/ruby/common/Consumer.cc @@ -33,23 +33,11 @@ void Consumer::scheduleEvent(Time timeDelta) { - scheduleEvent(g_system_ptr, timeDelta); -} - -void -Consumer::scheduleEvent(EventManager *em, Time timeDelta) -{ - scheduleEventAbsolute(em, timeDelta + g_system_ptr->getTime()); + scheduleEventAbsolute(timeDelta + g_system_ptr->getTime()); } void Consumer::scheduleEventAbsolute(Time timeAbs) -{ - scheduleEventAbsolute(g_system_ptr, timeAbs); -} - -void -Consumer::scheduleEventAbsolute(EventManager *em, Time timeAbs) { Tick evt_time = g_system_ptr->clockPeriod() * timeAbs; if (!alreadyScheduled(evt_time)) { diff --git a/src/mem/ruby/common/Consumer.hh b/src/mem/ruby/common/Consumer.hh index 6a67bde39..a10abf362 100644 --- a/src/mem/ruby/common/Consumer.hh +++ b/src/mem/ruby/common/Consumer.hh @@ -44,8 +44,8 @@ class Consumer { public: - Consumer() - : m_last_scheduled_wakeup(0), m_last_wakeup(0) + Consumer(EventManager *_em) + : m_last_scheduled_wakeup(0), m_last_wakeup(0), em(_em) { } @@ -88,8 +88,6 @@ class Consumer m_scheduled_wakeups.erase(time); } - void scheduleEvent(EventManager* em, Time timeDelta); - void scheduleEventAbsolute(EventManager* em, Time timeAbs); void scheduleEvent(Time timeDelta); void scheduleEventAbsolute(Time timeAbs); @@ -97,6 +95,7 @@ class Consumer Tick m_last_scheduled_wakeup; std::set m_scheduled_wakeups; Tick m_last_wakeup; + EventManager *em; class ConsumerEvent : public Event { diff --git a/src/mem/ruby/network/garnet/fixed-pipeline/InputUnit_d.cc b/src/mem/ruby/network/garnet/fixed-pipeline/InputUnit_d.cc index adafa4d24..62b8cd574 100644 --- a/src/mem/ruby/network/garnet/fixed-pipeline/InputUnit_d.cc +++ b/src/mem/ruby/network/garnet/fixed-pipeline/InputUnit_d.cc @@ -35,7 +35,7 @@ using namespace std; using m5::stl_helpers::deletePointers; -InputUnit_d::InputUnit_d(int id, Router_d *router) +InputUnit_d::InputUnit_d(int id, Router_d *router) : Consumer(router) { m_id = id; m_router = router; diff --git a/src/mem/ruby/network/garnet/fixed-pipeline/NetworkInterface_d.cc b/src/mem/ruby/network/garnet/fixed-pipeline/NetworkInterface_d.cc index 4bdce2a34..b0538d19f 100644 --- a/src/mem/ruby/network/garnet/fixed-pipeline/NetworkInterface_d.cc +++ b/src/mem/ruby/network/garnet/fixed-pipeline/NetworkInterface_d.cc @@ -44,6 +44,7 @@ using m5::stl_helpers::deletePointers; NetworkInterface_d::NetworkInterface_d(int id, int virtual_networks, GarnetNetwork_d *network_ptr) + : Consumer(network_ptr) { m_id = id; m_net_ptr = network_ptr; diff --git a/src/mem/ruby/network/garnet/fixed-pipeline/NetworkLink_d.cc b/src/mem/ruby/network/garnet/fixed-pipeline/NetworkLink_d.cc index ac41263e3..432097a91 100644 --- a/src/mem/ruby/network/garnet/fixed-pipeline/NetworkLink_d.cc +++ b/src/mem/ruby/network/garnet/fixed-pipeline/NetworkLink_d.cc @@ -32,7 +32,7 @@ #include "mem/ruby/network/garnet/fixed-pipeline/NetworkLink_d.hh" NetworkLink_d::NetworkLink_d(const Params *p) - : SimObject(p) + : SimObject(p), Consumer(this) { m_latency = p->link_latency; channel_width = p->channel_width; diff --git a/src/mem/ruby/network/garnet/fixed-pipeline/OutputUnit_d.cc b/src/mem/ruby/network/garnet/fixed-pipeline/OutputUnit_d.cc index 429ff4d91..33d1583e1 100644 --- a/src/mem/ruby/network/garnet/fixed-pipeline/OutputUnit_d.cc +++ b/src/mem/ruby/network/garnet/fixed-pipeline/OutputUnit_d.cc @@ -36,6 +36,7 @@ using namespace std; using m5::stl_helpers::deletePointers; OutputUnit_d::OutputUnit_d(int id, Router_d *router) + : Consumer(router) { m_id = id; m_router = router; diff --git a/src/mem/ruby/network/garnet/fixed-pipeline/SWallocator_d.cc b/src/mem/ruby/network/garnet/fixed-pipeline/SWallocator_d.cc index 530e8f1b2..41ff8d482 100644 --- a/src/mem/ruby/network/garnet/fixed-pipeline/SWallocator_d.cc +++ b/src/mem/ruby/network/garnet/fixed-pipeline/SWallocator_d.cc @@ -35,6 +35,7 @@ #include "mem/ruby/network/garnet/fixed-pipeline/SWallocator_d.hh" SWallocator_d::SWallocator_d(Router_d *router) + : Consumer(router) { m_router = router; m_num_vcs = m_router->get_num_vcs(); diff --git a/src/mem/ruby/network/garnet/fixed-pipeline/Switch_d.cc b/src/mem/ruby/network/garnet/fixed-pipeline/Switch_d.cc index 12c00d9d0..1cb31c3e3 100644 --- a/src/mem/ruby/network/garnet/fixed-pipeline/Switch_d.cc +++ b/src/mem/ruby/network/garnet/fixed-pipeline/Switch_d.cc @@ -37,6 +37,7 @@ using m5::stl_helpers::deletePointers; Switch_d::Switch_d(Router_d *router) + : Consumer(router) { m_router = router; m_num_vcs = m_router->get_num_vcs(); diff --git a/src/mem/ruby/network/garnet/fixed-pipeline/VCallocator_d.cc b/src/mem/ruby/network/garnet/fixed-pipeline/VCallocator_d.cc index 3940e1d6a..75533fb10 100644 --- a/src/mem/ruby/network/garnet/fixed-pipeline/VCallocator_d.cc +++ b/src/mem/ruby/network/garnet/fixed-pipeline/VCallocator_d.cc @@ -35,6 +35,7 @@ #include "mem/ruby/network/garnet/fixed-pipeline/VCallocator_d.hh" VCallocator_d::VCallocator_d(Router_d *router) + : Consumer(router) { m_router = router; m_num_vcs = m_router->get_num_vcs(); diff --git a/src/mem/ruby/network/garnet/flexible-pipeline/FlexibleConsumer.hh b/src/mem/ruby/network/garnet/flexible-pipeline/FlexibleConsumer.hh index 04a4ac95a..a2d6db60b 100644 --- a/src/mem/ruby/network/garnet/flexible-pipeline/FlexibleConsumer.hh +++ b/src/mem/ruby/network/garnet/flexible-pipeline/FlexibleConsumer.hh @@ -38,6 +38,7 @@ class FlexibleConsumer : public Consumer { public: + FlexibleConsumer(EventManager *em) : Consumer(em) {} virtual bool isBufferNotFull(int vc, int inport) { return true; } virtual void grant_vc(int out_port, int vc, Time grant_time) {} virtual void release_vc(int out_port, int vc, Time release_time) {} diff --git a/src/mem/ruby/network/garnet/flexible-pipeline/NetworkInterface.cc b/src/mem/ruby/network/garnet/flexible-pipeline/NetworkInterface.cc index cc7dd7146..824acce80 100644 --- a/src/mem/ruby/network/garnet/flexible-pipeline/NetworkInterface.cc +++ b/src/mem/ruby/network/garnet/flexible-pipeline/NetworkInterface.cc @@ -44,6 +44,7 @@ using m5::stl_helpers::deletePointers; NetworkInterface::NetworkInterface(int id, int virtual_networks, GarnetNetwork *network_ptr) + : FlexibleConsumer(network_ptr) { m_id = id; m_net_ptr = network_ptr; diff --git a/src/mem/ruby/network/garnet/flexible-pipeline/NetworkLink.cc b/src/mem/ruby/network/garnet/flexible-pipeline/NetworkLink.cc index fb7c9bd44..3908d34c3 100644 --- a/src/mem/ruby/network/garnet/flexible-pipeline/NetworkLink.cc +++ b/src/mem/ruby/network/garnet/flexible-pipeline/NetworkLink.cc @@ -32,7 +32,7 @@ #include "mem/ruby/network/garnet/flexible-pipeline/NetworkLink.hh" NetworkLink::NetworkLink(const Params *p) - : SimObject(p) + : SimObject(p), FlexibleConsumer(this) { linkBuffer = new flitBuffer(); m_in_port = 0; @@ -140,7 +140,7 @@ NetworkLink::wakeup() flit *t_flit = link_srcQueue->getTopFlit(); t_flit->set_time(g_system_ptr->getTime() + m_latency); linkBuffer->insert(t_flit); - link_consumer->scheduleEvent(this, m_latency); + link_consumer->scheduleEvent(m_latency); m_link_utilized++; m_vc_load[t_flit->get_vc()]++; } diff --git a/src/mem/ruby/network/garnet/flexible-pipeline/Router.cc b/src/mem/ruby/network/garnet/flexible-pipeline/Router.cc index 28e9fc497..88361d35a 100644 --- a/src/mem/ruby/network/garnet/flexible-pipeline/Router.cc +++ b/src/mem/ruby/network/garnet/flexible-pipeline/Router.cc @@ -41,7 +41,7 @@ using namespace std; using m5::stl_helpers::deletePointers; Router::Router(const Params *p) - : BasicRouter(p) + : BasicRouter(p), FlexibleConsumer(this) { m_id = p->router_id; m_virtual_networks = p->virt_nets; diff --git a/src/mem/ruby/network/garnet/flexible-pipeline/VCarbiter.cc b/src/mem/ruby/network/garnet/flexible-pipeline/VCarbiter.cc index e68e1b12f..5ed336699 100644 --- a/src/mem/ruby/network/garnet/flexible-pipeline/VCarbiter.cc +++ b/src/mem/ruby/network/garnet/flexible-pipeline/VCarbiter.cc @@ -32,6 +32,7 @@ #include "mem/ruby/network/garnet/flexible-pipeline/VCarbiter.hh" VCarbiter::VCarbiter(Router *router) + : Consumer(router) { m_router = router; } diff --git a/src/mem/ruby/network/simple/PerfectSwitch.cc b/src/mem/ruby/network/simple/PerfectSwitch.cc index 66065e22c..0ead3ac30 100644 --- a/src/mem/ruby/network/simple/PerfectSwitch.cc +++ b/src/mem/ruby/network/simple/PerfectSwitch.cc @@ -49,6 +49,7 @@ operator<(const LinkOrder& l1, const LinkOrder& l2) } PerfectSwitch::PerfectSwitch(SwitchID sid, SimpleNetwork* network_ptr) + : Consumer(network_ptr) { m_virtual_networks = network_ptr->getNumberOfVirtualNetworks(); m_switch_id = sid; diff --git a/src/mem/ruby/network/simple/Switch.cc b/src/mem/ruby/network/simple/Switch.cc index 922807a0b..42a4efae3 100644 --- a/src/mem/ruby/network/simple/Switch.cc +++ b/src/mem/ruby/network/simple/Switch.cc @@ -74,7 +74,8 @@ Switch::addOutPort(const vector& out, // Create a throttle throttle_ptr = new Throttle(m_switch_id, m_throttles.size(), link_latency, - bw_multiplier, net_ptr->getEndpointBandwidth()); + bw_multiplier, net_ptr->getEndpointBandwidth(), + net_ptr); m_throttles.push_back(throttle_ptr); // Create one buffer per vnet (these are intermediaryQueues) @@ -214,4 +215,3 @@ Switch::print(std::ostream& out) const // FIXME printing out << "[Switch]"; } - diff --git a/src/mem/ruby/network/simple/Switch.hh b/src/mem/ruby/network/simple/Switch.hh index 31ea6add1..0bc1e5eca 100644 --- a/src/mem/ruby/network/simple/Switch.hh +++ b/src/mem/ruby/network/simple/Switch.hh @@ -42,8 +42,6 @@ #include #include -#include "mem/ruby/common/Global.hh" - class MessageBuffer; class PerfectSwitch; class NetDest; diff --git a/src/mem/ruby/network/simple/Throttle.cc b/src/mem/ruby/network/simple/Throttle.cc index 05dfc2553..e4dc71527 100644 --- a/src/mem/ruby/network/simple/Throttle.cc +++ b/src/mem/ruby/network/simple/Throttle.cc @@ -49,14 +49,18 @@ const int PRIORITY_SWITCH_LIMIT = 128; static int network_message_to_size(NetworkMessage* net_msg_ptr); Throttle::Throttle(int sID, NodeID node, int link_latency, - int link_bandwidth_multiplier, int endpoint_bandwidth) + int link_bandwidth_multiplier, int endpoint_bandwidth, + EventManager *em) + : Consumer(em) { init(node, link_latency, link_bandwidth_multiplier, endpoint_bandwidth); m_sID = sID; } Throttle::Throttle(NodeID node, int link_latency, - int link_bandwidth_multiplier, int endpoint_bandwidth) + int link_bandwidth_multiplier, int endpoint_bandwidth, + EventManager *em) + : Consumer(em) { init(node, link_latency, link_bandwidth_multiplier, endpoint_bandwidth); m_sID = 0; diff --git a/src/mem/ruby/network/simple/Throttle.hh b/src/mem/ruby/network/simple/Throttle.hh index 37a53b80a..b86a247d2 100644 --- a/src/mem/ruby/network/simple/Throttle.hh +++ b/src/mem/ruby/network/simple/Throttle.hh @@ -53,9 +53,10 @@ class Throttle : public Consumer { public: Throttle(int sID, NodeID node, int link_latency, - int link_bandwidth_multiplier, int endpoint_bandwidth); + int link_bandwidth_multiplier, int endpoint_bandwidth, + EventManager *em); Throttle(NodeID node, int link_latency, int link_bandwidth_multiplier, - int endpoint_bandwidth); + int endpoint_bandwidth, EventManager *em); ~Throttle() {} std::string name() diff --git a/src/mem/ruby/slicc_interface/AbstractController.cc b/src/mem/ruby/slicc_interface/AbstractController.cc index 04bbb87d8..eca68ad05 100644 --- a/src/mem/ruby/slicc_interface/AbstractController.cc +++ b/src/mem/ruby/slicc_interface/AbstractController.cc @@ -29,7 +29,8 @@ #include "mem/ruby/slicc_interface/AbstractController.hh" #include "mem/ruby/system/System.hh" -AbstractController::AbstractController(const Params *p) : SimObject(p) +AbstractController::AbstractController(const Params *p) + : SimObject(p), Consumer(this) { p->ruby_system->registerAbstractController(this); } diff --git a/src/mem/ruby/system/AbstractMemOrCache.hh b/src/mem/ruby/system/AbstractMemOrCache.hh index 4d1fee69a..3f3fb6fa0 100644 --- a/src/mem/ruby/system/AbstractMemOrCache.hh +++ b/src/mem/ruby/system/AbstractMemOrCache.hh @@ -35,7 +35,6 @@ class Consumer; class MemoryNode; -class Message; class AbstractMemOrCache { diff --git a/src/mem/ruby/system/MemoryControl.cc b/src/mem/ruby/system/MemoryControl.cc index f1ebc07fa..c5ddb0c44 100644 --- a/src/mem/ruby/system/MemoryControl.cc +++ b/src/mem/ruby/system/MemoryControl.cc @@ -42,7 +42,8 @@ #include "mem/ruby/system/System.hh" using namespace std; -MemoryControl::MemoryControl(const Params *p) : ClockedObject(p), m_event(this) +MemoryControl::MemoryControl(const Params *p) + : ClockedObject(p), Consumer(this), m_event(this) { g_system_ptr->registerMemController(this); } diff --git a/src/mem/ruby/system/System.hh b/src/mem/ruby/system/System.hh index c7d005085..f7e0efc2a 100644 --- a/src/mem/ruby/system/System.hh +++ b/src/mem/ruby/system/System.hh @@ -133,7 +133,6 @@ class RubySystem : public ClockedObject void init(); - static void printSystemConfig(std::ostream& out); void readCompressedTrace(std::string filename, uint8_t *&raw_data, uint64& uncompressed_trace_size); diff --git a/src/mem/ruby/system/WireBuffer.cc b/src/mem/ruby/system/WireBuffer.cc index fb12998be..0845b3c8d 100644 --- a/src/mem/ruby/system/WireBuffer.cc +++ b/src/mem/ruby/system/WireBuffer.cc @@ -38,9 +38,6 @@ using namespace std; -class Consumer; - - // Output operator definition ostream& diff --git a/src/mem/ruby/system/WireBuffer.hh b/src/mem/ruby/system/WireBuffer.hh index c22fab70b..07da965c8 100644 --- a/src/mem/ruby/system/WireBuffer.hh +++ b/src/mem/ruby/system/WireBuffer.hh @@ -37,7 +37,7 @@ #include #include "mem/ruby/buffers/MessageBufferNode.hh" -#include "mem/ruby/common/Global.hh" +#include "mem/ruby/common/Consumer.hh" #include "params/RubyWireBuffer.hh" #include "sim/sim_object.hh" @@ -51,7 +51,6 @@ // separated by a network in real systems to simplify coherence. ///////////////////////////////////////////////////////////////////////////// -class Consumer; class Message; class WireBuffer : public SimObject diff --git a/src/mem/slicc/ast/FuncCallExprAST.py b/src/mem/slicc/ast/FuncCallExprAST.py index ab6261de2..1438934e6 100644 --- a/src/mem/slicc/ast/FuncCallExprAST.py +++ b/src/mem/slicc/ast/FuncCallExprAST.py @@ -142,7 +142,7 @@ class FuncCallExprAST(ExprAST): } if (result == TransitionResult_ResourceStall) { - scheduleEvent(this, 1); + scheduleEvent(1); // Cannot do anything with this transition, go check next doable transition (mostly likely of next port) } @@ -173,7 +173,7 @@ class FuncCallExprAST(ExprAST): } if (result1 == TransitionResult_ResourceStall) { - scheduleEvent(this, 1); + scheduleEvent(1); // Cannot do anything with this transition, go check next // doable transition (mostly likely of next port) } diff --git a/src/mem/slicc/symbols/StateMachine.py b/src/mem/slicc/symbols/StateMachine.py index 47f7daa00..43153c773 100644 --- a/src/mem/slicc/symbols/StateMachine.py +++ b/src/mem/slicc/symbols/StateMachine.py @@ -1047,7 +1047,7 @@ ${ident}_Controller::wakeup() g_system_ptr->getProfiler()->controllerBusy(m_machineID); // Wakeup in another cycle and try again - scheduleEvent(this, 1); + scheduleEvent(1); break; } ''') -- 2.30.2