packet_queue.hh (8914:8c3bd7bea667) packet_queue.hh (8948:e95ee70f876c)
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#ifndef __MEM_PACKET_QUEUE_HH__
45#define __MEM_PACKET_QUEUE_HH__
46
47/**
48 * @file
49 * Declaration of a simple PacketQueue that is associated with
50 * a port on which it attempts to send packets according to the time
51 * stamp given to them at insertion. The packet queue is responsible
52 * for the flow control of the port, but relies on the module
53 * notifying the queue when a transfer ends.
54 */
55
56#include <list>
57
58#include "mem/port.hh"
59#include "sim/eventq.hh"
60
61/**
62 * A packet queue is a class that holds deferred packets and later
63 * sends them using the associated slave port or master port.
64 */
65class PacketQueue
66{
67 private:
68 /** A deferred packet, buffered to transmit later. */
69 class DeferredPacket {
70 public:
71 Tick tick; ///< The tick when the packet is ready to transmit
72 PacketPtr pkt; ///< Pointer to the packet to transmit
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#ifndef __MEM_PACKET_QUEUE_HH__
45#define __MEM_PACKET_QUEUE_HH__
46
47/**
48 * @file
49 * Declaration of a simple PacketQueue that is associated with
50 * a port on which it attempts to send packets according to the time
51 * stamp given to them at insertion. The packet queue is responsible
52 * for the flow control of the port, but relies on the module
53 * notifying the queue when a transfer ends.
54 */
55
56#include <list>
57
58#include "mem/port.hh"
59#include "sim/eventq.hh"
60
61/**
62 * A packet queue is a class that holds deferred packets and later
63 * sends them using the associated slave port or master port.
64 */
65class PacketQueue
66{
67 private:
68 /** A deferred packet, buffered to transmit later. */
69 class DeferredPacket {
70 public:
71 Tick tick; ///< The tick when the packet is ready to transmit
72 PacketPtr pkt; ///< Pointer to the packet to transmit
73 DeferredPacket(Tick t, PacketPtr p)
74 : tick(t), pkt(p)
73 bool sendAsSnoop; ///< Should it be sent as a snoop or not
74 DeferredPacket(Tick t, PacketPtr p, bool send_as_snoop)
75 : tick(t), pkt(p), sendAsSnoop(send_as_snoop)
75 {}
76 };
77
78 typedef std::list<DeferredPacket> DeferredPacketList;
79 typedef std::list<DeferredPacket>::iterator DeferredPacketIterator;
80
81 /** A list of outgoing timing response packets that haven't been
82 * serviced yet. */
83 DeferredPacketList transmitList;
84
85 /** The manager which is used for the event queue */
86 EventManager& em;
87
88 /** Label to use for print request packets label stack. */
89 const std::string label;
90
91 /** This function attempts to send deferred packets. Scheduled to
92 * be called in the future via SendEvent. */
93 void processSendEvent();
94
95 /**
96 * Event used to call processSendEvent.
97 **/
98 EventWrapper<PacketQueue, &PacketQueue::processSendEvent> sendEvent;
99
100 /** If we need to drain, keep the drain event around until we're done
101 * here.*/
102 Event *drainEvent;
103
104 protected:
105
106 /** The port used to send the packets. */
107 Port& port;
108
109 /** Remember whether we're awaiting a retry from the bus. */
110 bool waitingOnRetry;
111
112 /** Check whether we have a packet ready to go on the transmit list. */
113 bool deferredPacketReady()
114 { return !transmitList.empty() && transmitList.front().tick <= curTick(); }
115
116 Tick deferredPacketReadyTime()
117 { return transmitList.empty() ? MaxTick : transmitList.front().tick; }
118
119 /**
120 * Attempt to send the packet at the head of the transmit
121 * list. Caller must guarantee that the list is non-empty and that
122 * the head packet is scheduled for curTick() (or earlier). Note
123 * that a subclass of the PacketQueue can override this method and
124 * thus change the behaviour (as done by the cache).
125 */
126 virtual void sendDeferredPacket();
127
128 /**
129 * Attempt to send the packet at the front of the transmit list,
130 * and set waitingOnRetry accordingly. The packet is temporarily
131 * taken off the list, but put back at the front if not
132 * successfully sent.
133 */
134 void trySendTiming();
135
136 /**
137 * Based on the transmit list, or the provided time, schedule a
138 * send event if there are packets to send. If we are idle and
139 * asked to drain then do so.
140 *
141 * @param time an alternative time for the next send event
142 */
143 void scheduleSend(Tick time = MaxTick);
144
145 /**
146 * Simple ports are generally used as slave ports (i.e. the
147 * respond to requests) and thus do not expect to receive any
148 * range changes (as the neighbouring port has a master role and
149 * do not have any address ranges. A subclass can override the
150 * default behaviuor if needed.
151 */
152 virtual void recvRangeChange() { }
153
154 public:
155
156 /**
157 * Create a packet queue, linked to an event manager, a port used
158 * to send the packets, and potentially give it a label that will
159 * be used for functional print request packets.
160 *
161 * @param _em Event manager used for scheduling this queue
162 * @param _port Port used to send the packets
163 * @param _label Label to push on the label stack for print request packets
164 */
165 PacketQueue(EventManager& _em, Port& _port,
166 const std::string _label = "PacketQueue");
167
168 /**
169 * Virtual desctructor since the class may be used as a base class.
170 */
171 virtual ~PacketQueue();
172
173 /**
174 * Provide a name to simplify debugging. Base it on the port.
175 *
176 * @return A complete name, appended to module and port
177 */
178 const std::string name() const { return port.name() + "-queue"; }
179
180 /** Check the list of buffered packets against the supplied
181 * functional request. */
182 bool checkFunctional(PacketPtr pkt);
183
184 /**
185 * Schedule a send even if not already waiting for a retry. If the
186 * requested time is before an already scheduled send event it
187 * will be rescheduled.
188 *
189 * @param when
190 */
191 void schedSendEvent(Tick when);
192
193 /**
194 * Add a packet to the transmit list, and ensure that a
195 * processSendEvent is called in the future.
196 *
197 * @param pkt Packet to send
198 * @param when Absolute time (in ticks) to send packet
76 {}
77 };
78
79 typedef std::list<DeferredPacket> DeferredPacketList;
80 typedef std::list<DeferredPacket>::iterator DeferredPacketIterator;
81
82 /** A list of outgoing timing response packets that haven't been
83 * serviced yet. */
84 DeferredPacketList transmitList;
85
86 /** The manager which is used for the event queue */
87 EventManager& em;
88
89 /** Label to use for print request packets label stack. */
90 const std::string label;
91
92 /** This function attempts to send deferred packets. Scheduled to
93 * be called in the future via SendEvent. */
94 void processSendEvent();
95
96 /**
97 * Event used to call processSendEvent.
98 **/
99 EventWrapper<PacketQueue, &PacketQueue::processSendEvent> sendEvent;
100
101 /** If we need to drain, keep the drain event around until we're done
102 * here.*/
103 Event *drainEvent;
104
105 protected:
106
107 /** The port used to send the packets. */
108 Port& port;
109
110 /** Remember whether we're awaiting a retry from the bus. */
111 bool waitingOnRetry;
112
113 /** Check whether we have a packet ready to go on the transmit list. */
114 bool deferredPacketReady()
115 { return !transmitList.empty() && transmitList.front().tick <= curTick(); }
116
117 Tick deferredPacketReadyTime()
118 { return transmitList.empty() ? MaxTick : transmitList.front().tick; }
119
120 /**
121 * Attempt to send the packet at the head of the transmit
122 * list. Caller must guarantee that the list is non-empty and that
123 * the head packet is scheduled for curTick() (or earlier). Note
124 * that a subclass of the PacketQueue can override this method and
125 * thus change the behaviour (as done by the cache).
126 */
127 virtual void sendDeferredPacket();
128
129 /**
130 * Attempt to send the packet at the front of the transmit list,
131 * and set waitingOnRetry accordingly. The packet is temporarily
132 * taken off the list, but put back at the front if not
133 * successfully sent.
134 */
135 void trySendTiming();
136
137 /**
138 * Based on the transmit list, or the provided time, schedule a
139 * send event if there are packets to send. If we are idle and
140 * asked to drain then do so.
141 *
142 * @param time an alternative time for the next send event
143 */
144 void scheduleSend(Tick time = MaxTick);
145
146 /**
147 * Simple ports are generally used as slave ports (i.e. the
148 * respond to requests) and thus do not expect to receive any
149 * range changes (as the neighbouring port has a master role and
150 * do not have any address ranges. A subclass can override the
151 * default behaviuor if needed.
152 */
153 virtual void recvRangeChange() { }
154
155 public:
156
157 /**
158 * Create a packet queue, linked to an event manager, a port used
159 * to send the packets, and potentially give it a label that will
160 * be used for functional print request packets.
161 *
162 * @param _em Event manager used for scheduling this queue
163 * @param _port Port used to send the packets
164 * @param _label Label to push on the label stack for print request packets
165 */
166 PacketQueue(EventManager& _em, Port& _port,
167 const std::string _label = "PacketQueue");
168
169 /**
170 * Virtual desctructor since the class may be used as a base class.
171 */
172 virtual ~PacketQueue();
173
174 /**
175 * Provide a name to simplify debugging. Base it on the port.
176 *
177 * @return A complete name, appended to module and port
178 */
179 const std::string name() const { return port.name() + "-queue"; }
180
181 /** Check the list of buffered packets against the supplied
182 * functional request. */
183 bool checkFunctional(PacketPtr pkt);
184
185 /**
186 * Schedule a send even if not already waiting for a retry. If the
187 * requested time is before an already scheduled send event it
188 * will be rescheduled.
189 *
190 * @param when
191 */
192 void schedSendEvent(Tick when);
193
194 /**
195 * Add a packet to the transmit list, and ensure that a
196 * processSendEvent is called in the future.
197 *
198 * @param pkt Packet to send
199 * @param when Absolute time (in ticks) to send packet
200 * @param send_as_snoop Send the packet as a snoop or not
199 */
201 */
200 void schedSendTiming(PacketPtr pkt, Tick when);
202 void schedSendTiming(PacketPtr pkt, Tick when, bool send_as_snoop = false);
201
202 /**
203 * Used by a port to notify the queue that a retry was received
204 * and that the queue can proceed and retry sending the packet
205 * that caused the wait.
206 */
207 void retry();
208
209 /**
210 * Hook for draining the packet queue.
211 *
212 * @param de An event which is used to signal back to the caller
213 * @return A number indicating how many times process will be called
214 */
215 unsigned int drain(Event *de);
216};
217
203
204 /**
205 * Used by a port to notify the queue that a retry was received
206 * and that the queue can proceed and retry sending the packet
207 * that caused the wait.
208 */
209 void retry();
210
211 /**
212 * Hook for draining the packet queue.
213 *
214 * @param de An event which is used to signal back to the caller
215 * @return A number indicating how many times process will be called
216 */
217 unsigned int drain(Event *de);
218};
219
218#endif // __MEM_TPORT_HH__
220#endif // __MEM_PACKET_QUEUE_HH__