2 * Copyright (c) 2008 Princeton University
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.
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.
28 * Authors: Niket Agarwal
31 #include "mem/ruby/network/garnet/flexible-pipeline/NetworkLink.hh"
32 #include "mem/ruby/network/garnet/flexible-pipeline/GarnetNetwork.hh"
34 NetworkLink::NetworkLink(int id
, int latency
, GarnetNetwork
*net_ptr
)
37 linkBuffer
= new flitBuffer();
43 int num_net
= net_ptr
->getNumberOfVirtualNetworks();
44 int num_vc
= m_net_ptr
->getVCsPerClass();
45 m_vc_load
.setSize(num_net
*num_vc
);
47 for(int i
= 0; i
< num_net
*num_vc
; i
++)
51 NetworkLink::~NetworkLink()
56 int NetworkLink::get_id()
61 void NetworkLink::setLinkConsumer(FlexibleConsumer
*consumer
)
63 link_consumer
= consumer
;
66 void NetworkLink::setSourceQueue(flitBuffer
*srcQueue
)
68 link_srcQueue
= srcQueue
;
71 void NetworkLink::setSource(FlexibleConsumer
*source
)
75 void NetworkLink::request_vc_link(int vc
, NetDest destination
, Time request_time
)
77 link_consumer
->request_vc(vc
, m_in_port
, destination
, request_time
);
79 bool NetworkLink::isBufferNotFull_link(int vc
)
81 return link_consumer
->isBufferNotFull(vc
, m_in_port
);
84 void NetworkLink::grant_vc_link(int vc
, Time grant_time
)
86 link_source
->grant_vc(m_out_port
, vc
, grant_time
);
89 void NetworkLink::release_vc_link(int vc
, Time release_time
)
91 link_source
->release_vc(m_out_port
, vc
, release_time
);
94 Vector
<int> NetworkLink::getVcLoad()
99 double NetworkLink::getLinkUtilization()
101 Time m_ruby_start
= m_net_ptr
->getRubyStartTime();
102 return (double(m_link_utilized
)) / (double(g_eventQueue_ptr
->getTime()-m_ruby_start
));
105 bool NetworkLink::isReady()
107 return linkBuffer
->isReady();
110 void NetworkLink::setInPort(int port
)
115 void NetworkLink::setOutPort(int port
)
120 void NetworkLink::wakeup()
122 if(link_srcQueue
->isReady())
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
);
129 m_vc_load
[t_flit
->get_vc()]++;
133 flit
* NetworkLink::peekLink()
135 return linkBuffer
->peekTopFlit();
138 flit
* NetworkLink::consumeLink()
140 return linkBuffer
->getTopFlit();