2 * Copyright (c) 2020 Advanced Micro Devices, Inc.
3 * Copyright (c) 2020 Inria
4 * Copyright (c) 2016 Georgia Institute of Technology
5 * Copyright (c) 2008 Princeton University
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer;
12 * redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution;
15 * neither the name of the copyright holders nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "mem/ruby/network/garnet2.0/NetworkLink.hh"
35 #include "base/trace.hh"
36 #include "debug/RubyNetwork.hh"
37 #include "mem/ruby/network/garnet2.0/CreditLink.hh"
39 NetworkLink::NetworkLink(const Params
*p
)
40 : ClockedObject(p
), Consumer(this), m_id(p
->link_id
),
41 m_type(NUM_LINK_TYPES_
),
42 m_latency(p
->link_latency
), m_link_utilized(0),
43 m_vc_load(p
->vcs_per_vnet
* p
->virt_nets
),
44 linkBuffer(), link_consumer(nullptr),
45 link_srcQueue(nullptr)
47 int num_vnets
= (p
->supported_vnets
).size();
48 assert(num_vnets
> 0);
49 mVnets
.resize(num_vnets
);
51 for (int i
= 0; i
< num_vnets
; i
++) {
52 mVnets
[i
] = p
->supported_vnets
[i
];
54 DPRINTF(RubyNetwork
,"Created with bitwidth:%d\n", bitWidth
);
58 NetworkLink::setLinkConsumer(Consumer
*consumer
)
60 link_consumer
= consumer
;
64 NetworkLink::setSourceQueue(flitBuffer
*src_queue
, ClockedObject
*srcClockObj
)
66 link_srcQueue
= src_queue
;
67 src_object
= srcClockObj
;
73 DPRINTF(RubyNetwork
, "Woke up to transfer flits from %s\n",
75 assert(link_srcQueue
!= nullptr);
76 assert(curTick() == clockEdge());
77 if (link_srcQueue
->isReady(curTick())) {
78 flit
*t_flit
= link_srcQueue
->getTopFlit();
79 DPRINTF(RubyNetwork
, "Transmission will finish at %ld :%s\n",
80 clockEdge(m_latency
), *t_flit
);
81 if (m_type
!= NUM_LINK_TYPES_
) {
82 // Only for assertions and debug messages
83 assert(t_flit
->m_width
== bitWidth
);
84 assert((std::find(mVnets
.begin(), mVnets
.end(),
85 t_flit
->get_vnet()) != mVnets
.end()) ||
86 (mVnets
.size() == 0));
88 t_flit
->set_time(clockEdge(m_latency
));
89 linkBuffer
.insert(t_flit
);
90 link_consumer
->scheduleEventAbsolute(clockEdge(m_latency
));
92 m_vc_load
[t_flit
->get_vc()]++;
95 if (!link_srcQueue
->isEmpty()) {
96 scheduleEvent(Cycles(1));
101 NetworkLink::resetStats()
103 for (int i
= 0; i
< m_vc_load
.size(); i
++) {
111 NetworkLinkParams::create()
113 return new NetworkLink(this);
117 CreditLinkParams::create()
119 return new CreditLink(this);
123 NetworkLink::functionalWrite(Packet
*pkt
)
125 return linkBuffer
.functionalWrite(pkt
);