gem5  v22.1.0.0
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 <set>
46 #include <string>
47 #include <unordered_map>
48 #include <utility>
49 #include <vector>
50 
52 #include "base/loader/symtab.hh"
53 #include "base/statistics.hh"
54 #include "cpu/pc_event.hh"
55 #include "enums/MemoryMode.hh"
56 #include "mem/mem_requestor.hh"
57 #include "mem/physical.hh"
58 #include "mem/port.hh"
59 #include "mem/port_proxy.hh"
60 #include "params/System.hh"
61 #include "sim/futex_map.hh"
62 #include "sim/redirect_path.hh"
63 #include "sim/se_signal.hh"
64 #include "sim/sim_object.hh"
65 #include "sim/workload.hh"
66 
67 namespace gem5
68 {
69 
70 class BaseRemoteGDB;
71 class KvmVM;
72 class ThreadContext;
73 
74 class System : public SimObject, public PCEventScope
75 {
76  private:
77 
83  class SystemPort : public RequestPort
84  {
85  public:
86 
90  SystemPort(const std::string &_name, SimObject *_owner)
91  : RequestPort(_name, _owner)
92  { }
93 
94  bool
95  recvTimingResp(PacketPtr pkt) override
96  {
97  panic("SystemPort does not receive timing!");
98  }
99 
100  void
101  recvReqRetry() override
102  {
103  panic("SystemPort does not expect retry!");
104  }
105  };
106 
109 
110  // Map of memory address ranges for devices with their own backing stores
111  std::unordered_map<RequestorID, std::vector<memory::AbstractMemory *>>
113 
114  public:
115 
116  class Threads
117  {
118  private:
119  struct Thread
120  {
121  ThreadContext *context = nullptr;
122  bool active = false;
123  Event *resumeEvent = nullptr;
124 
125  void resume();
126  std::string name() const;
127  void quiesce() const;
128  };
129 
131 
132  Thread &
134  {
135  assert(id < size());
136  return threads[id];
137  }
138 
139  const Thread &
140  thread(ContextID id) const
141  {
142  assert(id < size());
143  return threads[id];
144  }
145 
146  void insert(ThreadContext *tc);
147  void replace(ThreadContext *tc, ContextID id);
148 
149  friend class System;
150 
151  public:
153  {
154  private:
155  const Threads &threads;
156  int pos;
157 
158  friend class Threads;
159 
160  const_iterator(const Threads &_threads, int _pos) :
161  threads(_threads), pos(_pos)
162  {}
163 
164  public:
165  const_iterator(const const_iterator &) = default;
167 
168  using iterator_category = std::forward_iterator_tag;
170  using difference_type = int;
171  using pointer = const value_type *;
172  using reference = const value_type &;
173 
176  {
177  pos++;
178  return *this;
179  }
180 
183  {
184  return const_iterator(threads, pos++);
185  }
186 
189 
190  bool
191  operator == (const const_iterator &other) const
192  {
193  return &threads == &other.threads && pos == other.pos;
194  }
195 
196  bool
197  operator != (const const_iterator &other) const
198  {
199  return !(*this == other);
200  }
201  };
202 
204 
205  ThreadContext *
207  {
208  return thread(id).context;
209  }
210 
211  void markActive(ContextID id) { thread(id).active = true; }
212 
213  int size() const { return threads.size(); }
214  bool empty() const { return threads.empty(); }
215  int numRunning() const;
216  int
217  numActive() const
218  {
219  int count = 0;
220  for (auto &thread: threads) {
221  if (thread.active)
222  count++;
223  }
224  return count;
225  }
226 
227  void quiesce(ContextID id);
228  void quiesceTick(ContextID id, Tick when);
229 
230  const_iterator begin() const { return const_iterator(*this, 0); }
231  const_iterator end() const { return const_iterator(*this, size()); }
232  };
233 
243 
247  Port &getPort(const std::string &if_name,
248  PortID idx=InvalidPortID) override;
249 
260  bool
261  isAtomicMode() const
262  {
263  return memoryMode == enums::atomic ||
264  memoryMode == enums::atomic_noncaching;
265  }
266 
273  bool isTimingMode() const { return memoryMode == enums::timing; }
274 
281  bool
282  bypassCaches() const
283  {
284  return memoryMode == enums::atomic_noncaching;
285  }
296  enums::MemoryMode getMemoryMode() const { return memoryMode; }
297 
305  void setMemoryMode(enums::MemoryMode mode);
311  unsigned int cacheLineSize() const { return _cacheLineSize; }
312 
314 
315  const bool multiThread;
316 
317  using SimObject::schedule;
318 
319  bool schedule(PCEvent *event) override;
320  bool remove(PCEvent *event) override;
321 
322  uint64_t init_param;
323 
327 
329  Workload *workload = nullptr;
330 
331  public:
336  KvmVM *getKvmVM() const { return kvmVM; }
337 
342  void setKvmVM(KvmVM *const vm) { kvmVM = vm; }
343 
346  const memory::PhysicalMemory& getPhysMem() const { return physmem; }
347 
349  Addr memSize() const;
350 
358  bool isMemAddr(Addr addr) const;
359 
365  void addDeviceMemory(RequestorID requestorId,
366  memory::AbstractMemory *deviceMemory);
367 
373  bool isDeviceMemAddr(const PacketPtr& pkt) const;
374 
379 
380  /*
381  * Return the list of address ranges backed by a shadowed ROM.
382  *
383  * @return List of address ranges backed by a shadowed ROM
384  */
386 
390  ByteOrder
392  {
393  return workload->byteOrder();
394  }
395 
400 
401  protected:
402 
403  KvmVM *kvmVM = nullptr;
404 
406 
408 
409  enums::MemoryMode memoryMode;
410 
411  const unsigned int _cacheLineSize;
412 
413  uint64_t workItemsBegin = 0;
414  uint64_t workItemsEnd = 0;
415  uint32_t numWorkIds;
416 
423 
425 
426  protected:
430  std::string stripSystemName(const std::string& requestor_name) const;
431 
432  public:
433 
467  RequestorID getRequestorId(const SimObject* requestor,
468  std::string subrequestor={});
469 
478  RequestorID getGlobalRequestorId(const std::string& requestor_name);
479 
483  std::string getRequestorName(RequestorID requestor_id);
484 
489  RequestorID lookupRequestorId(const SimObject* obj) const;
490 
495  RequestorID lookupRequestorId(const std::string& name) const;
496 
498  RequestorID maxRequestors() { return requestors.size(); }
499 
500  protected:
502  RequestorID _getRequestorId(const SimObject* requestor,
503  const std::string& requestor_name);
504 
509  std::string leafRequestorName(const SimObject* requestor,
510  const std::string& subrequestor);
511 
512  public:
513 
514  void regStats() override;
519  uint64_t
521  {
522  return ++workItemsBegin;
523  }
524 
529  uint64_t
531  {
532  return ++workItemsEnd;
533  }
534 
540  int
542  {
544  return threads.numActive();
545  }
546 
547  void
548  workItemBegin(uint32_t tid, uint32_t workid)
549  {
550  std::pair<uint32_t, uint32_t> p(tid, workid);
552  }
553 
554  void workItemEnd(uint32_t tid, uint32_t workid);
555 
556  /* Returns whether we successfully trapped into GDB. */
557  bool trapToGdb(int signal, ContextID ctx_id) const;
558 
559  protected:
565 
566  public:
568 
569  System(const Params &p);
570  ~System();
571 
576  const AddrRange &m5opRange() const { return _m5opRange; }
577 
578  public:
579 
581  void replaceThreadContext(ThreadContext *tc, ContextID context_id);
582 
583  void serialize(CheckpointOut &cp) const override;
584  void unserialize(CheckpointIn &cp) override;
585 
586  public:
587  std::map<std::pair<uint32_t, uint32_t>, Tick> lastWorkItemStarted;
588  std::map<uint32_t, statistics::Histogram*> workItemStats;
589 
591  //
592  // STATIC GLOBAL SYSTEM LIST
593  //
595 
597  static int numSystemsRunning;
598 
599  static void printSystems();
600 
602 
603  static const int maxPID = 32768;
604 
606  std::set<int> PIDs;
607 
608  // By convention, all signals are owned by the receiving process. The
609  // receiver will delete the signal upon reception.
611 
612  // Used by syscall-emulation mode. This member contains paths which need
613  // to be redirected to the faux-filesystem (a duplicate filesystem
614  // intended to replace certain files on the host filesystem).
616 };
617 
618 void printSystems();
619 
620 } // namespace gem5
621 
622 #endif // __SYSTEM_HH__
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:82
FutexMap class holds a map of all futexes used in the system.
Definition: futex_map.hh:110
KVM VM container.
Definition: vm.hh:302
const std::string _name
Definition: named.hh:41
virtual std::string name() const
Definition: named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:87
Ports are used to interface objects to each other.
Definition: port.hh:62
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:79
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
SimObjectParams Params
Definition: sim_object.hh:170
Private class for the system port which is only used as a requestor for debug access and for non-stru...
Definition: system.hh:84
void recvReqRetry() override
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
Definition: system.hh:101
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
Definition: system.hh:95
SystemPort(const std::string &_name, SimObject *_owner)
Create a system port with a name and an owner.
Definition: system.hh:90
bool operator==(const const_iterator &other) const
Definition: system.hh:191
std::forward_iterator_tag iterator_category
Definition: system.hh:168
const_iterator(const const_iterator &)=default
const_iterator & operator=(const const_iterator &)=default
const_iterator(const Threads &_threads, int _pos)
Definition: system.hh:160
bool operator!=(const const_iterator &other) const
Definition: system.hh:197
int numActive() const
Definition: system.hh:217
const_iterator end() const
Definition: system.hh:231
void quiesceTick(ContextID id, Tick when)
Definition: system.cc:154
ThreadContext * operator[](ContextID id) const
Definition: system.hh:206
void markActive(ContextID id)
Definition: system.hh:211
const_iterator begin() const
Definition: system.hh:230
void quiesce(ContextID id)
Definition: system.cc:145
int size() const
Definition: system.hh:213
bool empty() const
Definition: system.hh:214
int numRunning() const
Definition: system.cc:131
Thread & thread(ContextID id)
Definition: system.hh:133
const Thread & thread(ContextID id) const
Definition: system.hh:140
void insert(ThreadContext *tc)
Definition: system.cc:93
std::vector< Thread > threads
Definition: system.hh:130
void replace(ThreadContext *tc, ContextID id)
Definition: system.cc:108
ThreadContext * findFree()
Definition: system.cc:121
uint64_t workItemsBegin
Definition: system.hh:413
void setKvmVM(KvmVM *const vm)
Set the pointer to the Kernel Virtual Machine (KVM) SimObject.
Definition: system.hh:342
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: system.cc:328
RequestorID lookupRequestorId(const SimObject *obj) const
Looks up the RequestorID for a given SimObject returns an invalid RequestorID (invldRequestorId) if n...
Definition: system.cc:432
int markWorkItem(int index)
Called by pseudo_inst to mark the cpus actively executing work items.
Definition: system.hh:541
bool remove(PCEvent *event) override
Definition: system.cc:258
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: system.hh:311
const memory::PhysicalMemory & getPhysMem() const
Definition: system.hh:346
RequestPort & getSystemPort()
Get a reference to the system port that can be used by non-structural simulation objects like process...
Definition: system.hh:242
bool isAtomicMode() const
Is the system in atomic mode?
Definition: system.hh:261
uint32_t numWorkIds
Definition: system.hh:415
RequestorID _getRequestorId(const SimObject *requestor, const std::string &requestor_name)
helper function for getRequestorId
Definition: system.cc:482
static int numSystemsRunning
Definition: system.hh:597
ThermalModel * getThermalModel() const
The thermal model used for this system (if any).
Definition: system.hh:399
void registerThreadContext(ThreadContext *tc)
Definition: system.cc:237
enums::MemoryMode memoryMode
Definition: system.hh:409
bool isTimingMode() const
Is the system in timing mode?
Definition: system.hh:273
uint64_t incWorkItemsEnd()
Called by pseudo_inst to track the number of work items completed by this system.
Definition: system.hh:530
std::string leafRequestorName(const SimObject *requestor, const std::string &subrequestor)
Helper function for constructing the full (sub)requestor name by providing the root requestor and the...
Definition: system.cc:513
KvmVM * getKvmVM() const
Get a pointer to the Kernel Virtual Machine (KVM) SimObject, if present.
Definition: system.hh:336
AddrRangeList getShadowRomRanges() const
Definition: system.hh:385
std::set< int > PIDs
Process set to track which PIDs have already been allocated.
Definition: system.hh:606
void addDeviceMemory(RequestorID requestorId, memory::AbstractMemory *deviceMemory)
Add a physical memory range for a device.
Definition: system.cc:294
Addr memSize() const
Amount of physical memory that exists.
Definition: system.cc:282
std::unordered_map< RequestorID, std::vector< memory::AbstractMemory * > > deviceMemMap
Definition: system.hh:112
std::string getRequestorName(RequestorID requestor_id)
Get the name of an object for a given request id.
Definition: system.cc:526
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: system.cc:344
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:288
RequestorID getRequestorId(const SimObject *requestor, std::string subrequestor={})
Request an id used to create a request object in the system.
Definition: system.cc:475
uint64_t incWorkItemsBegin()
Called by pseudo_inst to track the number of work items started by this system.
Definition: system.hh:520
bool schedule(PCEvent *event) override
Definition: system.cc:248
SystemPort _systemPort
Definition: system.hh:108
KvmVM * kvmVM
Definition: system.hh:403
static const int maxPID
Definition: system.hh:603
std::list< BasicSignal > signalList
Definition: system.hh:610
bool isDeviceMemAddr(const PacketPtr &pkt) const
Similar to isMemAddr but for devices.
Definition: system.cc:301
System(const Params &p)
Definition: system.cc:167
const unsigned int _cacheLineSize
Definition: system.hh:411
RequestorID maxRequestors()
Get the number of requestors registered in the system.
Definition: system.hh:498
std::map< std::pair< uint32_t, uint32_t >, Tick > lastWorkItemStarted
Definition: system.hh:587
FutexMap futexMap
Definition: system.hh:601
memory::PhysicalMemory physmem
Definition: system.hh:405
static void printSystems()
Definition: system.cc:400
enums::MemoryMode getMemoryMode() const
Get the memory mode of the system.
Definition: system.hh:296
bool bypassCaches() const
Should caches be bypassed?
Definition: system.hh:282
std::map< uint32_t, statistics::Histogram * > workItemStats
Definition: system.hh:588
std::string stripSystemName(const std::string &requestor_name) const
Strips off the system name from a requestor name.
Definition: system.cc:422
void setMemoryMode(enums::MemoryMode mode)
Change the memory mode of the system.
Definition: system.cc:230
void workItemEnd(uint32_t tid, uint32_t workid)
Definition: system.cc:377
Workload * workload
OS kernel.
Definition: system.hh:329
std::vector< RedirectPath * > redirectPaths
Definition: system.hh:615
uint64_t init_param
Definition: system.hh:322
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:326
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Additional function to return the Port of a memory object.
Definition: system.cc:223
const bool multiThread
Definition: system.hh:315
ThermalModel * thermalModel
Definition: system.hh:424
ByteOrder getGuestByteOrder() const
Get the guest byte order.
Definition: system.hh:391
void regStats() override
Callback to set stat parameters.
Definition: system.cc:361
RequestorID getGlobalRequestorId(const std::string &requestor_name)
Registers a GLOBAL RequestorID, which is a RequestorID not related to any particular SimObject; since...
Definition: system.cc:469
memory::AbstractMemory * getDeviceMemory(const PacketPtr &pkt) const
Return a pointer to the device memory.
Definition: system.cc:311
PARAMS(System)
std::list< PCEvent * > liveEvents
Definition: system.hh:107
memory::PhysicalMemory & getPhysMem()
Get a pointer to access the physical memory of the system.
Definition: system.hh:345
const AddrRange & m5opRange() const
Range used by memory-mapped m5 pseudo-ops if enabled.
Definition: system.hh:576
void workItemBegin(uint32_t tid, uint32_t workid)
Definition: system.hh:548
uint64_t workItemsEnd
Definition: system.hh:414
bool trapToGdb(int signal, ContextID ctx_id) const
Definition: system.cc:394
std::vector< RequestorInfo > requestors
This array is a per-system list of all devices capable of issuing a memory system request and an asso...
Definition: system.hh:422
static std::vector< System * > systemList
Definition: system.hh:596
AddrRangeList ShadowRomRanges
Definition: system.hh:407
void replaceThreadContext(ThreadContext *tc, ContextID context_id)
Definition: system.cc:268
Threads threads
Definition: system.hh:313
const AddrRange _m5opRange
Range for memory-mapped m5 pseudo ops.
Definition: system.hh:564
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual ByteOrder byteOrder() const =0
An abstract memory represents a contiguous block of physical memory, with an associated address range...
The physical memory encapsulates all memories in the system and provides basic functionality for acce...
Definition: physical.hh:137
STL list class.
Definition: stl.hh:51
STL pair class.
Definition: stl.hh:58
STL vector class.
Definition: stl.hh:37
void schedule(Event &event, Tick when)
Definition: eventq.hh:1019
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Port Object Declaration.
RequestorInfo declaration.
Bitfield< 23, 20 > atomic
Definition: misc_types.hh:100
Bitfield< 4, 0 > mode
Definition: misc_types.hh:74
Bitfield< 33 > id
Definition: misc_types.hh:257
Bitfield< 0 > vm
Definition: misc_types.hh:291
Bitfield< 10, 5 > event
Bitfield< 30, 0 > index
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
const PortID InvalidPortID
Definition: types.hh:246
void printSystems()
Definition: system.cc:416
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
std::ostream CheckpointOut
Definition: serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
uint64_t Tick
Tick count type.
Definition: types.hh:58
uint16_t RequestorID
Definition: request.hh:95
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
PortProxy Object Declaration.
Declaration of Statistics objects.
std::string name() const
Definition: system.cc:78
ThreadContext * context
Definition: system.hh:121

Generated on Wed Dec 21 2022 10:22:27 for gem5 by doxygen 1.9.1