ruby: Converted Garnet to M5 configuration
[gem5.git] / src / mem / ruby / network / garnet / flexible-pipeline / NetworkLink.cc
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 #include "mem/ruby/network/garnet/flexible-pipeline/NetworkLink.hh"
32 #include "mem/ruby/network/garnet/flexible-pipeline/GarnetNetwork.hh"
33
34 NetworkLink::NetworkLink(int id, int latency, GarnetNetwork *net_ptr)
35 {
36 m_id = id;
37 linkBuffer = new flitBuffer();
38 m_in_port = 0;
39 m_out_port = 0;
40 m_link_utilized = 0;
41 m_net_ptr = net_ptr;
42 m_latency = latency;
43 int num_net = net_ptr->getNumberOfVirtualNetworks();
44 int num_vc = m_net_ptr->getVCsPerClass();
45 m_vc_load.setSize(num_net*num_vc);
46
47 for(int i = 0; i < num_net*num_vc; i++)
48 m_vc_load[i] = 0;
49 }
50
51 NetworkLink::~NetworkLink()
52 {
53 delete linkBuffer;
54 }
55
56 int NetworkLink::get_id()
57 {
58 return m_id;
59 }
60
61 void NetworkLink::setLinkConsumer(FlexibleConsumer *consumer)
62 {
63 link_consumer = consumer;
64 }
65
66 void NetworkLink::setSourceQueue(flitBuffer *srcQueue)
67 {
68 link_srcQueue = srcQueue;
69 }
70
71 void NetworkLink::setSource(FlexibleConsumer *source)
72 {
73 link_source = source;
74 }
75 void NetworkLink::request_vc_link(int vc, NetDest destination, Time request_time)
76 {
77 link_consumer->request_vc(vc, m_in_port, destination, request_time);
78 }
79 bool NetworkLink::isBufferNotFull_link(int vc)
80 {
81 return link_consumer->isBufferNotFull(vc, m_in_port);
82 }
83
84 void NetworkLink::grant_vc_link(int vc, Time grant_time)
85 {
86 link_source->grant_vc(m_out_port, vc, grant_time);
87 }
88
89 void NetworkLink::release_vc_link(int vc, Time release_time)
90 {
91 link_source->release_vc(m_out_port, vc, release_time);
92 }
93
94 Vector<int> NetworkLink::getVcLoad()
95 {
96 return m_vc_load;
97 }
98
99 double NetworkLink::getLinkUtilization()
100 {
101 Time m_ruby_start = m_net_ptr->getRubyStartTime();
102 return (double(m_link_utilized)) / (double(g_eventQueue_ptr->getTime()-m_ruby_start));
103 }
104
105 bool NetworkLink::isReady()
106 {
107 return linkBuffer->isReady();
108 }
109
110 void NetworkLink::setInPort(int port)
111 {
112 m_in_port = port;
113 }
114
115 void NetworkLink::setOutPort(int port)
116 {
117 m_out_port = port;
118 }
119
120 void NetworkLink::wakeup()
121 {
122 if(link_srcQueue->isReady())
123 {
124 flit *t_flit = link_srcQueue->getTopFlit();
125 t_flit->set_time(g_eventQueue_ptr->getTime() + m_latency);
126 linkBuffer->insert(t_flit);
127 g_eventQueue_ptr->scheduleEvent(link_consumer, m_latency);
128 m_link_utilized++;
129 m_vc_load[t_flit->get_vc()]++;
130 }
131 }
132
133 flit* NetworkLink::peekLink()
134 {
135 return linkBuffer->peekTopFlit();
136 }
137
138 flit* NetworkLink::consumeLink()
139 {
140 return linkBuffer->getTopFlit();
141 }