ruby: message buffers: significant changes
[gem5.git] / src / mem / ruby / network / garnet / flexible-pipeline / NetworkInterface.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_NETWORK_INTERFACE_HH__
32 #define __MEM_RUBY_NETWORK_GARNET_FLEXIBLE_PIPELINE_NETWORK_INTERFACE_HH__
33
34 #include <iostream>
35 #include <vector>
36
37 #include "mem/ruby/network/garnet/flexible-pipeline/FlexibleConsumer.hh"
38 #include "mem/ruby/network/garnet/flexible-pipeline/GarnetNetwork.hh"
39 #include "mem/ruby/network/garnet/flexible-pipeline/NetworkLink.hh"
40 #include "mem/ruby/network/garnet/flexible-pipeline/OutVcState.hh"
41 #include "mem/ruby/network/garnet/NetworkHeader.hh"
42 #include "mem/ruby/slicc_interface/Message.hh"
43 #include "params/GarnetNetworkInterface.hh"
44
45 class NetworkMessage;
46 class MessageBuffer;
47 class flitBuffer;
48
49 class NetworkInterface : public ClockedObject, public FlexibleConsumer
50 {
51 public:
52 typedef GarnetNetworkInterfaceParams Params;
53 NetworkInterface(const Params *p);
54
55 ~NetworkInterface();
56
57 void addInPort(NetworkLink *in_link);
58 void addOutPort(NetworkLink *out_link);
59 void addNode(std::map<int, MessageBuffer *> &inNode,
60 std::map<int, MessageBuffer *> &outNode);
61
62 void wakeup();
63 void grant_vc(int out_port, int vc, Cycles grant_time);
64 void release_vc(int out_port, int vc, Cycles release_time);
65
66 bool isBufferNotFull(int vc, int inport) { return true; }
67 void request_vc(int in_vc, int in_port, NetDest destination,
68 Cycles request_time);
69
70 void print(std::ostream& out) const;
71
72 bool functionalRead(Packet *);
73 uint32_t functionalWrite(Packet *);
74
75 void init_net_ptr(GarnetNetwork* net_ptr) { m_net_ptr = net_ptr; }
76
77 private:
78 GarnetNetwork *m_net_ptr;
79 uint32_t m_virtual_networks, m_num_vcs, m_vc_per_vnet;
80 NodeID m_id;
81
82 std::vector<OutVcState *> m_out_vc_state;
83 std::vector<int> m_vc_allocator;
84 int m_vc_round_robin; // For round robin scheduling
85 flitBuffer *outSrcQueue; // For modelling link contention
86
87 NetworkLink *inNetLink;
88 NetworkLink *outNetLink;
89
90 // Input Flit Buffers
91
92 // The flit buffers which will serve the Consumer
93 std::vector<flitBuffer *> m_ni_buffers;
94
95 // The Message buffers that takes messages from the protocol
96 std::map<int, MessageBuffer *> inNode_ptr;
97
98 // The Message buffers that provides messages to the protocol
99 std::map<int, MessageBuffer *> outNode_ptr;
100
101 bool flitisizeMessage(MsgPtr msg_ptr, int vnet);
102 int calculateVC(int vnet);
103 void scheduleOutputLink();
104 void checkReschedule();
105 };
106
107 #endif // __MEM_RUBY_NETWORK_GARNET_FLEXIBLE_PIPELINE_NETWORK_INTERFACE_HH__