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;

--- 17 unchanged lines hidden (view full) ---

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
33void
34SimpleTimingPort::recvFunctional(PacketPtr pkt)
34SimpleTimingPort::checkFunctional(PacketPtr pkt)
35{
36 std::list<std::pair<Tick,PacketPtr> >::iterator i = transmitList.begin();
37 std::list<std::pair<Tick,PacketPtr> >::iterator end = transmitList.end();
38 bool notDone = true;
36 DeferredPacketIterator i = transmitList.begin();
37 DeferredPacketIterator end = transmitList.end();
38
40 while (i != end && notDone) {
41 PacketPtr target = i->second;
39 while (i != end) {
40 PacketPtr target = i->pkt;
41 // If the target contains data, and it overlaps the
42 // probed request, need to update data
44 if (target->intersect(pkt))
45 notDone = fixPacket(pkt, target);
43 if (target->intersect(pkt)) {
44 if (!fixPacket(pkt, target)) {
45 // fixPacket returns true for continue, false for done
46 return;
47 }
48 }
49
50 i++;
51 }
52}
53
50 //Then just do an atomic access and throw away the returned latency
54void
55SimpleTimingPort::recvFunctional(PacketPtr pkt)
56{
57 checkFunctional(pkt);
58
59 // Just do an atomic access and throw away the returned latency
60 if (pkt->result != Packet::Success)
61 recvAtomic(pkt);
62}
63
64bool
65SimpleTimingPort::recvTiming(PacketPtr pkt)
66{
67 // If the device is only a slave, it should only be sending
68 // responses, which should never get nacked. There used to be
69 // code to hanldle nacks here, but I'm pretty sure it didn't work
70 // correctly with the drain code, so that would need to be fixed
71 // if we ever added it back.
72 assert(pkt->result != Packet::Nacked);
73 Tick latency = recvAtomic(pkt);
74 // turn packet around to go back to requester if response expected
75 if (pkt->needsResponse()) {
76 pkt->makeTimingResponse();
77 sendTiming(pkt, latency);
78 }
70 else {
71 if (pkt->cmd != MemCmd::UpgradeReq)
72 {
73 delete pkt->req;
74 delete pkt;
75 }
79 else if (pkt->cmd != MemCmd::UpgradeReq) {
80 delete pkt->req;
81 delete pkt;
82 }
83 return true;
84}
85
86void
87SimpleTimingPort::recvRetry()
88{
89 assert(!transmitList.empty());
84 if (Port::sendTiming(transmitList.front().second)) {
90 if (Port::sendTiming(transmitList.front().pkt)) {
91 transmitList.pop_front();
92 DPRINTF(Bus, "No Longer waiting on retry\n");
93 if (!transmitList.empty()) {
88 Tick time = transmitList.front().first;
89 sendEvent.schedule(time <= curTick ? curTick+1 : time);
94 Tick time = transmitList.front().tick;
95 sendEvent->schedule(time <= curTick ? curTick+1 : time);
96 }
97 }
98
99 if (transmitList.empty() && drainEvent) {
100 drainEvent->process();
101 drainEvent = NULL;
102 }
103}
104
105void
106SimpleTimingPort::sendTiming(PacketPtr pkt, Tick time)
107{
108 // Nothing is on the list: add it and schedule an event
109 if (transmitList.empty()) {
104 assert(!sendEvent.scheduled());
105 sendEvent.schedule(curTick+time);
106 transmitList.push_back(std::pair<Tick,PacketPtr>(time+curTick,pkt));
110 assert(!sendEvent->scheduled());
111 sendEvent->schedule(curTick+time);
112 transmitList.push_back(DeferredPacket(time+curTick, pkt));
113 return;
114 }
115
116 // something is on the list and this belongs at the end
111 if (time+curTick >= transmitList.back().first) {
112 transmitList.push_back(std::pair<Tick,PacketPtr>(time+curTick,pkt));
117 if (time+curTick >= transmitList.back().tick) {
118 transmitList.push_back(DeferredPacket(time+curTick, pkt));
119 return;
120 }
121 // Something is on the list and this belongs somewhere else
116 std::list<std::pair<Tick,PacketPtr> >::iterator i = transmitList.begin();
117 std::list<std::pair<Tick,PacketPtr> >::iterator end = transmitList.end();
122 DeferredPacketIterator i = transmitList.begin();
123 DeferredPacketIterator end = transmitList.end();
124 bool done = false;
125
126 while (i != end && !done) {
121 if (time+curTick < i->first) {
127 if (time+curTick < i->tick) {
128 if (i == transmitList.begin()) {
129 //Inserting at begining, reschedule
124 sendEvent.reschedule(time+curTick);
130 sendEvent->reschedule(time+curTick);
131 }
126 transmitList.insert(i,std::pair<Tick,PacketPtr>(time+curTick,pkt));
132 transmitList.insert(i, DeferredPacket(time+curTick, pkt));
133 done = true;
134 }
135 i++;
136 }
137 assert(done);
138}
139
140void
135SimpleTimingPort::SendEvent::process()
141SimpleTimingPort::processSendEvent()
142{
137 assert(port->transmitList.size());
138 assert(port->transmitList.front().first <= curTick);
139 if (port->Port::sendTiming(port->transmitList.front().second)) {
143 assert(transmitList.size());
144 assert(transmitList.front().tick <= curTick);
145 if (Port::sendTiming(transmitList.front().pkt)) {
146 //send successful, remove packet
141 port->transmitList.pop_front();
142 if (!port->transmitList.empty()) {
143 Tick time = port->transmitList.front().first;
144 schedule(time <= curTick ? curTick+1 : time);
147 transmitList.pop_front();
148 if (!transmitList.empty()) {
149 Tick time = transmitList.front().tick;
150 sendEvent->schedule(time <= curTick ? curTick+1 : time);
151 }
146 if (port->transmitList.empty() && port->drainEvent) {
147 port->drainEvent->process();
148 port->drainEvent = NULL;
152 if (transmitList.empty() && drainEvent) {
153 drainEvent->process();
154 drainEvent = NULL;
155 }
156 return;
157 }
158 // send unsuccessful (due to flow control). Will get retry
159 // callback later; save for then if not already
160 DPRINTF(Bus, "Waiting on retry\n");
161}
162
163
164unsigned int
165SimpleTimingPort::drain(Event *de)
166{
167 if (transmitList.size() == 0)
168 return 0;
169 drainEvent = de;
170 return 1;
171}