gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timing.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Google, Inc.
3  * Copyright (c) 2010-2013,2015 ARM Limited
4  * All rights reserved
5  *
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.
14  *
15  * Copyright (c) 2002-2005 The Regents of The University of Michigan
16  * All rights reserved.
17  *
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.
28  *
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.
40  *
41  * Authors: Steve Reinhardt
42  */
43 
44 #include "cpu/simple/timing.hh"
45 
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"
63 
64 using namespace std;
65 using namespace TheISA;
66 
67 void
69 {
71 }
72 
73 void
75 {
76  pkt = _pkt;
77  cpu->schedule(this, t);
78 }
79 
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)
84 {
85  _status = Idle;
86 }
87 
88 
89 
91 {
92 }
93 
96 {
97  if (switchedOut())
98  return DrainState::Drained;
99 
100  if (_status == Idle ||
102  DPRINTF(Drain, "No need to drain.\n");
103  activeThreads.clear();
104  return DrainState::Drained;
105  } else {
106  DPRINTF(Drain, "Requesting drain.\n");
107 
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.
112  schedule(fetchEvent, clockEdge());
113 
114  return DrainState::Draining;
115  }
116 }
117 
118 void
120 {
121  assert(!fetchEvent.scheduled());
122  if (switchedOut())
123  return;
124 
125  DPRINTF(SimpleCPU, "Resume\n");
127 
128  assert(!threadContexts.empty());
129 
131 
132  for (ThreadID tid = 0; tid < numThreads; tid++) {
133  if (threadInfo[tid]->thread->status() == ThreadContext::Active) {
134  threadInfo[tid]->notIdleFraction = 1;
135 
136  activeThreads.push_back(tid);
137 
138  _status = BaseSimpleCPU::Running;
139 
140  // Fetch if any threads active
141  if (!fetchEvent.scheduled()) {
142  schedule(fetchEvent, nextCycle());
143  }
144  } else {
145  threadInfo[tid]->notIdleFraction = 0;
146  }
147  }
148 
149  system->totalNumInsts = 0;
150 }
151 
152 bool
154 {
155  if (drainState() != DrainState::Draining)
156  return false;
157 
158  DPRINTF(Drain, "tryCompleteDrain.\n");
159  if (!isDrained())
160  return false;
161 
162  DPRINTF(Drain, "CPU done draining, processing drain event\n");
163  signalDrainDone();
164 
165  return true;
166 }
167 
168 void
170 {
172  M5_VAR_USED SimpleThread* thread = t_info.thread;
173 
174  BaseSimpleCPU::switchOut();
175 
176  assert(!fetchEvent.scheduled());
177  assert(_status == BaseSimpleCPU::Running || _status == Idle);
178  assert(!t_info.stayAtPC);
179  assert(thread->microPC() == 0);
180 
182 }
183 
184 
185 void
187 {
189 
190  previousCycle = curCycle();
191 }
192 
193 void
195 {
196  if (!system->isTimingMode()) {
197  fatal("The timing CPU requires the memory system to be in "
198  "'timing' mode.\n");
199  }
200 }
201 
202 void
204 {
205  DPRINTF(SimpleCPU, "ActivateContext %d\n", thread_num);
206 
207  assert(thread_num < numThreads);
208 
209  threadInfo[thread_num]->notIdleFraction = 1;
212 
213  // kick things off by initiating the fetch of the next instruction
214  if (!fetchEvent.scheduled())
215  schedule(fetchEvent, clockEdge(Cycles(0)));
216 
217  if (std::find(activeThreads.begin(), activeThreads.end(), thread_num)
218  == activeThreads.end()) {
219  activeThreads.push_back(thread_num);
220  }
221 
222  BaseCPU::activateContext(thread_num);
223 }
224 
225 
226 void
228 {
229  DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num);
230 
231  assert(thread_num < numThreads);
232  activeThreads.remove(thread_num);
233 
234  if (_status == Idle)
235  return;
236 
237  assert(_status == BaseSimpleCPU::Running);
238 
239  threadInfo[thread_num]->notIdleFraction = 0;
240 
241  if (activeThreads.empty()) {
242  _status = Idle;
243 
244  if (fetchEvent.scheduled()) {
245  deschedule(fetchEvent);
246  }
247  }
248 
249  BaseCPU::suspendContext(thread_num);
250 }
251 
252 bool
254 {
256  SimpleThread* thread = t_info.thread;
257 
258  RequestPtr req = pkt->req;
259 
260  // We're about the issues a locked load, so tell the monitor
261  // to start caring about this address
262  if (pkt->isRead() && pkt->req->isLLSC()) {
263  TheISA::handleLockedRead(thread, pkt->req);
264  }
265  if (req->isMmappedIpr()) {
266  Cycles delay = TheISA::handleIprRead(thread->getTC(), pkt);
267  new IprEvent(pkt, this, clockEdge(delay));
269  dcache_pkt = NULL;
270  } else if (!dcachePort.sendTimingReq(pkt)) {
272  dcache_pkt = pkt;
273  } else {
275  // memory system takes ownership of packet
276  dcache_pkt = NULL;
277  }
278  return dcache_pkt == NULL;
279 }
280 
281 void
282 TimingSimpleCPU::sendData(RequestPtr req, uint8_t *data, uint64_t *res,
283  bool read)
284 {
286  SimpleThread* thread = t_info.thread;
287 
288  PacketPtr pkt = buildPacket(req, read);
289  pkt->dataDynamic<uint8_t>(data);
290  if (req->getFlags().isSet(Request::NO_ACCESS)) {
291  assert(!dcache_pkt);
292  pkt->makeResponse();
293  completeDataAccess(pkt);
294  } else if (read) {
295  handleReadPacket(pkt);
296  } else {
297  bool do_access = true; // flag to suppress cache access
298 
299  if (req->isLLSC()) {
300  do_access = TheISA::handleLockedWrite(thread, req, dcachePort.cacheBlockMask);
301  } else if (req->isCondSwap()) {
302  assert(res);
303  req->setExtraData(*res);
304  }
305 
306  if (do_access) {
307  dcache_pkt = pkt;
309  threadSnoop(pkt, curThread);
310  } else {
312  completeDataAccess(pkt);
313  }
314  }
315 }
316 
317 void
319  RequestPtr req, uint8_t *data, bool read)
320 {
321  PacketPtr pkt1, pkt2;
322  buildSplitPacket(pkt1, pkt2, req1, req2, req, data, read);
323  if (req->getFlags().isSet(Request::NO_ACCESS)) {
324  assert(!dcache_pkt);
325  pkt1->makeResponse();
326  completeDataAccess(pkt1);
327  } else if (read) {
328  SplitFragmentSenderState * send_state =
329  dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
330  if (handleReadPacket(pkt1)) {
331  send_state->clearFromParent();
332  send_state = dynamic_cast<SplitFragmentSenderState *>(
333  pkt2->senderState);
334  if (handleReadPacket(pkt2)) {
335  send_state->clearFromParent();
336  }
337  }
338  } else {
339  dcache_pkt = pkt1;
340  SplitFragmentSenderState * send_state =
341  dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
342  if (handleWritePacket()) {
343  send_state->clearFromParent();
344  dcache_pkt = pkt2;
345  send_state = dynamic_cast<SplitFragmentSenderState *>(
346  pkt2->senderState);
347  if (handleWritePacket()) {
348  send_state->clearFromParent();
349  }
350  }
351  }
352 }
353 
354 void
356 {
357  // fault may be NoFault in cases where a fault is suppressed,
358  // for instance prefetches.
360 
361  if (traceData) {
362  // Since there was a fault, we shouldn't trace this instruction.
363  delete traceData;
364  traceData = NULL;
365  }
366 
367  postExecute();
368 
369  advanceInst(fault);
370 }
371 
372 PacketPtr
374 {
375  return read ? Packet::createRead(req) : Packet::createWrite(req);
376 }
377 
378 void
380  RequestPtr req1, RequestPtr req2, RequestPtr req,
381  uint8_t *data, bool read)
382 {
383  pkt1 = pkt2 = NULL;
384 
385  assert(!req1->isMmappedIpr() && !req2->isMmappedIpr());
386 
387  if (req->getFlags().isSet(Request::NO_ACCESS)) {
388  pkt1 = buildPacket(req, read);
389  return;
390  }
391 
392  pkt1 = buildPacket(req1, read);
393  pkt2 = buildPacket(req2, read);
394 
395  PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand());
396 
397  pkt->dataDynamic<uint8_t>(data);
398  pkt1->dataStatic<uint8_t>(data);
399  pkt2->dataStatic<uint8_t>(data + req1->getSize());
400 
401  SplitMainSenderState * main_send_state = new SplitMainSenderState;
402  pkt->senderState = main_send_state;
403  main_send_state->fragments[0] = pkt1;
404  main_send_state->fragments[1] = pkt2;
405  main_send_state->outstanding = 2;
406  pkt1->senderState = new SplitFragmentSenderState(pkt, 0);
407  pkt2->senderState = new SplitFragmentSenderState(pkt, 1);
408 }
409 
410 Fault
412  unsigned size, Request::Flags flags)
413 {
414  panic("readMem() is for atomic accesses, and should "
415  "never be called on TimingSimpleCPU.\n");
416 }
417 
418 Fault
420  Request::Flags flags)
421 {
423  SimpleThread* thread = t_info.thread;
424 
425  Fault fault;
426  const int asid = 0;
427  const Addr pc = thread->instAddr();
428  unsigned block_size = cacheLineSize();
430 
431  if (traceData)
432  traceData->setMem(addr, size, flags);
433 
434  RequestPtr req = new Request(asid, addr, size, flags, dataMasterId(), pc,
435  thread->contextId());
436 
437  req->taskId(taskId());
438 
439  Addr split_addr = roundDown(addr + size - 1, block_size);
440  assert(split_addr <= addr || split_addr - addr < block_size);
441 
443  if (split_addr > addr) {
444  RequestPtr req1, req2;
445  assert(!req->isLLSC() && !req->isSwap());
446  req->splitOnVaddr(split_addr, req1, req2);
447 
448  WholeTranslationState *state =
449  new WholeTranslationState(req, req1, req2, new uint8_t[size],
450  NULL, mode);
452  new DataTranslation<TimingSimpleCPU *>(this, state, 0);
454  new DataTranslation<TimingSimpleCPU *>(this, state, 1);
455 
456  thread->dtb->translateTiming(req1, thread->getTC(), trans1, mode);
457  thread->dtb->translateTiming(req2, thread->getTC(), trans2, mode);
458  } else {
459  WholeTranslationState *state =
460  new WholeTranslationState(req, new uint8_t[size], NULL, mode);
462  = new DataTranslation<TimingSimpleCPU *>(this, state);
463  thread->dtb->translateTiming(req, thread->getTC(), translation, mode);
464  }
465 
466  return NoFault;
467 }
468 
469 bool
471 {
473  SimpleThread* thread = t_info.thread;
474 
475  RequestPtr req = dcache_pkt->req;
476  if (req->isMmappedIpr()) {
477  Cycles delay = TheISA::handleIprWrite(thread->getTC(), dcache_pkt);
478  new IprEvent(dcache_pkt, this, clockEdge(delay));
480  dcache_pkt = NULL;
481  } else if (!dcachePort.sendTimingReq(dcache_pkt)) {
483  } else {
485  // memory system takes ownership of packet
486  dcache_pkt = NULL;
487  }
488  return dcache_pkt == NULL;
489 }
490 
491 Fault
493  Addr addr, Request::Flags flags, uint64_t *res)
494 {
496  SimpleThread* thread = t_info.thread;
497 
498  uint8_t *newData = new uint8_t[size];
499  const int asid = 0;
500  const Addr pc = thread->instAddr();
501  unsigned block_size = cacheLineSize();
503 
504  if (data == NULL) {
505  assert(flags & Request::CACHE_BLOCK_ZERO);
506  // This must be a cache block cleaning request
507  memset(newData, 0, size);
508  } else {
509  memcpy(newData, data, size);
510  }
511 
512  if (traceData)
513  traceData->setMem(addr, size, flags);
514 
515  RequestPtr req = new Request(asid, addr, size, flags, dataMasterId(), pc,
516  thread->contextId());
517 
518  req->taskId(taskId());
519 
520  Addr split_addr = roundDown(addr + size - 1, block_size);
521  assert(split_addr <= addr || split_addr - addr < block_size);
522 
524  if (split_addr > addr) {
525  RequestPtr req1, req2;
526  assert(!req->isLLSC() && !req->isSwap());
527  req->splitOnVaddr(split_addr, req1, req2);
528 
529  WholeTranslationState *state =
530  new WholeTranslationState(req, req1, req2, newData, res, mode);
532  new DataTranslation<TimingSimpleCPU *>(this, state, 0);
534  new DataTranslation<TimingSimpleCPU *>(this, state, 1);
535 
536  thread->dtb->translateTiming(req1, thread->getTC(), trans1, mode);
537  thread->dtb->translateTiming(req2, thread->getTC(), trans2, mode);
538  } else {
539  WholeTranslationState *state =
540  new WholeTranslationState(req, newData, res, mode);
542  new DataTranslation<TimingSimpleCPU *>(this, state);
543  thread->dtb->translateTiming(req, thread->getTC(), translation, mode);
544  }
545 
546  // Translation faults will be returned via finishTranslation()
547  return NoFault;
548 }
549 
550 void
552 {
553  for (ThreadID tid = 0; tid < numThreads; tid++) {
554  if (tid != sender) {
555  if (getCpuAddrMonitor(tid)->doMonitor(pkt)) {
556  wakeup(tid);
557  }
558  TheISA::handleLockedSnoop(threadInfo[tid]->thread, pkt,
560  }
561  }
562 }
563 
564 void
566 {
568 
569  if (state->getFault() != NoFault) {
570  if (state->isPrefetch()) {
571  state->setNoFault();
572  }
573  delete [] state->data;
574  state->deleteReqs();
575  translationFault(state->getFault());
576  } else {
577  if (!state->isSplit) {
578  sendData(state->mainReq, state->data, state->res,
579  state->mode == BaseTLB::Read);
580  } else {
581  sendSplitData(state->sreqLow, state->sreqHigh, state->mainReq,
582  state->data, state->mode == BaseTLB::Read);
583  }
584  }
585 
586  delete state;
587 }
588 
589 
590 void
592 {
593  // Change thread if multi-threaded
595 
597  SimpleThread* thread = t_info.thread;
598 
599  DPRINTF(SimpleCPU, "Fetch\n");
600 
604  }
605 
606  // We must have just got suspended by a PC event
607  if (_status == Idle)
608  return;
609 
610  TheISA::PCState pcState = thread->pcState();
611  bool needToFetch = !isRomMicroPC(pcState.microPC()) &&
613 
614  if (needToFetch) {
616  Request *ifetch_req = new Request();
617  ifetch_req->taskId(taskId());
618  ifetch_req->setContext(thread->contextId());
619  setupFetchRequest(ifetch_req);
620  DPRINTF(SimpleCPU, "Translating address %#x\n", ifetch_req->getVaddr());
621  thread->itb->translateTiming(ifetch_req, thread->getTC(),
623  } else {
625  completeIfetch(NULL);
626 
628  }
629 }
630 
631 
632 void
634  ThreadContext *tc)
635 {
636  if (fault == NoFault) {
637  DPRINTF(SimpleCPU, "Sending fetch for addr %#x(pa: %#x)\n",
638  req->getVaddr(), req->getPaddr());
639  ifetch_pkt = new Packet(req, MemCmd::ReadReq);
640  ifetch_pkt->dataStatic(&inst);
641  DPRINTF(SimpleCPU, " -- pkt addr: %#x\n", ifetch_pkt->getAddr());
642 
643  if (!icachePort.sendTimingReq(ifetch_pkt)) {
644  // Need to wait for retry
646  } else {
647  // Need to wait for cache to respond
649  // ownership of packet transferred to memory system
650  ifetch_pkt = NULL;
651  }
652  } else {
653  DPRINTF(SimpleCPU, "Translation of addr %#x faulted\n", req->getVaddr());
654  delete req;
655  // fetch fault: advance directly to next instruction (fault handler)
657  advanceInst(fault);
658  }
659 
661 }
662 
663 
664 void
666 {
668 
669  if (_status == Faulting)
670  return;
671 
672  if (fault != NoFault) {
673  DPRINTF(SimpleCPU, "Fault occured, scheduling fetch event\n");
674 
675  advancePC(fault);
676 
677  Tick stall = dynamic_pointer_cast<SyscallRetryFault>(fault) ?
678  clockEdge(syscallRetryLatency) : clockEdge();
679 
680  reschedule(fetchEvent, stall, true);
681 
682  _status = Faulting;
683  return;
684  }
685 
686 
687  if (!t_info.stayAtPC)
688  advancePC(fault);
689 
690  if (tryCompleteDrain())
691  return;
692 
694  // kick off fetch of next instruction... callback from icache
695  // response will cause that instruction to be executed,
696  // keeping the CPU running.
697  fetch();
698  }
699 }
700 
701 
702 void
704 {
706 
707  DPRINTF(SimpleCPU, "Complete ICache Fetch for addr %#x\n", pkt ?
708  pkt->getAddr() : 0);
709 
710  // received a response from the icache: execute the received
711  // instruction
712  assert(!pkt || !pkt->isError());
713  assert(_status == IcacheWaitResponse);
714 
716 
718 
719  if (pkt)
720  pkt->req->setAccessLatency();
721 
722 
723  preExecute();
725  // load or store: just send to dcache
726  Fault fault = curStaticInst->initiateAcc(&t_info, traceData);
727 
728  // If we're not running now the instruction will complete in a dcache
729  // response callback or the instruction faulted and has started an
730  // ifetch
732  if (fault != NoFault && traceData) {
733  // If there was a fault, we shouldn't trace this instruction.
734  delete traceData;
735  traceData = NULL;
736  }
737 
738  postExecute();
739  // @todo remove me after debugging with legion done
740  if (curStaticInst && (!curStaticInst->isMicroop() ||
742  instCnt++;
743  advanceInst(fault);
744  }
745  } else if (curStaticInst) {
746  // non-memory instruction: execute completely now
747  Fault fault = curStaticInst->execute(&t_info, traceData);
748 
749  // keep an instruction count
750  if (fault == NoFault)
751  countInst();
752  else if (traceData && !DTRACE(ExecFaulting)) {
753  delete traceData;
754  traceData = NULL;
755  }
756 
757  postExecute();
758  // @todo remove me after debugging with legion done
759  if (curStaticInst && (!curStaticInst->isMicroop() ||
761  instCnt++;
762  advanceInst(fault);
763  } else {
765  }
766 
767  if (pkt) {
768  delete pkt->req;
769  delete pkt;
770  }
771 }
772 
773 void
775 {
777 }
778 
779 bool
781 {
782  DPRINTF(SimpleCPU, "Received fetch response %#x\n", pkt->getAddr());
783  // we should only ever see one response per cycle since we only
784  // issue a new request once this response is sunk
785  assert(!tickEvent.scheduled());
786  // delay processing of returned data until next CPU clock edge
787  tickEvent.schedule(pkt, cpu->clockEdge());
788 
789  return true;
790 }
791 
792 void
794 {
795  // we shouldn't get a retry unless we have a packet that we're
796  // waiting to transmit
797  assert(cpu->ifetch_pkt != NULL);
798  assert(cpu->_status == IcacheRetry);
799  PacketPtr tmp = cpu->ifetch_pkt;
800  if (sendTimingReq(tmp)) {
802  cpu->ifetch_pkt = NULL;
803  }
804 }
805 
806 void
808 {
809  // received a response from the dcache: complete the load or store
810  // instruction
811  assert(!pkt->isError());
814 
815  pkt->req->setAccessLatency();
816 
818 
819  if (pkt->senderState) {
820  SplitFragmentSenderState * send_state =
821  dynamic_cast<SplitFragmentSenderState *>(pkt->senderState);
822  assert(send_state);
823  delete pkt->req;
824  delete pkt;
825  PacketPtr big_pkt = send_state->bigPkt;
826  delete send_state;
827 
828  SplitMainSenderState * main_send_state =
829  dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
830  assert(main_send_state);
831  // Record the fact that this packet is no longer outstanding.
832  assert(main_send_state->outstanding != 0);
833  main_send_state->outstanding--;
834 
835  if (main_send_state->outstanding) {
836  return;
837  } else {
838  delete main_send_state;
839  big_pkt->senderState = NULL;
840  pkt = big_pkt;
841  }
842  }
843 
845 
847  traceData);
848 
849  // keep an instruction count
850  if (fault == NoFault)
851  countInst();
852  else if (traceData) {
853  // If there was a fault, we shouldn't trace this instruction.
854  delete traceData;
855  traceData = NULL;
856  }
857 
858  delete pkt->req;
859  delete pkt;
860 
861  postExecute();
862 
863  advanceInst(fault);
864 }
865 
866 void
868 {
869  const Cycles delta(curCycle() - previousCycle);
870 
871  numCycles += delta;
872  ppCycles->notify(delta);
873 
874  previousCycle = curCycle();
875 }
876 
877 void
879 {
880  for (ThreadID tid = 0; tid < cpu->numThreads; tid++) {
881  if (cpu->getCpuAddrMonitor(tid)->doMonitor(pkt)) {
882  cpu->wakeup(tid);
883  }
884  }
885 
886  // Making it uniform across all CPUs:
887  // The CPUs need to be woken up only on an invalidation packet (when using caches)
888  // or on an incoming write packet (when not using caches)
889  // It is not necessary to wake up the processor on all incoming packets
890  if (pkt->isInvalidate() || pkt->isWrite()) {
891  for (auto &t_info : cpu->threadInfo) {
892  TheISA::handleLockedSnoop(t_info->thread, pkt, cacheBlockMask);
893  }
894  }
895 }
896 
897 void
899 {
900  for (ThreadID tid = 0; tid < cpu->numThreads; tid++) {
901  if (cpu->getCpuAddrMonitor(tid)->doMonitor(pkt)) {
902  cpu->wakeup(tid);
903  }
904  }
905 }
906 
907 bool
909 {
910  DPRINTF(SimpleCPU, "Received load/store response %#x\n", pkt->getAddr());
911 
912  // The timing CPU is not really ticked, instead it relies on the
913  // memory system (fetch and load/store) to set the pace.
914  if (!tickEvent.scheduled()) {
915  // Delay processing of returned data until next CPU clock edge
916  tickEvent.schedule(pkt, cpu->clockEdge());
917  return true;
918  } else {
919  // In the case of a split transaction and a cache that is
920  // faster than a CPU we could get two responses in the
921  // same tick, delay the second one
922  if (!retryRespEvent.scheduled())
923  cpu->schedule(retryRespEvent, cpu->clockEdge(Cycles(1)));
924  return false;
925  }
926 }
927 
928 void
930 {
931  cpu->completeDataAccess(pkt);
932 }
933 
934 void
936 {
937  // we shouldn't get a retry unless we have a packet that we're
938  // waiting to transmit
939  assert(cpu->dcache_pkt != NULL);
940  assert(cpu->_status == DcacheRetry);
941  PacketPtr tmp = cpu->dcache_pkt;
942  if (tmp->senderState) {
943  // This is a packet from a split access.
944  SplitFragmentSenderState * send_state =
945  dynamic_cast<SplitFragmentSenderState *>(tmp->senderState);
946  assert(send_state);
947  PacketPtr big_pkt = send_state->bigPkt;
948 
949  SplitMainSenderState * main_send_state =
950  dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
951  assert(main_send_state);
952 
953  if (sendTimingReq(tmp)) {
954  // If we were able to send without retrying, record that fact
955  // and try sending the other fragment.
956  send_state->clearFromParent();
957  int other_index = main_send_state->getPendingFragment();
958  if (other_index > 0) {
959  tmp = main_send_state->fragments[other_index];
960  cpu->dcache_pkt = tmp;
961  if ((big_pkt->isRead() && cpu->handleReadPacket(tmp)) ||
962  (big_pkt->isWrite() && cpu->handleWritePacket())) {
963  main_send_state->fragments[other_index] = NULL;
964  }
965  } else {
967  // memory system takes ownership of packet
968  cpu->dcache_pkt = NULL;
969  }
970  }
971  } else if (sendTimingReq(tmp)) {
973  // memory system takes ownership of packet
974  cpu->dcache_pkt = NULL;
975  }
976 }
977 
979  Tick t)
980  : pkt(_pkt), cpu(_cpu)
981 {
982  cpu->schedule(this, t);
983 }
984 
985 void
987 {
988  cpu->completeDataAccess(pkt);
989 }
990 
991 const char *
993 {
994  return "Timing Simple CPU Delay IPR event";
995 }
996 
997 
998 void
1000 {
1001  dcachePort.printAddr(a);
1002 }
1003 
1004 
1006 //
1007 // TimingSimpleCPU Simulation Object
1008 //
1010 TimingSimpleCPUParams::create()
1011 {
1012  return new TimingSimpleCPU(this);
1013 }
StaticInstPtr curStaticInst
Definition: base.hh:107
void advancePC(const Fault &fault)
Definition: base.cc:642
#define DPRINTF(x,...)
Definition: trace.hh:212
This class represents part of a data address translation.
Definition: translation.hh:218
bool isFirstMicroop() const
Definition: static_inst.hh:172
virtual const char * description() const
Return a C string describing the event.
Definition: timing.cc:992
std::list< ThreadID > activeThreads
Definition: base.hh:103
decltype(nullptr) constexpr NoFault
Definition: types.hh:189
PacketPtr dcache_pkt
Definition: timing.hh:256
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
void checkPcEventQueue()
Definition: base.cc:145
DcachePort dcachePort
Definition: timing.hh:253
void switchOut() override
Definition: timing.cc:169
DrainState
Object drain/handover states.
Definition: drain.hh:71
void schedule(PacketPtr _pkt, Tick t)
Definition: timing.cc:74
#define panic(...)
Definition: misc.hh:153
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the slave port.
Definition: timing.cc:780
Running normally.
bool isDrained()
Check if a system is in a drained state.
Definition: timing.hh:345
void setExtraData(uint64_t extraData)
Accessor function for store conditional return value.
Definition: request.hh:680
bool isDelayedCommit() const
Definition: static_inst.hh:170
Bitfield< 8 > a
Definition: miscregs.hh:1377
void suspendContext(ThreadID thread_num) override
Definition: timing.cc:227
TheISA::MachInst inst
Current instruction.
Definition: base.hh:106
void deleteReqs()
Delete all requests that make up this translation.
Definition: translation.hh:197
ip6_addr_t addr
Definition: inet.hh:335
bool isWrite() const
Definition: packet.hh:503
void wakeup(ThreadID tid) override
Definition: base.cc:420
void sendData(RequestPtr req, uint8_t *data, uint64_t *res, bool read)
Definition: timing.cc:282
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:381
bool isMicroop() const
Definition: static_inst.hh:169
bool isMmappedIpr() const
Definition: request.hh:776
virtual Fault initiateAcc(ExecContext *xc, Trace::InstRecord *traceData) const
Definition: static_inst.hh:269
void verifyMemoryMode() const override
Definition: timing.cc:194
bool isSet() const
Definition: flags.hh:62
bool handleLockedWrite(XC *xc, Request *req, Addr cacheBlockMask)
Definition: locked_mem.hh:102
virtual Fault execute(ExecContext *xc, Trace::InstRecord *traceData) const =0
void setContext(ContextID context_id)
Set up Context numbers.
Definition: request.hh:449
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
void init() override
Definition: timing.cc:68
This is a write that is targeted and zeroing an entire cache block.
Definition: request.hh:134
void checkForInterrupts()
Definition: base.cc:431
PacketPtr buildPacket(RequestPtr req, bool read)
Definition: timing.cc:373
This class captures the state of an address translation.
Definition: translation.hh:61
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the slave port by calling its corresponding receive function...
Definition: port.cc:180
ThreadID curThread
Definition: base.hh:87
Bitfield< 4, 0 > mode
Definition: miscregs.hh:1385
void preExecute()
Definition: base.cc:468
Cycles handleIprRead(ThreadContext *xc, Packet *pkt)
Helper function to handle IPRs when the target architecture doesn't need its own IPR handling...
Definition: mmapped_ipr.hh:139
Cycles handleIprWrite(ThreadContext *xc, Packet *pkt)
Helper function to handle IPRs when the target architecture doesn't need its own IPR handling...
Definition: mmapped_ipr.hh:160
ThreadContext is the external interface to all thread state for anything outside of the CPU...
void setAccessLatency()
Set/Get the time taken to complete this request's access, not including the time to successfully tran...
Definition: request.hh:738
bool isCondSwap() const
Definition: request.hh:775
void dataStatic(T *p)
Set the data pointer to the following value that should not be freed.
Definition: packet.hh:909
TheISA::TLB * dtb
bool isMemRef() const
Definition: static_inst.hh:132
const char data[]
Definition: circlebuf.cc:43
void completeIfetch(PacketPtr)
Definition: timing.cc:703
void fetch()
Definition: timing.cc:591
Fault getFault() const
Determine whether this translation produced a fault.
Definition: translation.hh:136
void swapActiveThread()
Definition: base.cc:156
void handleLockedSnoop(XC *xc, PacketPtr pkt, Addr cacheBlockMask)
Definition: locked_mem.hh:69
void buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2, RequestPtr req1, RequestPtr req2, RequestPtr req, uint8_t *data, bool read)
Definition: timing.cc:379
PacketPtr ifetch_pkt
Definition: timing.hh:255
bool tryCompleteDrain()
Try to complete a drain request.
Definition: timing.cc:153
system
Definition: isa.cc:226
void sendFetch(const Fault &fault, RequestPtr req, ThreadContext *tc)
Definition: timing.cc:633
void countInst()
Definition: base.cc:172
void init() override
Definition: base.cc:129
bool isPrefetch() const
Check if this request is a prefetch.
Definition: translation.hh:172
#define DTRACE(x)
Definition: trace.hh:210
bool isLLSC() const
Definition: request.hh:771
void takeOverFrom(ThreadContext &ntc, ThreadContext &otc)
Copy state between thread contexts in preparation for CPU handover.
uint64_t Tick
Tick count type.
Definition: types.hh:63
bool handleReadPacket(PacketPtr pkt)
Definition: timing.cc:253
FetchTranslation fetchTranslation
Definition: timing.hh:133
TheISA::TLB * itb
void translationFault(const Fault &fault)
Definition: timing.cc:355
EventWrapper< MasterPort,&MasterPort::sendRetryResp > retryRespEvent
Definition: timing.hh:179
void takeOverFrom(BaseCPU *oldCPU) override
Definition: timing.cc:186
Addr getPaddr() const
Definition: request.hh:519
void setMem(Addr a, Addr s, unsigned f)
Definition: insttracer.hh:157
#define fatal(...)
Definition: misc.hh:163
const RequestPtr req
A pointer to the original request.
Definition: packet.hh:304
void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
Generate two requests as if this request had been split into two pieces.
Definition: request.hh:497
virtual void recvFunctionalSnoop(PacketPtr pkt)
Receive a functional snoop request packet from the slave port.
Definition: timing.cc:898
T roundDown(const T &val, const U &align)
Definition: intmath.hh:213
TimingSimpleCPU * cpu
Definition: timing.hh:167
Status _status
Definition: base.hh:125
bool isRead() const
Definition: packet.hh:502
bool isSwap() const
Definition: request.hh:774
BaseTLB::Mode mode
Definition: translation.hh:75
StaticInstPtr curMacroStaticInst
Definition: base.hh:108
SimpleThread * thread
Definition: exec_context.hh:69
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
ThreadContext * getTC()
Returns the pointer to this SimpleThread's ThreadContext.
void printAddr(Addr a)
Inject a PrintReq for the given address to print the state of that address throughout the memory syst...
Definition: port.cc:200
Draining buffers pending serialization/handover.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
virtual void recvReqRetry()
Called by the slave port if sendTimingReq was called on this master port (causing recvTimingReq to be...
Definition: timing.cc:793
static bool isRomMicroPC(MicroPC upc)
Definition: types.hh:161
void threadSnoop(PacketPtr pkt, ThreadID sender)
Definition: timing.cc:551
void activateContext(ThreadID thread_num) override
Definition: timing.cc:203
virtual ~TimingSimpleCPU()
Definition: timing.cc:90
void sendSplitData(RequestPtr req1, RequestPtr req2, RequestPtr req, uint8_t *data, bool read)
Definition: timing.cc:318
TheISA::PCState pcState()
static const int NumArgumentRegs M5_VAR_USED
Definition: process.cc:83
Flags getFlags()
Accessor for flags.
Definition: request.hh:584
Mode
Definition: tlb.hh:61
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition: packet.hh:845
int size()
Definition: pagetable.hh:146
Cycles previousCycle
Definition: timing.hh:258
virtual void recvReqRetry()
Called by the slave port if sendTimingReq was called on this master port (causing recvTimingReq to be...
Definition: timing.cc:935
Declaration of the Packet class.
The request should not cause a memory access.
Definition: request.hh:137
bool isError() const
Definition: packet.hh:528
Trace::InstRecord * traceData
Definition: base.hh:99
IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu, Tick t)
Definition: timing.cc:978
SenderState * senderState
This packet's sender state.
Definition: packet.hh:454
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
MemCmd cmd
The command field of the packet.
Definition: packet.hh:301
virtual Fault completeAcc(Packet *pkt, ExecContext *xc, Trace::InstRecord *traceData) const
Definition: static_inst.hh:275
Addr getVaddr() const
Definition: request.hh:616
void advanceInst(const Fault &fault)
Definition: timing.cc:665
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the slave port.
Definition: timing.cc:908
std::vector< SimpleExecContext * > threadInfo
Definition: base.hh:102
Fault readMem(Addr addr, uint8_t *data, unsigned size, Request::Flags flags) override
Definition: timing.cc:411
IcachePort icachePort
Definition: timing.hh:252
static PacketPtr createRead(const RequestPtr req)
Constructor-like methods that return Packets based on Request objects.
Definition: packet.hh:809
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition: packet.hh:947
void finishTranslation(WholeTranslationState *state)
Finish a DTB translation.
Definition: timing.cc:565
Fault writeMem(uint8_t *data, unsigned size, Addr addr, Request::Flags flags, uint64_t *res) override
Definition: timing.cc:492
void completeDataAccess(PacketPtr pkt)
Definition: timing.cc:807
void postExecute()
Definition: base.cc:558
void setNoFault()
Remove all faults from the translation.
Definition: translation.hh:150
FetchEvent fetchEvent
Definition: timing.hh:319
IntReg pc
Definition: remote_gdb.hh:91
TimingSimpleCPU * cpu
Definition: timing.hh:323
DrainState drain() override
Definition: timing.cc:95
TimingSimpleCPU(TimingSimpleCPUParams *params)
Definition: timing.cc:80
Bitfield< 5 > t
Definition: miscregs.hh:1382
ContextID contextId() const
Definition: thread_state.hh:74
virtual void process()
Definition: timing.cc:986
bool isInvalidate() const
Definition: packet.hh:517
static PacketPtr createWrite(const RequestPtr req)
Definition: packet.hh:815
void printAddr(Addr a)
Print state of address in memory system via PrintReq (for debugging).
Definition: timing.cc:999
unsigned getSize() const
Definition: request.hh:552
virtual void recvTimingSnoopReq(PacketPtr pkt)
Snoop a coherence request, we need to check if this causes a wakeup event on a cpu that is monitoring...
Definition: timing.cc:878
Bitfield< 0 > p
Command responseCommand() const
Definition: packet.hh:221
Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags) override
Definition: timing.cc:419
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
void setupFetchRequest(Request *req)
Definition: base.cc:451
void drainResume() override
Definition: timing.cc:119
bool handleWritePacket()
Definition: timing.cc:470
uint32_t taskId() const
Definition: request.hh:630
void handleLockedRead(XC *xc, Request *req)
Definition: locked_mem.hh:88
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:102
Addr getAddr() const
Definition: packet.hh:639
void updateCycleCounts()
Definition: timing.cc:867

Generated on Fri Jun 9 2017 13:03:44 for gem5 by doxygen 1.8.6