961e31935c54c198c05d5c42f8b6deaed81f0ddf
2 * Copyright 2014 Google, Inc.
3 * Copyright (c) 2010-2013,2015,2017 ARM Limited
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
15 * Copyright (c) 2002-2005 The Regents of The University of Michigan
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 * Authors: Steve Reinhardt
44 #include "cpu/simple/timing.hh"
46 #include "arch/locked_mem.hh"
47 #include "arch/mmapped_ipr.hh"
48 #include "arch/utility.hh"
49 #include "base/bigint.hh"
50 #include "config/the_isa.hh"
51 #include "cpu/exetrace.hh"
52 #include "debug/Config.hh"
53 #include "debug/Drain.hh"
54 #include "debug/ExecFaulting.hh"
55 #include "debug/Mwait.hh"
56 #include "debug/SimpleCPU.hh"
57 #include "mem/packet.hh"
58 #include "mem/packet_access.hh"
59 #include "params/TimingSimpleCPU.hh"
60 #include "sim/faults.hh"
61 #include "sim/full_system.hh"
62 #include "sim/system.hh"
65 using namespace TheISA
;
68 TimingSimpleCPU::init()
70 BaseSimpleCPU::init();
74 TimingSimpleCPU::TimingCPUPort::TickEvent::schedule(PacketPtr _pkt
, Tick t
)
77 cpu
->schedule(this, t
);
80 TimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams
*p
)
81 : BaseSimpleCPU(p
), fetchTranslation(this), icachePort(this),
82 dcachePort(this), ifetch_pkt(NULL
), dcache_pkt(NULL
), previousCycle(0),
83 fetchEvent([this]{ fetch(); }, name())
90 TimingSimpleCPU::~TimingSimpleCPU()
95 TimingSimpleCPU::drain()
97 // Deschedule any power gating event (if any)
98 deschedulePowerGatingEvent();
101 return DrainState::Drained
;
103 if (_status
== Idle
||
104 (_status
== BaseSimpleCPU::Running
&& isDrained())) {
105 DPRINTF(Drain
, "No need to drain.\n");
106 activeThreads
.clear();
107 return DrainState::Drained
;
109 DPRINTF(Drain
, "Requesting drain.\n");
111 // The fetch event can become descheduled if a drain didn't
112 // succeed on the first attempt. We need to reschedule it if
113 // the CPU is waiting for a microcode routine to complete.
114 if (_status
== BaseSimpleCPU::Running
&& !fetchEvent
.scheduled())
115 schedule(fetchEvent
, clockEdge());
117 return DrainState::Draining
;
122 TimingSimpleCPU::drainResume()
124 assert(!fetchEvent
.scheduled());
128 DPRINTF(SimpleCPU
, "Resume\n");
131 assert(!threadContexts
.empty());
133 _status
= BaseSimpleCPU::Idle
;
135 for (ThreadID tid
= 0; tid
< numThreads
; tid
++) {
136 if (threadInfo
[tid
]->thread
->status() == ThreadContext::Active
) {
137 threadInfo
[tid
]->notIdleFraction
= 1;
139 activeThreads
.push_back(tid
);
141 _status
= BaseSimpleCPU::Running
;
143 // Fetch if any threads active
144 if (!fetchEvent
.scheduled()) {
145 schedule(fetchEvent
, nextCycle());
148 threadInfo
[tid
]->notIdleFraction
= 0;
152 // Reschedule any power gating event (if any)
153 schedulePowerGatingEvent();
155 system
->totalNumInsts
= 0;
159 TimingSimpleCPU::tryCompleteDrain()
161 if (drainState() != DrainState::Draining
)
164 DPRINTF(Drain
, "tryCompleteDrain.\n");
168 DPRINTF(Drain
, "CPU done draining, processing drain event\n");
175 TimingSimpleCPU::switchOut()
177 SimpleExecContext
& t_info
= *threadInfo
[curThread
];
178 M5_VAR_USED SimpleThread
* thread
= t_info
.thread
;
180 BaseSimpleCPU::switchOut();
182 assert(!fetchEvent
.scheduled());
183 assert(_status
== BaseSimpleCPU::Running
|| _status
== Idle
);
184 assert(!t_info
.stayAtPC
);
185 assert(thread
->microPC() == 0);
188 updateCycleCounters(BaseCPU::CPU_STATE_ON
);
193 TimingSimpleCPU::takeOverFrom(BaseCPU
*oldCPU
)
195 BaseSimpleCPU::takeOverFrom(oldCPU
);
197 previousCycle
= curCycle();
201 TimingSimpleCPU::verifyMemoryMode() const
203 if (!system
->isTimingMode()) {
204 fatal("The timing CPU requires the memory system to be in "
210 TimingSimpleCPU::activateContext(ThreadID thread_num
)
212 DPRINTF(SimpleCPU
, "ActivateContext %d\n", thread_num
);
214 assert(thread_num
< numThreads
);
216 threadInfo
[thread_num
]->notIdleFraction
= 1;
217 if (_status
== BaseSimpleCPU::Idle
)
218 _status
= BaseSimpleCPU::Running
;
220 // kick things off by initiating the fetch of the next instruction
221 if (!fetchEvent
.scheduled())
222 schedule(fetchEvent
, clockEdge(Cycles(0)));
224 if (std::find(activeThreads
.begin(), activeThreads
.end(), thread_num
)
225 == activeThreads
.end()) {
226 activeThreads
.push_back(thread_num
);
229 BaseCPU::activateContext(thread_num
);
234 TimingSimpleCPU::suspendContext(ThreadID thread_num
)
236 DPRINTF(SimpleCPU
, "SuspendContext %d\n", thread_num
);
238 assert(thread_num
< numThreads
);
239 activeThreads
.remove(thread_num
);
244 assert(_status
== BaseSimpleCPU::Running
);
246 threadInfo
[thread_num
]->notIdleFraction
= 0;
248 if (activeThreads
.empty()) {
251 if (fetchEvent
.scheduled()) {
252 deschedule(fetchEvent
);
256 BaseCPU::suspendContext(thread_num
);
260 TimingSimpleCPU::handleReadPacket(PacketPtr pkt
)
262 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
263 SimpleThread
* thread
= t_info
.thread
;
265 RequestPtr req
= pkt
->req
;
267 // We're about the issues a locked load, so tell the monitor
268 // to start caring about this address
269 if (pkt
->isRead() && pkt
->req
->isLLSC()) {
270 TheISA::handleLockedRead(thread
, pkt
->req
);
272 if (req
->isMmappedIpr()) {
273 Cycles delay
= TheISA::handleIprRead(thread
->getTC(), pkt
);
274 new IprEvent(pkt
, this, clockEdge(delay
));
275 _status
= DcacheWaitResponse
;
277 } else if (!dcachePort
.sendTimingReq(pkt
)) {
278 _status
= DcacheRetry
;
281 _status
= DcacheWaitResponse
;
282 // memory system takes ownership of packet
285 return dcache_pkt
== NULL
;
289 TimingSimpleCPU::sendData(RequestPtr req
, uint8_t *data
, uint64_t *res
,
292 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
293 SimpleThread
* thread
= t_info
.thread
;
295 PacketPtr pkt
= buildPacket(req
, read
);
296 pkt
->dataDynamic
<uint8_t>(data
);
297 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
300 completeDataAccess(pkt
);
302 handleReadPacket(pkt
);
304 bool do_access
= true; // flag to suppress cache access
307 do_access
= TheISA::handleLockedWrite(thread
, req
, dcachePort
.cacheBlockMask
);
308 } else if (req
->isCondSwap()) {
310 req
->setExtraData(*res
);
316 threadSnoop(pkt
, curThread
);
318 _status
= DcacheWaitResponse
;
319 completeDataAccess(pkt
);
325 TimingSimpleCPU::sendSplitData(RequestPtr req1
, RequestPtr req2
,
326 RequestPtr req
, uint8_t *data
, bool read
)
328 PacketPtr pkt1
, pkt2
;
329 buildSplitPacket(pkt1
, pkt2
, req1
, req2
, req
, data
, read
);
330 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
332 pkt1
->makeResponse();
333 completeDataAccess(pkt1
);
335 SplitFragmentSenderState
* send_state
=
336 dynamic_cast<SplitFragmentSenderState
*>(pkt1
->senderState
);
337 if (handleReadPacket(pkt1
)) {
338 send_state
->clearFromParent();
339 send_state
= dynamic_cast<SplitFragmentSenderState
*>(
341 if (handleReadPacket(pkt2
)) {
342 send_state
->clearFromParent();
347 SplitFragmentSenderState
* send_state
=
348 dynamic_cast<SplitFragmentSenderState
*>(pkt1
->senderState
);
349 if (handleWritePacket()) {
350 send_state
->clearFromParent();
352 send_state
= dynamic_cast<SplitFragmentSenderState
*>(
354 if (handleWritePacket()) {
355 send_state
->clearFromParent();
362 TimingSimpleCPU::translationFault(const Fault
&fault
)
364 // fault may be NoFault in cases where a fault is suppressed,
365 // for instance prefetches.
367 updateCycleCounters(BaseCPU::CPU_STATE_ON
);
370 // Since there was a fault, we shouldn't trace this instruction.
381 TimingSimpleCPU::buildPacket(RequestPtr req
, bool read
)
383 return read
? Packet::createRead(req
) : Packet::createWrite(req
);
387 TimingSimpleCPU::buildSplitPacket(PacketPtr
&pkt1
, PacketPtr
&pkt2
,
388 RequestPtr req1
, RequestPtr req2
, RequestPtr req
,
389 uint8_t *data
, bool read
)
393 assert(!req1
->isMmappedIpr() && !req2
->isMmappedIpr());
395 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
396 pkt1
= buildPacket(req
, read
);
400 pkt1
= buildPacket(req1
, read
);
401 pkt2
= buildPacket(req2
, read
);
403 PacketPtr pkt
= new Packet(req
, pkt1
->cmd
.responseCommand());
405 pkt
->dataDynamic
<uint8_t>(data
);
406 pkt1
->dataStatic
<uint8_t>(data
);
407 pkt2
->dataStatic
<uint8_t>(data
+ req1
->getSize());
409 SplitMainSenderState
* main_send_state
= new SplitMainSenderState
;
410 pkt
->senderState
= main_send_state
;
411 main_send_state
->fragments
[0] = pkt1
;
412 main_send_state
->fragments
[1] = pkt2
;
413 main_send_state
->outstanding
= 2;
414 pkt1
->senderState
= new SplitFragmentSenderState(pkt
, 0);
415 pkt2
->senderState
= new SplitFragmentSenderState(pkt
, 1);
419 TimingSimpleCPU::readMem(Addr addr
, uint8_t *data
,
420 unsigned size
, Request::Flags flags
)
422 panic("readMem() is for atomic accesses, and should "
423 "never be called on TimingSimpleCPU.\n");
427 TimingSimpleCPU::initiateMemRead(Addr addr
, unsigned size
,
428 Request::Flags flags
)
430 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
431 SimpleThread
* thread
= t_info
.thread
;
435 const Addr pc
= thread
->instAddr();
436 unsigned block_size
= cacheLineSize();
437 BaseTLB::Mode mode
= BaseTLB::Read
;
440 traceData
->setMem(addr
, size
, flags
);
442 RequestPtr req
= new Request(asid
, addr
, size
, flags
, dataMasterId(), pc
,
443 thread
->contextId());
445 req
->taskId(taskId());
447 Addr split_addr
= roundDown(addr
+ size
- 1, block_size
);
448 assert(split_addr
<= addr
|| split_addr
- addr
< block_size
);
450 _status
= DTBWaitResponse
;
451 if (split_addr
> addr
) {
452 RequestPtr req1
, req2
;
453 assert(!req
->isLLSC() && !req
->isSwap());
454 req
->splitOnVaddr(split_addr
, req1
, req2
);
456 WholeTranslationState
*state
=
457 new WholeTranslationState(req
, req1
, req2
, new uint8_t[size
],
459 DataTranslation
<TimingSimpleCPU
*> *trans1
=
460 new DataTranslation
<TimingSimpleCPU
*>(this, state
, 0);
461 DataTranslation
<TimingSimpleCPU
*> *trans2
=
462 new DataTranslation
<TimingSimpleCPU
*>(this, state
, 1);
464 thread
->dtb
->translateTiming(req1
, thread
->getTC(), trans1
, mode
);
465 thread
->dtb
->translateTiming(req2
, thread
->getTC(), trans2
, mode
);
467 WholeTranslationState
*state
=
468 new WholeTranslationState(req
, new uint8_t[size
], NULL
, mode
);
469 DataTranslation
<TimingSimpleCPU
*> *translation
470 = new DataTranslation
<TimingSimpleCPU
*>(this, state
);
471 thread
->dtb
->translateTiming(req
, thread
->getTC(), translation
, mode
);
478 TimingSimpleCPU::handleWritePacket()
480 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
481 SimpleThread
* thread
= t_info
.thread
;
483 RequestPtr req
= dcache_pkt
->req
;
484 if (req
->isMmappedIpr()) {
485 Cycles delay
= TheISA::handleIprWrite(thread
->getTC(), dcache_pkt
);
486 new IprEvent(dcache_pkt
, this, clockEdge(delay
));
487 _status
= DcacheWaitResponse
;
489 } else if (!dcachePort
.sendTimingReq(dcache_pkt
)) {
490 _status
= DcacheRetry
;
492 _status
= DcacheWaitResponse
;
493 // memory system takes ownership of packet
496 return dcache_pkt
== NULL
;
500 TimingSimpleCPU::writeMem(uint8_t *data
, unsigned size
,
501 Addr addr
, Request::Flags flags
, uint64_t *res
)
503 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
504 SimpleThread
* thread
= t_info
.thread
;
506 uint8_t *newData
= new uint8_t[size
];
508 const Addr pc
= thread
->instAddr();
509 unsigned block_size
= cacheLineSize();
510 BaseTLB::Mode mode
= BaseTLB::Write
;
513 assert(flags
& Request::STORE_NO_DATA
);
514 // This must be a cache block cleaning request
515 memset(newData
, 0, size
);
517 memcpy(newData
, data
, size
);
521 traceData
->setMem(addr
, size
, flags
);
523 RequestPtr req
= new Request(asid
, addr
, size
, flags
, dataMasterId(), pc
,
524 thread
->contextId());
526 req
->taskId(taskId());
528 Addr split_addr
= roundDown(addr
+ size
- 1, block_size
);
529 assert(split_addr
<= addr
|| split_addr
- addr
< block_size
);
531 _status
= DTBWaitResponse
;
532 if (split_addr
> addr
) {
533 RequestPtr req1
, req2
;
534 assert(!req
->isLLSC() && !req
->isSwap());
535 req
->splitOnVaddr(split_addr
, req1
, req2
);
537 WholeTranslationState
*state
=
538 new WholeTranslationState(req
, req1
, req2
, newData
, res
, mode
);
539 DataTranslation
<TimingSimpleCPU
*> *trans1
=
540 new DataTranslation
<TimingSimpleCPU
*>(this, state
, 0);
541 DataTranslation
<TimingSimpleCPU
*> *trans2
=
542 new DataTranslation
<TimingSimpleCPU
*>(this, state
, 1);
544 thread
->dtb
->translateTiming(req1
, thread
->getTC(), trans1
, mode
);
545 thread
->dtb
->translateTiming(req2
, thread
->getTC(), trans2
, mode
);
547 WholeTranslationState
*state
=
548 new WholeTranslationState(req
, newData
, res
, mode
);
549 DataTranslation
<TimingSimpleCPU
*> *translation
=
550 new DataTranslation
<TimingSimpleCPU
*>(this, state
);
551 thread
->dtb
->translateTiming(req
, thread
->getTC(), translation
, mode
);
554 // Translation faults will be returned via finishTranslation()
559 TimingSimpleCPU::threadSnoop(PacketPtr pkt
, ThreadID sender
)
561 for (ThreadID tid
= 0; tid
< numThreads
; tid
++) {
563 if (getCpuAddrMonitor(tid
)->doMonitor(pkt
)) {
566 TheISA::handleLockedSnoop(threadInfo
[tid
]->thread
, pkt
,
567 dcachePort
.cacheBlockMask
);
573 TimingSimpleCPU::finishTranslation(WholeTranslationState
*state
)
575 _status
= BaseSimpleCPU::Running
;
577 if (state
->getFault() != NoFault
) {
578 if (state
->isPrefetch()) {
581 delete [] state
->data
;
583 translationFault(state
->getFault());
585 if (!state
->isSplit
) {
586 sendData(state
->mainReq
, state
->data
, state
->res
,
587 state
->mode
== BaseTLB::Read
);
589 sendSplitData(state
->sreqLow
, state
->sreqHigh
, state
->mainReq
,
590 state
->data
, state
->mode
== BaseTLB::Read
);
599 TimingSimpleCPU::fetch()
601 // Change thread if multi-threaded
604 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
605 SimpleThread
* thread
= t_info
.thread
;
607 DPRINTF(SimpleCPU
, "Fetch\n");
609 if (!curStaticInst
|| !curStaticInst
->isDelayedCommit()) {
610 checkForInterrupts();
614 // We must have just got suspended by a PC event
618 TheISA::PCState pcState
= thread
->pcState();
619 bool needToFetch
= !isRomMicroPC(pcState
.microPC()) &&
623 _status
= BaseSimpleCPU::Running
;
624 Request
*ifetch_req
= new Request();
625 ifetch_req
->taskId(taskId());
626 ifetch_req
->setContext(thread
->contextId());
627 setupFetchRequest(ifetch_req
);
628 DPRINTF(SimpleCPU
, "Translating address %#x\n", ifetch_req
->getVaddr());
629 thread
->itb
->translateTiming(ifetch_req
, thread
->getTC(),
630 &fetchTranslation
, BaseTLB::Execute
);
632 _status
= IcacheWaitResponse
;
633 completeIfetch(NULL
);
636 updateCycleCounters(BaseCPU::CPU_STATE_ON
);
642 TimingSimpleCPU::sendFetch(const Fault
&fault
, RequestPtr req
,
645 if (fault
== NoFault
) {
646 DPRINTF(SimpleCPU
, "Sending fetch for addr %#x(pa: %#x)\n",
647 req
->getVaddr(), req
->getPaddr());
648 ifetch_pkt
= new Packet(req
, MemCmd::ReadReq
);
649 ifetch_pkt
->dataStatic(&inst
);
650 DPRINTF(SimpleCPU
, " -- pkt addr: %#x\n", ifetch_pkt
->getAddr());
652 if (!icachePort
.sendTimingReq(ifetch_pkt
)) {
653 // Need to wait for retry
654 _status
= IcacheRetry
;
656 // Need to wait for cache to respond
657 _status
= IcacheWaitResponse
;
658 // ownership of packet transferred to memory system
662 DPRINTF(SimpleCPU
, "Translation of addr %#x faulted\n", req
->getVaddr());
664 // fetch fault: advance directly to next instruction (fault handler)
665 _status
= BaseSimpleCPU::Running
;
670 updateCycleCounters(BaseCPU::CPU_STATE_ON
);
675 TimingSimpleCPU::advanceInst(const Fault
&fault
)
677 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
679 if (_status
== Faulting
)
682 if (fault
!= NoFault
) {
683 DPRINTF(SimpleCPU
, "Fault occured, scheduling fetch event\n");
687 Tick stall
= dynamic_pointer_cast
<SyscallRetryFault
>(fault
) ?
688 clockEdge(syscallRetryLatency
) : clockEdge();
690 reschedule(fetchEvent
, stall
, true);
697 if (!t_info
.stayAtPC
)
700 if (tryCompleteDrain())
703 if (_status
== BaseSimpleCPU::Running
) {
704 // kick off fetch of next instruction... callback from icache
705 // response will cause that instruction to be executed,
706 // keeping the CPU running.
713 TimingSimpleCPU::completeIfetch(PacketPtr pkt
)
715 SimpleExecContext
& t_info
= *threadInfo
[curThread
];
717 DPRINTF(SimpleCPU
, "Complete ICache Fetch for addr %#x\n", pkt
?
720 // received a response from the icache: execute the received
722 assert(!pkt
|| !pkt
->isError());
723 assert(_status
== IcacheWaitResponse
);
725 _status
= BaseSimpleCPU::Running
;
728 updateCycleCounters(BaseCPU::CPU_STATE_ON
);
731 pkt
->req
->setAccessLatency();
735 if (curStaticInst
&& curStaticInst
->isMemRef()) {
736 // load or store: just send to dcache
737 Fault fault
= curStaticInst
->initiateAcc(&t_info
, traceData
);
739 // If we're not running now the instruction will complete in a dcache
740 // response callback or the instruction faulted and has started an
742 if (_status
== BaseSimpleCPU::Running
) {
743 if (fault
!= NoFault
&& traceData
) {
744 // If there was a fault, we shouldn't trace this instruction.
750 // @todo remove me after debugging with legion done
751 if (curStaticInst
&& (!curStaticInst
->isMicroop() ||
752 curStaticInst
->isFirstMicroop()))
756 } else if (curStaticInst
) {
757 // non-memory instruction: execute completely now
758 Fault fault
= curStaticInst
->execute(&t_info
, traceData
);
760 // keep an instruction count
761 if (fault
== NoFault
)
763 else if (traceData
&& !DTRACE(ExecFaulting
)) {
769 // @todo remove me after debugging with legion done
770 if (curStaticInst
&& (!curStaticInst
->isMicroop() ||
771 curStaticInst
->isFirstMicroop()))
775 advanceInst(NoFault
);
785 TimingSimpleCPU::IcachePort::ITickEvent::process()
787 cpu
->completeIfetch(pkt
);
791 TimingSimpleCPU::IcachePort::recvTimingResp(PacketPtr pkt
)
793 DPRINTF(SimpleCPU
, "Received fetch response %#x\n", pkt
->getAddr());
794 // we should only ever see one response per cycle since we only
795 // issue a new request once this response is sunk
796 assert(!tickEvent
.scheduled());
797 // delay processing of returned data until next CPU clock edge
798 tickEvent
.schedule(pkt
, cpu
->clockEdge());
804 TimingSimpleCPU::IcachePort::recvReqRetry()
806 // we shouldn't get a retry unless we have a packet that we're
807 // waiting to transmit
808 assert(cpu
->ifetch_pkt
!= NULL
);
809 assert(cpu
->_status
== IcacheRetry
);
810 PacketPtr tmp
= cpu
->ifetch_pkt
;
811 if (sendTimingReq(tmp
)) {
812 cpu
->_status
= IcacheWaitResponse
;
813 cpu
->ifetch_pkt
= NULL
;
818 TimingSimpleCPU::completeDataAccess(PacketPtr pkt
)
820 // received a response from the dcache: complete the load or store
822 assert(!pkt
->isError());
823 assert(_status
== DcacheWaitResponse
|| _status
== DTBWaitResponse
||
824 pkt
->req
->getFlags().isSet(Request::NO_ACCESS
));
826 pkt
->req
->setAccessLatency();
829 updateCycleCounters(BaseCPU::CPU_STATE_ON
);
831 if (pkt
->senderState
) {
832 SplitFragmentSenderState
* send_state
=
833 dynamic_cast<SplitFragmentSenderState
*>(pkt
->senderState
);
837 PacketPtr big_pkt
= send_state
->bigPkt
;
840 SplitMainSenderState
* main_send_state
=
841 dynamic_cast<SplitMainSenderState
*>(big_pkt
->senderState
);
842 assert(main_send_state
);
843 // Record the fact that this packet is no longer outstanding.
844 assert(main_send_state
->outstanding
!= 0);
845 main_send_state
->outstanding
--;
847 if (main_send_state
->outstanding
) {
850 delete main_send_state
;
851 big_pkt
->senderState
= NULL
;
856 _status
= BaseSimpleCPU::Running
;
858 Fault fault
= curStaticInst
->completeAcc(pkt
, threadInfo
[curThread
],
861 // keep an instruction count
862 if (fault
== NoFault
)
864 else if (traceData
) {
865 // If there was a fault, we shouldn't trace this instruction.
879 TimingSimpleCPU::updateCycleCounts()
881 const Cycles
delta(curCycle() - previousCycle
);
885 previousCycle
= curCycle();
889 TimingSimpleCPU::DcachePort::recvTimingSnoopReq(PacketPtr pkt
)
891 for (ThreadID tid
= 0; tid
< cpu
->numThreads
; tid
++) {
892 if (cpu
->getCpuAddrMonitor(tid
)->doMonitor(pkt
)) {
897 // Making it uniform across all CPUs:
898 // The CPUs need to be woken up only on an invalidation packet (when using caches)
899 // or on an incoming write packet (when not using caches)
900 // It is not necessary to wake up the processor on all incoming packets
901 if (pkt
->isInvalidate() || pkt
->isWrite()) {
902 for (auto &t_info
: cpu
->threadInfo
) {
903 TheISA::handleLockedSnoop(t_info
->thread
, pkt
, cacheBlockMask
);
909 TimingSimpleCPU::DcachePort::recvFunctionalSnoop(PacketPtr pkt
)
911 for (ThreadID tid
= 0; tid
< cpu
->numThreads
; tid
++) {
912 if (cpu
->getCpuAddrMonitor(tid
)->doMonitor(pkt
)) {
919 TimingSimpleCPU::DcachePort::recvTimingResp(PacketPtr pkt
)
921 DPRINTF(SimpleCPU
, "Received load/store response %#x\n", pkt
->getAddr());
923 // The timing CPU is not really ticked, instead it relies on the
924 // memory system (fetch and load/store) to set the pace.
925 if (!tickEvent
.scheduled()) {
926 // Delay processing of returned data until next CPU clock edge
927 tickEvent
.schedule(pkt
, cpu
->clockEdge());
930 // In the case of a split transaction and a cache that is
931 // faster than a CPU we could get two responses in the
932 // same tick, delay the second one
933 if (!retryRespEvent
.scheduled())
934 cpu
->schedule(retryRespEvent
, cpu
->clockEdge(Cycles(1)));
940 TimingSimpleCPU::DcachePort::DTickEvent::process()
942 cpu
->completeDataAccess(pkt
);
946 TimingSimpleCPU::DcachePort::recvReqRetry()
948 // we shouldn't get a retry unless we have a packet that we're
949 // waiting to transmit
950 assert(cpu
->dcache_pkt
!= NULL
);
951 assert(cpu
->_status
== DcacheRetry
);
952 PacketPtr tmp
= cpu
->dcache_pkt
;
953 if (tmp
->senderState
) {
954 // This is a packet from a split access.
955 SplitFragmentSenderState
* send_state
=
956 dynamic_cast<SplitFragmentSenderState
*>(tmp
->senderState
);
958 PacketPtr big_pkt
= send_state
->bigPkt
;
960 SplitMainSenderState
* main_send_state
=
961 dynamic_cast<SplitMainSenderState
*>(big_pkt
->senderState
);
962 assert(main_send_state
);
964 if (sendTimingReq(tmp
)) {
965 // If we were able to send without retrying, record that fact
966 // and try sending the other fragment.
967 send_state
->clearFromParent();
968 int other_index
= main_send_state
->getPendingFragment();
969 if (other_index
> 0) {
970 tmp
= main_send_state
->fragments
[other_index
];
971 cpu
->dcache_pkt
= tmp
;
972 if ((big_pkt
->isRead() && cpu
->handleReadPacket(tmp
)) ||
973 (big_pkt
->isWrite() && cpu
->handleWritePacket())) {
974 main_send_state
->fragments
[other_index
] = NULL
;
977 cpu
->_status
= DcacheWaitResponse
;
978 // memory system takes ownership of packet
979 cpu
->dcache_pkt
= NULL
;
982 } else if (sendTimingReq(tmp
)) {
983 cpu
->_status
= DcacheWaitResponse
;
984 // memory system takes ownership of packet
985 cpu
->dcache_pkt
= NULL
;
989 TimingSimpleCPU::IprEvent::IprEvent(Packet
*_pkt
, TimingSimpleCPU
*_cpu
,
991 : pkt(_pkt
), cpu(_cpu
)
993 cpu
->schedule(this, t
);
997 TimingSimpleCPU::IprEvent::process()
999 cpu
->completeDataAccess(pkt
);
1003 TimingSimpleCPU::IprEvent::description() const
1005 return "Timing Simple CPU Delay IPR event";
1010 TimingSimpleCPU::printAddr(Addr a
)
1012 dcachePort
.printAddr(a
);
1016 ////////////////////////////////////////////////////////////////////////
1018 // TimingSimpleCPU Simulation Object
1021 TimingSimpleCPUParams::create()
1023 return new TimingSimpleCPU(this);