gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
system.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 2014, 2018 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  * Lisa Hsu
43  * Nathan Binkert
44  * Rick Strong
45  */
46 
47 #ifndef __SYSTEM_HH__
48 #define __SYSTEM_HH__
49 
50 #include <string>
51 #include <unordered_map>
52 #include <utility>
53 #include <vector>
54 
55 #include "arch/isa_traits.hh"
57 #include "base/loader/symtab.hh"
58 #include "base/statistics.hh"
59 #include "config/the_isa.hh"
60 #include "cpu/pc_event.hh"
61 #include "enums/MemoryMode.hh"
62 #include "mem/mem_master.hh"
63 #include "mem/physical.hh"
64 #include "mem/port.hh"
65 #include "mem/port_proxy.hh"
66 #include "params/System.hh"
67 #include "sim/futex_map.hh"
68 #include "sim/redirect_path.hh"
69 #include "sim/se_signal.hh"
70 #include "sim/sim_object.hh"
71 
72 class BaseRemoteGDB;
73 class KvmVM;
74 class ObjectFile;
75 class ThreadContext;
76 
77 class System : public SimObject, public PCEventScope
78 {
79  private:
80 
86  class SystemPort : public MasterPort
87  {
88  public:
89 
93  SystemPort(const std::string &_name, SimObject *_owner)
94  : MasterPort(_name, _owner)
95  { }
96  bool recvTimingResp(PacketPtr pkt) override
97  { panic("SystemPort does not receive timing!\n"); return false; }
98  void recvReqRetry() override
99  { panic("SystemPort does not expect retry!\n"); }
100  };
101 
104 
105  public:
106 
111  void init() override;
112 
122 
126  Port &getPort(const std::string &if_name,
127  PortID idx=InvalidPortID) override;
128 
139  bool isAtomicMode() const {
140  return memoryMode == Enums::atomic ||
141  memoryMode == Enums::atomic_noncaching;
142  }
143 
150  bool isTimingMode() const {
151  return memoryMode == Enums::timing;
152  }
153 
160  bool bypassCaches() const {
161  return memoryMode == Enums::atomic_noncaching;
162  }
173  Enums::MemoryMode getMemoryMode() const { return memoryMode; }
174 
182  void setMemoryMode(Enums::MemoryMode mode);
188  unsigned int cacheLineSize() const { return _cacheLineSize; }
189 
192 
193  ThreadContext *
195  {
196  return threadContexts[tid];
197  }
198 
199  const bool multiThread;
200 
201  using SimObject::schedule;
202 
203  bool schedule(PCEvent *event) override;
204  bool remove(PCEvent *event) override;
205 
206  unsigned numContexts() const { return threadContexts.size(); }
207 
210  int numRunningContexts();
211 
213 
214  uint64_t init_param;
215 
219 
222 
226 
229 
232 
235 
238 
246 
253 
254  public:
260  return kvmVM;
261  }
262 
264  bool validKvmEnvironment() const;
265 
268 
270  Addr freeMemSize() const;
271 
273  Addr memSize() const;
274 
282  bool isMemAddr(Addr addr) const;
283 
287  Arch getArch() const { return Arch::TheISA; }
288 
292  ByteOrder
294  {
295 #if THE_ISA != NULL_ISA
296  return TheISA::GuestByteOrder;
297 #else
298  panic("The NULL ISA has no endianness.");
299 #endif
300  }
301 
305  Addr getPageBytes() const { return TheISA::PageBytes; }
306 
310  Addr getPageShift() const { return TheISA::PageShift; }
311 
316 
317  protected:
318 
319  KvmVM *const kvmVM;
320 
322 
323  Enums::MemoryMode memoryMode;
324 
325  const unsigned int _cacheLineSize;
326 
327  uint64_t workItemsBegin;
328  uint64_t workItemsEnd;
329  uint32_t numWorkIds;
331 
338 
340 
341  protected:
345  std::string stripSystemName(const std::string& master_name) const;
346 
347  public:
348 
381  MasterID getMasterId(const SimObject* master,
382  std::string submaster = std::string());
383 
392  MasterID getGlobalMasterId(const std::string& master_name);
393 
397  std::string getMasterName(MasterID master_id);
398 
403  MasterID lookupMasterId(const SimObject* obj) const;
404 
409  MasterID lookupMasterId(const std::string& name) const;
410 
412  MasterID maxMasters() { return masters.size(); }
413 
414  protected:
416  MasterID _getMasterId(const SimObject* master,
417  const std::string& master_name);
418 
423  std::string leafMasterName(const SimObject* master,
424  const std::string& submaster);
425 
426  public:
427 
428  void regStats() override;
433  uint64_t
435  {
436  return ++workItemsBegin;
437  }
438 
443  uint64_t
445  {
446  return ++workItemsEnd;
447  }
448 
454  int
456  {
457  int count = 0;
458  assert(index < activeCpus.size());
459  activeCpus[index] = true;
460  for (std::vector<bool>::iterator i = activeCpus.begin();
461  i < activeCpus.end(); i++) {
462  if (*i) count++;
463  }
464  return count;
465  }
466 
467  inline void workItemBegin(uint32_t tid, uint32_t workid)
468  {
469  std::pair<uint32_t,uint32_t> p(tid, workid);
471  }
472 
473  void workItemEnd(uint32_t tid, uint32_t workid);
474 
480  virtual Addr fixFuncEventAddr(Addr addr)
481  {
482  panic("Base fixFuncEventAddr not implemented.\n");
483  }
484 
498  template <class T, typename... Args>
499  T *addFuncEvent(const SymbolTable *symtab, const char *lbl,
500  const std::string &desc, Args... args)
501  {
502  Addr addr M5_VAR_USED = 0; // initialize only to avoid compiler warning
503 
504  if (symtab->findAddress(lbl, addr)) {
505  T *ev = new T(this, desc, fixFuncEventAddr(addr),
506  std::forward<Args>(args)...);
507  return ev;
508  }
509 
510  return NULL;
511  }
512 
513  template <class T>
514  T *addFuncEvent(const SymbolTable *symtab, const char *lbl)
515  {
516  return addFuncEvent<T>(symtab, lbl, lbl);
517  }
518 
519  template <class T, typename... Args>
520  T *addFuncEventOrPanic(const SymbolTable *symtab, const char *lbl,
521  Args... args)
522  {
523  T *e(addFuncEvent<T>(symtab, lbl, std::forward<Args>(args)...));
524  if (!e)
525  panic("Failed to find symbol '%s'", lbl);
526  return e;
527  }
545  template <class T, typename... Args>
546  T *addKernelFuncEvent(const char *lbl, Args... args)
547  {
548  return addFuncEvent<T>(kernelSymtab, lbl,
549  std::forward<Args>(args)...);
550  }
551 
552  template <class T, typename... Args>
553  T *addKernelFuncEventOrPanic(const char *lbl, Args... args)
554  {
555  T *e(addFuncEvent<T>(kernelSymtab, lbl,
556  std::forward<Args>(args)...));
557  if (!e)
558  panic("Failed to find kernel symbol '%s'", lbl);
559  return e;
560  }
563  public:
565  bool breakpoint();
566 
567  public:
568  typedef SystemParams Params;
569 
570  protected:
571  Params *_params;
572 
578 
579  public:
580  System(Params *p);
581  ~System();
582 
583  void initState() override;
584 
585  const Params *params() const { return (const Params *)_params; }
586 
591  const AddrRange &m5opRange() const { return _m5opRange; }
592 
593  public:
594 
599  Addr getKernelStart() const { return kernelStart; }
600 
605  Addr getKernelEnd() const { return kernelEnd; }
606 
611  Addr getKernelEntry() const { return kernelEntry; }
612 
615  Addr allocPhysPages(int npages);
616 
618  ContextID assigned = InvalidContextID);
619  void replaceThreadContext(ThreadContext *tc, ContextID context_id);
620 
621  void serialize(CheckpointOut &cp) const override;
622  void unserialize(CheckpointIn &cp) override;
623 
624  void drainResume() override;
625 
626  public:
628  std::map<std::pair<uint32_t,uint32_t>, Tick> lastWorkItemStarted;
629  std::map<uint32_t, Stats::Histogram*> workItemStats;
630 
632  //
633  // STATIC GLOBAL SYSTEM LIST
634  //
636 
638  static int numSystemsRunning;
639 
640  static void printSystems();
641 
643 
644  static const int maxPID = 32768;
645 
647  std::set<int> PIDs;
648 
649  // By convention, all signals are owned by the receiving process. The
650  // receiver will delete the signal upon reception.
652 
653  // Used by syscall-emulation mode. This member contains paths which need
654  // to be redirected to the faux-filesystem (a duplicate filesystem
655  // intended to replace certain files on the host filesystem).
657 
658  protected:
659 
667  virtual void serializeSymtab(CheckpointOut &os) const {}
668 
676  virtual void unserializeSymtab(CheckpointIn &cp) {}
677 };
678 
679 void printSystems();
680 
681 #endif // __SYSTEM_HH__
bool schedule(PCEvent *event) override
Definition: system.cc:316
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:75
count
Definition: misc.hh:705
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
FutexMap futexMap
Definition: system.hh:642
T * addKernelFuncEventOrPanic(const char *lbl, Args... args)
Definition: system.hh:553
Ports are used to interface objects to each other.
Definition: port.hh:60
ThermalModel * getThermalModel() const
The thermal model used for this system (if any).
Definition: system.hh:315
Bitfield< 30, 0 > index
virtual void unserializeSymtab(CheckpointIn &cp)
If needed, unserialize additional symbol table entries for a specific subclass of this system...
Definition: system.hh:676
Addr getKernelEntry() const
Returns the address the entry point to the kernel code.
Definition: system.hh:611
Bitfield< 7 > i
const PortID InvalidPortID
Definition: types.hh:238
std::string getMasterName(MasterID master_id)
Get the name of an object for a given request id.
Definition: system.cc:652
Enums::MemoryMode memoryMode
Definition: system.hh:323
ContextID registerThreadContext(ThreadContext *tc, ContextID assigned=InvalidContextID)
Definition: system.cc:259
Bitfield< 23, 20 > atomic
std::vector< RedirectPath * > redirectPaths
Definition: system.hh:656
MasterPort & getSystemPort()
Get a reference to the system port that can be used by non-structural simulation objects like process...
Definition: system.hh:121
System(Params *p)
Definition: system.cc:91
const Params * params() const
Definition: system.hh:585
Addr freeMemSize() const
Amount of physical memory that is still free.
Definition: system.cc:453
SystemParams Params
Definition: system.hh:568
const Addr PageShift
Definition: isa_traits.hh:46
static void printSystems()
Definition: system.cc:529
ip6_addr_t addr
Definition: inet.hh:335
uint64_t incWorkItemsEnd()
Called by pseudo_inst to track the number of work items completed by this system. ...
Definition: system.hh:444
PhysicalMemory physmem
Definition: system.hh:321
Addr allocPhysPages(int npages)
Allocate npages contiguous unused physical pages.
Definition: system.cc:428
void workItemEnd(uint32_t tid, uint32_t workid)
Definition: system.cc:512
Definition: system.hh:77
Addr getPageShift() const
Get the number of bits worth of in-page address for the ISA.
Definition: system.hh:310
const bool multiThread
Definition: system.hh:199
SystemPort _systemPort
Definition: system.hh:103
ByteOrder getGuestByteOrder() const
Get the guest byte order.
Definition: system.hh:293
Definition: cprintf.cc:42
Bitfield< 4, 0 > mode
T * addFuncEvent(const SymbolTable *symtab, const char *lbl)
Definition: system.hh:514
std::list< PCEvent * > liveEvents
Definition: system.hh:102
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Declaration of Statistics objects.
Bitfield< 17 > os
Definition: misc.hh:805
const ByteOrder GuestByteOrder
Definition: isa_traits.hh:42
STL vector class.
Definition: stl.hh:40
void init() override
After all objects have been created and all ports are connected, check that the system port is connec...
Definition: system.cc:230
int numRunningContexts()
Return number of running (non-halted) thread contexts in system.
Definition: system.cc:336
ThreadContext * getThreadContext(ContextID tid) const
Definition: system.hh:194
Addr kernelStart
Beginning of kernel code.
Definition: system.hh:231
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: system.cc:484
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:218
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:72
void regStats() override
Callback to set stat parameters.
Definition: system.cc:496
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: system.cc:349
PortProxy Object Declaration.
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
Definition: system.hh:96
bool isAtomicMode() const
Is the system in atomic mode?
Definition: system.hh:139
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Addr memSize() const
Amount of physical memory that exists.
Definition: system.cc:447
static const int maxPID
Definition: system.hh:644
bool findAddress(const std::string &symbol, Addr &address) const
Definition: symtab.hh:97
MasterID getGlobalMasterId(const std::string &master_name)
Registers a GLOBAL MasterID, which is a MasterID not related to any particular SimObject; since no Si...
Definition: system.cc:597
Addr loadAddrMask
Mask that should be anded for binary/symbol loading.
Definition: system.hh:245
void drainResume() override
Resume execution after a successful drain.
Definition: system.cc:465
bool isMemAddr(Addr addr) const
Check if a physical address is within a range of a memory that is part of the global address map...
Definition: system.cc:459
uint64_t Tick
Tick count type.
Definition: types.hh:63
std::set< int > PIDs
Process set to track which PIDs have already been allocated.
Definition: system.hh:647
const unsigned int _cacheLineSize
Definition: system.hh:325
int markWorkItem(int index)
Called by pseudo_inst to mark the cpus actively executing work items.
Definition: system.hh:455
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: system.cc:471
ByteOrder
Definition: types.hh:247
MasterID getMasterId(const SimObject *master, std::string submaster=std::string())
Request an id used to create a request object in the system.
Definition: system.cc:603
void recvReqRetry() override
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
Definition: system.hh:98
const AddrRange _m5opRange
Range for memory-mapped m5 pseudo ops.
Definition: system.hh:577
Addr pagePtr
Definition: system.hh:212
KvmVM * getKvmVM()
Get a pointer to the Kernel Virtual Machine (KVM) SimObject, if present.
Definition: system.hh:259
std::vector< ThreadContext * > threadContexts
Definition: system.hh:190
ThermalModel * thermalModel
Definition: system.hh:339
unsigned numContexts() const
Definition: system.hh:206
Addr kernelEntry
Entry point in the kernel to start at.
Definition: system.hh:237
MasterInfo declaration.
Port Object Declaration.
ThreadContext * findFreeContext()
Definition: system.cc:306
std::map< uint32_t, Stats::Histogram * > workItemStats
Definition: system.hh:629
STL list class.
Definition: stl.hh:54
virtual Addr fixFuncEventAddr(Addr addr)
Fix up an address used to match PCs for hooking simulator events on to target function executions...
Definition: system.hh:480
Addr getKernelStart() const
Returns the address the kernel starts at.
Definition: system.hh:599
std::vector< ObjectFile * > kernelExtras
Additional object files.
Definition: system.hh:228
~System()
Definition: system.cc:220
The physical memory encapsulates all memories in the system and provides basic functionality for acce...
Definition: physical.hh:112
Enums::MemoryMode getMemoryMode() const
Get the memory mode of the system.
Definition: system.hh:173
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: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
Bitfield< 10, 5 > event
std::list< BasicSignal > signalList
Definition: system.hh:651
std::vector< bool > activeCpus
Definition: system.hh:330
SymbolTable * kernelSymtab
kernel symbol table
Definition: system.hh:221
const Addr PageBytes
Definition: isa_traits.hh:47
uint32_t numWorkIds
Definition: system.hh:329
MasterID maxMasters()
Get the number of masters registered in the system.
Definition: system.hh:412
MasterID lookupMasterId(const SimObject *obj) const
Looks up the MasterID for a given SimObject returns an invalid MasterID (invldMasterId) if not found...
Definition: system.cc:560
SystemPort(const std::string &_name, SimObject *_owner)
Create a system port with a name and an owner.
Definition: system.hh:93
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:82
Bitfield< 9 > e
ObjectFile * kernel
Object pointer for the kernel code.
Definition: system.hh:224
const AddrRange & m5opRange() const
Range used by memory-mapped m5 pseudo-ops if enabled.
Definition: system.hh:591
std::vector< MasterInfo > masters
This array is a per-system list of all devices capable of issuing a memory system request and an asso...
Definition: system.hh:337
bool validKvmEnvironment() const
Verify gem5 configuration will support KVM emulation.
Definition: system.cc:410
T * addFuncEvent(const SymbolTable *symtab, const char *lbl, const std::string &desc, Args... args)
Add a function-based event to the given function, to be looked up in the specified symbol table...
Definition: system.hh:499
Params * _params
Definition: system.hh:571
KVM VM container.
Definition: vm.hh:291
uint64_t incWorkItemsBegin()
Called by pseudo_inst to track the number of work items started by this system.
Definition: system.hh:434
std::ostream CheckpointOut
Definition: serialize.hh:68
static int numSystemsRunning
Definition: system.hh:638
T * addKernelFuncEvent(const char *lbl, Args... args)
Add a function-based event to a kernel symbol.
Definition: system.hh:546
void workItemBegin(uint32_t tid, uint32_t workid)
Definition: system.hh:467
bool bypassCaches() const
Should caches be bypassed?
Definition: system.hh:160
Private class for the system port which is only used as a master for debug access and for non-structu...
Definition: system.hh:86
MasterID _getMasterId(const SimObject *master, const std::string &master_name)
helper function for getMasterId
Definition: system.cc:610
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:106
FutexMap class holds a map of all futexes used in the system.
Definition: futex_map.hh:121
PhysicalMemory & getPhysMem()
Get a pointer to access the physical memory of the system.
Definition: system.hh:267
const ContextID InvalidContextID
Definition: types.hh:232
void replaceThreadContext(ThreadContext *tc, ContextID context_id)
Definition: system.cc:393
void schedule(Event &event, Tick when)
Definition: eventq.hh:744
virtual void serializeSymtab(CheckpointOut &os) const
If needed, serialize additional symbol table entries for a specific subclass of this system...
Definition: system.hh:667
uint64_t workItemsBegin
Definition: system.hh:327
std::map< std::pair< uint32_t, uint32_t >, Tick > lastWorkItemStarted
Definition: system.hh:628
std::vector< BaseRemoteGDB * > remoteGDB
Definition: system.hh:564
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
std::string stripSystemName(const std::string &master_name) const
Strips off the system name from a master name.
Definition: system.cc:550
MemoryImage kernelImage
Definition: system.hh:225
bool isTimingMode() const
Is the system in timing mode?
Definition: system.hh:150
bool breakpoint()
Definition: system.cc:251
Addr loadAddrOffset
Offset that should be used for binary/symbol loading.
Definition: system.hh:252
static const int NumArgumentRegs M5_VAR_USED
Definition: process.cc:84
KvmVM *const kvmVM
Definition: system.hh:319
Bitfield< 0 > p
uint64_t init_param
Definition: system.hh:214
Addr getKernelEnd() const
Returns the address the kernel ends at.
Definition: system.hh:605
T * addFuncEventOrPanic(const SymbolTable *symtab, const char *lbl, Args... args)
Definition: system.hh:520
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
Addr kernelEnd
End of kernel code.
Definition: system.hh:234
uint64_t workItemsEnd
Definition: system.hh:328
Counter totalNumInsts
Definition: system.hh:627
Addr getPageBytes() const
Get the page bytes for the ISA.
Definition: system.hh:305
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Additional function to return the Port of a memory object.
Definition: system.cc:238
Arch getArch() const
Get the architecture.
Definition: system.hh:287
std::string leafMasterName(const SimObject *master, const std::string &submaster)
Helper function for constructing the full (sub)master name by providing the root master and the relat...
Definition: system.cc:640
void setMemoryMode(Enums::MemoryMode mode)
Change the memory mode of the system.
Definition: system.cc:245
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: system.hh:188
static std::vector< System * > systemList
Definition: system.hh:637

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