arch-arm: Initialize some cases of destReg
[gem5.git] / src / mem / ruby / network / garnet2.0 / InputUnit.hh
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
32 #ifndef __MEM_RUBY_NETWORK_GARNET2_0_INPUTUNIT_HH__
33 #define __MEM_RUBY_NETWORK_GARNET2_0_INPUTUNIT_HH__
34
35 #include <iostream>
36 #include <vector>
37
38 #include "mem/ruby/common/Consumer.hh"
39 #include "mem/ruby/network/garnet2.0/CommonTypes.hh"
40 #include "mem/ruby/network/garnet2.0/CreditLink.hh"
41 #include "mem/ruby/network/garnet2.0/NetworkLink.hh"
42 #include "mem/ruby/network/garnet2.0/Router.hh"
43 #include "mem/ruby/network/garnet2.0/VirtualChannel.hh"
44 #include "mem/ruby/network/garnet2.0/flitBuffer.hh"
45
46 class InputUnit : public Consumer
47 {
48 public:
49 InputUnit(int id, PortDirection direction, Router *router);
50 ~InputUnit() = default;
51
52 void wakeup();
53 void print(std::ostream& out) const {};
54
55 inline PortDirection get_direction() { return m_direction; }
56
57 inline void
58 set_vc_idle(int vc, Tick curTime)
59 {
60 virtualChannels[vc].set_idle(curTime);
61 }
62
63 inline void
64 set_vc_active(int vc, Tick curTime)
65 {
66 virtualChannels[vc].set_active(curTime);
67 }
68
69 inline void
70 grant_outport(int vc, int outport)
71 {
72 virtualChannels[vc].set_outport(outport);
73 }
74
75 inline void
76 grant_outvc(int vc, int outvc)
77 {
78 virtualChannels[vc].set_outvc(outvc);
79 }
80
81 inline int
82 get_outport(int invc)
83 {
84 return virtualChannels[invc].get_outport();
85 }
86
87 inline int
88 get_outvc(int invc)
89 {
90 return virtualChannels[invc].get_outvc();
91 }
92
93 inline Tick
94 get_enqueue_time(int invc)
95 {
96 return virtualChannels[invc].get_enqueue_time();
97 }
98
99 void increment_credit(int in_vc, bool free_signal, Tick curTime);
100
101 inline flit*
102 peekTopFlit(int vc)
103 {
104 return virtualChannels[vc].peekTopFlit();
105 }
106
107 inline flit*
108 getTopFlit(int vc)
109 {
110 return virtualChannels[vc].getTopFlit();
111 }
112
113 inline bool
114 need_stage(int vc, flit_stage stage, Tick time)
115 {
116 return virtualChannels[vc].need_stage(stage, time);
117 }
118
119 inline bool
120 isReady(int invc, Tick curTime)
121 {
122 return virtualChannels[invc].isReady(curTime);
123 }
124
125 flitBuffer* getCreditQueue() { return &creditQueue; }
126
127 inline void
128 set_in_link(NetworkLink *link)
129 {
130 m_in_link = link;
131 }
132
133 inline int get_inlink_id() { return m_in_link->get_id(); }
134
135 inline void
136 set_credit_link(CreditLink *credit_link)
137 {
138 m_credit_link = credit_link;
139 }
140
141 double get_buf_read_activity(unsigned int vnet) const
142 { return m_num_buffer_reads[vnet]; }
143 double get_buf_write_activity(unsigned int vnet) const
144 { return m_num_buffer_writes[vnet]; }
145
146 uint32_t functionalWrite(Packet *pkt);
147 void resetStats();
148
149 private:
150 Router *m_router;
151 int m_id;
152 PortDirection m_direction;
153 int m_vc_per_vnet;
154 NetworkLink *m_in_link;
155 CreditLink *m_credit_link;
156 flitBuffer creditQueue;
157
158 // Input Virtual channels
159 std::vector<VirtualChannel> virtualChannels;
160
161 // Statistical variables
162 std::vector<double> m_num_buffer_writes;
163 std::vector<double> m_num_buffer_reads;
164 };
165
166 #endif // __MEM_RUBY_NETWORK_GARNET2_0_INPUTUNIT_HH__