packet_queue.cc (9390:5490105626dc) packet_queue.cc (9663:45df88079f04)
1/*
2 * Copyright (c) 2012 ARM Limited
3 * All rights reserved.
4 *
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.
13 *
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
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.
27 *
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.
39 *
40 * Authors: Ali Saidi
41 * Andreas Hansson
42 */
43
44#include "base/trace.hh"
45#include "debug/Drain.hh"
46#include "debug/PacketQueue.hh"
47#include "mem/packet_queue.hh"
48
49using namespace std;
50
51PacketQueue::PacketQueue(EventManager& _em, const std::string& _label)
52 : em(_em), sendEvent(this), drainManager(NULL), label(_label),
53 waitingOnRetry(false)
54{
55}
56
57PacketQueue::~PacketQueue()
58{
59}
60
61void
62PacketQueue::retry()
63{
64 DPRINTF(PacketQueue, "Queue %s received retry\n", name());
65 assert(waitingOnRetry);
66 sendDeferredPacket();
67}
68
69bool
70PacketQueue::checkFunctional(PacketPtr pkt)
71{
72 pkt->pushLabel(label);
73
74 DeferredPacketIterator i = transmitList.begin();
75 DeferredPacketIterator end = transmitList.end();
76 bool found = false;
77
78 while (!found && i != end) {
79 // If the buffered packet contains data, and it overlaps the
80 // current packet, then update data
81 found = pkt->checkFunctional(i->pkt);
82 ++i;
83 }
84
85 pkt->popLabel();
86
87 return found;
88}
89
90void
91PacketQueue::schedSendEvent(Tick when)
92{
93 // if we are waiting on a retry, do not schedule a send event, and
94 // instead rely on retry being called
95 if (waitingOnRetry) {
96 assert(!sendEvent.scheduled());
97 return;
98 }
99
100 if (!sendEvent.scheduled()) {
101 em.schedule(&sendEvent, when);
102 } else if (sendEvent.when() > when) {
103 em.reschedule(&sendEvent, when);
104 }
105}
106
107void
108PacketQueue::schedSendTiming(PacketPtr pkt, Tick when, bool send_as_snoop)
109{
1/*
2 * Copyright (c) 2012 ARM Limited
3 * All rights reserved.
4 *
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.
13 *
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
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.
27 *
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.
39 *
40 * Authors: Ali Saidi
41 * Andreas Hansson
42 */
43
44#include "base/trace.hh"
45#include "debug/Drain.hh"
46#include "debug/PacketQueue.hh"
47#include "mem/packet_queue.hh"
48
49using namespace std;
50
51PacketQueue::PacketQueue(EventManager& _em, const std::string& _label)
52 : em(_em), sendEvent(this), drainManager(NULL), label(_label),
53 waitingOnRetry(false)
54{
55}
56
57PacketQueue::~PacketQueue()
58{
59}
60
61void
62PacketQueue::retry()
63{
64 DPRINTF(PacketQueue, "Queue %s received retry\n", name());
65 assert(waitingOnRetry);
66 sendDeferredPacket();
67}
68
69bool
70PacketQueue::checkFunctional(PacketPtr pkt)
71{
72 pkt->pushLabel(label);
73
74 DeferredPacketIterator i = transmitList.begin();
75 DeferredPacketIterator end = transmitList.end();
76 bool found = false;
77
78 while (!found && i != end) {
79 // If the buffered packet contains data, and it overlaps the
80 // current packet, then update data
81 found = pkt->checkFunctional(i->pkt);
82 ++i;
83 }
84
85 pkt->popLabel();
86
87 return found;
88}
89
90void
91PacketQueue::schedSendEvent(Tick when)
92{
93 // if we are waiting on a retry, do not schedule a send event, and
94 // instead rely on retry being called
95 if (waitingOnRetry) {
96 assert(!sendEvent.scheduled());
97 return;
98 }
99
100 if (!sendEvent.scheduled()) {
101 em.schedule(&sendEvent, when);
102 } else if (sendEvent.when() > when) {
103 em.reschedule(&sendEvent, when);
104 }
105}
106
107void
108PacketQueue::schedSendTiming(PacketPtr pkt, Tick when, bool send_as_snoop)
109{
110 DPRINTF(PacketQueue, "%s for %s address %x size %d\n", __func__,
111 pkt->cmdString(), pkt->getAddr(), pkt->getSize());
110 // we can still send a packet before the end of this tick
111 assert(when >= curTick());
112
113 // express snoops should never be queued
114 assert(!pkt->isExpressSnoop());
115
116 // add a very basic sanity check on the port to ensure the
117 // invisible buffer is not growing beyond reasonable limits
118 if (transmitList.size() > 100) {
119 panic("Packet queue %s has grown beyond 100 packets\n",
120 name());
121 }
122
123 // nothing on the list, or earlier than current front element,
124 // schedule an event
125 if (transmitList.empty() || when < transmitList.front().tick) {
126 // note that currently we ignore a potentially outstanding retry
127 // and could in theory put a new packet at the head of the
128 // transmit list before retrying the existing packet
129 transmitList.push_front(DeferredPacket(when, pkt, send_as_snoop));
130 schedSendEvent(when);
131 return;
132 }
133
134 // list is non-empty and this belongs at the end
135 if (when >= transmitList.back().tick) {
136 transmitList.push_back(DeferredPacket(when, pkt, send_as_snoop));
137 return;
138 }
139
140 // this belongs in the middle somewhere, insertion sort
141 DeferredPacketIterator i = transmitList.begin();
142 ++i; // already checked for insertion at front
143 while (i != transmitList.end() && when >= i->tick)
144 ++i;
145 transmitList.insert(i, DeferredPacket(when, pkt, send_as_snoop));
146}
147
148void PacketQueue::trySendTiming()
149{
150 assert(deferredPacketReady());
151
152 // take the next packet off the list here, as we might return to
153 // ourselves through the sendTiming call below
154 DeferredPacket dp = transmitList.front();
155 transmitList.pop_front();
156
157 // use the appropriate implementation of sendTiming based on the
158 // type of port associated with the queue, and whether the packet
159 // is to be sent as a snoop or not
160 waitingOnRetry = !sendTiming(dp.pkt, dp.sendAsSnoop);
161
162 if (waitingOnRetry) {
163 // put the packet back at the front of the list (packet should
164 // not have changed since it wasn't accepted)
165 assert(!sendEvent.scheduled());
166 transmitList.push_front(dp);
167 }
168}
169
170void
171PacketQueue::scheduleSend(Tick time)
172{
173 // the next ready time is either determined by the next deferred packet,
174 // or in the cache through the MSHR ready time
175 Tick nextReady = std::min(deferredPacketReadyTime(), time);
176
177 if (nextReady != MaxTick) {
178 // if the sendTiming caused someone else to call our
179 // recvTiming we could already have an event scheduled, check
180 if (!sendEvent.scheduled())
181 em.schedule(&sendEvent, std::max(nextReady, curTick() + 1));
182 } else {
183 // no more to send, so if we're draining, we may be done
184 if (drainManager && transmitList.empty() && !sendEvent.scheduled()) {
185 DPRINTF(Drain, "PacketQueue done draining,"
186 "processing drain event\n");
187 drainManager->signalDrainDone();
188 drainManager = NULL;
189 }
190 }
191}
192
193void
194PacketQueue::sendDeferredPacket()
195{
196 // try to send what is on the list, this will set waitingOnRetry
197 // accordingly
198 trySendTiming();
199
200 // if we succeeded and are not waiting for a retry, schedule the
201 // next send
202 if (!waitingOnRetry) {
203 scheduleSend();
204 }
205}
206
207void
208PacketQueue::processSendEvent()
209{
210 assert(!waitingOnRetry);
211 sendDeferredPacket();
212}
213
214unsigned int
215PacketQueue::drain(DrainManager *dm)
216{
217 if (transmitList.empty() && !sendEvent.scheduled())
218 return 0;
219 DPRINTF(Drain, "PacketQueue not drained\n");
220 drainManager = dm;
221 return 1;
222}
223
224MasterPacketQueue::MasterPacketQueue(EventManager& _em, MasterPort& _masterPort,
225 const std::string _label)
226 : PacketQueue(_em, _label), masterPort(_masterPort)
227{
228}
229
230bool
231MasterPacketQueue::sendTiming(PacketPtr pkt, bool send_as_snoop)
232{
233 // attempt to send the packet and return according to the outcome
234 if (!send_as_snoop)
235 return masterPort.sendTimingReq(pkt);
236 else
237 return masterPort.sendTimingSnoopResp(pkt);
238}
239
240SlavePacketQueue::SlavePacketQueue(EventManager& _em, SlavePort& _slavePort,
241 const std::string _label)
242 : PacketQueue(_em, _label), slavePort(_slavePort)
243{
244}
245
246bool
247SlavePacketQueue::sendTiming(PacketPtr pkt, bool send_as_snoop)
248{
249 // we should never have queued snoop requests
250 assert(!send_as_snoop);
251 return slavePort.sendTimingResp(pkt);
252}
112 // we can still send a packet before the end of this tick
113 assert(when >= curTick());
114
115 // express snoops should never be queued
116 assert(!pkt->isExpressSnoop());
117
118 // add a very basic sanity check on the port to ensure the
119 // invisible buffer is not growing beyond reasonable limits
120 if (transmitList.size() > 100) {
121 panic("Packet queue %s has grown beyond 100 packets\n",
122 name());
123 }
124
125 // nothing on the list, or earlier than current front element,
126 // schedule an event
127 if (transmitList.empty() || when < transmitList.front().tick) {
128 // note that currently we ignore a potentially outstanding retry
129 // and could in theory put a new packet at the head of the
130 // transmit list before retrying the existing packet
131 transmitList.push_front(DeferredPacket(when, pkt, send_as_snoop));
132 schedSendEvent(when);
133 return;
134 }
135
136 // list is non-empty and this belongs at the end
137 if (when >= transmitList.back().tick) {
138 transmitList.push_back(DeferredPacket(when, pkt, send_as_snoop));
139 return;
140 }
141
142 // this belongs in the middle somewhere, insertion sort
143 DeferredPacketIterator i = transmitList.begin();
144 ++i; // already checked for insertion at front
145 while (i != transmitList.end() && when >= i->tick)
146 ++i;
147 transmitList.insert(i, DeferredPacket(when, pkt, send_as_snoop));
148}
149
150void PacketQueue::trySendTiming()
151{
152 assert(deferredPacketReady());
153
154 // take the next packet off the list here, as we might return to
155 // ourselves through the sendTiming call below
156 DeferredPacket dp = transmitList.front();
157 transmitList.pop_front();
158
159 // use the appropriate implementation of sendTiming based on the
160 // type of port associated with the queue, and whether the packet
161 // is to be sent as a snoop or not
162 waitingOnRetry = !sendTiming(dp.pkt, dp.sendAsSnoop);
163
164 if (waitingOnRetry) {
165 // put the packet back at the front of the list (packet should
166 // not have changed since it wasn't accepted)
167 assert(!sendEvent.scheduled());
168 transmitList.push_front(dp);
169 }
170}
171
172void
173PacketQueue::scheduleSend(Tick time)
174{
175 // the next ready time is either determined by the next deferred packet,
176 // or in the cache through the MSHR ready time
177 Tick nextReady = std::min(deferredPacketReadyTime(), time);
178
179 if (nextReady != MaxTick) {
180 // if the sendTiming caused someone else to call our
181 // recvTiming we could already have an event scheduled, check
182 if (!sendEvent.scheduled())
183 em.schedule(&sendEvent, std::max(nextReady, curTick() + 1));
184 } else {
185 // no more to send, so if we're draining, we may be done
186 if (drainManager && transmitList.empty() && !sendEvent.scheduled()) {
187 DPRINTF(Drain, "PacketQueue done draining,"
188 "processing drain event\n");
189 drainManager->signalDrainDone();
190 drainManager = NULL;
191 }
192 }
193}
194
195void
196PacketQueue::sendDeferredPacket()
197{
198 // try to send what is on the list, this will set waitingOnRetry
199 // accordingly
200 trySendTiming();
201
202 // if we succeeded and are not waiting for a retry, schedule the
203 // next send
204 if (!waitingOnRetry) {
205 scheduleSend();
206 }
207}
208
209void
210PacketQueue::processSendEvent()
211{
212 assert(!waitingOnRetry);
213 sendDeferredPacket();
214}
215
216unsigned int
217PacketQueue::drain(DrainManager *dm)
218{
219 if (transmitList.empty() && !sendEvent.scheduled())
220 return 0;
221 DPRINTF(Drain, "PacketQueue not drained\n");
222 drainManager = dm;
223 return 1;
224}
225
226MasterPacketQueue::MasterPacketQueue(EventManager& _em, MasterPort& _masterPort,
227 const std::string _label)
228 : PacketQueue(_em, _label), masterPort(_masterPort)
229{
230}
231
232bool
233MasterPacketQueue::sendTiming(PacketPtr pkt, bool send_as_snoop)
234{
235 // attempt to send the packet and return according to the outcome
236 if (!send_as_snoop)
237 return masterPort.sendTimingReq(pkt);
238 else
239 return masterPort.sendTimingSnoopResp(pkt);
240}
241
242SlavePacketQueue::SlavePacketQueue(EventManager& _em, SlavePort& _slavePort,
243 const std::string _label)
244 : PacketQueue(_em, _label), slavePort(_slavePort)
245{
246}
247
248bool
249SlavePacketQueue::sendTiming(PacketPtr pkt, bool send_as_snoop)
250{
251 // we should never have queued snoop requests
252 assert(!send_as_snoop);
253 return slavePort.sendTimingResp(pkt);
254}