gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
base.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2013, 2017 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
58 #include "arch/isa_traits.hh"
59 #include "arch/microcode_rom.hh"
60 #include "base/statistics.hh"
61 #include "sim/clocked_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/probe/probe.hh"
67 #include "sim/system.hh"
68 #include "debug/Mwait.hh"
69 
70 class BaseCPU;
71 struct BaseCPUParams;
72 class CheckerCPU;
73 class ThreadContext;
74 
76 {
78  bool doMonitor(PacketPtr pkt);
79 
80  bool armed;
83  uint64_t val;
84  bool waiting; // 0=normal, 1=mwaiting
85  bool gotWakeup;
86 };
87 
88 class CPUProgressEvent : public Event
89 {
90  protected:
95 
96  public:
97  CPUProgressEvent(BaseCPU *_cpu, Tick ival = 0);
98 
99  void process();
100 
101  void interval(Tick ival) { _interval = ival; }
102  Tick interval() { return _interval; }
103 
104  void repeatEvent(bool repeat) { _repeatEvent = repeat; }
105 
106  virtual const char *description() const;
107 };
108 
109 class BaseCPU : public ClockedObject
110 {
111  protected:
112 
116 
117  // every cpu has an id, put it in the base cpu
118  // Set at initialization, only time a cpuId might change is during a
119  // takeover (which should be done from within the BaseCPU anyway,
120  // therefore no setCpuId() method is provided
121  int _cpuId;
122 
128  const uint32_t _socketId;
129 
132 
135 
141  uint32_t _taskId;
142 
145  uint32_t _pid;
146 
149 
151  const unsigned int _cacheLineSize;
152 
153  public:
154 
161  virtual Port &getDataPort() = 0;
162 
168  {
169  auto port = dynamic_cast<MasterPort *>(&getDataPort());
170  assert(port);
171  return [port](PacketPtr pkt)->void { port->sendFunctional(pkt); };
172  }
173 
180  virtual Port &getInstPort() = 0;
181 
183  int cpuId() const { return _cpuId; }
184 
186  uint32_t socketId() const { return _socketId; }
187 
189  MasterID dataMasterId() const { return _dataMasterId; }
191  MasterID instMasterId() const { return _instMasterId; }
192 
203  Port &getPort(const std::string &if_name,
204  PortID idx=InvalidPortID) override;
205 
207  uint32_t taskId() const { return _taskId; }
209  void taskId(uint32_t id) { _taskId = id; }
210 
211  uint32_t getPid() const { return _pid; }
212  void setPid(uint32_t pid) { _pid = pid; }
213 
214  inline void workItemBegin() { numWorkItemsStarted++; }
215  inline void workItemEnd() { numWorkItemsCompleted++; }
216  // @todo remove me after debugging with legion done
217  Tick instCount() { return instCnt; }
218 
219  TheISA::MicrocodeRom microcodeRom;
220 
221  protected:
223 
224  public:
227  {
228  if (interrupts.empty())
229  return NULL;
230 
231  assert(interrupts.size() > tid);
232  return interrupts[tid];
233  }
234 
235  virtual void wakeup(ThreadID tid) = 0;
236 
237  void
238  postInterrupt(ThreadID tid, int int_num, int index)
239  {
240  interrupts[tid]->post(int_num, index);
241  if (FullSystem)
242  wakeup(tid);
243  }
244 
245  void
246  clearInterrupt(ThreadID tid, int int_num, int index)
247  {
248  interrupts[tid]->clear(int_num, index);
249  }
250 
251  void
253  {
254  interrupts[tid]->clearAll();
255  }
256 
257  bool
259  {
260  return FullSystem && interrupts[tc->threadId()]->checkInterrupts(tc);
261  }
262 
263  void processProfileEvent();
265 
266  protected:
268 
270 
271  public:
272 
273 
276  static const uint32_t invldPid = std::numeric_limits<uint32_t>::max();
277 
278  // Mask to align PCs to MachInst sized boundaries
279  static const Addr PCMask = ~((Addr)sizeof(TheISA::MachInst) - 1);
280 
282  Trace::InstTracer * getTracer() { return tracer; }
283 
285  virtual void activateContext(ThreadID thread_num);
286 
289  virtual void suspendContext(ThreadID thread_num);
290 
292  virtual void haltContext(ThreadID thread_num);
293 
295  int findContext(ThreadContext *tc);
296 
298  virtual ThreadContext *getContext(int tn) { return threadContexts[tn]; }
299 
301  unsigned numContexts() {
302  return static_cast<unsigned>(threadContexts.size());
303  }
304 
307  { return static_cast<ThreadID>(cid - threadContexts[0]->contextId()); }
308 
309  public:
310  typedef BaseCPUParams Params;
311  const Params *params() const
312  { return reinterpret_cast<const Params *>(_params); }
313  BaseCPU(Params *params, bool is_checker = false);
314  virtual ~BaseCPU();
315 
316  void init() override;
317  void startup() override;
318  void regStats() override;
319 
320  void regProbePoints() override;
321 
322  void registerThreadContexts();
323 
324  // Functions to deschedule and reschedule the events to enter the
325  // power gating sleep before and after checkpoiting respectively.
326  void deschedulePowerGatingEvent();
327  void schedulePowerGatingEvent();
328 
336  virtual void switchOut();
337 
349  virtual void takeOverFrom(BaseCPU *cpu);
350 
360  void flushTLBs();
361 
367  bool switchedOut() const { return _switchedOut; }
368 
378  virtual void verifyMemoryMode() const { };
379 
384  ThreadID numThreads;
385 
387 
391  inline unsigned int cacheLineSize() const { return _cacheLineSize; }
392 
403  void serialize(CheckpointOut &cp) const override;
404 
415  void unserialize(CheckpointIn &cp) override;
416 
423  virtual void serializeThread(CheckpointOut &cp, ThreadID tid) const {};
424 
431  virtual void unserializeThread(CheckpointIn &cp, ThreadID tid) {};
432 
433  virtual Counter totalInsts() const = 0;
434 
435  virtual Counter totalOps() const = 0;
436 
450  void scheduleInstStop(ThreadID tid, Counter insts, const char *cause);
451 
459  uint64_t getCurrentInstCount(ThreadID tid);
460 
461  public:
474  virtual void probeInstCommit(const StaticInstPtr &inst, Addr pc);
475 
476  protected:
484  ProbePoints::PMUUPtr pmuProbePoint(const char *name);
485 
496 
501 
504 
507 
510 
522  enum CPUState {
525  CPU_STATE_WAKEUP
526  };
527 
530 
532  inline void updateCycleCounters(CPUState state)
533  {
534  uint32_t delta = curCycle() - previousCycle;
535 
536  if (previousState == CPU_STATE_ON) {
537  ppActiveCycles->notify(delta);
538  }
539 
540  switch (state)
541  {
542  case CPU_STATE_WAKEUP:
543  ppSleeping->notify(false);
544  break;
545  case CPU_STATE_SLEEP:
546  ppSleeping->notify(true);
547  break;
548  default:
549  break;
550  }
551 
552  ppAllCycles->notify(delta);
553 
554  previousCycle = curCycle();
555  previousState = state;
556  }
557 
558  // Function tracing
559  private:
561  std::ostream *functionTraceStream;
565  void enableFunctionTrace();
566  void traceFunctionsInternal(Addr pc);
567 
568  private:
570 
571  public:
573  {
574  if (functionTracingEnabled)
575  traceFunctionsInternal(pc);
576  }
577 
578  static int numSimulatedCPUs() { return cpuList.size(); }
580  {
581  Counter total = 0;
582 
583  int size = cpuList.size();
584  for (int i = 0; i < size; ++i)
585  total += cpuList[i]->totalInsts();
586 
587  return total;
588  }
589 
591  {
592  Counter total = 0;
593 
594  int size = cpuList.size();
595  for (int i = 0; i < size; ++i)
596  total += cpuList[i]->totalOps();
597 
598  return total;
599  }
600 
601  public:
602  // Number of CPU cycles simulated
606 
607  private:
609 
610  public:
611  void armMonitor(ThreadID tid, Addr address);
612  bool mwait(ThreadID tid, PacketPtr pkt);
613  void mwaitAtomic(ThreadID tid, ThreadContext *tc, BaseTLB *dtb);
615  {
616  assert(tid < numThreads);
617  return &addressMonitor[tid];
618  }
619 
620  bool waitForRemoteGDB() const;
621 
623 
624  // Enables CPU to enter power gating on a configurable cycle count
625  protected:
626  void enterPwrGating();
627 
629  const bool powerGatingOnIdle;
631 };
632 
633 #endif // THE_ISA == NULL_ISA
634 
635 #endif // __CPU_BASE_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:75
uint32_t taskId() const
Get cpu task id.
Definition: base.hh:207
virtual void unserializeThread(CheckpointIn &cp, ThreadID tid)
Unserialize one thread.
Definition: base.hh:431
Counter lastNumInst
Definition: base.hh:92
MasterID _dataMasterId
data side request id that must be placed in all requests
Definition: base.hh:134
Ports are used to interface objects to each other.
Definition: port.hh:60
BaseCPUParams Params
Definition: base.hh:310
Bitfield< 30, 0 > index
bool waiting
Definition: base.hh:84
Tick functionEntryTick
Definition: base.hh:564
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
AddressMonitor * getCpuAddrMonitor(ThreadID tid)
Definition: base.hh:614
Tick interval()
Definition: base.hh:102
ProbePoints::PMUUPtr ppRetiredStores
Retired store instructions.
Definition: base.hh:500
const std::string & name()
Definition: trace.cc:54
CheckerCPU class.
Definition: cpu.hh:87
Bitfield< 7 > i
const PortID InvalidPortID
Definition: types.hh:238
Trace::InstTracer * getTracer()
Provide access to the tracer pointer.
Definition: base.hh:282
void traceFunctions(Addr pc)
Definition: base.hh:572
const unsigned int _cacheLineSize
Cache the cache line size that we get from the system.
Definition: base.hh:151
Tick instCnt
Instruction count used for SPARC misc register.
Definition: base.hh:115
std::vector< BaseInterrupts * > interrupts
Definition: base.hh:222
void takeOverFrom(ThreadContext &ntc, ThreadContext &otc)
Copy state between thread contexts in preparation for CPU handover.
void notify(const Arg &arg)
called at the ProbePoint call site, passes arg to each listener.
Definition: probe.hh:288
Stats::Scalar numWorkItemsCompleted
Definition: base.hh:605
EventFunctionWrapper enterPwrGatingEvent
Definition: base.hh:630
MasterID _instMasterId
instruction side request id that must be placed in all requests
Definition: base.hh:131
bool armed
Definition: base.hh:80
Addr pAddr
Definition: base.hh:82
void clearInterrupt(ThreadID tid, int int_num, int index)
Definition: base.hh:246
Cycles previousCycle
Definition: base.hh:528
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:136
BaseCPU * cpu
Definition: base.hh:93
bool switchedOut() const
Determine if the CPU is switched out.
Definition: base.hh:367
bool _switchedOut
Is the CPU switched out or active?
Definition: base.hh:148
void workItemEnd()
Definition: base.hh:215
Definition: system.hh:77
void clearInterrupts(ThreadID tid)
Definition: base.hh:252
System * system
Definition: base.hh:386
Definition: cprintf.cc:42
unsigned numContexts()
Get the number of thread contexts available.
Definition: base.hh:301
bool gotWakeup
Definition: base.hh:85
int cpuId() const
Reads this CPU&#39;s ID.
Definition: base.hh:183
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:2508
STL vector class.
Definition: stl.hh:40
Bitfield< 33 > id
static Counter numSimulatedInsts()
Definition: base.hh:579
static Counter numSimulatedOps()
Definition: base.hh:590
uint32_t MachInst
Definition: types.hh:40
const uint32_t _socketId
Each cpu will have a socket ID that corresponds to its physical location in the system.
Definition: base.hh:128
virtual void serializeThread(CheckpointOut &cp, ThreadID tid) const
Serialize a single thread.
Definition: base.hh:423
void taskId(uint32_t id)
Set cpu task id.
Definition: base.hh:209
ProbePoints::PMUUPtr ppActiveCycles
CPU cycle counter, only counts if any thread contexts is active.
Definition: base.hh:509
std::vector< ThreadContext * > threadContexts
Definition: base.hh:267
Definition: tlb.hh:52
Tick instCount()
Definition: base.hh:217
Bitfield< 4 > pc
Tick _interval
Definition: base.hh:91
std::unique_ptr< PMU > PMUUPtr
Definition: pmu.hh:57
MasterID dataMasterId() const
Reads this CPU&#39;s unique data requestor ID.
Definition: base.hh:189
uint64_t Tick
Tick count type.
Definition: types.hh:63
static int numSimulatedCPUs()
Definition: base.hh:578
void updateCycleCounters(CPUState state)
base method keeping track of cycle progression
Definition: base.hh:532
ProbePointArg< bool > * ppSleeping
ProbePoint that signals transitions of threadContexts sets.
Definition: base.hh:519
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
EventFunctionWrapper * profileEvent
Definition: base.hh:264
bool checkInterrupts(ThreadContext *tc) const
Definition: base.hh:258
virtual PortProxy::SendFunctionalFunc getSendFunctional()
Returns a sendFunctional delegate for use with port proxies.
Definition: base.hh:167
TheISA::MicrocodeRom microcodeRom
Definition: base.hh:219
ClockedObject declaration and implementation.
bool doMonitor(PacketPtr pkt)
Definition: base.cc:741
ProbePoints::PMUUPtr ppRetiredInstsPC
Definition: base.hh:495
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
int _cpuId
Definition: base.hh:121
Cycles syscallRetryLatency
Definition: base.hh:622
std::vector< AddressMonitor > addressMonitor
Definition: base.hh:608
bool functionTracingEnabled
Definition: base.hh:560
virtual void verifyMemoryMode() const
Verify that the system is in a memory mode supported by the CPU.
Definition: base.hh:378
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
uint32_t _pid
The current OS process ID that is executing on this processor.
Definition: base.hh:145
uint16_t MasterID
Definition: request.hh:86
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:255
Addr vAddr
Definition: base.hh:81
const FlagsType total
Print the total.
Definition: info.hh:51
void repeatEvent(bool repeat)
Definition: base.hh:104
ProbePoints::PMUUPtr ppAllCycles
CPU cycle counter even if any thread Context is suspended.
Definition: base.hh:506
const bool powerGatingOnIdle
Definition: base.hh:629
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:227
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: base.hh:391
static std::vector< BaseCPU * > cpuList
Static global cpu list.
Definition: base.hh:569
void interval(Tick ival)
Definition: base.hh:101
std::function< void(PacketPtr pkt)> SendFunctionalFunc
Definition: port_proxy.hh:85
std::ostream CheckpointOut
Definition: serialize.hh:68
Definition: eventq.hh:189
CPUState previousState
Definition: base.hh:529
ProbePoints::PMUUPtr ppRetiredBranches
Retired branches (any type)
Definition: base.hh:503
virtual int threadId() const =0
uint32_t socketId() const
Reads this CPU&#39;s Socket ID.
Definition: base.hh:186
ThreadID contextToThread(ContextID cid)
Convert ContextID to threadID.
Definition: base.hh:306
virtual ThreadContext * getContext(int tn)
Given a thread num get tho thread context for it.
Definition: base.hh:298
ProbePoints::PMUUPtr ppRetiredLoads
Retired load instructions.
Definition: base.hh:498
Stats::Scalar numCycles
Definition: base.hh:603
BaseInterrupts * getInterruptController(ThreadID tid)
Definition: base.hh:226
uint32_t _taskId
An intrenal representation of a task identifier within gem5.
Definition: base.hh:141
Trace::InstTracer * tracer
Definition: base.hh:269
void unserialize(ThreadContext &tc, CheckpointIn &cp)
AddressMonitor()
Definition: base.cc:735
Addr currentFunctionEnd
Definition: base.hh:563
const Cycles pwrGatingLatency
Definition: base.hh:628
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
void setPid(uint32_t pid)
Definition: base.hh:212
uint64_t val
Definition: base.hh:83
void workItemBegin()
Definition: base.hh:214
const Params * params() const
Definition: base.hh:311
void postInterrupt(ThreadID tid, int int_num, int index)
Definition: base.hh:238
CPUState
Definition: base.hh:522
ProbePoints::PMUUPtr ppRetiredInsts
Instruction commit probe point.
Definition: base.hh:494
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
std::ostream * functionTraceStream
Definition: base.hh:561
const FlagsType init
This Stat is Initialized.
Definition: info.hh:47
MasterID instMasterId() const
Reads this CPU&#39;s unique instruction requestor ID.
Definition: base.hh:191
uint32_t getPid() const
Definition: base.hh:211
Stats::Scalar numWorkItemsStarted
Definition: base.hh:604
Addr currentFunctionStart
Definition: base.hh:562
bool _repeatEvent
Definition: base.hh:94

Generated on Fri Feb 28 2020 16:26:58 for gem5 by doxygen 1.8.13