gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
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
67namespace gem5
68{
69
70class BaseRemoteGDB;
71class KvmVM;
72class ThreadContext;
73
74class System : public SimObject, public PCEventScope
75{
76 private:
77
83 class SystemPort : public RequestPort
84 {
85 public:
86
90 SystemPort(const std::string &_name)
92 { }
93
94 bool
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 // List of address ranges that are have valid physical addresses but
115 // don't appear in the physical memory map. Note that these are assumed
116 // to be coherent addresses, not I/O or device addresses
118
119 public:
120
122 {
123 private:
124 struct Thread
125 {
127 bool active = false;
128 Event *resumeEvent = nullptr;
129
130 void resume();
131 std::string name() const;
132 void quiesce() const;
133 };
134
136
137 Thread &
139 {
140 assert(id < size());
141 return threads[id];
142 }
143
144 const Thread &
146 {
147 assert(id < size());
148 return threads[id];
149 }
150
151 void insert(ThreadContext *tc);
152 void replace(ThreadContext *tc, ContextID id);
153
154 friend class System;
155
156 public:
158 {
159 private:
161 int pos;
162
163 friend class Threads;
164
165 const_iterator(const Threads &_threads, int _pos) :
166 threads(&_threads), pos(_pos)
167 {}
168
169 public:
170 using iterator_category = std::forward_iterator_tag;
172 using difference_type = int;
173 using pointer = const value_type *;
174 using reference = const value_type &;
175
178 {
179 pos++;
180 return *this;
181 }
182
185 {
186 return const_iterator(*threads, pos++);
187 }
188
189 reference operator * () { return threads->thread(pos).context; }
190 pointer operator -> () { return &threads->thread(pos).context; }
191
192 bool
193 operator == (const const_iterator &other) const
194 {
195 return threads == other.threads && pos == other.pos;
196 }
197
198 bool
199 operator != (const const_iterator &other) const
200 {
201 return !(*this == other);
202 }
203 };
204
206
209 {
210 return thread(id).context;
211 }
212
213 void markActive(ContextID id) { thread(id).active = true; }
214
215 int size() const { return threads.size(); }
216 bool empty() const { return threads.empty(); }
217 int numRunning() const;
218 int
219 numActive() const
220 {
221 int count = 0;
222 for (auto &thread: threads) {
223 if (thread.active)
224 count++;
225 }
226 return count;
227 }
228
229 void quiesce(ContextID id);
230 void quiesceTick(ContextID id, Tick when);
231
232 const_iterator begin() const { return const_iterator(*this, 0); }
233 const_iterator end() const { return const_iterator(*this, size()); }
234 };
235
245
249 Port &getPort(const std::string &if_name,
250 PortID idx=InvalidPortID) override;
251
262 bool
264 {
265 return memoryMode == enums::atomic ||
266 memoryMode == enums::atomic_noncaching;
267 }
268
275 bool isTimingMode() const { return memoryMode == enums::timing; }
276
283 bool
285 {
286 return memoryMode == enums::atomic_noncaching;
287 }
288
289
298 enums::MemoryMode getMemoryMode() const { return memoryMode; }
299
307 void setMemoryMode(enums::MemoryMode mode);
309
314
316
317 const bool multiThread;
318
320
321 bool schedule(PCEvent *event) override;
322 bool remove(PCEvent *event) override;
323
324 uint64_t init_param;
325
329
331 Workload *workload = nullptr;
332
333 public:
338 KvmVM *getKvmVM() const { return kvmVM; }
339
344 void setKvmVM(KvmVM *const vm) { kvmVM = vm; }
345
348 const memory::PhysicalMemory& getPhysMem() const { return physmem; }
349
351 Addr memSize() const;
352
360 bool isMemAddr(Addr addr) const;
361
367 void addDeviceMemory(RequestorID requestorId,
368 memory::AbstractMemory *deviceMemory);
369
375 bool isDeviceMemAddr(const PacketPtr& pkt) const;
376
381
382 /*
383 * Return the list of address ranges backed by a shadowed ROM.
384 *
385 * @return List of address ranges backed by a shadowed ROM
386 */
388
392 ByteOrder
394 {
395 return workload->byteOrder();
396 }
397
402
403 protected:
404
405 KvmVM *kvmVM = nullptr;
406
408
410
411 enums::MemoryMode memoryMode;
412
414
415 uint64_t workItemsBegin = 0;
416 uint64_t workItemsEnd = 0;
417 uint32_t numWorkIds;
418
425
427
428 protected:
432 std::string stripSystemName(const std::string& requestor_name) const;
433
434 public:
435
469 RequestorID getRequestorId(const SimObject* requestor,
470 std::string subrequestor={});
471
480 RequestorID getGlobalRequestorId(const std::string& requestor_name);
481
485 std::string getRequestorName(RequestorID requestor_id);
486
491 RequestorID lookupRequestorId(const SimObject* obj) const;
492
497 RequestorID lookupRequestorId(const std::string& name) const;
498
501
502 protected:
504 RequestorID _getRequestorId(const SimObject* requestor,
505 const std::string& requestor_name);
506
511 std::string leafRequestorName(const SimObject* requestor,
512 const std::string& subrequestor);
513
514 public:
515
516 void regStats() override;
521 uint64_t
523 {
524 return ++workItemsBegin;
525 }
526
531 uint64_t
533 {
534 return ++workItemsEnd;
535 }
536
542 int
544 {
545 threads.markActive(index);
546 return threads.numActive();
547 }
548
549 void
550 workItemBegin(uint32_t tid, uint32_t workid)
551 {
552 std::pair<uint32_t, uint32_t> p(tid, workid);
554 }
555
556 void workItemEnd(uint32_t tid, uint32_t workid);
557
558 /* Returns whether we successfully trapped into GDB. */
559 bool trapToGdb(GDBSignal signal, ContextID ctx_id) const;
560
561 protected:
567
568 public:
570
571 System(const Params &p);
572 ~System();
573
578 const AddrRange &m5opRange() const { return _m5opRange; }
579
580 public:
581
583 void replaceThreadContext(ThreadContext *tc, ContextID context_id);
584
585 void serialize(CheckpointOut &cp) const override;
586 void unserialize(CheckpointIn &cp) override;
587
588 public:
589 std::map<std::pair<uint32_t, uint32_t>, Tick> lastWorkItemStarted;
590 std::map<uint32_t, statistics::Histogram*> workItemStats;
591
593 //
594 // STATIC GLOBAL SYSTEM LIST
595 //
597
600
601 static void printSystems();
602
604
605 static const int maxPID = 32768;
606
608 std::set<int> PIDs;
609
610 // By convention, all signals are owned by the receiving process. The
611 // receiver will delete the signal upon reception.
613
614 // Used by syscall-emulation mode. This member contains paths which need
615 // to be redirected to the faux-filesystem (a duplicate filesystem
616 // intended to replace certain files on the host filesystem).
618};
619
620void printSystems();
621
622} // namespace gem5
623
624#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:54
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:136
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition port.cc:125
Abstract superclass for simulation objects.
SimObjectParams Params
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)
Create a system port with a name and an owner.
Definition system.hh:90
bool operator==(const const_iterator &other) const
Definition system.hh:193
std::forward_iterator_tag iterator_category
Definition system.hh:170
const_iterator(const Threads &_threads, int _pos)
Definition system.hh:165
bool operator!=(const const_iterator &other) const
Definition system.hh:199
const Thread & thread(ContextID id) const
Definition system.hh:145
int numActive() const
Definition system.hh:219
const_iterator end() const
Definition system.hh:233
void quiesceTick(ContextID id, Tick when)
Definition system.cc:154
void markActive(ContextID id)
Definition system.hh:213
const_iterator begin() const
Definition system.hh:232
void quiesce(ContextID id)
Definition system.cc:145
int size() const
Definition system.hh:215
Thread & thread(ContextID id)
Definition system.hh:138
bool empty() const
Definition system.hh:216
int numRunning() const
Definition system.cc:131
void insert(ThreadContext *tc)
Definition system.cc:93
std::vector< Thread > threads
Definition system.hh:135
ThreadContext * operator[](ContextID id) const
Definition system.hh:208
void replace(ThreadContext *tc, ContextID id)
Definition system.cc:108
ThreadContext * findFree()
Definition system.cc:121
friend class System
Definition system.hh:154
uint64_t workItemsBegin
Definition system.hh:415
KvmVM * getKvmVM() const
Get a pointer to the Kernel Virtual Machine (KVM) SimObject, if present.
Definition system.hh:338
ThermalModel * getThermalModel() const
The thermal model used for this system (if any).
Definition system.hh:401
void setKvmVM(KvmVM *const vm)
Set the pointer to the Kernel Virtual Machine (KVM) SimObject.
Definition system.hh:344
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition system.cc:341
RequestorID lookupRequestorId(const SimObject *obj) const
Looks up the RequestorID for a given SimObject returns an invalid RequestorID (invldRequestorId) if n...
Definition system.cc:445
int markWorkItem(int index)
Called by pseudo_inst to mark the cpus actively executing work items.
Definition system.hh:543
bool remove(PCEvent *event) override
Definition system.cc:260
memory::PhysicalMemory & getPhysMem()
Get a pointer to access the physical memory of the system.
Definition system.hh:347
bool isAtomicMode() const
Is the system in atomic mode?
Definition system.hh:263
uint32_t numWorkIds
Definition system.hh:417
RequestorID _getRequestorId(const SimObject *requestor, const std::string &requestor_name)
helper function for getRequestorId
Definition system.cc:495
static int numSystemsRunning
Definition system.hh:599
void registerThreadContext(ThreadContext *tc)
Definition system.cc:239
enums::MemoryMode memoryMode
Definition system.hh:411
bool isTimingMode() const
Is the system in timing mode?
Definition system.hh:275
uint64_t incWorkItemsEnd()
Called by pseudo_inst to track the number of work items completed by this system.
Definition system.hh:532
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:526
AddrRangeList getShadowRomRanges() const
Definition system.hh:387
std::set< int > PIDs
Process set to track which PIDs have already been allocated.
Definition system.hh:608
void addDeviceMemory(RequestorID requestorId, memory::AbstractMemory *deviceMemory)
Add a physical memory range for a device.
Definition system.cc:307
Addr memSize() const
Amount of physical memory that exists.
Definition system.cc:284
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:539
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition system.cc:357
AddrRangeList externalMemRanges
Definition system.hh:117
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:290
RequestorID getRequestorId(const SimObject *requestor, std::string subrequestor={})
Request an id used to create a request object in the system.
Definition system.cc:488
uint64_t incWorkItemsBegin()
Called by pseudo_inst to track the number of work items started by this system.
Definition system.hh:522
bool schedule(PCEvent *event) override
Definition system.cc:250
SystemPort _systemPort
Definition system.hh:108
const AddrRange & m5opRange() const
Range used by memory-mapped m5 pseudo-ops if enabled.
Definition system.hh:578
KvmVM * kvmVM
Definition system.hh:405
static const int maxPID
Definition system.hh:605
std::list< BasicSignal > signalList
Definition system.hh:612
bool isDeviceMemAddr(const PacketPtr &pkt) const
Similar to isMemAddr but for devices.
Definition system.cc:314
System(const Params &p)
Definition system.cc:167
RequestorID maxRequestors()
Get the number of requestors registered in the system.
Definition system.hh:500
std::map< std::pair< uint32_t, uint32_t >, Tick > lastWorkItemStarted
Definition system.hh:589
FutexMap futexMap
Definition system.hh:603
memory::PhysicalMemory physmem
Definition system.hh:407
static void printSystems()
Definition system.cc:413
enums::MemoryMode getMemoryMode() const
Get the memory mode of the system.
Definition system.hh:298
bool bypassCaches() const
Should caches be bypassed?
Definition system.hh:284
std::map< uint32_t, statistics::Histogram * > workItemStats
Definition system.hh:590
std::string stripSystemName(const std::string &requestor_name) const
Strips off the system name from a requestor name.
Definition system.cc:435
void setMemoryMode(enums::MemoryMode mode)
Change the memory mode of the system.
Definition system.cc:232
void workItemEnd(uint32_t tid, uint32_t workid)
Definition system.cc:390
Workload * workload
OS kernel.
Definition system.hh:331
std::vector< RedirectPath * > redirectPaths
Definition system.hh:617
uint64_t init_param
Definition system.hh:324
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition system.hh:328
Addr cacheLineSize() const
Get the cache line size of the system.
Definition system.hh:313
const Addr _cacheLineSize
Definition system.hh:413
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Additional function to return the Port of a memory object.
Definition system.cc:225
RequestPort & getSystemPort()
Get a reference to the system port that can be used by non-structural simulation objects like process...
Definition system.hh:244
const bool multiThread
Definition system.hh:317
ThermalModel * thermalModel
Definition system.hh:426
ByteOrder getGuestByteOrder() const
Get the guest byte order.
Definition system.hh:393
void regStats() override
Callback to set stat parameters.
Definition system.cc:374
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:482
memory::AbstractMemory * getDeviceMemory(const PacketPtr &pkt) const
Return a pointer to the device memory.
Definition system.cc:324
PARAMS(System)
std::list< PCEvent * > liveEvents
Definition system.hh:107
const memory::PhysicalMemory & getPhysMem() const
Definition system.hh:348
void workItemBegin(uint32_t tid, uint32_t workid)
Definition system.hh:550
uint64_t workItemsEnd
Definition system.hh:416
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:424
static std::vector< System * > systemList
Definition system.hh:598
bool trapToGdb(GDBSignal signal, ContextID ctx_id) const
Definition system.cc:407
AddrRangeList ShadowRomRanges
Definition system.hh:409
void replaceThreadContext(ThreadContext *tc, ContextID context_id)
Definition system.cc:270
Threads threads
Definition system.hh:315
const AddrRange _m5opRange
Range for memory-mapped m5 pseudo ops.
Definition system.hh:566
ThreadContext is the external interface to all thread state for anything outside of the CPU.
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
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition addr_range.hh:64
void schedule(Event &event, Tick when)
Definition eventq.hh:1012
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:220
SimObject(const Params &p)
Definition sim_object.cc:58
Port Object Declaration.
RequestorInfo declaration.
Bitfield< 4, 0 > mode
Definition misc_types.hh:74
Bitfield< 33 > id
Bitfield< 0 > vm
Bitfield< 10, 5 > event
Bitfield< 30, 0 > index
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
void printSystems()
Definition system.cc:429
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
Packet * PacketPtr
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:126
const std::string & name()
Definition trace.cc:48

Generated on Mon May 26 2025 09:18:58 for gem5 by doxygen 1.13.2