gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OutputUnit.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Princeton University
3  * Copyright (c) 2016 Georgia Institute of Technology
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Authors: Niket Agarwal
30  * Tushar Krishna
31  */
32 
33 
35 
36 #include "base/stl_helpers.hh"
37 #include "debug/RubyNetwork.hh"
40 
41 using namespace std;
43 
44 OutputUnit::OutputUnit(int id, PortDirection direction, Router *router)
45  : Consumer(router)
46 {
47  m_id = id;
48  m_direction = direction;
49  m_router = router;
52  m_out_buffer = new flitBuffer();
53 
54  for (int i = 0; i < m_num_vcs; i++) {
55  m_outvc_state.push_back(new OutVcState(i, m_router->get_net_ptr()));
56  }
57 }
58 
60 {
61  delete m_out_buffer;
63 }
64 
65 void
67 {
68  DPRINTF(RubyNetwork, "Router %d OutputUnit %d decrementing credit for "
69  "outvc %d at time: %lld\n",
70  m_router->get_id(), m_id, out_vc, m_router->curCycle());
71 
72  m_outvc_state[out_vc]->decrement_credit();
73 }
74 
75 void
77 {
78  DPRINTF(RubyNetwork, "Router %d OutputUnit %d incrementing credit for "
79  "outvc %d at time: %lld\n",
80  m_router->get_id(), m_id, out_vc, m_router->curCycle());
81 
82  m_outvc_state[out_vc]->increment_credit();
83 }
84 
85 // Check if the output VC (i.e., input VC at next router)
86 // has free credits (i..e, buffer slots).
87 // This is tracked by OutVcState
88 bool
90 {
91  assert(m_outvc_state[out_vc]->isInState(ACTIVE_, m_router->curCycle()));
92  return m_outvc_state[out_vc]->has_credit();
93 }
94 
95 
96 // Check if the output port (i.e., input port at next router) has free VCs.
97 bool
99 {
100  int vc_base = vnet*m_vc_per_vnet;
101  for (int vc = vc_base; vc < vc_base + m_vc_per_vnet; vc++) {
102  if (is_vc_idle(vc, m_router->curCycle()))
103  return true;
104  }
105 
106  return false;
107 }
108 
109 // Assign a free output VC to the winner of Switch Allocation
110 int
112 {
113  int vc_base = vnet*m_vc_per_vnet;
114  for (int vc = vc_base; vc < vc_base + m_vc_per_vnet; vc++) {
115  if (is_vc_idle(vc, m_router->curCycle())) {
116  m_outvc_state[vc]->setState(ACTIVE_, m_router->curCycle());
117  return vc;
118  }
119  }
120 
121  return -1;
122 }
123 
124 /*
125  * The wakeup function of the OutputUnit reads the credit signal from the
126  * downstream router for the output VC (i.e., input VC at downstream router).
127  * It increments the credit count in the appropriate output VC state.
128  * If the credit carries is_free_signal as true,
129  * the output VC is marked IDLE.
130  */
131 
132 void
134 {
136  Credit *t_credit = (Credit*) m_credit_link->consumeLink();
137  increment_credit(t_credit->get_vc());
138 
139  if (t_credit->is_free_signal())
140  set_vc_state(IDLE_, t_credit->get_vc(), m_router->curCycle());
141 
142  delete t_credit;
143  }
144 }
145 
146 flitBuffer*
148 {
149  return m_out_buffer;
150 }
151 
152 void
154 {
155  m_out_link = link;
156 }
157 
158 void
160 {
161  m_credit_link = credit_link;
162 }
163 
164 uint32_t
166 {
167  return m_out_buffer->functionalWrite(pkt);
168 }
#define DPRINTF(x,...)
Definition: trace.hh:212
void wakeup()
Definition: OutputUnit.cc:133
void set_out_link(NetworkLink *link)
Definition: OutputUnit.cc:153
int get_vc()
Definition: flit.hh:58
int m_vc_per_vnet
Definition: OutputUnit.hh:103
Bitfield< 7 > i
Definition: miscregs.hh:1378
void decrement_credit(int out_vc)
Definition: OutputUnit.cc:66
CreditLink * m_credit_link
Definition: OutputUnit.hh:106
flitBuffer * getOutQueue()
Definition: OutputUnit.cc:147
int get_id()
Definition: Router.hh:81
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
bool has_credit(int out_vc)
Definition: OutputUnit.cc:89
NetworkLink * m_out_link
Definition: OutputUnit.hh:105
std::string PortDirection
Definition: Topology.hh:55
GarnetNetwork * get_net_ptr()
Definition: Router.hh:88
PortDirection m_direction
Definition: OutputUnit.hh:101
void deletePointers(C< T, A > &container)
Definition: stl_helpers.hh:77
int get_vc_per_vnet()
Definition: Router.hh:78
Definition: Credit.hh:48
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
void set_credit_link(CreditLink *credit_link)
Definition: OutputUnit.cc:159
bool has_free_vc(int vnet)
Definition: OutputUnit.cc:98
Definition: Router.hh:57
int get_num_vcs()
Definition: Router.hh:76
bool is_free_signal()
Definition: Credit.hh:54
void increment_credit(int out_vc)
Definition: OutputUnit.cc:76
Router * m_router
Definition: OutputUnit.hh:104
flitBuffer * m_out_buffer
Definition: OutputUnit.hh:108
OutputUnit(int id, PortDirection direction, Router *router)
Definition: OutputUnit.cc:44
Bitfield< 11 > id
Definition: miscregs.hh:124
bool is_vc_idle(int vc, Cycles curTime)
Definition: OutputUnit.hh:85
uint32_t functionalWrite(Packet *pkt)
Definition: OutputUnit.cc:165
std::vector< OutVcState * > m_outvc_state
Definition: OutputUnit.hh:109
void set_vc_state(VC_state_type state, int vc, Cycles curTime)
Definition: OutputUnit.hh:79
int select_free_vc(int vnet)
Definition: OutputUnit.cc:111
uint32_t functionalWrite(Packet *pkt)
Definition: flitBuffer.cc:82

Generated on Fri Jun 9 2017 13:03:49 for gem5 by doxygen 1.8.6