tport.cc (5459:b84a60dbf862) tport.cc (5606:6da7a58b0bc8)
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Ali Saidi
29 */
30
31#include "mem/tport.hh"
32
33bool
34SimpleTimingPort::checkFunctional(PacketPtr pkt)
35{
36 DeferredPacketIterator i = transmitList.begin();
37 DeferredPacketIterator end = transmitList.end();
38
39 for (; i != end; ++i) {
40 PacketPtr target = i->pkt;
41 // If the target contains data, and it overlaps the
42 // probed request, need to update data
43 if (pkt->checkFunctional(target)) {
44 return true;
45 }
46 }
47
48 return false;
49}
50
51void
52SimpleTimingPort::recvFunctional(PacketPtr pkt)
53{
54 if (!checkFunctional(pkt)) {
55 // Just do an atomic access and throw away the returned latency
56 recvAtomic(pkt);
57 }
58}
59
60bool
61SimpleTimingPort::recvTiming(PacketPtr pkt)
62{
63 // If the device is only a slave, it should only be sending
64 // responses, which should never get nacked. There used to be
65 // code to hanldle nacks here, but I'm pretty sure it didn't work
66 // correctly with the drain code, so that would need to be fixed
67 // if we ever added it back.
68 assert(pkt->isRequest());
69
70 if (pkt->memInhibitAsserted()) {
71 // snooper will supply based on copy of packet
72 // still target's responsibility to delete packet
73 delete pkt;
74 return true;
75 }
76
77 bool needsResponse = pkt->needsResponse();
78 Tick latency = recvAtomic(pkt);
79 // turn packet around to go back to requester if response expected
80 if (needsResponse) {
81 // recvAtomic() should already have turned packet into
82 // atomic response
83 assert(pkt->isResponse());
84 schedSendTiming(pkt, curTick + latency);
85 } else {
86 delete pkt;
87 }
88
89 return true;
90}
91
92
93void
94SimpleTimingPort::schedSendTiming(PacketPtr pkt, Tick when)
95{
96 assert(when > curTick);
97 assert(when < curTick + Clock::Int::ms);
98
99 // Nothing is on the list: add it and schedule an event
100 if (transmitList.empty() || when < transmitList.front().tick) {
101 transmitList.push_front(DeferredPacket(when, pkt));
102 schedSendEvent(when);
103 return;
104 }
105
106 // list is non-empty & this belongs at the end
107 if (when >= transmitList.back().tick) {
108 transmitList.push_back(DeferredPacket(when, pkt));
109 return;
110 }
111
112 // this belongs in the middle somewhere
113 DeferredPacketIterator i = transmitList.begin();
114 i++; // already checked for insertion at front
115 DeferredPacketIterator end = transmitList.end();
116
117 for (; i != end; ++i) {
118 if (when < i->tick) {
119 transmitList.insert(i, DeferredPacket(when, pkt));
120 return;
121 }
122 }
123 assert(false); // should never get here
124}
125
126
127void
128SimpleTimingPort::sendDeferredPacket()
129{
130 assert(deferredPacketReady());
131 // take packet off list here; if recvTiming() on the other side
132 // calls sendTiming() back on us (like SimpleTimingCpu does), then
133 // we get confused by having a non-active packet on transmitList
134 DeferredPacket dp = transmitList.front();
135 transmitList.pop_front();
136 bool success = sendTiming(dp.pkt);
137
138 if (success) {
139 if (!transmitList.empty() && !sendEvent->scheduled()) {
140 Tick time = transmitList.front().tick;
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Ali Saidi
29 */
30
31#include "mem/tport.hh"
32
33bool
34SimpleTimingPort::checkFunctional(PacketPtr pkt)
35{
36 DeferredPacketIterator i = transmitList.begin();
37 DeferredPacketIterator end = transmitList.end();
38
39 for (; i != end; ++i) {
40 PacketPtr target = i->pkt;
41 // If the target contains data, and it overlaps the
42 // probed request, need to update data
43 if (pkt->checkFunctional(target)) {
44 return true;
45 }
46 }
47
48 return false;
49}
50
51void
52SimpleTimingPort::recvFunctional(PacketPtr pkt)
53{
54 if (!checkFunctional(pkt)) {
55 // Just do an atomic access and throw away the returned latency
56 recvAtomic(pkt);
57 }
58}
59
60bool
61SimpleTimingPort::recvTiming(PacketPtr pkt)
62{
63 // If the device is only a slave, it should only be sending
64 // responses, which should never get nacked. There used to be
65 // code to hanldle nacks here, but I'm pretty sure it didn't work
66 // correctly with the drain code, so that would need to be fixed
67 // if we ever added it back.
68 assert(pkt->isRequest());
69
70 if (pkt->memInhibitAsserted()) {
71 // snooper will supply based on copy of packet
72 // still target's responsibility to delete packet
73 delete pkt;
74 return true;
75 }
76
77 bool needsResponse = pkt->needsResponse();
78 Tick latency = recvAtomic(pkt);
79 // turn packet around to go back to requester if response expected
80 if (needsResponse) {
81 // recvAtomic() should already have turned packet into
82 // atomic response
83 assert(pkt->isResponse());
84 schedSendTiming(pkt, curTick + latency);
85 } else {
86 delete pkt;
87 }
88
89 return true;
90}
91
92
93void
94SimpleTimingPort::schedSendTiming(PacketPtr pkt, Tick when)
95{
96 assert(when > curTick);
97 assert(when < curTick + Clock::Int::ms);
98
99 // Nothing is on the list: add it and schedule an event
100 if (transmitList.empty() || when < transmitList.front().tick) {
101 transmitList.push_front(DeferredPacket(when, pkt));
102 schedSendEvent(when);
103 return;
104 }
105
106 // list is non-empty & this belongs at the end
107 if (when >= transmitList.back().tick) {
108 transmitList.push_back(DeferredPacket(when, pkt));
109 return;
110 }
111
112 // this belongs in the middle somewhere
113 DeferredPacketIterator i = transmitList.begin();
114 i++; // already checked for insertion at front
115 DeferredPacketIterator end = transmitList.end();
116
117 for (; i != end; ++i) {
118 if (when < i->tick) {
119 transmitList.insert(i, DeferredPacket(when, pkt));
120 return;
121 }
122 }
123 assert(false); // should never get here
124}
125
126
127void
128SimpleTimingPort::sendDeferredPacket()
129{
130 assert(deferredPacketReady());
131 // take packet off list here; if recvTiming() on the other side
132 // calls sendTiming() back on us (like SimpleTimingCpu does), then
133 // we get confused by having a non-active packet on transmitList
134 DeferredPacket dp = transmitList.front();
135 transmitList.pop_front();
136 bool success = sendTiming(dp.pkt);
137
138 if (success) {
139 if (!transmitList.empty() && !sendEvent->scheduled()) {
140 Tick time = transmitList.front().tick;
141 sendEvent->schedule(time <= curTick ? curTick+1 : time);
141 schedule(sendEvent, time <= curTick ? curTick+1 : time);
142 }
143
144 if (transmitList.empty() && drainEvent) {
145 drainEvent->process();
146 drainEvent = NULL;
147 }
148 } else {
149 // Unsuccessful, need to put back on transmitList. Callee
150 // should not have messed with it (since it didn't accept that
151 // packet), so we can just push it back on the front.
152 assert(!sendEvent->scheduled());
153 transmitList.push_front(dp);
154 }
155
156 waitingOnRetry = !success;
157
158 if (waitingOnRetry) {
159 DPRINTF(Bus, "Send failed, waiting on retry\n");
160 }
161}
162
163
164void
165SimpleTimingPort::recvRetry()
166{
167 DPRINTF(Bus, "Received retry\n");
168 assert(waitingOnRetry);
169 sendDeferredPacket();
170}
171
172
173void
174SimpleTimingPort::processSendEvent()
175{
176 assert(!waitingOnRetry);
177 sendDeferredPacket();
178}
179
180
181unsigned int
182SimpleTimingPort::drain(Event *de)
183{
184 if (transmitList.size() == 0)
185 return 0;
186 drainEvent = de;
187 return 1;
188}
142 }
143
144 if (transmitList.empty() && drainEvent) {
145 drainEvent->process();
146 drainEvent = NULL;
147 }
148 } else {
149 // Unsuccessful, need to put back on transmitList. Callee
150 // should not have messed with it (since it didn't accept that
151 // packet), so we can just push it back on the front.
152 assert(!sendEvent->scheduled());
153 transmitList.push_front(dp);
154 }
155
156 waitingOnRetry = !success;
157
158 if (waitingOnRetry) {
159 DPRINTF(Bus, "Send failed, waiting on retry\n");
160 }
161}
162
163
164void
165SimpleTimingPort::recvRetry()
166{
167 DPRINTF(Bus, "Received retry\n");
168 assert(waitingOnRetry);
169 sendDeferredPacket();
170}
171
172
173void
174SimpleTimingPort::processSendEvent()
175{
176 assert(!waitingOnRetry);
177 sendDeferredPacket();
178}
179
180
181unsigned int
182SimpleTimingPort::drain(Event *de)
183{
184 if (transmitList.size() == 0)
185 return 0;
186 drainEvent = de;
187 return 1;
188}