gem5  v20.0.0.3
InputUnit.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Inria
3  * Copyright (c) 2016 Georgia Institute of Technology
4  * Copyright (c) 2008 Princeton University
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met: redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer;
11  * redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution;
14  * neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 
33 
34 #include "debug/RubyNetwork.hh"
37 
38 using namespace std;
39 
40 InputUnit::InputUnit(int id, PortDirection direction, Router *router)
41  : Consumer(router), m_router(router), m_id(id), m_direction(direction),
42  m_vc_per_vnet(m_router->get_vc_per_vnet())
43 {
44  const int m_num_vcs = m_router->get_num_vcs();
45  m_num_buffer_reads.resize(m_num_vcs/m_vc_per_vnet);
46  m_num_buffer_writes.resize(m_num_vcs/m_vc_per_vnet);
47  for (int i = 0; i < m_num_buffer_reads.size(); i++) {
48  m_num_buffer_reads[i] = 0;
50  }
51 
52  // Instantiating the virtual channels
53  virtualChannels.reserve(m_num_vcs);
54  for (int i=0; i < m_num_vcs; i++) {
55  virtualChannels.emplace_back();
56  }
57 }
58 
59 /*
60  * The InputUnit wakeup function reads the input flit from its input link.
61  * Each flit arrives with an input VC.
62  * For HEAD/HEAD_TAIL flits, performs route computation,
63  * and updates route in the input VC.
64  * The flit is buffered for (m_latency - 1) cycles in the input VC
65  * and marked as valid for SwitchAllocation starting that cycle.
66  *
67  */
68 
69 void
71 {
72  flit *t_flit;
74 
75  t_flit = m_in_link->consumeLink();
76  int vc = t_flit->get_vc();
77  t_flit->increment_hops(); // for stats
78 
79  if ((t_flit->get_type() == HEAD_) ||
80  (t_flit->get_type() == HEAD_TAIL_)) {
81 
82  assert(virtualChannels[vc].get_state() == IDLE_);
84 
85  // Route computation for this vc
86  int outport = m_router->route_compute(t_flit->get_route(),
87  m_id, m_direction);
88 
89  // Update output port in VC
90  // All flits in this packet will use this output port
91  // The output port field in the flit is updated after it wins SA
92  grant_outport(vc, outport);
93 
94  } else {
95  assert(virtualChannels[vc].get_state() == ACTIVE_);
96  }
97 
98 
99  // Buffer the flit
100  virtualChannels[vc].insertFlit(t_flit);
101 
102  int vnet = vc/m_vc_per_vnet;
103  // number of writes same as reads
104  // any flit that is written will be read only once
105  m_num_buffer_writes[vnet]++;
106  m_num_buffer_reads[vnet]++;
107 
108  Cycles pipe_stages = m_router->get_pipe_stages();
109  if (pipe_stages == 1) {
110  // 1-cycle router
111  // Flit goes for SA directly
112  t_flit->advance_stage(SA_, m_router->curCycle());
113  } else {
114  assert(pipe_stages > 1);
115  // Router delay is modeled by making flit wait in buffer for
116  // (pipe_stages cycles - 1) cycles before going for SA
117 
118  Cycles wait_time = pipe_stages - Cycles(1);
119  t_flit->advance_stage(SA_, m_router->curCycle() + wait_time);
120 
121  // Wakeup the router in that cycle to perform SA
122  m_router->schedule_wakeup(Cycles(wait_time));
123  }
124  }
125 }
126 
127 // Send a credit back to upstream router for this VC.
128 // Called by SwitchAllocator when the flit in this VC wins the Switch.
129 void
130 InputUnit::increment_credit(int in_vc, bool free_signal, Cycles curTime)
131 {
132  Credit *t_credit = new Credit(in_vc, free_signal, curTime);
133  creditQueue.insert(t_credit);
135 }
136 
137 
138 uint32_t
140 {
141  uint32_t num_functional_writes = 0;
142  for (auto& virtual_channel : virtualChannels) {
143  num_functional_writes += virtual_channel.functionalWrite(pkt);
144  }
145 
146  return num_functional_writes;
147 }
148 
149 void
151 {
152  for (int j = 0; j < m_num_buffer_reads.size(); j++) {
153  m_num_buffer_reads[j] = 0;
154  m_num_buffer_writes[j] = 0;
155  }
156 }
int m_vc_per_vnet
Definition: InputUnit.hh:153
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:81
int get_vc()
Definition: flit.hh:55
void set_vc_active(int vc, Cycles curTime)
Definition: InputUnit.hh:64
InputUnit(int id, PortDirection direction, Router *router)
Definition: InputUnit.cc:40
Bitfield< 7 > i
flitBuffer creditQueue
Definition: InputUnit.hh:156
int route_compute(RouteInfo route, int inport, PortDirection direction)
Definition: Router.cc:140
CreditLink * m_credit_link
Definition: InputUnit.hh:155
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
std::vector< double > m_num_buffer_reads
Definition: InputUnit.hh:163
std::vector< double > m_num_buffer_writes
Definition: InputUnit.hh:162
void scheduleEventAbsolute(Tick timeAbs)
Definition: Consumer.cc:40
void schedule_wakeup(Cycles time)
Definition: Router.cc:152
Definition: flit.hh:41
Router * m_router
Definition: InputUnit.hh:150
std::string PortDirection
Definition: Topology.hh:55
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
uint32_t functionalWrite(Packet *pkt)
Definition: InputUnit.cc:139
Definition: Credit.hh:45
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Bitfield< 24 > j
PortDirection m_direction
Definition: InputUnit.hh:152
void increment_credit(int in_vc, bool free_signal, Cycles curTime)
Definition: InputUnit.cc:130
void resetStats()
Definition: InputUnit.cc:150
Definition: Router.hh:56
void increment_hops()
Definition: flit.hh:69
void wakeup()
Definition: InputUnit.cc:70
void grant_outport(int vc, int outport)
Definition: InputUnit.hh:70
std::vector< VirtualChannel > virtualChannels
Definition: InputUnit.hh:159
int get_num_vcs()
Definition: Router.hh:75
Cycles get_pipe_stages()
Definition: Router.hh:74
void advance_stage(flit_stage t_stage, Cycles newTime)
Definition: flit.hh:80
flit_type get_type()
Definition: flit.hh:58
void insert(flit *flt)
Definition: flitBuffer.hh:70
RouteInfo get_route()
Definition: flit.hh:56
NetworkLink * m_in_link
Definition: InputUnit.hh:154

Generated on Fri Jul 3 2020 15:53:04 for gem5 by doxygen 1.8.13