atomic.cc (4027:53292b42ee1c) atomic.cc (4040:eb894f3fc168)
1/*
2 * Copyright (c) 2002-2005 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: Steve Reinhardt
29 */
30
31#include "arch/locked_mem.hh"
32#include "arch/mmaped_ipr.hh"
33#include "arch/utility.hh"
1/*
2 * Copyright (c) 2002-2005 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: Steve Reinhardt
29 */
30
31#include "arch/locked_mem.hh"
32#include "arch/mmaped_ipr.hh"
33#include "arch/utility.hh"
34#include "base/bigint.hh"
34#include "cpu/exetrace.hh"
35#include "cpu/simple/atomic.hh"
36#include "mem/packet.hh"
37#include "mem/packet_access.hh"
38#include "sim/builder.hh"
39#include "sim/system.hh"
40
41using namespace std;
42using namespace TheISA;
43
44AtomicSimpleCPU::TickEvent::TickEvent(AtomicSimpleCPU *c)
45 : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c)
46{
47}
48
49
50void
51AtomicSimpleCPU::TickEvent::process()
52{
53 cpu->tick();
54}
55
56const char *
57AtomicSimpleCPU::TickEvent::description()
58{
59 return "AtomicSimpleCPU tick event";
60}
61
62Port *
63AtomicSimpleCPU::getPort(const std::string &if_name, int idx)
64{
65 if (if_name == "dcache_port")
66 return &dcachePort;
67 else if (if_name == "icache_port")
68 return &icachePort;
69 else
70 panic("No Such Port\n");
71}
72
73void
74AtomicSimpleCPU::init()
75{
76 BaseCPU::init();
77#if FULL_SYSTEM
78 for (int i = 0; i < threadContexts.size(); ++i) {
79 ThreadContext *tc = threadContexts[i];
80
81 // initialize CPU, including PC
82 TheISA::initCPU(tc, tc->readCpuId());
83 }
84#endif
85}
86
87bool
88AtomicSimpleCPU::CpuPort::recvTiming(PacketPtr pkt)
89{
90 panic("AtomicSimpleCPU doesn't expect recvTiming callback!");
91 return true;
92}
93
94Tick
95AtomicSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt)
96{
97 //Snooping a coherence request, just return
98 return 0;
99}
100
101void
102AtomicSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt)
103{
104 //No internal storage to update, just return
105 return;
106}
107
108void
109AtomicSimpleCPU::CpuPort::recvStatusChange(Status status)
110{
111 if (status == RangeChange) {
112 if (!snoopRangeSent) {
113 snoopRangeSent = true;
114 sendStatusChange(Port::RangeChange);
115 }
116 return;
117 }
118
119 panic("AtomicSimpleCPU doesn't expect recvStatusChange callback!");
120}
121
122void
123AtomicSimpleCPU::CpuPort::recvRetry()
124{
125 panic("AtomicSimpleCPU doesn't expect recvRetry callback!");
126}
127
128
129AtomicSimpleCPU::AtomicSimpleCPU(Params *p)
130 : BaseSimpleCPU(p), tickEvent(this),
131 width(p->width), simulate_stalls(p->simulate_stalls),
132 icachePort(name() + "-iport", this), dcachePort(name() + "-iport", this)
133{
134 _status = Idle;
135
136 icachePort.snoopRangeSent = false;
137 dcachePort.snoopRangeSent = false;
138
139 ifetch_req = new Request();
140 ifetch_req->setThreadContext(p->cpu_id, 0); // Add thread ID if we add MT
141 ifetch_pkt = new Packet(ifetch_req, MemCmd::ReadReq, Packet::Broadcast);
142 ifetch_pkt->dataStatic(&inst);
143
144 data_read_req = new Request();
145 data_read_req->setThreadContext(p->cpu_id, 0); // Add thread ID here too
146 data_read_pkt = new Packet(data_read_req, MemCmd::ReadReq,
147 Packet::Broadcast);
148 data_read_pkt->dataStatic(&dataReg);
149
150 data_write_req = new Request();
151 data_write_req->setThreadContext(p->cpu_id, 0); // Add thread ID here too
152 data_write_pkt = new Packet(data_write_req, MemCmd::WriteReq,
153 Packet::Broadcast);
35#include "cpu/exetrace.hh"
36#include "cpu/simple/atomic.hh"
37#include "mem/packet.hh"
38#include "mem/packet_access.hh"
39#include "sim/builder.hh"
40#include "sim/system.hh"
41
42using namespace std;
43using namespace TheISA;
44
45AtomicSimpleCPU::TickEvent::TickEvent(AtomicSimpleCPU *c)
46 : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c)
47{
48}
49
50
51void
52AtomicSimpleCPU::TickEvent::process()
53{
54 cpu->tick();
55}
56
57const char *
58AtomicSimpleCPU::TickEvent::description()
59{
60 return "AtomicSimpleCPU tick event";
61}
62
63Port *
64AtomicSimpleCPU::getPort(const std::string &if_name, int idx)
65{
66 if (if_name == "dcache_port")
67 return &dcachePort;
68 else if (if_name == "icache_port")
69 return &icachePort;
70 else
71 panic("No Such Port\n");
72}
73
74void
75AtomicSimpleCPU::init()
76{
77 BaseCPU::init();
78#if FULL_SYSTEM
79 for (int i = 0; i < threadContexts.size(); ++i) {
80 ThreadContext *tc = threadContexts[i];
81
82 // initialize CPU, including PC
83 TheISA::initCPU(tc, tc->readCpuId());
84 }
85#endif
86}
87
88bool
89AtomicSimpleCPU::CpuPort::recvTiming(PacketPtr pkt)
90{
91 panic("AtomicSimpleCPU doesn't expect recvTiming callback!");
92 return true;
93}
94
95Tick
96AtomicSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt)
97{
98 //Snooping a coherence request, just return
99 return 0;
100}
101
102void
103AtomicSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt)
104{
105 //No internal storage to update, just return
106 return;
107}
108
109void
110AtomicSimpleCPU::CpuPort::recvStatusChange(Status status)
111{
112 if (status == RangeChange) {
113 if (!snoopRangeSent) {
114 snoopRangeSent = true;
115 sendStatusChange(Port::RangeChange);
116 }
117 return;
118 }
119
120 panic("AtomicSimpleCPU doesn't expect recvStatusChange callback!");
121}
122
123void
124AtomicSimpleCPU::CpuPort::recvRetry()
125{
126 panic("AtomicSimpleCPU doesn't expect recvRetry callback!");
127}
128
129
130AtomicSimpleCPU::AtomicSimpleCPU(Params *p)
131 : BaseSimpleCPU(p), tickEvent(this),
132 width(p->width), simulate_stalls(p->simulate_stalls),
133 icachePort(name() + "-iport", this), dcachePort(name() + "-iport", this)
134{
135 _status = Idle;
136
137 icachePort.snoopRangeSent = false;
138 dcachePort.snoopRangeSent = false;
139
140 ifetch_req = new Request();
141 ifetch_req->setThreadContext(p->cpu_id, 0); // Add thread ID if we add MT
142 ifetch_pkt = new Packet(ifetch_req, MemCmd::ReadReq, Packet::Broadcast);
143 ifetch_pkt->dataStatic(&inst);
144
145 data_read_req = new Request();
146 data_read_req->setThreadContext(p->cpu_id, 0); // Add thread ID here too
147 data_read_pkt = new Packet(data_read_req, MemCmd::ReadReq,
148 Packet::Broadcast);
149 data_read_pkt->dataStatic(&dataReg);
150
151 data_write_req = new Request();
152 data_write_req->setThreadContext(p->cpu_id, 0); // Add thread ID here too
153 data_write_pkt = new Packet(data_write_req, MemCmd::WriteReq,
154 Packet::Broadcast);
155 data_swap_pkt = new Packet(data_write_req, MemCmd::SwapReq,
156 Packet::Broadcast);
154}
155
156
157AtomicSimpleCPU::~AtomicSimpleCPU()
158{
159}
160
161void
162AtomicSimpleCPU::serialize(ostream &os)
163{
164 SimObject::State so_state = SimObject::getState();
165 SERIALIZE_ENUM(so_state);
166 Status _status = status();
167 SERIALIZE_ENUM(_status);
168 BaseSimpleCPU::serialize(os);
169 nameOut(os, csprintf("%s.tickEvent", name()));
170 tickEvent.serialize(os);
171}
172
173void
174AtomicSimpleCPU::unserialize(Checkpoint *cp, const string &section)
175{
176 SimObject::State so_state;
177 UNSERIALIZE_ENUM(so_state);
178 UNSERIALIZE_ENUM(_status);
179 BaseSimpleCPU::unserialize(cp, section);
180 tickEvent.unserialize(cp, csprintf("%s.tickEvent", section));
181}
182
183void
184AtomicSimpleCPU::resume()
185{
186 if (_status != SwitchedOut && _status != Idle) {
187 assert(system->getMemoryMode() == System::Atomic);
188
189 changeState(SimObject::Running);
190 if (thread->status() == ThreadContext::Active) {
191 if (!tickEvent.scheduled()) {
192 tickEvent.schedule(nextCycle());
193 }
194 }
195 }
196}
197
198void
199AtomicSimpleCPU::switchOut()
200{
201 assert(status() == Running || status() == Idle);
202 _status = SwitchedOut;
203
204 tickEvent.squash();
205}
206
207
208void
209AtomicSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
210{
211 BaseCPU::takeOverFrom(oldCPU);
212
213 assert(!tickEvent.scheduled());
214
215 // if any of this CPU's ThreadContexts are active, mark the CPU as
216 // running and schedule its tick event.
217 for (int i = 0; i < threadContexts.size(); ++i) {
218 ThreadContext *tc = threadContexts[i];
219 if (tc->status() == ThreadContext::Active && _status != Running) {
220 _status = Running;
221 tickEvent.schedule(nextCycle());
222 break;
223 }
224 }
225 if (_status != Running) {
226 _status = Idle;
227 }
228}
229
230
231void
232AtomicSimpleCPU::activateContext(int thread_num, int delay)
233{
234 assert(thread_num == 0);
235 assert(thread);
236
237 assert(_status == Idle);
238 assert(!tickEvent.scheduled());
239
240 notIdleFraction++;
241
242#if FULL_SYSTEM
243 // Connect the ThreadContext's memory ports (Functional/Virtual
244 // Ports)
245 tc->connectMemPorts();
246#endif
247
248 //Make sure ticks are still on multiples of cycles
249 tickEvent.schedule(nextCycle(curTick + cycles(delay)));
250 _status = Running;
251}
252
253
254void
255AtomicSimpleCPU::suspendContext(int thread_num)
256{
257 assert(thread_num == 0);
258 assert(thread);
259
260 assert(_status == Running);
261
262 // tick event may not be scheduled if this gets called from inside
263 // an instruction's execution, e.g. "quiesce"
264 if (tickEvent.scheduled())
265 tickEvent.deschedule();
266
267 notIdleFraction--;
268 _status = Idle;
269}
270
271
272template <class T>
273Fault
274AtomicSimpleCPU::read(Addr addr, T &data, unsigned flags)
275{
276 // use the CPU's statically allocated read request and packet objects
277 Request *req = data_read_req;
278 PacketPtr pkt = data_read_pkt;
279
280 req->setVirt(0, addr, sizeof(T), flags, thread->readPC());
281
282 if (traceData) {
283 traceData->setAddr(addr);
284 }
285
286 // translate to physical address
287 Fault fault = thread->translateDataReadReq(req);
288
289 // Now do the access.
290 if (fault == NoFault) {
291 pkt->reinitFromRequest();
292
293 if (req->isMmapedIpr())
294 dcache_latency = TheISA::handleIprRead(thread->getTC(),pkt);
295 else
296 dcache_latency = dcachePort.sendAtomic(pkt);
297 dcache_access = true;
298#if !defined(NDEBUG)
299 if (pkt->result != Packet::Success)
300 panic("Unable to find responder for address pa = %#X va = %#X\n",
301 pkt->req->getPaddr(), pkt->req->getVaddr());
302#endif
303 data = pkt->get<T>();
304
305 if (req->isLocked()) {
306 TheISA::handleLockedRead(thread, req);
307 }
308 }
309
310 // This will need a new way to tell if it has a dcache attached.
311 if (req->isUncacheable())
312 recordEvent("Uncached Read");
313
314 return fault;
315}
316
317#ifndef DOXYGEN_SHOULD_SKIP_THIS
318
319template
320Fault
157}
158
159
160AtomicSimpleCPU::~AtomicSimpleCPU()
161{
162}
163
164void
165AtomicSimpleCPU::serialize(ostream &os)
166{
167 SimObject::State so_state = SimObject::getState();
168 SERIALIZE_ENUM(so_state);
169 Status _status = status();
170 SERIALIZE_ENUM(_status);
171 BaseSimpleCPU::serialize(os);
172 nameOut(os, csprintf("%s.tickEvent", name()));
173 tickEvent.serialize(os);
174}
175
176void
177AtomicSimpleCPU::unserialize(Checkpoint *cp, const string &section)
178{
179 SimObject::State so_state;
180 UNSERIALIZE_ENUM(so_state);
181 UNSERIALIZE_ENUM(_status);
182 BaseSimpleCPU::unserialize(cp, section);
183 tickEvent.unserialize(cp, csprintf("%s.tickEvent", section));
184}
185
186void
187AtomicSimpleCPU::resume()
188{
189 if (_status != SwitchedOut && _status != Idle) {
190 assert(system->getMemoryMode() == System::Atomic);
191
192 changeState(SimObject::Running);
193 if (thread->status() == ThreadContext::Active) {
194 if (!tickEvent.scheduled()) {
195 tickEvent.schedule(nextCycle());
196 }
197 }
198 }
199}
200
201void
202AtomicSimpleCPU::switchOut()
203{
204 assert(status() == Running || status() == Idle);
205 _status = SwitchedOut;
206
207 tickEvent.squash();
208}
209
210
211void
212AtomicSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
213{
214 BaseCPU::takeOverFrom(oldCPU);
215
216 assert(!tickEvent.scheduled());
217
218 // if any of this CPU's ThreadContexts are active, mark the CPU as
219 // running and schedule its tick event.
220 for (int i = 0; i < threadContexts.size(); ++i) {
221 ThreadContext *tc = threadContexts[i];
222 if (tc->status() == ThreadContext::Active && _status != Running) {
223 _status = Running;
224 tickEvent.schedule(nextCycle());
225 break;
226 }
227 }
228 if (_status != Running) {
229 _status = Idle;
230 }
231}
232
233
234void
235AtomicSimpleCPU::activateContext(int thread_num, int delay)
236{
237 assert(thread_num == 0);
238 assert(thread);
239
240 assert(_status == Idle);
241 assert(!tickEvent.scheduled());
242
243 notIdleFraction++;
244
245#if FULL_SYSTEM
246 // Connect the ThreadContext's memory ports (Functional/Virtual
247 // Ports)
248 tc->connectMemPorts();
249#endif
250
251 //Make sure ticks are still on multiples of cycles
252 tickEvent.schedule(nextCycle(curTick + cycles(delay)));
253 _status = Running;
254}
255
256
257void
258AtomicSimpleCPU::suspendContext(int thread_num)
259{
260 assert(thread_num == 0);
261 assert(thread);
262
263 assert(_status == Running);
264
265 // tick event may not be scheduled if this gets called from inside
266 // an instruction's execution, e.g. "quiesce"
267 if (tickEvent.scheduled())
268 tickEvent.deschedule();
269
270 notIdleFraction--;
271 _status = Idle;
272}
273
274
275template <class T>
276Fault
277AtomicSimpleCPU::read(Addr addr, T &data, unsigned flags)
278{
279 // use the CPU's statically allocated read request and packet objects
280 Request *req = data_read_req;
281 PacketPtr pkt = data_read_pkt;
282
283 req->setVirt(0, addr, sizeof(T), flags, thread->readPC());
284
285 if (traceData) {
286 traceData->setAddr(addr);
287 }
288
289 // translate to physical address
290 Fault fault = thread->translateDataReadReq(req);
291
292 // Now do the access.
293 if (fault == NoFault) {
294 pkt->reinitFromRequest();
295
296 if (req->isMmapedIpr())
297 dcache_latency = TheISA::handleIprRead(thread->getTC(),pkt);
298 else
299 dcache_latency = dcachePort.sendAtomic(pkt);
300 dcache_access = true;
301#if !defined(NDEBUG)
302 if (pkt->result != Packet::Success)
303 panic("Unable to find responder for address pa = %#X va = %#X\n",
304 pkt->req->getPaddr(), pkt->req->getVaddr());
305#endif
306 data = pkt->get<T>();
307
308 if (req->isLocked()) {
309 TheISA::handleLockedRead(thread, req);
310 }
311 }
312
313 // This will need a new way to tell if it has a dcache attached.
314 if (req->isUncacheable())
315 recordEvent("Uncached Read");
316
317 return fault;
318}
319
320#ifndef DOXYGEN_SHOULD_SKIP_THIS
321
322template
323Fault
324AtomicSimpleCPU::read(Addr addr, Twin64_t &data, unsigned flags);
325
326template
327Fault
321AtomicSimpleCPU::read(Addr addr, uint64_t &data, unsigned flags);
322
323template
324Fault
325AtomicSimpleCPU::read(Addr addr, uint32_t &data, unsigned flags);
326
327template
328Fault
329AtomicSimpleCPU::read(Addr addr, uint16_t &data, unsigned flags);
330
331template
332Fault
333AtomicSimpleCPU::read(Addr addr, uint8_t &data, unsigned flags);
334
335#endif //DOXYGEN_SHOULD_SKIP_THIS
336
337template<>
338Fault
339AtomicSimpleCPU::read(Addr addr, double &data, unsigned flags)
340{
341 return read(addr, *(uint64_t*)&data, flags);
342}
343
344template<>
345Fault
346AtomicSimpleCPU::read(Addr addr, float &data, unsigned flags)
347{
348 return read(addr, *(uint32_t*)&data, flags);
349}
350
351
352template<>
353Fault
354AtomicSimpleCPU::read(Addr addr, int32_t &data, unsigned flags)
355{
356 return read(addr, (uint32_t&)data, flags);
357}
358
359
360template <class T>
361Fault
362AtomicSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res)
363{
364 // use the CPU's statically allocated write request and packet objects
365 Request *req = data_write_req;
328AtomicSimpleCPU::read(Addr addr, uint64_t &data, unsigned flags);
329
330template
331Fault
332AtomicSimpleCPU::read(Addr addr, uint32_t &data, unsigned flags);
333
334template
335Fault
336AtomicSimpleCPU::read(Addr addr, uint16_t &data, unsigned flags);
337
338template
339Fault
340AtomicSimpleCPU::read(Addr addr, uint8_t &data, unsigned flags);
341
342#endif //DOXYGEN_SHOULD_SKIP_THIS
343
344template<>
345Fault
346AtomicSimpleCPU::read(Addr addr, double &data, unsigned flags)
347{
348 return read(addr, *(uint64_t*)&data, flags);
349}
350
351template<>
352Fault
353AtomicSimpleCPU::read(Addr addr, float &data, unsigned flags)
354{
355 return read(addr, *(uint32_t*)&data, flags);
356}
357
358
359template<>
360Fault
361AtomicSimpleCPU::read(Addr addr, int32_t &data, unsigned flags)
362{
363 return read(addr, (uint32_t&)data, flags);
364}
365
366
367template <class T>
368Fault
369AtomicSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res)
370{
371 // use the CPU's statically allocated write request and packet objects
372 Request *req = data_write_req;
366 PacketPtr pkt = data_write_pkt;
373 PacketPtr pkt;
367
368 req->setVirt(0, addr, sizeof(T), flags, thread->readPC());
369
374
375 req->setVirt(0, addr, sizeof(T), flags, thread->readPC());
376
377 if (req->isSwap())
378 pkt = data_swap_pkt;
379 else
380 pkt = data_write_pkt;
381
370 if (traceData) {
371 traceData->setAddr(addr);
372 }
373
374 // translate to physical address
375 Fault fault = thread->translateDataWriteReq(req);
376
377 // Now do the access.
378 if (fault == NoFault) {
379 bool do_access = true; // flag to suppress cache access
380
381 if (req->isLocked()) {
382 do_access = TheISA::handleLockedWrite(thread, req);
383 }
382 if (traceData) {
383 traceData->setAddr(addr);
384 }
385
386 // translate to physical address
387 Fault fault = thread->translateDataWriteReq(req);
388
389 // Now do the access.
390 if (fault == NoFault) {
391 bool do_access = true; // flag to suppress cache access
392
393 if (req->isLocked()) {
394 do_access = TheISA::handleLockedWrite(thread, req);
395 }
396 if (req->isCondSwap()) {
397 assert(res);
398 req->setExtraData(*res);
399 }
384
400
401
385 if (do_access) {
386 pkt->reinitFromRequest();
387 pkt->dataStatic(&data);
388
389 if (req->isMmapedIpr()) {
390 dcache_latency = TheISA::handleIprWrite(thread->getTC(), pkt);
391 } else {
392 data = htog(data);
393 dcache_latency = dcachePort.sendAtomic(pkt);
394 }
395 dcache_access = true;
396
397#if !defined(NDEBUG)
398 if (pkt->result != Packet::Success)
399 panic("Unable to find responder for address pa = %#X va = %#X\n",
400 pkt->req->getPaddr(), pkt->req->getVaddr());
401#endif
402 }
403
402 if (do_access) {
403 pkt->reinitFromRequest();
404 pkt->dataStatic(&data);
405
406 if (req->isMmapedIpr()) {
407 dcache_latency = TheISA::handleIprWrite(thread->getTC(), pkt);
408 } else {
409 data = htog(data);
410 dcache_latency = dcachePort.sendAtomic(pkt);
411 }
412 dcache_access = true;
413
414#if !defined(NDEBUG)
415 if (pkt->result != Packet::Success)
416 panic("Unable to find responder for address pa = %#X va = %#X\n",
417 pkt->req->getPaddr(), pkt->req->getVaddr());
418#endif
419 }
420
404 if (res) {
405 *res = req->getScResult();
421 if (req->isSwap()) {
422 assert(res);
423 *res = pkt->get<T>();
406 }
424 }
425
426 if (req->isLocked()) {
427 uint64_t scResult = req->getExtraData();
428 if (scResult != 0) {
429 // clear failure counter
430 thread->setStCondFailures(0);
431 }
432 if (res) {
433 *res = req->getExtraData();
434 }
435 }
407 }
408
409 // This will need a new way to tell if it's hooked up to a cache or not.
410 if (req->isUncacheable())
411 recordEvent("Uncached Write");
412
413 // If the write needs to have a fault on the access, consider calling
414 // changeStatus() and changing it to "bad addr write" or something.
415 return fault;
416}
417
418
419#ifndef DOXYGEN_SHOULD_SKIP_THIS
420template
421Fault
422AtomicSimpleCPU::write(uint64_t data, Addr addr,
423 unsigned flags, uint64_t *res);
424
425template
426Fault
427AtomicSimpleCPU::write(uint32_t data, Addr addr,
428 unsigned flags, uint64_t *res);
429
430template
431Fault
432AtomicSimpleCPU::write(uint16_t data, Addr addr,
433 unsigned flags, uint64_t *res);
434
435template
436Fault
437AtomicSimpleCPU::write(uint8_t data, Addr addr,
438 unsigned flags, uint64_t *res);
439
440#endif //DOXYGEN_SHOULD_SKIP_THIS
441
442template<>
443Fault
444AtomicSimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res)
445{
446 return write(*(uint64_t*)&data, addr, flags, res);
447}
448
449template<>
450Fault
451AtomicSimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res)
452{
453 return write(*(uint32_t*)&data, addr, flags, res);
454}
455
456
457template<>
458Fault
459AtomicSimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res)
460{
461 return write((uint32_t)data, addr, flags, res);
462}
463
464
465void
466AtomicSimpleCPU::tick()
467{
468 Tick latency = cycles(1); // instruction takes one cycle by default
469
470 for (int i = 0; i < width; ++i) {
471 numCycles++;
472
473 if (!curStaticInst || !curStaticInst->isDelayedCommit())
474 checkForInterrupts();
475
476 Fault fault = setupFetchRequest(ifetch_req);
477
478 if (fault == NoFault) {
479 ifetch_pkt->reinitFromRequest();
480
481 Tick icache_latency = icachePort.sendAtomic(ifetch_pkt);
482 // ifetch_req is initialized to read the instruction directly
483 // into the CPU object's inst field.
484
485 dcache_access = false; // assume no dcache access
486 preExecute();
487
488 fault = curStaticInst->execute(this, traceData);
489 postExecute();
490
491 // @todo remove me after debugging with legion done
492 if (curStaticInst && (!curStaticInst->isMicroOp() ||
493 curStaticInst->isFirstMicroOp()))
494 instCnt++;
495
496 if (simulate_stalls) {
497 Tick icache_stall = icache_latency - cycles(1);
498 Tick dcache_stall =
499 dcache_access ? dcache_latency - cycles(1) : 0;
500 Tick stall_cycles = (icache_stall + dcache_stall) / cycles(1);
501 if (cycles(stall_cycles) < (icache_stall + dcache_stall))
502 latency += cycles(stall_cycles+1);
503 else
504 latency += cycles(stall_cycles);
505 }
506
507 }
508
509 advancePC(fault);
510 }
511
512 if (_status != Idle)
513 tickEvent.schedule(curTick + latency);
514}
515
516
517////////////////////////////////////////////////////////////////////////
518//
519// AtomicSimpleCPU Simulation Object
520//
521BEGIN_DECLARE_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
522
523 Param<Counter> max_insts_any_thread;
524 Param<Counter> max_insts_all_threads;
525 Param<Counter> max_loads_any_thread;
526 Param<Counter> max_loads_all_threads;
527 Param<Tick> progress_interval;
528 SimObjectParam<System *> system;
529 Param<int> cpu_id;
530
531#if FULL_SYSTEM
532 SimObjectParam<TheISA::ITB *> itb;
533 SimObjectParam<TheISA::DTB *> dtb;
534 Param<Tick> profile;
535
536 Param<bool> do_quiesce;
537 Param<bool> do_checkpoint_insts;
538 Param<bool> do_statistics_insts;
539#else
540 SimObjectParam<Process *> workload;
541#endif // FULL_SYSTEM
542
543 Param<int> clock;
544 Param<int> phase;
545
546 Param<bool> defer_registration;
547 Param<int> width;
548 Param<bool> function_trace;
549 Param<Tick> function_trace_start;
550 Param<bool> simulate_stalls;
551
552END_DECLARE_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
553
554BEGIN_INIT_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
555
556 INIT_PARAM(max_insts_any_thread,
557 "terminate when any thread reaches this inst count"),
558 INIT_PARAM(max_insts_all_threads,
559 "terminate when all threads have reached this inst count"),
560 INIT_PARAM(max_loads_any_thread,
561 "terminate when any thread reaches this load count"),
562 INIT_PARAM(max_loads_all_threads,
563 "terminate when all threads have reached this load count"),
564 INIT_PARAM(progress_interval, "Progress interval"),
565 INIT_PARAM(system, "system object"),
566 INIT_PARAM(cpu_id, "processor ID"),
567
568#if FULL_SYSTEM
569 INIT_PARAM(itb, "Instruction TLB"),
570 INIT_PARAM(dtb, "Data TLB"),
571 INIT_PARAM(profile, ""),
572 INIT_PARAM(do_quiesce, ""),
573 INIT_PARAM(do_checkpoint_insts, ""),
574 INIT_PARAM(do_statistics_insts, ""),
575#else
576 INIT_PARAM(workload, "processes to run"),
577#endif // FULL_SYSTEM
578
579 INIT_PARAM(clock, "clock speed"),
580 INIT_PARAM_DFLT(phase, "clock phase", 0),
581 INIT_PARAM(defer_registration, "defer system registration (for sampling)"),
582 INIT_PARAM(width, "cpu width"),
583 INIT_PARAM(function_trace, "Enable function trace"),
584 INIT_PARAM(function_trace_start, "Cycle to start function trace"),
585 INIT_PARAM(simulate_stalls, "Simulate cache stall cycles")
586
587END_INIT_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
588
589
590CREATE_SIM_OBJECT(AtomicSimpleCPU)
591{
592 AtomicSimpleCPU::Params *params = new AtomicSimpleCPU::Params();
593 params->name = getInstanceName();
594 params->numberOfThreads = 1;
595 params->max_insts_any_thread = max_insts_any_thread;
596 params->max_insts_all_threads = max_insts_all_threads;
597 params->max_loads_any_thread = max_loads_any_thread;
598 params->max_loads_all_threads = max_loads_all_threads;
599 params->progress_interval = progress_interval;
600 params->deferRegistration = defer_registration;
601 params->phase = phase;
602 params->clock = clock;
603 params->functionTrace = function_trace;
604 params->functionTraceStart = function_trace_start;
605 params->width = width;
606 params->simulate_stalls = simulate_stalls;
607 params->system = system;
608 params->cpu_id = cpu_id;
609
610#if FULL_SYSTEM
611 params->itb = itb;
612 params->dtb = dtb;
613 params->profile = profile;
614 params->do_quiesce = do_quiesce;
615 params->do_checkpoint_insts = do_checkpoint_insts;
616 params->do_statistics_insts = do_statistics_insts;
617#else
618 params->process = workload;
619#endif
620
621 AtomicSimpleCPU *cpu = new AtomicSimpleCPU(params);
622 return cpu;
623}
624
625REGISTER_SIM_OBJECT("AtomicSimpleCPU", AtomicSimpleCPU)
626
436 }
437
438 // This will need a new way to tell if it's hooked up to a cache or not.
439 if (req->isUncacheable())
440 recordEvent("Uncached Write");
441
442 // If the write needs to have a fault on the access, consider calling
443 // changeStatus() and changing it to "bad addr write" or something.
444 return fault;
445}
446
447
448#ifndef DOXYGEN_SHOULD_SKIP_THIS
449template
450Fault
451AtomicSimpleCPU::write(uint64_t data, Addr addr,
452 unsigned flags, uint64_t *res);
453
454template
455Fault
456AtomicSimpleCPU::write(uint32_t data, Addr addr,
457 unsigned flags, uint64_t *res);
458
459template
460Fault
461AtomicSimpleCPU::write(uint16_t data, Addr addr,
462 unsigned flags, uint64_t *res);
463
464template
465Fault
466AtomicSimpleCPU::write(uint8_t data, Addr addr,
467 unsigned flags, uint64_t *res);
468
469#endif //DOXYGEN_SHOULD_SKIP_THIS
470
471template<>
472Fault
473AtomicSimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res)
474{
475 return write(*(uint64_t*)&data, addr, flags, res);
476}
477
478template<>
479Fault
480AtomicSimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res)
481{
482 return write(*(uint32_t*)&data, addr, flags, res);
483}
484
485
486template<>
487Fault
488AtomicSimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res)
489{
490 return write((uint32_t)data, addr, flags, res);
491}
492
493
494void
495AtomicSimpleCPU::tick()
496{
497 Tick latency = cycles(1); // instruction takes one cycle by default
498
499 for (int i = 0; i < width; ++i) {
500 numCycles++;
501
502 if (!curStaticInst || !curStaticInst->isDelayedCommit())
503 checkForInterrupts();
504
505 Fault fault = setupFetchRequest(ifetch_req);
506
507 if (fault == NoFault) {
508 ifetch_pkt->reinitFromRequest();
509
510 Tick icache_latency = icachePort.sendAtomic(ifetch_pkt);
511 // ifetch_req is initialized to read the instruction directly
512 // into the CPU object's inst field.
513
514 dcache_access = false; // assume no dcache access
515 preExecute();
516
517 fault = curStaticInst->execute(this, traceData);
518 postExecute();
519
520 // @todo remove me after debugging with legion done
521 if (curStaticInst && (!curStaticInst->isMicroOp() ||
522 curStaticInst->isFirstMicroOp()))
523 instCnt++;
524
525 if (simulate_stalls) {
526 Tick icache_stall = icache_latency - cycles(1);
527 Tick dcache_stall =
528 dcache_access ? dcache_latency - cycles(1) : 0;
529 Tick stall_cycles = (icache_stall + dcache_stall) / cycles(1);
530 if (cycles(stall_cycles) < (icache_stall + dcache_stall))
531 latency += cycles(stall_cycles+1);
532 else
533 latency += cycles(stall_cycles);
534 }
535
536 }
537
538 advancePC(fault);
539 }
540
541 if (_status != Idle)
542 tickEvent.schedule(curTick + latency);
543}
544
545
546////////////////////////////////////////////////////////////////////////
547//
548// AtomicSimpleCPU Simulation Object
549//
550BEGIN_DECLARE_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
551
552 Param<Counter> max_insts_any_thread;
553 Param<Counter> max_insts_all_threads;
554 Param<Counter> max_loads_any_thread;
555 Param<Counter> max_loads_all_threads;
556 Param<Tick> progress_interval;
557 SimObjectParam<System *> system;
558 Param<int> cpu_id;
559
560#if FULL_SYSTEM
561 SimObjectParam<TheISA::ITB *> itb;
562 SimObjectParam<TheISA::DTB *> dtb;
563 Param<Tick> profile;
564
565 Param<bool> do_quiesce;
566 Param<bool> do_checkpoint_insts;
567 Param<bool> do_statistics_insts;
568#else
569 SimObjectParam<Process *> workload;
570#endif // FULL_SYSTEM
571
572 Param<int> clock;
573 Param<int> phase;
574
575 Param<bool> defer_registration;
576 Param<int> width;
577 Param<bool> function_trace;
578 Param<Tick> function_trace_start;
579 Param<bool> simulate_stalls;
580
581END_DECLARE_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
582
583BEGIN_INIT_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
584
585 INIT_PARAM(max_insts_any_thread,
586 "terminate when any thread reaches this inst count"),
587 INIT_PARAM(max_insts_all_threads,
588 "terminate when all threads have reached this inst count"),
589 INIT_PARAM(max_loads_any_thread,
590 "terminate when any thread reaches this load count"),
591 INIT_PARAM(max_loads_all_threads,
592 "terminate when all threads have reached this load count"),
593 INIT_PARAM(progress_interval, "Progress interval"),
594 INIT_PARAM(system, "system object"),
595 INIT_PARAM(cpu_id, "processor ID"),
596
597#if FULL_SYSTEM
598 INIT_PARAM(itb, "Instruction TLB"),
599 INIT_PARAM(dtb, "Data TLB"),
600 INIT_PARAM(profile, ""),
601 INIT_PARAM(do_quiesce, ""),
602 INIT_PARAM(do_checkpoint_insts, ""),
603 INIT_PARAM(do_statistics_insts, ""),
604#else
605 INIT_PARAM(workload, "processes to run"),
606#endif // FULL_SYSTEM
607
608 INIT_PARAM(clock, "clock speed"),
609 INIT_PARAM_DFLT(phase, "clock phase", 0),
610 INIT_PARAM(defer_registration, "defer system registration (for sampling)"),
611 INIT_PARAM(width, "cpu width"),
612 INIT_PARAM(function_trace, "Enable function trace"),
613 INIT_PARAM(function_trace_start, "Cycle to start function trace"),
614 INIT_PARAM(simulate_stalls, "Simulate cache stall cycles")
615
616END_INIT_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
617
618
619CREATE_SIM_OBJECT(AtomicSimpleCPU)
620{
621 AtomicSimpleCPU::Params *params = new AtomicSimpleCPU::Params();
622 params->name = getInstanceName();
623 params->numberOfThreads = 1;
624 params->max_insts_any_thread = max_insts_any_thread;
625 params->max_insts_all_threads = max_insts_all_threads;
626 params->max_loads_any_thread = max_loads_any_thread;
627 params->max_loads_all_threads = max_loads_all_threads;
628 params->progress_interval = progress_interval;
629 params->deferRegistration = defer_registration;
630 params->phase = phase;
631 params->clock = clock;
632 params->functionTrace = function_trace;
633 params->functionTraceStart = function_trace_start;
634 params->width = width;
635 params->simulate_stalls = simulate_stalls;
636 params->system = system;
637 params->cpu_id = cpu_id;
638
639#if FULL_SYSTEM
640 params->itb = itb;
641 params->dtb = dtb;
642 params->profile = profile;
643 params->do_quiesce = do_quiesce;
644 params->do_checkpoint_insts = do_checkpoint_insts;
645 params->do_statistics_insts = do_statistics_insts;
646#else
647 params->process = workload;
648#endif
649
650 AtomicSimpleCPU *cpu = new AtomicSimpleCPU(params);
651 return cpu;
652}
653
654REGISTER_SIM_OBJECT("AtomicSimpleCPU", AtomicSimpleCPU)
655