2 * Copyright 2014 Google, Inc.
3 * Copyright (c) 2010-2013,2015 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 "arch/locked_mem.hh"
45 #include "arch/mmapped_ipr.hh"
46 #include "arch/utility.hh"
47 #include "base/bigint.hh"
48 #include "config/the_isa.hh"
49 #include "cpu/simple/timing.hh"
50 #include "cpu/exetrace.hh"
51 #include "debug/Config.hh"
52 #include "debug/Drain.hh"
53 #include "debug/ExecFaulting.hh"
54 #include "debug/SimpleCPU.hh"
55 #include "mem/packet.hh"
56 #include "mem/packet_access.hh"
57 #include "params/TimingSimpleCPU.hh"
58 #include "sim/faults.hh"
59 #include "sim/full_system.hh"
60 #include "sim/system.hh"
62 #include "debug/Mwait.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),
90 TimingSimpleCPU::~TimingSimpleCPU()
95 TimingSimpleCPU::drain()
98 return DrainState::Drained
;
100 if (_status
== Idle
||
101 (_status
== BaseSimpleCPU::Running
&& isDrained())) {
102 DPRINTF(Drain
, "No need to drain.\n");
103 activeThreads
.clear();
104 return DrainState::Drained
;
106 DPRINTF(Drain
, "Requesting drain.\n");
108 // The fetch event can become descheduled if a drain didn't
109 // succeed on the first attempt. We need to reschedule it if
110 // the CPU is waiting for a microcode routine to complete.
111 if (_status
== BaseSimpleCPU::Running
&& !fetchEvent
.scheduled())
112 schedule(fetchEvent
, clockEdge());
114 return DrainState::Draining
;
119 TimingSimpleCPU::drainResume()
121 assert(!fetchEvent
.scheduled());
125 DPRINTF(SimpleCPU
, "Resume\n");
128 assert(!threadContexts
.empty());
130 _status
= BaseSimpleCPU::Idle
;
132 for (ThreadID tid
= 0; tid
< numThreads
; tid
++) {
133 if (threadInfo
[tid
]->thread
->status() == ThreadContext::Active
) {
134 threadInfo
[tid
]->notIdleFraction
= 1;
136 activeThreads
.push_back(tid
);
138 _status
= BaseSimpleCPU::Running
;
140 // Fetch if any threads active
141 if (!fetchEvent
.scheduled()) {
142 schedule(fetchEvent
, nextCycle());
145 threadInfo
[tid
]->notIdleFraction
= 0;
149 system
->totalNumInsts
= 0;
153 TimingSimpleCPU::tryCompleteDrain()
155 if (drainState() != DrainState::Draining
)
158 DPRINTF(Drain
, "tryCompleteDrain.\n");
162 DPRINTF(Drain
, "CPU done draining, processing drain event\n");
169 TimingSimpleCPU::switchOut()
171 SimpleExecContext
& t_info
= *threadInfo
[curThread
];
172 M5_VAR_USED SimpleThread
* thread
= t_info
.thread
;
174 BaseSimpleCPU::switchOut();
176 assert(!fetchEvent
.scheduled());
177 assert(_status
== BaseSimpleCPU::Running
|| _status
== Idle
);
178 assert(!t_info
.stayAtPC
);
179 assert(thread
->microPC() == 0);
186 TimingSimpleCPU::takeOverFrom(BaseCPU
*oldCPU
)
188 BaseSimpleCPU::takeOverFrom(oldCPU
);
190 previousCycle
= curCycle();
194 TimingSimpleCPU::verifyMemoryMode() const
196 if (!system
->isTimingMode()) {
197 fatal("The timing CPU requires the memory system to be in "
203 TimingSimpleCPU::activateContext(ThreadID thread_num
)
205 DPRINTF(SimpleCPU
, "ActivateContext %d\n", thread_num
);
207 assert(thread_num
< numThreads
);
209 threadInfo
[thread_num
]->notIdleFraction
= 1;
210 if (_status
== BaseSimpleCPU::Idle
)
211 _status
= BaseSimpleCPU::Running
;
213 // kick things off by initiating the fetch of the next instruction
214 if (!fetchEvent
.scheduled())
215 schedule(fetchEvent
, clockEdge(Cycles(0)));
217 if (std::find(activeThreads
.begin(), activeThreads
.end(), thread_num
)
218 == activeThreads
.end()) {
219 activeThreads
.push_back(thread_num
);
225 TimingSimpleCPU::suspendContext(ThreadID thread_num
)
227 DPRINTF(SimpleCPU
, "SuspendContext %d\n", thread_num
);
229 assert(thread_num
< numThreads
);
230 activeThreads
.remove(thread_num
);
235 assert(_status
== BaseSimpleCPU::Running
);
237 threadInfo
[thread_num
]->notIdleFraction
= 0;
239 if (activeThreads
.empty()) {
242 if (fetchEvent
.scheduled()) {
243 deschedule(fetchEvent
);
249 TimingSimpleCPU::handleReadPacket(PacketPtr pkt
)
251 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
252 SimpleThread
* thread
= t_info
.thread
;
254 RequestPtr req
= pkt
->req
;
256 // We're about the issues a locked load, so tell the monitor
257 // to start caring about this address
258 if (pkt
->isRead() && pkt
->req
->isLLSC()) {
259 TheISA::handleLockedRead(thread
, pkt
->req
);
261 if (req
->isMmappedIpr()) {
262 Cycles delay
= TheISA::handleIprRead(thread
->getTC(), pkt
);
263 new IprEvent(pkt
, this, clockEdge(delay
));
264 _status
= DcacheWaitResponse
;
266 } else if (!dcachePort
.sendTimingReq(pkt
)) {
267 _status
= DcacheRetry
;
270 _status
= DcacheWaitResponse
;
271 // memory system takes ownership of packet
274 return dcache_pkt
== NULL
;
278 TimingSimpleCPU::sendData(RequestPtr req
, uint8_t *data
, uint64_t *res
,
281 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
282 SimpleThread
* thread
= t_info
.thread
;
284 PacketPtr pkt
= buildPacket(req
, read
);
285 pkt
->dataDynamic
<uint8_t>(data
);
286 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
289 completeDataAccess(pkt
);
291 handleReadPacket(pkt
);
293 bool do_access
= true; // flag to suppress cache access
296 do_access
= TheISA::handleLockedWrite(thread
, req
, dcachePort
.cacheBlockMask
);
297 } else if (req
->isCondSwap()) {
299 req
->setExtraData(*res
);
305 threadSnoop(pkt
, curThread
);
307 _status
= DcacheWaitResponse
;
308 completeDataAccess(pkt
);
314 TimingSimpleCPU::sendSplitData(RequestPtr req1
, RequestPtr req2
,
315 RequestPtr req
, uint8_t *data
, bool read
)
317 PacketPtr pkt1
, pkt2
;
318 buildSplitPacket(pkt1
, pkt2
, req1
, req2
, req
, data
, read
);
319 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
321 pkt1
->makeResponse();
322 completeDataAccess(pkt1
);
324 SplitFragmentSenderState
* send_state
=
325 dynamic_cast<SplitFragmentSenderState
*>(pkt1
->senderState
);
326 if (handleReadPacket(pkt1
)) {
327 send_state
->clearFromParent();
328 send_state
= dynamic_cast<SplitFragmentSenderState
*>(
330 if (handleReadPacket(pkt2
)) {
331 send_state
->clearFromParent();
336 SplitFragmentSenderState
* send_state
=
337 dynamic_cast<SplitFragmentSenderState
*>(pkt1
->senderState
);
338 if (handleWritePacket()) {
339 send_state
->clearFromParent();
341 send_state
= dynamic_cast<SplitFragmentSenderState
*>(
343 if (handleWritePacket()) {
344 send_state
->clearFromParent();
351 TimingSimpleCPU::translationFault(const Fault
&fault
)
353 // fault may be NoFault in cases where a fault is suppressed,
354 // for instance prefetches.
358 // Since there was a fault, we shouldn't trace this instruction.
369 TimingSimpleCPU::buildPacket(RequestPtr req
, bool read
)
371 return read
? Packet::createRead(req
) : Packet::createWrite(req
);
375 TimingSimpleCPU::buildSplitPacket(PacketPtr
&pkt1
, PacketPtr
&pkt2
,
376 RequestPtr req1
, RequestPtr req2
, RequestPtr req
,
377 uint8_t *data
, bool read
)
381 assert(!req1
->isMmappedIpr() && !req2
->isMmappedIpr());
383 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
384 pkt1
= buildPacket(req
, read
);
388 pkt1
= buildPacket(req1
, read
);
389 pkt2
= buildPacket(req2
, read
);
391 PacketPtr pkt
= new Packet(req
, pkt1
->cmd
.responseCommand());
393 pkt
->dataDynamic
<uint8_t>(data
);
394 pkt1
->dataStatic
<uint8_t>(data
);
395 pkt2
->dataStatic
<uint8_t>(data
+ req1
->getSize());
397 SplitMainSenderState
* main_send_state
= new SplitMainSenderState
;
398 pkt
->senderState
= main_send_state
;
399 main_send_state
->fragments
[0] = pkt1
;
400 main_send_state
->fragments
[1] = pkt2
;
401 main_send_state
->outstanding
= 2;
402 pkt1
->senderState
= new SplitFragmentSenderState(pkt
, 0);
403 pkt2
->senderState
= new SplitFragmentSenderState(pkt
, 1);
407 TimingSimpleCPU::readMem(Addr addr
, uint8_t *data
,
408 unsigned size
, unsigned flags
)
410 panic("readMem() is for atomic accesses, and should "
411 "never be called on TimingSimpleCPU.\n");
415 TimingSimpleCPU::initiateMemRead(Addr addr
, unsigned size
, unsigned flags
)
417 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
418 SimpleThread
* thread
= t_info
.thread
;
422 const Addr pc
= thread
->instAddr();
423 unsigned block_size
= cacheLineSize();
424 BaseTLB::Mode mode
= BaseTLB::Read
;
427 traceData
->setMem(addr
, size
, flags
);
429 RequestPtr req
= new Request(asid
, addr
, size
, flags
, dataMasterId(), pc
,
430 thread
->contextId());
432 req
->taskId(taskId());
434 Addr split_addr
= roundDown(addr
+ size
- 1, block_size
);
435 assert(split_addr
<= addr
|| split_addr
- addr
< block_size
);
437 _status
= DTBWaitResponse
;
438 if (split_addr
> addr
) {
439 RequestPtr req1
, req2
;
440 assert(!req
->isLLSC() && !req
->isSwap());
441 req
->splitOnVaddr(split_addr
, req1
, req2
);
443 WholeTranslationState
*state
=
444 new WholeTranslationState(req
, req1
, req2
, new uint8_t[size
],
446 DataTranslation
<TimingSimpleCPU
*> *trans1
=
447 new DataTranslation
<TimingSimpleCPU
*>(this, state
, 0);
448 DataTranslation
<TimingSimpleCPU
*> *trans2
=
449 new DataTranslation
<TimingSimpleCPU
*>(this, state
, 1);
451 thread
->dtb
->translateTiming(req1
, thread
->getTC(), trans1
, mode
);
452 thread
->dtb
->translateTiming(req2
, thread
->getTC(), trans2
, mode
);
454 WholeTranslationState
*state
=
455 new WholeTranslationState(req
, new uint8_t[size
], NULL
, mode
);
456 DataTranslation
<TimingSimpleCPU
*> *translation
457 = new DataTranslation
<TimingSimpleCPU
*>(this, state
);
458 thread
->dtb
->translateTiming(req
, thread
->getTC(), translation
, mode
);
465 TimingSimpleCPU::handleWritePacket()
467 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
468 SimpleThread
* thread
= t_info
.thread
;
470 RequestPtr req
= dcache_pkt
->req
;
471 if (req
->isMmappedIpr()) {
472 Cycles delay
= TheISA::handleIprWrite(thread
->getTC(), dcache_pkt
);
473 new IprEvent(dcache_pkt
, this, clockEdge(delay
));
474 _status
= DcacheWaitResponse
;
476 } else if (!dcachePort
.sendTimingReq(dcache_pkt
)) {
477 _status
= DcacheRetry
;
479 _status
= DcacheWaitResponse
;
480 // memory system takes ownership of packet
483 return dcache_pkt
== NULL
;
487 TimingSimpleCPU::writeMem(uint8_t *data
, unsigned size
,
488 Addr addr
, unsigned flags
, uint64_t *res
)
490 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
491 SimpleThread
* thread
= t_info
.thread
;
493 uint8_t *newData
= new uint8_t[size
];
495 const Addr pc
= thread
->instAddr();
496 unsigned block_size
= cacheLineSize();
497 BaseTLB::Mode mode
= BaseTLB::Write
;
500 assert(flags
& Request::CACHE_BLOCK_ZERO
);
501 // This must be a cache block cleaning request
502 memset(newData
, 0, size
);
504 memcpy(newData
, data
, size
);
508 traceData
->setMem(addr
, size
, flags
);
510 RequestPtr req
= new Request(asid
, addr
, size
, flags
, dataMasterId(), pc
,
511 thread
->contextId());
513 req
->taskId(taskId());
515 Addr split_addr
= roundDown(addr
+ size
- 1, block_size
);
516 assert(split_addr
<= addr
|| split_addr
- addr
< block_size
);
518 _status
= DTBWaitResponse
;
519 if (split_addr
> addr
) {
520 RequestPtr req1
, req2
;
521 assert(!req
->isLLSC() && !req
->isSwap());
522 req
->splitOnVaddr(split_addr
, req1
, req2
);
524 WholeTranslationState
*state
=
525 new WholeTranslationState(req
, req1
, req2
, newData
, res
, mode
);
526 DataTranslation
<TimingSimpleCPU
*> *trans1
=
527 new DataTranslation
<TimingSimpleCPU
*>(this, state
, 0);
528 DataTranslation
<TimingSimpleCPU
*> *trans2
=
529 new DataTranslation
<TimingSimpleCPU
*>(this, state
, 1);
531 thread
->dtb
->translateTiming(req1
, thread
->getTC(), trans1
, mode
);
532 thread
->dtb
->translateTiming(req2
, thread
->getTC(), trans2
, mode
);
534 WholeTranslationState
*state
=
535 new WholeTranslationState(req
, newData
, res
, mode
);
536 DataTranslation
<TimingSimpleCPU
*> *translation
=
537 new DataTranslation
<TimingSimpleCPU
*>(this, state
);
538 thread
->dtb
->translateTiming(req
, thread
->getTC(), translation
, mode
);
541 // Translation faults will be returned via finishTranslation()
546 TimingSimpleCPU::threadSnoop(PacketPtr pkt
, ThreadID sender
)
548 for (ThreadID tid
= 0; tid
< numThreads
; tid
++) {
550 if (getCpuAddrMonitor(tid
)->doMonitor(pkt
)) {
553 TheISA::handleLockedSnoop(threadInfo
[tid
]->thread
, pkt
,
554 dcachePort
.cacheBlockMask
);
560 TimingSimpleCPU::finishTranslation(WholeTranslationState
*state
)
562 _status
= BaseSimpleCPU::Running
;
564 if (state
->getFault() != NoFault
) {
565 if (state
->isPrefetch()) {
568 delete [] state
->data
;
570 translationFault(state
->getFault());
572 if (!state
->isSplit
) {
573 sendData(state
->mainReq
, state
->data
, state
->res
,
574 state
->mode
== BaseTLB::Read
);
576 sendSplitData(state
->sreqLow
, state
->sreqHigh
, state
->mainReq
,
577 state
->data
, state
->mode
== BaseTLB::Read
);
586 TimingSimpleCPU::fetch()
588 // Change thread if multi-threaded
591 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
592 SimpleThread
* thread
= t_info
.thread
;
594 DPRINTF(SimpleCPU
, "Fetch\n");
596 if (!curStaticInst
|| !curStaticInst
->isDelayedCommit()) {
597 checkForInterrupts();
601 // We must have just got suspended by a PC event
605 TheISA::PCState pcState
= thread
->pcState();
606 bool needToFetch
= !isRomMicroPC(pcState
.microPC()) &&
610 _status
= BaseSimpleCPU::Running
;
611 Request
*ifetch_req
= new Request();
612 ifetch_req
->taskId(taskId());
613 ifetch_req
->setContext(thread
->contextId());
614 setupFetchRequest(ifetch_req
);
615 DPRINTF(SimpleCPU
, "Translating address %#x\n", ifetch_req
->getVaddr());
616 thread
->itb
->translateTiming(ifetch_req
, thread
->getTC(),
617 &fetchTranslation
, BaseTLB::Execute
);
619 _status
= IcacheWaitResponse
;
620 completeIfetch(NULL
);
628 TimingSimpleCPU::sendFetch(const Fault
&fault
, RequestPtr req
,
631 if (fault
== NoFault
) {
632 DPRINTF(SimpleCPU
, "Sending fetch for addr %#x(pa: %#x)\n",
633 req
->getVaddr(), req
->getPaddr());
634 ifetch_pkt
= new Packet(req
, MemCmd::ReadReq
);
635 ifetch_pkt
->dataStatic(&inst
);
636 DPRINTF(SimpleCPU
, " -- pkt addr: %#x\n", ifetch_pkt
->getAddr());
638 if (!icachePort
.sendTimingReq(ifetch_pkt
)) {
639 // Need to wait for retry
640 _status
= IcacheRetry
;
642 // Need to wait for cache to respond
643 _status
= IcacheWaitResponse
;
644 // ownership of packet transferred to memory system
648 DPRINTF(SimpleCPU
, "Translation of addr %#x faulted\n", req
->getVaddr());
650 // fetch fault: advance directly to next instruction (fault handler)
651 _status
= BaseSimpleCPU::Running
;
660 TimingSimpleCPU::advanceInst(const Fault
&fault
)
662 SimpleExecContext
&t_info
= *threadInfo
[curThread
];
664 if (_status
== Faulting
)
667 if (fault
!= NoFault
) {
669 DPRINTF(SimpleCPU
, "Fault occured, scheduling fetch event\n");
670 reschedule(fetchEvent
, clockEdge(), true);
676 if (!t_info
.stayAtPC
)
679 if (tryCompleteDrain())
682 if (_status
== BaseSimpleCPU::Running
) {
683 // kick off fetch of next instruction... callback from icache
684 // response will cause that instruction to be executed,
685 // keeping the CPU running.
692 TimingSimpleCPU::completeIfetch(PacketPtr pkt
)
694 SimpleExecContext
& t_info
= *threadInfo
[curThread
];
696 DPRINTF(SimpleCPU
, "Complete ICache Fetch for addr %#x\n", pkt
?
699 // received a response from the icache: execute the received
701 assert(!pkt
|| !pkt
->isError());
702 assert(_status
== IcacheWaitResponse
);
704 _status
= BaseSimpleCPU::Running
;
709 pkt
->req
->setAccessLatency();
713 if (curStaticInst
&& curStaticInst
->isMemRef()) {
714 // load or store: just send to dcache
715 Fault fault
= curStaticInst
->initiateAcc(&t_info
, traceData
);
717 // If we're not running now the instruction will complete in a dcache
718 // response callback or the instruction faulted and has started an
720 if (_status
== BaseSimpleCPU::Running
) {
721 if (fault
!= NoFault
&& traceData
) {
722 // If there was a fault, we shouldn't trace this instruction.
728 // @todo remove me after debugging with legion done
729 if (curStaticInst
&& (!curStaticInst
->isMicroop() ||
730 curStaticInst
->isFirstMicroop()))
734 } else if (curStaticInst
) {
735 // non-memory instruction: execute completely now
736 Fault fault
= curStaticInst
->execute(&t_info
, traceData
);
738 // keep an instruction count
739 if (fault
== NoFault
)
741 else if (traceData
&& !DTRACE(ExecFaulting
)) {
747 // @todo remove me after debugging with legion done
748 if (curStaticInst
&& (!curStaticInst
->isMicroop() ||
749 curStaticInst
->isFirstMicroop()))
753 advanceInst(NoFault
);
763 TimingSimpleCPU::IcachePort::ITickEvent::process()
765 cpu
->completeIfetch(pkt
);
769 TimingSimpleCPU::IcachePort::recvTimingResp(PacketPtr pkt
)
771 DPRINTF(SimpleCPU
, "Received fetch response %#x\n", pkt
->getAddr());
772 // we should only ever see one response per cycle since we only
773 // issue a new request once this response is sunk
774 assert(!tickEvent
.scheduled());
775 // delay processing of returned data until next CPU clock edge
776 tickEvent
.schedule(pkt
, cpu
->clockEdge());
782 TimingSimpleCPU::IcachePort::recvReqRetry()
784 // we shouldn't get a retry unless we have a packet that we're
785 // waiting to transmit
786 assert(cpu
->ifetch_pkt
!= NULL
);
787 assert(cpu
->_status
== IcacheRetry
);
788 PacketPtr tmp
= cpu
->ifetch_pkt
;
789 if (sendTimingReq(tmp
)) {
790 cpu
->_status
= IcacheWaitResponse
;
791 cpu
->ifetch_pkt
= NULL
;
796 TimingSimpleCPU::completeDataAccess(PacketPtr pkt
)
798 // received a response from the dcache: complete the load or store
800 assert(!pkt
->isError());
801 assert(_status
== DcacheWaitResponse
|| _status
== DTBWaitResponse
||
802 pkt
->req
->getFlags().isSet(Request::NO_ACCESS
));
804 pkt
->req
->setAccessLatency();
808 if (pkt
->senderState
) {
809 SplitFragmentSenderState
* send_state
=
810 dynamic_cast<SplitFragmentSenderState
*>(pkt
->senderState
);
814 PacketPtr big_pkt
= send_state
->bigPkt
;
817 SplitMainSenderState
* main_send_state
=
818 dynamic_cast<SplitMainSenderState
*>(big_pkt
->senderState
);
819 assert(main_send_state
);
820 // Record the fact that this packet is no longer outstanding.
821 assert(main_send_state
->outstanding
!= 0);
822 main_send_state
->outstanding
--;
824 if (main_send_state
->outstanding
) {
827 delete main_send_state
;
828 big_pkt
->senderState
= NULL
;
833 _status
= BaseSimpleCPU::Running
;
835 Fault fault
= curStaticInst
->completeAcc(pkt
, threadInfo
[curThread
],
838 // keep an instruction count
839 if (fault
== NoFault
)
841 else if (traceData
) {
842 // If there was a fault, we shouldn't trace this instruction.
856 TimingSimpleCPU::updateCycleCounts()
858 const Cycles
delta(curCycle() - previousCycle
);
861 ppCycles
->notify(delta
);
863 previousCycle
= curCycle();
867 TimingSimpleCPU::DcachePort::recvTimingSnoopReq(PacketPtr pkt
)
869 for (ThreadID tid
= 0; tid
< cpu
->numThreads
; tid
++) {
870 if (cpu
->getCpuAddrMonitor(tid
)->doMonitor(pkt
)) {
875 // Making it uniform across all CPUs:
876 // The CPUs need to be woken up only on an invalidation packet (when using caches)
877 // or on an incoming write packet (when not using caches)
878 // It is not necessary to wake up the processor on all incoming packets
879 if (pkt
->isInvalidate() || pkt
->isWrite()) {
880 for (auto &t_info
: cpu
->threadInfo
) {
881 TheISA::handleLockedSnoop(t_info
->thread
, pkt
, cacheBlockMask
);
887 TimingSimpleCPU::DcachePort::recvFunctionalSnoop(PacketPtr pkt
)
889 for (ThreadID tid
= 0; tid
< cpu
->numThreads
; tid
++) {
890 if (cpu
->getCpuAddrMonitor(tid
)->doMonitor(pkt
)) {
897 TimingSimpleCPU::DcachePort::recvTimingResp(PacketPtr pkt
)
899 DPRINTF(SimpleCPU
, "Received load/store response %#x\n", pkt
->getAddr());
901 // The timing CPU is not really ticked, instead it relies on the
902 // memory system (fetch and load/store) to set the pace.
903 if (!tickEvent
.scheduled()) {
904 // Delay processing of returned data until next CPU clock edge
905 tickEvent
.schedule(pkt
, cpu
->clockEdge());
908 // In the case of a split transaction and a cache that is
909 // faster than a CPU we could get two responses in the
910 // same tick, delay the second one
911 if (!retryRespEvent
.scheduled())
912 cpu
->schedule(retryRespEvent
, cpu
->clockEdge(Cycles(1)));
918 TimingSimpleCPU::DcachePort::DTickEvent::process()
920 cpu
->completeDataAccess(pkt
);
924 TimingSimpleCPU::DcachePort::recvReqRetry()
926 // we shouldn't get a retry unless we have a packet that we're
927 // waiting to transmit
928 assert(cpu
->dcache_pkt
!= NULL
);
929 assert(cpu
->_status
== DcacheRetry
);
930 PacketPtr tmp
= cpu
->dcache_pkt
;
931 if (tmp
->senderState
) {
932 // This is a packet from a split access.
933 SplitFragmentSenderState
* send_state
=
934 dynamic_cast<SplitFragmentSenderState
*>(tmp
->senderState
);
936 PacketPtr big_pkt
= send_state
->bigPkt
;
938 SplitMainSenderState
* main_send_state
=
939 dynamic_cast<SplitMainSenderState
*>(big_pkt
->senderState
);
940 assert(main_send_state
);
942 if (sendTimingReq(tmp
)) {
943 // If we were able to send without retrying, record that fact
944 // and try sending the other fragment.
945 send_state
->clearFromParent();
946 int other_index
= main_send_state
->getPendingFragment();
947 if (other_index
> 0) {
948 tmp
= main_send_state
->fragments
[other_index
];
949 cpu
->dcache_pkt
= tmp
;
950 if ((big_pkt
->isRead() && cpu
->handleReadPacket(tmp
)) ||
951 (big_pkt
->isWrite() && cpu
->handleWritePacket())) {
952 main_send_state
->fragments
[other_index
] = NULL
;
955 cpu
->_status
= DcacheWaitResponse
;
956 // memory system takes ownership of packet
957 cpu
->dcache_pkt
= NULL
;
960 } else if (sendTimingReq(tmp
)) {
961 cpu
->_status
= DcacheWaitResponse
;
962 // memory system takes ownership of packet
963 cpu
->dcache_pkt
= NULL
;
967 TimingSimpleCPU::IprEvent::IprEvent(Packet
*_pkt
, TimingSimpleCPU
*_cpu
,
969 : pkt(_pkt
), cpu(_cpu
)
971 cpu
->schedule(this, t
);
975 TimingSimpleCPU::IprEvent::process()
977 cpu
->completeDataAccess(pkt
);
981 TimingSimpleCPU::IprEvent::description() const
983 return "Timing Simple CPU Delay IPR event";
988 TimingSimpleCPU::printAddr(Addr a
)
990 dcachePort
.printAddr(a
);
994 ////////////////////////////////////////////////////////////////////////
996 // TimingSimpleCPU Simulation Object
999 TimingSimpleCPUParams::create()
1001 return new TimingSimpleCPU(this);