diff --git a/src/mem/ruby/network/MessageBuffer.hh b/src/mem/ruby/network/MessageBuffer.hh --- a/src/mem/ruby/network/MessageBuffer.hh +++ b/src/mem/ruby/network/MessageBuffer.hh @@ -102,6 +102,9 @@ //! removes it from the queue and returns its total delay. Tick dequeue(Tick current_time, bool decrement_messages = true); + void registerDequeueCallback(std::function callback); + void unregisterDequeueCallback(); + void recycle(Tick current_time, Tick recycle_latency); bool isEmpty() const { return m_prio_heap.size() == 0; } bool isStallMapEmpty() { return m_stall_msg_map.size() == 0; } @@ -133,6 +136,8 @@ Consumer* m_consumer; std::vector m_prio_heap; + std::function m_dequeue_callback; + // use a std::map for the stalled messages as this container is // sorted and ensures a well-defined iteration order typedef std::map > StallMsgMapType; # Node ID fd4126ef5e73f6d16b258d2ccb9bc2db0339edae # Parent 676d3e045d22663f15e57ad6c73d4991ea8b4fae diff --git a/src/mem/ruby/network/MessageBuffer.cc b/src/mem/ruby/network/MessageBuffer.cc --- a/src/mem/ruby/network/MessageBuffer.cc +++ b/src/mem/ruby/network/MessageBuffer.cc @@ -59,6 +59,8 @@ m_buf_msgs = 0; m_stall_time = 0; + + m_dequeue_callback = nullptr; } unsigned int @@ -240,10 +242,27 @@ m_buf_msgs--; } + // if a dequeue callback was requested, call it now + if (m_dequeue_callback) { + m_dequeue_callback(); + } + return delay; } void +MessageBuffer::registerDequeueCallback(std::function callback) +{ + m_dequeue_callback = callback; +} + +void +MessageBuffer::unregisterDequeueCallback() +{ + m_dequeue_callback = nullptr; +} + +void MessageBuffer::clear() { m_prio_heap.clear(); diff --git a/src/mem/ruby/network/garnet2.0/NetworkInterface.hh b/src/mem/ruby/network/garnet2.0/NetworkInterface.hh --- a/src/mem/ruby/network/garnet2.0/NetworkInterface.hh +++ b/src/mem/ruby/network/garnet2.0/NetworkInterface.hh @@ -62,6 +62,7 @@ void addOutPort(NetworkLink *out_link, CreditLink *credit_link, SwitchID router_id); + void dequeueCallback(); void wakeup(); void addNode(std::vector &inNode, std::vector &outNode); @@ -89,6 +90,9 @@ CreditLink *inCreditLink; CreditLink *outCreditLink; + // Queue for stalled flits + std::deque m_stall_queue; + // Input Flit Buffers // The flit buffers which will serve the Consumer std::vector m_ni_out_vcs; @@ -99,10 +103,15 @@ // The Message buffers that provides messages to the protocol std::vector outNode_ptr; + bool checkStallQueue(); bool flitisizeMessage(MsgPtr msg_ptr, int vnet); int calculateVC(int vnet); + void scheduleOutputLink(); void checkReschedule(); + void sendCredit(flit *t_flit, bool is_free); + + void incrementStats(flit *t_flit); }; #endif // __MEM_RUBY_NETWORK_GARNET_NETWORK_INTERFACE_HH__ diff --git a/src/mem/ruby/network/garnet2.0/NetworkInterface.cc b/src/mem/ruby/network/garnet2.0/NetworkInterface.cc --- a/src/mem/ruby/network/garnet2.0/NetworkInterface.cc +++ b/src/mem/ruby/network/garnet2.0/NetworkInterface.cc @@ -125,6 +125,38 @@ } } +void +NetworkInterface::dequeueCallback() +{ + // An output MessageBuffer has dequeued something this cycle and there + // is now space to enqueue a stalled message. However, we cannot wake + // on the same cycle as the dequeue. Schedule a wake at the soonest + // possible time (next cycle). + scheduleEventAbsolute(clockEdge(Cycles(1))); +} + +void +NetworkInterface::incrementStats(flit *t_flit) +{ + int vnet = t_flit->get_vnet(); + + // Latency + m_net_ptr->increment_received_flits(vnet); + Cycles network_delay = curCycle() - t_flit->get_enqueue_time(); + Cycles queueing_delay = t_flit->get_src_delay(); + + m_net_ptr->increment_flit_network_latency(network_delay, vnet); + m_net_ptr->increment_flit_queueing_latency(queueing_delay, vnet); + + if (t_flit->get_type() == TAIL_ || t_flit->get_type() == HEAD_TAIL_) { + m_net_ptr->increment_received_packets(vnet); + m_net_ptr->increment_packet_network_latency(network_delay, vnet); + m_net_ptr->increment_packet_queueing_latency(queueing_delay, vnet); + } + + // Hops + m_net_ptr->increment_total_hops(t_flit->get_route().hops_traversed); +} /* * The NI wakeup checks whether there are any ready messages in the protocol @@ -164,48 +196,46 @@ scheduleOutputLink(); checkReschedule(); + // Check if there are flits stalling a virtual channel + bool unstalledMessage = checkStallQueue(); + /*********** Check the incoming flit link **********/ - - if (inNetLink->isReady(curCycle())) { + if (inNetLink->isReady(curCycle()) && !unstalledMessage) { flit *t_flit = inNetLink->consumeLink(); - bool free_signal = false; - if (t_flit->get_type() == TAIL_ || t_flit->get_type() == HEAD_TAIL_) { - free_signal = true; - - // enqueue into the protocol buffers - outNode_ptr[t_flit->get_vnet()]->enqueue( - t_flit->get_msg_ptr(), curTime, cyclesToTicks(Cycles(1))); - } - // Simply send a credit back since we are not buffering - // this flit in the NI - Credit *t_credit = new Credit(t_flit->get_vc(), free_signal, - curCycle()); - outCreditQueue->insert(t_credit); - outCreditLink-> - scheduleEventAbsolute(clockEdge(Cycles(1))); - int vnet = t_flit->get_vnet(); - // Update Stats + // If a tail flit is received, enqueue into the protocol buffers if + // space is available. Otherwise, exchange non-tail flits for credits. + if (t_flit->get_type() == TAIL_ || t_flit->get_type() == HEAD_TAIL_) { + if (outNode_ptr[vnet]->areNSlotsAvailable(1, curTime)) { + // Space is available. Enqueue to protocol buffer. + outNode_ptr[vnet]->enqueue(t_flit->get_msg_ptr(), curTime, + cyclesToTicks(Cycles(1))); - // Latency - m_net_ptr->increment_received_flits(vnet); - Cycles network_delay = curCycle() - t_flit->get_enqueue_time(); - Cycles queueing_delay = t_flit->get_src_delay(); + // Simply send a credit back since we are not buffering + // this flit in the NI + sendCredit(t_flit, true); - m_net_ptr->increment_flit_network_latency(network_delay, vnet); - m_net_ptr->increment_flit_queueing_latency(queueing_delay, vnet); + // Update stats and delete flit pointer + incrementStats(t_flit); + delete t_flit; + } else { + // No space available- Place tail flit in stall queue and set + // up a callback for when protocol buffer is dequeued. Stat + // update and flit pointer deletion will occur upon unstall. + m_stall_queue.push_back(t_flit); - if (t_flit->get_type() == TAIL_ || t_flit->get_type() == HEAD_TAIL_) { - m_net_ptr->increment_received_packets(vnet); - m_net_ptr->increment_packet_network_latency(network_delay, vnet); - m_net_ptr->increment_packet_queueing_latency(queueing_delay, vnet); + auto cb = std::bind(&NetworkInterface::dequeueCallback, this); + outNode_ptr[vnet]->registerDequeueCallback(cb); + } + } else { + // Non-tail flit. Send back a credit but not VC free signal. + sendCredit(t_flit, false); + + // Update stats and delete flit pointer. + incrementStats(t_flit); + delete t_flit; } - - // Hops - m_net_ptr->increment_total_hops(t_flit->get_route().hops_traversed); - - delete t_flit; } /****************** Check the incoming credit link *******/ @@ -220,6 +250,56 @@ } } +void +NetworkInterface::sendCredit(flit *t_flit, bool is_free) +{ + Credit *credit_flit = new Credit(t_flit->get_vc(), is_free, curCycle()); + outCreditQueue->insert(credit_flit); + outCreditLink->scheduleEventAbsolute(clockEdge(Cycles(1))); +} + +bool +NetworkInterface::checkStallQueue() +{ + bool unstalledMessage = false; + Tick curTime = clockEdge(); + + if (!m_stall_queue.empty()) { + for (auto stallIter = m_stall_queue.begin(); + stallIter != m_stall_queue.end(); ) { + flit *stallFlit = *stallIter; + int vnet = stallFlit->get_vnet(); + + // If we can now eject to the protocol buffer, send back credits + if (outNode_ptr[vnet]->areNSlotsAvailable(1, curTime)) { + outNode_ptr[vnet]->enqueue(stallFlit->get_msg_ptr(), curTime, + cyclesToTicks(Cycles(1))); + + // Send back a credit with free signal now that the VC is no + // longer stalled. + sendCredit(stallFlit, true); + + // Update Stats + incrementStats(stallFlit); + + // Flit can now safely be deleted and removed from stall queue + delete stallFlit; + m_stall_queue.erase(stallIter); + + // If there are no more stalled messages for this vnet, the + // callback on it's MessageBuffer is not needed. + outNode_ptr[vnet]->unregisterDequeueCallback(); + + unstalledMessage = true; + break; + } else { + ++stallIter; + } + } + } + + return unstalledMessage; +} // Embed the protocol message into flits bool