2 * Copyright (c) 2012 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 #include "debug/PacketQueue.hh"
45 #include "mem/packet_queue.hh"
49 PacketQueue::PacketQueue(EventManager
& _em
, Port
& _port
,
50 const std::string _label
)
51 : em(_em
), label(_label
), sendEvent(this), drainEvent(NULL
), port(_port
),
56 PacketQueue::~PacketQueue()
63 DPRINTF(PacketQueue
, "Queue %s received retry\n", name());
64 assert(waitingOnRetry
);
69 PacketQueue::checkFunctional(PacketPtr pkt
)
71 pkt
->pushLabel(label
);
73 DeferredPacketIterator i
= transmitList
.begin();
74 DeferredPacketIterator end
= transmitList
.end();
77 while (!found
&& i
!= end
) {
78 // If the buffered packet contains data, and it overlaps the
79 // current packet, then update data
80 found
= pkt
->checkFunctional(i
->pkt
);
90 PacketQueue::schedSendEvent(Tick when
)
92 // if we are waiting on a retry, do not schedule a send event, and
93 // instead rely on retry being called
95 assert(!sendEvent
.scheduled());
99 if (!sendEvent
.scheduled()) {
100 em
.schedule(&sendEvent
, when
);
101 } else if (sendEvent
.when() > when
) {
102 em
.reschedule(&sendEvent
, when
);
107 PacketQueue::schedSendTiming(PacketPtr pkt
, Tick when
, bool send_as_snoop
)
109 assert(when
> curTick());
111 // nothing on the list, or earlier than current front element,
113 if (transmitList
.empty() || when
< transmitList
.front().tick
) {
114 // note that currently we ignore a potentially outstanding retry
115 // and could in theory put a new packet at the head of the
116 // transmit list before retrying the existing packet
117 transmitList
.push_front(DeferredPacket(when
, pkt
, send_as_snoop
));
118 schedSendEvent(when
);
122 // list is non-empty and this belongs at the end
123 if (when
>= transmitList
.back().tick
) {
124 transmitList
.push_back(DeferredPacket(when
, pkt
, send_as_snoop
));
128 // this belongs in the middle somewhere, insertion sort
129 DeferredPacketIterator i
= transmitList
.begin();
130 ++i
; // already checked for insertion at front
131 while (i
!= transmitList
.end() && when
>= i
->tick
)
133 transmitList
.insert(i
, DeferredPacket(when
, pkt
, send_as_snoop
));
136 void PacketQueue::trySendTiming()
138 assert(deferredPacketReady());
140 // take the next packet off the list here, as we might return to
141 // ourselves through the sendTiming call below
142 DeferredPacket dp
= transmitList
.front();
143 transmitList
.pop_front();
145 // attempt to send the packet and remember the outcome
147 waitingOnRetry
= !port
.sendTiming(dp
.pkt
);
149 waitingOnRetry
= !port
.sendTimingSnoop(dp
.pkt
);
151 if (waitingOnRetry
) {
152 // put the packet back at the front of the list (packet should
153 // not have changed since it wasn't accepted)
154 assert(!sendEvent
.scheduled());
155 transmitList
.push_front(dp
);
160 PacketQueue::scheduleSend(Tick time
)
162 // the next ready time is either determined by the next deferred packet,
163 // or in the cache through the MSHR ready time
164 Tick nextReady
= std::min(deferredPacketReadyTime(), time
);
166 if (nextReady
!= MaxTick
) {
167 // if the sendTiming caused someone else to call our
168 // recvTiming we could already have an event scheduled, check
169 if (!sendEvent
.scheduled())
170 em
.schedule(&sendEvent
, std::max(nextReady
, curTick() + 1));
172 // no more to send, so if we're draining, we may be done
173 if (drainEvent
&& !sendEvent
.scheduled()) {
174 drainEvent
->process();
181 PacketQueue::sendDeferredPacket()
183 // try to send what is on the list, this will set waitingOnRetry
187 // if we succeeded and are not waiting for a retry, schedule the
189 if (!waitingOnRetry
) {
195 PacketQueue::processSendEvent()
197 assert(!waitingOnRetry
);
198 sendDeferredPacket();
202 PacketQueue::drain(Event
*de
)
204 if (transmitList
.empty() && !sendEvent
.scheduled())