gem5  v20.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 
42 #ifndef __SYSTEM_HH__
43 #define __SYSTEM_HH__
44 
45 #include <string>
46 #include <unordered_map>
47 #include <utility>
48 #include <vector>
49 
50 #include "arch/isa_traits.hh"
52 #include "base/loader/symtab.hh"
53 #include "base/statistics.hh"
54 #include "config/the_isa.hh"
55 #include "cpu/pc_event.hh"
56 #include "enums/MemoryMode.hh"
57 #include "mem/mem_master.hh"
58 #include "mem/physical.hh"
59 #include "mem/port.hh"
60 #include "mem/port_proxy.hh"
61 #include "params/System.hh"
62 #include "sim/futex_map.hh"
63 #include "sim/redirect_path.hh"
64 #include "sim/se_signal.hh"
65 #include "sim/sim_object.hh"
66 #include "sim/workload.hh"
67 
68 class BaseRemoteGDB;
69 class KvmVM;
70 class ThreadContext;
71 
72 class System : public SimObject, public PCEventScope
73 {
74  private:
75 
81  class SystemPort : public MasterPort
82  {
83  public:
84 
88  SystemPort(const std::string &_name, SimObject *_owner)
89  : MasterPort(_name, _owner)
90  { }
91  bool recvTimingResp(PacketPtr pkt) override
92  { panic("SystemPort does not receive timing!\n"); return false; }
93  void recvReqRetry() override
94  { panic("SystemPort does not expect retry!\n"); }
95  };
96 
99 
100  public:
101 
102  void init() override;
103  void startup() override;
104 
114 
118  Port &getPort(const std::string &if_name,
119  PortID idx=InvalidPortID) override;
120 
131  bool isAtomicMode() const {
132  return memoryMode == Enums::atomic ||
133  memoryMode == Enums::atomic_noncaching;
134  }
135 
142  bool isTimingMode() const {
143  return memoryMode == Enums::timing;
144  }
145 
152  bool bypassCaches() const {
153  return memoryMode == Enums::atomic_noncaching;
154  }
165  Enums::MemoryMode getMemoryMode() const { return memoryMode; }
166 
174  void setMemoryMode(Enums::MemoryMode mode);
180  unsigned int cacheLineSize() const { return _cacheLineSize; }
181 
184 
185  ThreadContext *
187  {
188  return threadContexts[tid];
189  }
190 
191  const bool multiThread;
192 
193  using SimObject::schedule;
194 
195  bool schedule(PCEvent *event) override;
196  bool remove(PCEvent *event) override;
197 
198  unsigned numContexts() const { return threadContexts.size(); }
199 
202  int numRunningContexts();
203 
205 
206  uint64_t init_param;
207 
211 
213  Workload *workload = nullptr;
214 
215  public:
221  return kvmVM;
222  }
223 
225  bool validKvmEnvironment() const;
226 
229 
231  Addr freeMemSize() const;
232 
234  Addr memSize() const;
235 
243  bool isMemAddr(Addr addr) const;
244 
248  Arch getArch() const { return Arch::TheISA; }
249 
253  ByteOrder
255  {
256 #if THE_ISA != NULL_ISA
257  return TheISA::GuestByteOrder;
258 #else
259  panic("The NULL ISA has no endianness.");
260 #endif
261  }
262 
266  Addr getPageBytes() const { return TheISA::PageBytes; }
267 
271  Addr getPageShift() const { return TheISA::PageShift; }
272 
277 
278  protected:
279 
280  KvmVM *const kvmVM;
281 
283 
284  Enums::MemoryMode memoryMode;
285 
286  const unsigned int _cacheLineSize;
287 
288  uint64_t workItemsBegin;
289  uint64_t workItemsEnd;
290  uint32_t numWorkIds;
292 
299 
301 
302  protected:
306  std::string stripSystemName(const std::string& master_name) const;
307 
308  public:
309 
342  MasterID getMasterId(const SimObject* master,
343  std::string submaster = std::string());
344 
353  MasterID getGlobalMasterId(const std::string& master_name);
354 
358  std::string getMasterName(MasterID master_id);
359 
364  MasterID lookupMasterId(const SimObject* obj) const;
365 
370  MasterID lookupMasterId(const std::string& name) const;
371 
373  MasterID maxMasters() { return masters.size(); }
374 
375  protected:
377  MasterID _getMasterId(const SimObject* master,
378  const std::string& master_name);
379 
384  std::string leafMasterName(const SimObject* master,
385  const std::string& submaster);
386 
387  public:
388 
389  void regStats() override;
394  uint64_t
396  {
397  return ++workItemsBegin;
398  }
399 
404  uint64_t
406  {
407  return ++workItemsEnd;
408  }
409 
415  int
417  {
418  int count = 0;
419  assert(index < activeCpus.size());
420  activeCpus[index] = true;
421  for (std::vector<bool>::iterator i = activeCpus.begin();
422  i < activeCpus.end(); i++) {
423  if (*i) count++;
424  }
425  return count;
426  }
427 
428  inline void workItemBegin(uint32_t tid, uint32_t workid)
429  {
430  std::pair<uint32_t,uint32_t> p(tid, workid);
432  }
433 
434  void workItemEnd(uint32_t tid, uint32_t workid);
435 
436  public:
438  bool breakpoint();
439 
440  public:
441  typedef SystemParams Params;
442 
443  protected:
444  Params *_params;
445 
451 
452  public:
453  System(Params *p);
454  ~System();
455 
456  const Params *params() const { return (const Params *)_params; }
457 
462  const AddrRange &m5opRange() const { return _m5opRange; }
463 
464  public:
465 
468  Addr allocPhysPages(int npages);
469 
471  ContextID assigned = InvalidContextID);
472  void replaceThreadContext(ThreadContext *tc, ContextID context_id);
473 
474  void serialize(CheckpointOut &cp) const override;
475  void unserialize(CheckpointIn &cp) override;
476 
477  void drainResume() override;
478 
479  public:
481  std::map<std::pair<uint32_t,uint32_t>, Tick> lastWorkItemStarted;
482  std::map<uint32_t, Stats::Histogram*> workItemStats;
483 
485  //
486  // STATIC GLOBAL SYSTEM LIST
487  //
489 
491  static int numSystemsRunning;
492 
493  static void printSystems();
494 
496 
497  static const int maxPID = 32768;
498 
500  std::set<int> PIDs;
501 
502  // By convention, all signals are owned by the receiving process. The
503  // receiver will delete the signal upon reception.
505 
506  // Used by syscall-emulation mode. This member contains paths which need
507  // to be redirected to the faux-filesystem (a duplicate filesystem
508  // intended to replace certain files on the host filesystem).
510 };
511 
512 void printSystems();
513 
514 #endif // __SYSTEM_HH__
bool schedule(PCEvent *event) override
Definition: system.cc:255
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:71
count
Definition: misc.hh:703
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
FutexMap futexMap
Definition: system.hh:495
Ports are used to interface objects to each other.
Definition: port.hh:56
ThermalModel * getThermalModel() const
The thermal model used for this system (if any).
Definition: system.hh:276
Bitfield< 30, 0 > index
Bitfield< 7 > i
const PortID InvalidPortID
Definition: types.hh:236
std::string getMasterName(MasterID master_id)
Get the name of an object for a given request id.
Definition: system.cc:541
Enums::MemoryMode memoryMode
Definition: system.hh:284
ContextID registerThreadContext(ThreadContext *tc, ContextID assigned=InvalidContextID)
Definition: system.cc:206
Bitfield< 23, 20 > atomic
std::vector< RedirectPath * > redirectPaths
Definition: system.hh:509
MasterPort & getSystemPort()
Get a reference to the system port that can be used by non-structural simulation objects like process...
Definition: system.hh:113
const Addr PageShift
Definition: isa_traits.hh:55
System(Params *p)
Definition: system.cc:85
const Params * params() const
Definition: system.hh:456
Addr freeMemSize() const
Amount of physical memory that is still free.
Definition: system.cc:348
SystemParams Params
Definition: system.hh:441
static void printSystems()
Definition: system.cc:418
ip6_addr_t addr
Definition: inet.hh:330
uint64_t incWorkItemsEnd()
Called by pseudo_inst to track the number of work items completed by this system. ...
Definition: system.hh:405
PhysicalMemory physmem
Definition: system.hh:282
Addr allocPhysPages(int npages)
Allocate npages contiguous unused physical pages.
Definition: system.cc:323
void workItemEnd(uint32_t tid, uint32_t workid)
Definition: system.cc:401
Definition: system.hh:72
Addr getPageShift() const
Get the number of bits worth of in-page address for the ISA.
Definition: system.hh:271
const bool multiThread
Definition: system.hh:191
SystemPort _systemPort
Definition: system.hh:98
ByteOrder getGuestByteOrder() const
Get the guest byte order.
Definition: system.hh:254
Definition: cprintf.cc:40
Bitfield< 4, 0 > mode
std::list< PCEvent * > liveEvents
Definition: system.hh:97
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Declaration of Statistics objects.
STL vector class.
Definition: stl.hh:37
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: system.cc:152
int numRunningContexts()
Return number of running (non-halted) thread contexts in system.
Definition: system.cc:275
ThreadContext * getThreadContext(ContextID tid) const
Definition: system.hh:186
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: system.cc:376
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:210
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:68
void regStats() override
Callback to set stat parameters.
Definition: system.cc:385
PortProxy Object Declaration.
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
Definition: system.hh:91
bool isAtomicMode() const
Is the system in atomic mode?
Definition: system.hh:131
Tick curTick()
The current simulated tick.
Definition: core.hh:44
Addr memSize() const
Amount of physical memory that exists.
Definition: system.cc:342
static const int maxPID
Definition: system.hh:497
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:486
void drainResume() override
Resume execution after a successful drain.
Definition: system.cc:360
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:354
uint64_t Tick
Tick count type.
Definition: types.hh:61
std::set< int > PIDs
Process set to track which PIDs have already been allocated.
Definition: system.hh:500
const unsigned int _cacheLineSize
Definition: system.hh:286
int markWorkItem(int index)
Called by pseudo_inst to mark the cpus actively executing work items.
Definition: system.hh:416
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: system.cc:366
ByteOrder
Definition: types.hh:245
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:492
void recvReqRetry() override
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
Definition: system.hh:93
const AddrRange _m5opRange
Range for memory-mapped m5 pseudo ops.
Definition: system.hh:450
Addr pagePtr
Definition: system.hh:204
KvmVM * getKvmVM()
Get a pointer to the Kernel Virtual Machine (KVM) SimObject, if present.
Definition: system.hh:220
std::vector< ThreadContext * > threadContexts
Definition: system.hh:182
ThermalModel * thermalModel
Definition: system.hh:300
unsigned numContexts() const
Definition: system.hh:198
void schedule(Event &event, Tick when)
Definition: eventq.hh:934
MasterInfo declaration.
Port Object Declaration.
ThreadContext * findFreeContext()
Definition: system.cc:245
std::map< uint32_t, Stats::Histogram * > workItemStats
Definition: system.hh:482
STL list class.
Definition: stl.hh:51
Workload * workload
OS kernel.
Definition: system.hh:213
~System()
Definition: system.cc:145
The physical memory encapsulates all memories in the system and provides basic functionality for acce...
Definition: physical.hh:110
Enums::MemoryMode getMemoryMode() const
Get the memory mode of the system.
Definition: system.hh:165
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
uint16_t MasterID
Definition: request.hh:84
int64_t Counter
Statistics counter type.
Definition: types.hh:56
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
Bitfield< 10, 5 > event
std::list< BasicSignal > signalList
Definition: system.hh:504
std::vector< bool > activeCpus
Definition: system.hh:291
uint32_t numWorkIds
Definition: system.hh:290
MasterID maxMasters()
Get the number of masters registered in the system.
Definition: system.hh:373
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:449
SystemPort(const std::string &_name, SimObject *_owner)
Create a system port with a name and an owner.
Definition: system.hh:88
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:80
const AddrRange & m5opRange() const
Range used by memory-mapped m5 pseudo-ops if enabled.
Definition: system.hh:462
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:298
bool validKvmEnvironment() const
Verify gem5 configuration will support KVM emulation.
Definition: system.cc:305
Params * _params
Definition: system.hh:444
KVM VM container.
Definition: vm.hh:289
uint64_t incWorkItemsBegin()
Called by pseudo_inst to track the number of work items started by this system.
Definition: system.hh:395
std::ostream CheckpointOut
Definition: serialize.hh:63
static int numSystemsRunning
Definition: system.hh:491
void workItemBegin(uint32_t tid, uint32_t workid)
Definition: system.hh:428
bool bypassCaches() const
Should caches be bypassed?
Definition: system.hh:152
Private class for the system port which is only used as a master for debug access and for non-structu...
Definition: system.hh:81
MasterID _getMasterId(const SimObject *master, const std::string &master_name)
helper function for getMasterId
Definition: system.cc:499
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:102
FutexMap class holds a map of all futexes used in the system.
Definition: futex_map.hh:117
PhysicalMemory & getPhysMem()
Get a pointer to access the physical memory of the system.
Definition: system.hh:228
const ContextID InvalidContextID
Definition: types.hh:230
void replaceThreadContext(ThreadContext *tc, ContextID context_id)
Definition: system.cc:288
const Addr PageBytes
Definition: isa_traits.hh:56
uint64_t workItemsBegin
Definition: system.hh:288
std::map< std::pair< uint32_t, uint32_t >, Tick > lastWorkItemStarted
Definition: system.hh:481
std::vector< BaseRemoteGDB * > remoteGDB
Definition: system.hh:437
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:235
std::string stripSystemName(const std::string &master_name) const
Strips off the system name from a master name.
Definition: system.cc:439
const ByteOrder GuestByteOrder
Definition: isa_traits.hh:51
bool isTimingMode() const
Is the system in timing mode?
Definition: system.hh:142
bool breakpoint()
Definition: system.cc:198
KvmVM *const kvmVM
Definition: system.hh:280
Bitfield< 0 > p
uint64_t init_param
Definition: system.hh:206
Abstract superclass for simulation objects.
Definition: sim_object.hh:93
int ContextID
Globally unique thread context ID.
Definition: types.hh:229
void startup() override
startup() is the final initialization call before simulation.
Definition: system.cc:160
uint64_t workItemsEnd
Definition: system.hh:289
Counter totalNumInsts
Definition: system.hh:480
Addr getPageBytes() const
Get the page bytes for the ISA.
Definition: system.hh:266
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Additional function to return the Port of a memory object.
Definition: system.cc:185
Arch getArch() const
Get the architecture.
Definition: system.hh:248
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:529
void setMemoryMode(Enums::MemoryMode mode)
Change the memory mode of the system.
Definition: system.cc:192
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: system.hh:180
static std::vector< System * > systemList
Definition: system.hh:490

Generated on Thu May 28 2020 16:11:02 for gem5 by doxygen 1.8.13