From bc87fa30d72df7db6265be50b2c39dc218076f9f Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 10 Jun 2010 23:17:06 -0700 Subject: ruby: get rid of RefCnt and Allocator stuff use base/refcnt.hh This was somewhat tricky because the RefCnt API was somewhat odd. The biggest confusion was that the the RefCnt object's constructor that took a TYPE& cloned the object. I created an explicit virtual clone() function for things that took advantage of this version of the constructor. I was conservative and used clone() when I was in doubt of whether or not it was necessary. I still think that there are probably too many instances of clone(), but hopefully not too many. I converted several instances of const MsgPtr & to a simple MsgPtr. If the function wants to avoid the overhead of creating another reference, then it should just use a regular pointer instead of a ref counting ptr. There were a couple of instances where refcounted objects were created on the stack. This seems pretty dangerous since if you ever accidentally make a reference to that object with a ref counting pointer, bad things are bound to happen. --- .../ruby/network/garnet/fixed-pipeline/NetworkInterface_d.cc | 10 ++++++---- src/mem/ruby/network/garnet/fixed-pipeline/RoutingUnit_d.cc | 4 ++-- .../ruby/network/garnet/flexible-pipeline/NetworkInterface.cc | 8 +++++--- src/mem/ruby/network/garnet/flexible-pipeline/Router.cc | 4 +++- 4 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/mem/ruby/network/garnet') 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 da86c32fa..2a2536d53 100644 --- a/src/mem/ruby/network/garnet/fixed-pipeline/NetworkInterface_d.cc +++ b/src/mem/ruby/network/garnet/fixed-pipeline/NetworkInterface_d.cc @@ -107,7 +107,8 @@ void NetworkInterface_d::addNode(Vector& in, Vector(msg_ptr.ref()); + NetworkMessage *net_msg_ptr = + safe_cast(msg_ptr.get()); NetDest net_msg_dest = net_msg_ptr->getInternalDestination(); Vector dest_nodes = net_msg_dest.getAllDest(); // gets all the destinations associated with this message. @@ -120,10 +121,11 @@ bool NetworkInterface_d::flitisizeMessage(MsgPtr msg_ptr, int vnet) { return false ; } - MsgPtr new_msg_ptr = *(msg_ptr.ref()); + MsgPtr new_msg_ptr = msg_ptr->clone(); NodeID destID = dest_nodes[ctr]; - NetworkMessage *new_net_msg_ptr = dynamic_cast(new_msg_ptr.ref()); + NetworkMessage *new_net_msg_ptr = + safe_cast(new_msg_ptr.get()); if(dest_nodes.size() > 1) { NetDest personal_dest; @@ -145,7 +147,7 @@ bool NetworkInterface_d::flitisizeMessage(MsgPtr msg_ptr, int vnet) { m_net_ptr->increment_injected_flits(); flit_d *fl = new flit_d(i, vc, vnet, num_flits, new_msg_ptr); - fl->set_delay(g_eventQueue_ptr->getTime() - (msg_ptr.ref())->getTime()); + fl->set_delay(g_eventQueue_ptr->getTime() - msg_ptr->getTime()); m_ni_buffers[vc]->insert(fl); } m_ni_enqueue_time[vc] = g_eventQueue_ptr->getTime(); diff --git a/src/mem/ruby/network/garnet/fixed-pipeline/RoutingUnit_d.cc b/src/mem/ruby/network/garnet/fixed-pipeline/RoutingUnit_d.cc index 0c215efd3..fabda735a 100644 --- a/src/mem/ruby/network/garnet/fixed-pipeline/RoutingUnit_d.cc +++ b/src/mem/ruby/network/garnet/fixed-pipeline/RoutingUnit_d.cc @@ -61,8 +61,8 @@ void RoutingUnit_d::RC_stage(flit_d *t_flit, InputUnit_d *in_unit, int invc) int RoutingUnit_d::routeCompute(flit_d *t_flit) { MsgPtr msg_ptr = t_flit->get_msg_ptr(); - NetworkMessage* net_msg_ptr = NULL; - net_msg_ptr = dynamic_cast(msg_ptr.ref()); + NetworkMessage* net_msg_ptr = + safe_cast(msg_ptr.get()); NetDest msg_destination = net_msg_ptr->getInternalDestination(); int output_link = -1; diff --git a/src/mem/ruby/network/garnet/flexible-pipeline/NetworkInterface.cc b/src/mem/ruby/network/garnet/flexible-pipeline/NetworkInterface.cc index 697f954ab..c81f5e4b2 100644 --- a/src/mem/ruby/network/garnet/flexible-pipeline/NetworkInterface.cc +++ b/src/mem/ruby/network/garnet/flexible-pipeline/NetworkInterface.cc @@ -103,7 +103,8 @@ void NetworkInterface::request_vc(int in_vc, int in_port, NetDest destination, T bool NetworkInterface::flitisizeMessage(MsgPtr msg_ptr, int vnet) { - NetworkMessage *net_msg_ptr = dynamic_cast(msg_ptr.ref()); + NetworkMessage *net_msg_ptr = + safe_cast(msg_ptr.get()); NetDest net_msg_dest = net_msg_ptr->getInternalDestination(); Vector dest_nodes = net_msg_dest.getAllDest(); // gets all the destinations associated with this message. int num_flits = (int) ceil((double) m_net_ptr->MessageSizeType_to_int(net_msg_ptr->getMessageSize())/m_net_ptr->getFlitSize() ); // Number of flits is dependent on the link bandwidth available. This is expressed in terms of bytes/cycle or the flit size @@ -117,10 +118,11 @@ bool NetworkInterface::flitisizeMessage(MsgPtr msg_ptr, int vnet) // did not find a free output vc return false ; } - MsgPtr new_msg_ptr = *(msg_ptr.ref()); + MsgPtr new_msg_ptr = msg_ptr->clone(); NodeID destID = dest_nodes[ctr]; - NetworkMessage *new_net_msg_ptr = dynamic_cast(new_msg_ptr.ref()); + NetworkMessage *new_net_msg_ptr = + safe_cast(new_msg_ptr.get()); if(dest_nodes.size() > 1) { NetDest personal_dest; diff --git a/src/mem/ruby/network/garnet/flexible-pipeline/Router.cc b/src/mem/ruby/network/garnet/flexible-pipeline/Router.cc index 10696f1ad..4cdb9dad8 100644 --- a/src/mem/ruby/network/garnet/flexible-pipeline/Router.cc +++ b/src/mem/ruby/network/garnet/flexible-pipeline/Router.cc @@ -252,7 +252,9 @@ void Router::routeCompute(flit *m_flit, int inport) g_eventQueue_ptr->scheduleEvent(this, m_net_ptr->getNumPipeStages() -1 ); if((m_flit->get_type() == HEAD_) || (m_flit->get_type() == HEAD_TAIL_)) { - NetDest destination = dynamic_cast(m_flit->get_msg_ptr().ref())->getInternalDestination(); + NetworkMessage *nm = + safe_cast(m_flit->get_msg_ptr().get()); + NetDest destination = nm->getInternalDestination(); if(m_net_ptr->getNumPipeStages() > 1) { m_out_vc_state[outport][outvc]->setState(VC_AB_, g_eventQueue_ptr->getTime() + 1); -- cgit v1.2.3