e3f193045ef0ae8cf90151aaadfaddf181b0b91a
[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 int get_vnet(int vc);
69
70 void print(std::ostream& out) const;
71
72 void init_net_ptr(GarnetNetwork* net_ptr)
73 {
74 m_net_ptr = net_ptr;
75 }
76
77 bool functionalRead(Packet *);
78 uint32_t functionalWrite(Packet *);
79
80 private:
81 int m_virtual_networks, m_num_vcs, m_vc_per_vnet;
82 GarnetNetwork *m_net_ptr;
83 std::vector<int> m_vc_round_robin; // For scheduling of out source queues
84 int m_round_robin_inport, m_round_robin_start; // for vc arbitration
85 std::vector<int> m_round_robin_invc; // For vc arbitration of each outport
86
87 // These are essentially output buffers
88 std::vector<std::vector<flitBuffer *> > m_router_buffers;
89
90 // These are source queues for the output link
91 std::vector<flitBuffer *> m_out_src_queue;
92
93 std::vector<NetworkLink *> m_in_link;
94 std::vector<NetworkLink *> m_out_link;
95 std::vector<std::vector<InVcState *> > m_in_vc_state;
96 std::vector<std::vector<OutVcState *> > m_out_vc_state;
97 std::vector<NetDest> m_routing_table;
98 std::vector<int> m_link_weights;
99 VCarbiter *m_vc_arbiter;
100
101 int getRoute(NetDest destination);
102 std::vector<int> get_valid_vcs(int invc);
103 void routeCompute(flit *m_flit, int inport);
104 void checkReschedule();
105 void check_arbiter_reschedule();
106 void scheduleOutputLinks();
107 };
108
109 #endif // __MEM_RUBY_NETWORK_GARNET_FLEXIBLE_PIPELINE_ROUTER_HH__