mem-ruby: Added M5_CLASS_VAR_USED to m_id in OutputUnit
[gem5.git] / src / mem / ruby / network / garnet2.0 / OutputUnit.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_OUTPUTUNIT_HH__
33 #define __MEM_RUBY_NETWORK_GARNET2_0_OUTPUTUNIT_HH__
34
35 #include <iostream>
36 #include <vector>
37
38 #include "base/compiler.hh"
39 #include "mem/ruby/common/Consumer.hh"
40 #include "mem/ruby/network/garnet2.0/CommonTypes.hh"
41 #include "mem/ruby/network/garnet2.0/NetworkLink.hh"
42 #include "mem/ruby/network/garnet2.0/OutVcState.hh"
43
44 class CreditLink;
45 class Router;
46
47 class OutputUnit : public Consumer
48 {
49 public:
50 OutputUnit(int id, PortDirection direction, Router *router);
51 ~OutputUnit() = default;
52 void set_out_link(NetworkLink *link);
53 void set_credit_link(CreditLink *credit_link);
54 void wakeup();
55 flitBuffer* getOutQueue();
56 void print(std::ostream& out) const {};
57 void decrement_credit(int out_vc);
58 void increment_credit(int out_vc);
59 bool has_credit(int out_vc);
60 bool has_free_vc(int vnet);
61 int select_free_vc(int vnet);
62
63 inline PortDirection get_direction() { return m_direction; }
64
65 int
66 get_credit_count(int vc)
67 {
68 return outVcState[vc].get_credit_count();
69 }
70
71 inline int
72 get_outlink_id()
73 {
74 return m_out_link->get_id();
75 }
76
77 inline void
78 set_vc_state(VC_state_type state, int vc, Cycles curTime)
79 {
80 outVcState[vc].setState(state, curTime);
81 }
82
83 inline bool
84 is_vc_idle(int vc, Cycles curTime)
85 {
86 return (outVcState[vc].isInState(IDLE_, curTime));
87 }
88
89 void insert_flit(flit *t_flit);
90
91 uint32_t functionalWrite(Packet *pkt);
92
93 private:
94 Router *m_router;
95 int M5_CLASS_VAR_USED m_id;
96 PortDirection m_direction;
97 int m_vc_per_vnet;
98 NetworkLink *m_out_link;
99 CreditLink *m_credit_link;
100
101 // This is for the network link to consume
102 flitBuffer outBuffer;
103 // vc state of downstream router
104 std::vector<OutVcState> outVcState;
105 };
106
107 #endif // __MEM_RUBY_NETWORK_GARNET2_0_OUTPUTUNIT_HH__