gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
base.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2013 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2002-2005 The Regents of The University of Michigan
15  * Copyright (c) 2011 Regents of the University of California
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  * Nathan Binkert
43  * Rick Strong
44  */
45 
46 #ifndef __CPU_BASE_HH__
47 #define __CPU_BASE_HH__
48 
49 #include <vector>
50 
51 // Before we do anything else, check if this build is the NULL ISA,
52 // and if so stop here
53 #include "config/the_isa.hh"
54 #if THE_ISA == NULL_ISA
55 #include "arch/null/cpu_dummy.hh"
56 #else
57 #include "arch/interrupts.hh"
58 #include "arch/isa_traits.hh"
59 #include "arch/microcode_rom.hh"
60 #include "base/statistics.hh"
61 #include "mem/mem_object.hh"
62 #include "sim/eventq.hh"
63 #include "sim/full_system.hh"
64 #include "sim/insttracer.hh"
65 #include "sim/probe/pmu.hh"
66 #include "sim/system.hh"
67 #include "debug/Mwait.hh"
68 
69 class BaseCPU;
70 struct BaseCPUParams;
71 class CheckerCPU;
72 class ThreadContext;
73 
74 struct AddressMonitor
75 {
76  AddressMonitor();
77  bool doMonitor(PacketPtr pkt);
78 
79  bool armed;
80  Addr vAddr;
81  Addr pAddr;
82  uint64_t val;
83  bool waiting; // 0=normal, 1=mwaiting
84  bool gotWakeup;
85 };
86 
87 class CPUProgressEvent : public Event
88 {
89  protected:
90  Tick _interval;
91  Counter lastNumInst;
92  BaseCPU *cpu;
93  bool _repeatEvent;
94 
95  public:
96  CPUProgressEvent(BaseCPU *_cpu, Tick ival = 0);
97 
98  void process();
99 
100  void interval(Tick ival) { _interval = ival; }
101  Tick interval() { return _interval; }
102 
103  void repeatEvent(bool repeat) { _repeatEvent = repeat; }
104 
105  virtual const char *description() const;
106 };
107 
108 class BaseCPU : public MemObject
109 {
110  protected:
111 
114  Tick instCnt;
115 
116  // every cpu has an id, put it in the base cpu
117  // Set at initialization, only time a cpuId might change is during a
118  // takeover (which should be done from within the BaseCPU anyway,
119  // therefore no setCpuId() method is provided
120  int _cpuId;
121 
127  const uint32_t _socketId;
128 
130  MasterID _instMasterId;
131 
133  MasterID _dataMasterId;
134 
140  uint32_t _taskId;
141 
144  uint32_t _pid;
145 
147  bool _switchedOut;
148 
150  const unsigned int _cacheLineSize;
151 
152  public:
153 
160  virtual MasterPort &getDataPort() = 0;
161 
168  virtual MasterPort &getInstPort() = 0;
169 
171  int cpuId() const { return _cpuId; }
172 
174  uint32_t socketId() const { return _socketId; }
175 
177  MasterID dataMasterId() { return _dataMasterId; }
179  MasterID instMasterId() { return _instMasterId; }
180 
191  BaseMasterPort &getMasterPort(const std::string &if_name,
192  PortID idx = InvalidPortID) override;
193 
195  uint32_t taskId() const { return _taskId; }
197  void taskId(uint32_t id) { _taskId = id; }
198 
199  uint32_t getPid() const { return _pid; }
200  void setPid(uint32_t pid) { _pid = pid; }
201 
202  inline void workItemBegin() { numWorkItemsStarted++; }
203  inline void workItemEnd() { numWorkItemsCompleted++; }
204  // @todo remove me after debugging with legion done
205  Tick instCount() { return instCnt; }
206 
207  TheISA::MicrocodeRom microcodeRom;
208 
209  protected:
211 
212  public:
213  TheISA::Interrupts *
214  getInterruptController(ThreadID tid)
215  {
216  if (interrupts.empty())
217  return NULL;
218 
219  assert(interrupts.size() > tid);
220  return interrupts[tid];
221  }
222 
223  virtual void wakeup(ThreadID tid) = 0;
224 
225  void
226  postInterrupt(ThreadID tid, int int_num, int index)
227  {
228  interrupts[tid]->post(int_num, index);
229  if (FullSystem)
230  wakeup(tid);
231  }
232 
233  void
234  clearInterrupt(ThreadID tid, int int_num, int index)
235  {
236  interrupts[tid]->clear(int_num, index);
237  }
238 
239  void
240  clearInterrupts(ThreadID tid)
241  {
242  interrupts[tid]->clearAll();
243  }
244 
245  bool
246  checkInterrupts(ThreadContext *tc) const
247  {
248  return FullSystem && interrupts[tc->threadId()]->checkInterrupts(tc);
249  }
250 
251  class ProfileEvent : public Event
252  {
253  private:
254  BaseCPU *cpu;
255  Tick interval;
256 
257  public:
258  ProfileEvent(BaseCPU *cpu, Tick interval);
259  void process();
260  };
261  ProfileEvent *profileEvent;
262 
263  protected:
264  std::vector<ThreadContext *> threadContexts;
265 
266  Trace::InstTracer * tracer;
267 
268  public:
269 
270 
273  static const uint32_t invldPid = std::numeric_limits<uint32_t>::max();
274 
275  // Mask to align PCs to MachInst sized boundaries
276  static const Addr PCMask = ~((Addr)sizeof(TheISA::MachInst) - 1);
277 
279  Trace::InstTracer * getTracer() { return tracer; }
280 
282  virtual void activateContext(ThreadID thread_num);
283 
286  virtual void suspendContext(ThreadID thread_num);
287 
289  virtual void haltContext(ThreadID thread_num) {}
290 
292  int findContext(ThreadContext *tc);
293 
295  virtual ThreadContext *getContext(int tn) { return threadContexts[tn]; }
296 
298  unsigned numContexts() { return threadContexts.size(); }
299 
301  ThreadID contextToThread(ContextID cid)
302  { return static_cast<ThreadID>(cid - threadContexts[0]->contextId()); }
303 
304  public:
305  typedef BaseCPUParams Params;
306  const Params *params() const
307  { return reinterpret_cast<const Params *>(_params); }
308  BaseCPU(Params *params, bool is_checker = false);
309  virtual ~BaseCPU();
310 
311  void init() override;
312  void startup() override;
313  void regStats() override;
314 
315  void regProbePoints() override;
316 
317  void registerThreadContexts();
318 
326  virtual void switchOut();
327 
339  virtual void takeOverFrom(BaseCPU *cpu);
340 
350  void flushTLBs();
351 
357  bool switchedOut() const { return _switchedOut; }
358 
368  virtual void verifyMemoryMode() const { };
369 
374  ThreadID numThreads;
375 
381  EventQueue **comInstEventQueue;
382 
388  EventQueue **comLoadEventQueue;
389 
390  System *system;
391 
395  inline unsigned int cacheLineSize() const { return _cacheLineSize; }
396 
407  void serialize(CheckpointOut &cp) const override;
408 
420  void unserialize(CheckpointIn &cp) override;
421 
428  virtual void serializeThread(CheckpointOut &cp, ThreadID tid) const {};
429 
437  virtual void unserializeThread(CheckpointIn &cp, ThreadID tid) {};
438 
439  virtual Counter totalInsts() const = 0;
440 
441  virtual Counter totalOps() const = 0;
442 
456  void scheduleInstStop(ThreadID tid, Counter insts, const char *cause);
457 
471  void scheduleLoadStop(ThreadID tid, Counter loads, const char *cause);
472 
480  uint64_t getCurrentInstCount(ThreadID tid);
481 
482  public:
494  virtual void probeInstCommit(const StaticInstPtr &inst);
495 
503  ProbePoints::PMUUPtr pmuProbePoint(const char *name);
504 
506  ProbePoints::PMUUPtr ppCycles;
507 
516  ProbePoints::PMUUPtr ppRetiredInsts;
517 
519  ProbePoints::PMUUPtr ppRetiredLoads;
521  ProbePoints::PMUUPtr ppRetiredStores;
522 
524  ProbePoints::PMUUPtr ppRetiredBranches;
525 
530  // Function tracing
531  private:
532  bool functionTracingEnabled;
533  std::ostream *functionTraceStream;
534  Addr currentFunctionStart;
535  Addr currentFunctionEnd;
536  Tick functionEntryTick;
537  void enableFunctionTrace();
538  void traceFunctionsInternal(Addr pc);
539 
540  private:
541  static std::vector<BaseCPU *> cpuList;
542 
543  public:
544  void traceFunctions(Addr pc)
545  {
546  if (functionTracingEnabled)
547  traceFunctionsInternal(pc);
548  }
549 
550  static int numSimulatedCPUs() { return cpuList.size(); }
551  static Counter numSimulatedInsts()
552  {
553  Counter total = 0;
554 
555  int size = cpuList.size();
556  for (int i = 0; i < size; ++i)
557  total += cpuList[i]->totalInsts();
558 
559  return total;
560  }
561 
562  static Counter numSimulatedOps()
563  {
564  Counter total = 0;
565 
566  int size = cpuList.size();
567  for (int i = 0; i < size; ++i)
568  total += cpuList[i]->totalOps();
569 
570  return total;
571  }
572 
573  public:
574  // Number of CPU cycles simulated
575  Stats::Scalar numCycles;
576  Stats::Scalar numWorkItemsStarted;
577  Stats::Scalar numWorkItemsCompleted;
578 
579  private:
580  std::vector<AddressMonitor> addressMonitor;
581 
582  public:
583  void armMonitor(ThreadID tid, Addr address);
584  bool mwait(ThreadID tid, PacketPtr pkt);
585  void mwaitAtomic(ThreadID tid, ThreadContext *tc, TheISA::TLB *dtb);
586  AddressMonitor *getCpuAddrMonitor(ThreadID tid)
587  {
588  assert(tid < numThreads);
589  return &addressMonitor[tid];
590  }
591 
592  Cycles syscallRetryLatency;
593 };
594 
595 #endif // THE_ISA == NULL_ISA
596 
597 #endif // __CPU_BASE_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:167
Bitfield< 30, 0 > index
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
const std::string & name()
Definition: trace.cc:49
CheckerCPU class.
Definition: cpu.hh:91
Bitfield< 7 > i
Definition: miscregs.hh:1378
const PortID InvalidPortID
Definition: types.hh:182
MemObject declaration.
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:146
Definition: system.hh:83
virtual void process()=0
If you want a reference counting pointer to a mutable object, create it like this: ...
Definition: refcnt.hh:106
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2475
STL vector class.
Definition: stl.hh:40
static int numSimulatedOps()
Definition: cpu_dummy.hh:49
Bitfield< 63 > val
Definition: misc.hh:770
uint32_t MachInst
Definition: types.hh:40
system
Definition: isa.cc:226
Queue of events sorted in time order.
Definition: eventq.hh:488
std::unique_ptr< PMU > PMUUPtr
Definition: pmu.hh:57
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
static void wakeup(ThreadID tid)
Definition: cpu_dummy.hh:50
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
uint16_t MasterID
Definition: request.hh:85
int64_t Counter
Statistics counter type.
Definition: types.hh:58
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
const FlagsType total
Print the total.
Definition: info.hh:49
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
int size()
Definition: pagetable.hh:146
std::ostream CheckpointOut
Definition: serialize.hh:67
Definition: eventq.hh:185
The MemObject class extends the ClockedObject with accessor functions to get its master and slave por...
Definition: mem_object.hh:60
virtual int threadId() const =0
A BaseMasterPort is a protocol-agnostic master port, responsible only for the structural connection t...
Definition: port.hh:115
IntReg pc
Definition: remote_gdb.hh:91
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:181
void serialize(CheckpointOut &cp) const override
void unserialize(CheckpointIn &cp) override
Bitfield< 11 > id
Definition: miscregs.hh:124
virtual const char * description() const
Return a C string describing the event.
Definition: eventq.cc:378
int ContextID
Globally unique thread context ID.
Definition: types.hh:175
const FlagsType init
This Stat is Initialized.
Definition: info.hh:45
static int numSimulatedInsts()
Definition: cpu_dummy.hh:48

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