ruby: message buffers: significant changes
[gem5.git] / src / mem / ruby / network / garnet / fixed-pipeline / NetworkInterface_d.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_FIXED_PIPELINE_NETWORK_INTERFACE_D_HH__
32 #define __MEM_RUBY_NETWORK_GARNET_FIXED_PIPELINE_NETWORK_INTERFACE_D_HH__
33
34 #include <iostream>
35 #include <vector>
36
37 #include "mem/ruby/common/Consumer.hh"
38 #include "mem/ruby/network/garnet/fixed-pipeline/CreditLink_d.hh"
39 #include "mem/ruby/network/garnet/fixed-pipeline/GarnetNetwork_d.hh"
40 #include "mem/ruby/network/garnet/fixed-pipeline/NetworkLink_d.hh"
41 #include "mem/ruby/network/garnet/fixed-pipeline/OutVcState_d.hh"
42 #include "mem/ruby/network/garnet/NetworkHeader.hh"
43 #include "mem/ruby/slicc_interface/Message.hh"
44 #include "params/GarnetNetworkInterface_d.hh"
45
46 class NetworkMessage;
47 class MessageBuffer;
48 class flitBuffer_d;
49
50 class NetworkInterface_d : public ClockedObject, public Consumer
51 {
52 public:
53 typedef GarnetNetworkInterface_dParams Params;
54 NetworkInterface_d(const Params *p);
55 ~NetworkInterface_d();
56
57 void init();
58
59 void addInPort(NetworkLink_d *in_link, CreditLink_d *credit_link);
60 void addOutPort(NetworkLink_d *out_link, CreditLink_d *credit_link);
61
62 void wakeup();
63 void addNode(std::map<int, MessageBuffer *> &inNode,
64 std::map<int, MessageBuffer *> &outNode);
65
66 void print(std::ostream& out) const;
67 int get_vnet(int vc);
68 void init_net_ptr(GarnetNetwork_d *net_ptr) { m_net_ptr = net_ptr; }
69
70 uint32_t functionalWrite(Packet *);
71
72 private:
73 GarnetNetwork_d *m_net_ptr;
74 int m_virtual_networks, m_num_vcs, m_vc_per_vnet;
75 NodeID m_id;
76 std::vector<OutVcState_d *> m_out_vc_state;
77 std::vector<int> m_vc_allocator;
78 int m_vc_round_robin; // For round robin scheduling
79 flitBuffer_d *outSrcQueue; // For modelling link contention
80 flitBuffer_d *creditQueue;
81
82 NetworkLink_d *inNetLink;
83 NetworkLink_d *outNetLink;
84 CreditLink_d *m_credit_link;
85 CreditLink_d *m_ni_credit_link;
86
87 // Input Flit Buffers
88 // The flit buffers which will serve the Consumer
89 std::vector<flitBuffer_d *> m_ni_buffers;
90 std::vector<Cycles> m_ni_enqueue_time;
91
92 // The Message buffers that takes messages from the protocol
93 std::map<int, MessageBuffer *> inNode_ptr;
94 // The Message buffers that provides messages to the protocol
95 std::map<int, MessageBuffer *> outNode_ptr;
96
97 bool flitisizeMessage(MsgPtr msg_ptr, int vnet);
98 int calculateVC(int vnet);
99 void scheduleOutputLink();
100 void checkReschedule();
101 };
102
103 #endif // __MEM_RUBY_NETWORK_GARNET_FIXED_PIPELINE_NETWORK_INTERFACE_D_HH__