ruby: perfect switch: refactor code

Refactored the code in operateVnet(), moved partly to a new function
operateMessageBuffer().  This is required since a later patch moves to having a
wakeup event per MessageBuffer instead of one event for the entire Switch.
This commit is contained in:
Nilay Vaish 2015-09-12 16:16:17 -05:00
parent 25cd13dbf1
commit 8b199b775e
2 changed files with 136 additions and 129 deletions

View file

@ -103,9 +103,6 @@ PerfectSwitch::~PerfectSwitch()
void
PerfectSwitch::operateVnet(int vnet)
{
MsgPtr msg_ptr;
Message *net_msg_ptr = NULL;
// This is for round-robin scheduling
int incoming = m_round_robin_start;
m_round_robin_start++;
@ -122,10 +119,6 @@ PerfectSwitch::operateVnet(int vnet)
incoming = 0;
}
// temporary vectors to store the routing results
vector<LinkID> output_links;
vector<NetDest> output_link_destinations;
// Is there a message waiting?
if (m_in[incoming].size() <= vnet) {
continue;
@ -136,6 +129,22 @@ PerfectSwitch::operateVnet(int vnet)
continue;
}
operateMessageBuffer(buffer, incoming, vnet);
}
}
}
void
PerfectSwitch::operateMessageBuffer(MessageBuffer *buffer, int incoming,
int vnet)
{
MsgPtr msg_ptr;
Message *net_msg_ptr = NULL;
// temporary vectors to store the routing results
vector<LinkID> output_links;
vector<NetDest> output_link_destinations;
while (buffer->isReady()) {
DPRINTF(RubyNetwork, "incoming: %d\n", incoming);
@ -257,8 +266,7 @@ PerfectSwitch::operateVnet(int vnet)
// Change the internal destination set of the message so it
// knows which destinations this link is responsible for.
net_msg_ptr = msg_ptr.get();
net_msg_ptr->getDestination() =
output_link_destinations[i];
net_msg_ptr->getDestination() = output_link_destinations[i];
// Enqeue msg
DPRINTF(RubyNetwork, "Enqueuing net msg from "
@ -268,8 +276,6 @@ PerfectSwitch::operateVnet(int vnet)
m_out[outgoing][vnet]->enqueue(msg_ptr);
}
}
}
}
}
void

View file

@ -85,6 +85,7 @@ class PerfectSwitch : public Consumer
PerfectSwitch& operator=(const PerfectSwitch& obj);
void operateVnet(int vnet);
void operateMessageBuffer(MessageBuffer *b, int incoming, int vnet);
const SwitchID m_switch_id;
Switch * const m_switch;