ruby: network: drop member m_in_use
[gem5.git] / src / mem / ruby / network / garnet / flexible-pipeline / Router.hh
1 /*
2 * Copyright (c) 2008 Princeton University
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Niket Agarwal
29 */
30
31 #ifndef __MEM_RUBY_NETWORK_GARNET_FLEXIBLE_PIPELINE_ROUTER_HH__
32 #define __MEM_RUBY_NETWORK_GARNET_FLEXIBLE_PIPELINE_ROUTER_HH__
33
34 #include <iostream>
35 #include <vector>
36
37 #include "mem/ruby/common/NetDest.hh"
38 #include "mem/ruby/network/BasicRouter.hh"
39 #include "mem/ruby/network/garnet/flexible-pipeline/FlexibleConsumer.hh"
40 #include "mem/ruby/network/garnet/flexible-pipeline/GarnetNetwork.hh"
41 #include "mem/ruby/network/garnet/flexible-pipeline/InVcState.hh"
42 #include "mem/ruby/network/garnet/flexible-pipeline/NetworkLink.hh"
43 #include "mem/ruby/network/garnet/flexible-pipeline/OutVcState.hh"
44 #include "mem/ruby/network/garnet/flexible-pipeline/flitBuffer.hh"
45 #include "mem/ruby/network/garnet/NetworkHeader.hh"
46 #include "params/GarnetRouter.hh"
47
48 class VCarbiter;
49
50 class Router : public BasicRouter, public FlexibleConsumer
51 {
52 public:
53 typedef GarnetRouterParams Params;
54 Router(const Params *p);
55
56 ~Router();
57
58 void addInPort(NetworkLink *in_link);
59 void addOutPort(NetworkLink *out_link, const NetDest& routing_table_entry,
60 int link_weight);
61 void wakeup();
62 void request_vc(int in_vc, int in_port, NetDest destination,
63 Cycles request_time);
64 bool isBufferNotFull(int vc, int inport);
65 void grant_vc(int out_port, int vc, Cycles grant_time);
66 void release_vc(int out_port, int vc, Cycles release_time);
67 void vc_arbitrate();
68
69 void print(std::ostream& out) const;
70
71 void init_net_ptr(GarnetNetwork* net_ptr)
72 {
73 m_net_ptr = net_ptr;
74 }
75
76 bool functionalRead(Packet *);
77 uint32_t functionalWrite(Packet *);
78
79 private:
80 int m_virtual_networks, m_num_vcs, m_vc_per_vnet;
81 GarnetNetwork *m_net_ptr;
82 std::vector<int> m_vc_round_robin; // For scheduling of out source queues
83 int m_round_robin_inport, m_round_robin_start; // for vc arbitration
84 std::vector<int> m_round_robin_invc; // For vc arbitration of each outport
85
86 // These are essentially output buffers
87 std::vector<std::vector<flitBuffer *> > m_router_buffers;
88
89 // These are source queues for the output link
90 std::vector<flitBuffer *> m_out_src_queue;
91
92 std::vector<NetworkLink *> m_in_link;
93 std::vector<NetworkLink *> m_out_link;
94 std::vector<std::vector<InVcState *> > m_in_vc_state;
95 std::vector<std::vector<OutVcState *> > m_out_vc_state;
96 std::vector<NetDest> m_routing_table;
97 std::vector<int> m_link_weights;
98 VCarbiter *m_vc_arbiter;
99
100 int getRoute(NetDest destination);
101 std::vector<int> get_valid_vcs(int invc);
102 void routeCompute(flit *m_flit, int inport);
103 void checkReschedule();
104 void check_arbiter_reschedule();
105 void scheduleOutputLinks();
106 int get_vnet(int vc) const;
107 int get_next_round_robin_vc(int vc) const;
108 };
109
110 #endif // __MEM_RUBY_NETWORK_GARNET_FLEXIBLE_PIPELINE_ROUTER_HH__