gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
system.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 2014 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"
56 #include "base/loader/symtab.hh"
57 #include "base/statistics.hh"
58 #include "config/the_isa.hh"
59 #include "enums/MemoryMode.hh"
60 #include "mem/mem_object.hh"
61 #include "mem/physical.hh"
62 #include "mem/port.hh"
63 #include "mem/port_proxy.hh"
64 #include "params/System.hh"
65 #include "sim/futex_map.hh"
66 #include "sim/se_signal.hh"
67 
72 #if THE_ISA != NULL_ISA
73 #include "cpu/pc_event.hh"
74 
75 #endif
76 
77 class BaseRemoteGDB;
78 class GDBListener;
79 class KvmVM;
80 class ObjectFile;
81 class ThreadContext;
82 
83 class System : public MemObject
84 {
85  private:
86 
92  class SystemPort : public MasterPort
93  {
94  public:
95 
99  SystemPort(const std::string &_name, MemObject *_owner)
100  : MasterPort(_name, _owner)
101  { }
102  bool recvTimingResp(PacketPtr pkt) override
103  { panic("SystemPort does not receive timing!\n"); return false; }
104  void recvReqRetry() override
105  { panic("SystemPort does not expect retry!\n"); }
106  };
107 
109 
110  public:
111 
116  void init() override;
117 
127 
131  BaseMasterPort& getMasterPort(const std::string &if_name,
132  PortID idx = InvalidPortID) override;
133 
144  bool isAtomicMode() const {
145  return memoryMode == Enums::atomic ||
146  memoryMode == Enums::atomic_noncaching;
147  }
148 
155  bool isTimingMode() const {
156  return memoryMode == Enums::timing;
157  }
158 
165  bool bypassCaches() const {
166  return memoryMode == Enums::atomic_noncaching;
167  }
178  Enums::MemoryMode getMemoryMode() const { return memoryMode; }
179 
187  void setMemoryMode(Enums::MemoryMode mode);
193  unsigned int cacheLineSize() const { return _cacheLineSize; }
194 
195 #if THE_ISA != NULL_ISA
196  PCEventQueue pcEventQueue;
197 #endif
198 
201  const bool multiThread;
202 
204  {
205  return threadContexts[tid];
206  }
207 
209  {
210  assert(_numContexts == (int)threadContexts.size());
211  return _numContexts;
212  }
213 
216  int numRunningContexts();
217 
219 
220  uint64_t init_param;
221 
225 
228 
231 
234 
237 
240 
248 
255 
256  public:
262  return kvmVM;
263  }
264 
267 
269  Addr freeMemSize() const;
270 
272  Addr memSize() const;
273 
281  bool isMemAddr(Addr addr) const;
282 
286  Arch getArch() const { return Arch::TheISA; }
287 
291  Addr getPageBytes() const { return TheISA::PageBytes; }
292 
296  Addr getPageShift() const { return TheISA::PageShift; }
297 
302 
303  protected:
304 
305  KvmVM *const kvmVM;
306 
308 
309  Enums::MemoryMode memoryMode;
310 
311  const unsigned int _cacheLineSize;
312 
313  uint64_t workItemsBegin;
314  uint64_t workItemsEnd;
315  uint32_t numWorkIds;
317 
324 
326 
327  public:
328 
337  MasterID getMasterId(std::string req_name);
338 
341  std::string getMasterName(MasterID master_id);
342 
345  {
346  return masterIds.size();
347  }
348 
349  void regStats() override;
354  uint64_t
356  {
357  return ++workItemsBegin;
358  }
359 
364  uint64_t
366  {
367  return ++workItemsEnd;
368  }
369 
375  int
377  {
378  int count = 0;
379  assert(index < activeCpus.size());
380  activeCpus[index] = true;
381  for (std::vector<bool>::iterator i = activeCpus.begin();
382  i < activeCpus.end(); i++) {
383  if (*i) count++;
384  }
385  return count;
386  }
387 
388  inline void workItemBegin(uint32_t tid, uint32_t workid)
389  {
390  std::pair<uint32_t,uint32_t> p(tid, workid);
392  }
393 
394  void workItemEnd(uint32_t tid, uint32_t workid);
395 
402  {
403  panic("Base fixFuncEventAddr not implemented.\n");
404  }
405 
419  template <class T, typename... Args>
420  T *addFuncEvent(const SymbolTable *symtab, const char *lbl,
421  const std::string &desc, Args... args)
422  {
423  Addr addr M5_VAR_USED = 0; // initialize only to avoid compiler warning
424 
425 #if THE_ISA != NULL_ISA
426  if (symtab->findAddress(lbl, addr)) {
427  T *ev = new T(&pcEventQueue, desc, fixFuncEventAddr(addr),
428  std::forward<Args>(args)...);
429  return ev;
430  }
431 #endif
432 
433  return NULL;
434  }
435 
436  template <class T>
437  T *addFuncEvent(const SymbolTable *symtab, const char *lbl)
438  {
439  return addFuncEvent<T>(symtab, lbl, lbl);
440  }
441 
442  template <class T, typename... Args>
443  T *addFuncEventOrPanic(const SymbolTable *symtab, const char *lbl,
444  Args... args)
445  {
446  T *e(addFuncEvent<T>(symtab, lbl, std::forward<Args>(args)...));
447  if (!e)
448  panic("Failed to find symbol '%s'", lbl);
449  return e;
450  }
468  template <class T, typename... Args>
469  T *addKernelFuncEvent(const char *lbl, Args... args)
470  {
471  return addFuncEvent<T>(kernelSymtab, lbl,
472  std::forward<Args>(args)...);
473  }
474 
475  template <class T, typename... Args>
476  T *addKernelFuncEventOrPanic(const char *lbl, Args... args)
477  {
478  T *e(addFuncEvent<T>(kernelSymtab, lbl,
479  std::forward<Args>(args)...));
480  if (!e)
481  panic("Failed to find kernel symbol '%s'", lbl);
482  return e;
483  }
486  public:
489  bool breakpoint();
490 
491  public:
492  typedef SystemParams Params;
493 
494  protected:
496 
497  public:
498  System(Params *p);
499  ~System();
500 
501  void initState() override;
502 
503  const Params *params() const { return (const Params *)_params; }
504 
505  public:
506 
511  Addr getKernelStart() const { return kernelStart; }
512 
517  Addr getKernelEnd() const { return kernelEnd; }
518 
523  Addr getKernelEntry() const { return kernelEntry; }
524 
527  Addr allocPhysPages(int npages);
528 
530  ContextID assigned = InvalidContextID);
531  void replaceThreadContext(ThreadContext *tc, ContextID context_id);
532 
533  void serialize(CheckpointOut &cp) const override;
534  void unserialize(CheckpointIn &cp) override;
535 
536  void drainResume() override;
537 
538  public:
541  std::map<std::pair<uint32_t,uint32_t>, Tick> lastWorkItemStarted;
542  std::map<uint32_t, Stats::Histogram*> workItemStats;
543 
545  //
546  // STATIC GLOBAL SYSTEM LIST
547  //
549 
551  static int numSystemsRunning;
552 
553  static void printSystems();
554 
556 
557  static const int maxPID = 32768;
558 
560  std::set<int> PIDs;
561 
562  // By convention, all signals are owned by the receiving process. The
563  // receiver will delete the signal upon reception.
565 
566  protected:
567 
575  virtual void serializeSymtab(CheckpointOut &os) const {}
576 
584  virtual void unserializeSymtab(CheckpointIn &cp) {}
585 
586 };
587 
588 void printSystems();
589 
590 #endif // __SYSTEM_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:167
count
Definition: misc.hh:704
FutexMap futexMap
Definition: system.hh:555
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:584
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:371
Bitfield< 7 > i
Definition: miscregs.hh:1378
const PortID InvalidPortID
Definition: types.hh:182
std::string getMasterName(MasterID master_id)
Get the name of an object for a given request id.
Definition: system.cc:490
Enums::MemoryMode memoryMode
Definition: system.hh:309
ContextID registerThreadContext(ThreadContext *tc, ContextID assigned=InvalidContextID)
Definition: system.cc:231
#define panic(...)
Definition: misc.hh:153
Addr getKernelStart() const
Returns the address the kernel starts at.
Definition: system.hh:511
MasterPort & getSystemPort()
Get a reference to the system port that can be used by non-structural simulation objects like process...
Definition: system.hh:126
System(Params *p)
Definition: system.cc:86
T * addKernelFuncEventOrPanic(const char *lbl, Args...args)
Definition: system.hh:476
Enums::MemoryMode getMemoryMode() const
Get the memory mode of the system.
Definition: system.hh:178
SystemParams Params
Definition: system.hh:492
const Addr PageShift
Definition: isa_traits.hh:51
int _numContexts
Definition: system.hh:200
bool bypassCaches() const
Should caches be bypassed?
Definition: system.hh:165
const Params * params() const
Definition: system.hh:503
static void printSystems()
Definition: system.cc:441
ip6_addr_t addr
Definition: inet.hh:335
MemObject declaration.
uint64_t incWorkItemsEnd()
Called by pseudo_inst to track the number of work items completed by this system. ...
Definition: system.hh:365
PhysicalMemory physmem
Definition: system.hh:307
Addr freeMemSize() const
Amount of physical memory that is still free.
Definition: system.cc:365
Addr allocPhysPages(int npages)
Allocate npages contiguous unused physical pages.
Definition: system.cc:339
Port Object Declaration.
void workItemEnd(uint32_t tid, uint32_t workid)
Definition: system.cc:424
Definition: system.hh:83
bool findAddress(const std::string &symbol, Addr &address) const
Definition: symtab.hh:97
const bool multiThread
Definition: system.hh:201
SystemPort _systemPort
Definition: system.hh:108
Addr getPageBytes() const
Get the page bytes for the ISA.
Definition: system.hh:291
Bitfield< 4, 0 > mode
Definition: miscregs.hh:1385
T * addFuncEvent(const SymbolTable *symtab, const char *lbl)
Definition: system.hh:437
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:804
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: system.hh:193
void init() override
After all objects have been created and all ports are connected, check that the system port is connec...
Definition: system.cc:195
int numRunningContexts()
Return number of running (non-halted) thread contexts in system.
Definition: system.cc:278
Addr kernelStart
Beginning of kernel code.
Definition: system.hh:233
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: system.cc:396
BaseMasterPort & getMasterPort(const std::string &if_name, PortID idx=InvalidPortID) override
Additional function to return the Port of a memory object.
Definition: system.cc:203
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:224
std::vector< GDBListener * > gdbListen
Definition: system.hh:488
void regStats() override
Register statistics for this object.
Definition: system.cc:408
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: system.cc:289
PortProxy Object Declaration.
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the slave port.
Definition: system.hh:102
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Queue of events sorted in time order.
Definition: eventq.hh:488
static const int maxPID
Definition: system.hh:557
Addr loadAddrMask
Mask that should be anded for binary/symbol loading.
Definition: system.hh:247
void drainResume() override
Resume execution after a successful drain.
Definition: system.cc:377
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:560
const unsigned int _cacheLineSize
Definition: system.hh:311
int markWorkItem(int index)
Called by pseudo_inst to mark the cpus actively executing work items.
Definition: system.hh:376
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: system.cc:383
void recvReqRetry() override
Called by the slave port if sendTimingReq was called on this master port (causing recvTimingReq to be...
Definition: system.hh:104
Addr pagePtr
Definition: system.hh:218
KvmVM * getKvmVM()
Get a pointer to the Kernel Virtual Machine (KVM) SimObject, if present.
Definition: system.hh:261
std::vector< ThreadContext * > threadContexts
Definition: system.hh:199
ThermalModel * thermalModel
Definition: system.hh:325
Addr kernelEntry
Entry point in the kernel to start at.
Definition: system.hh:239
std::map< uint32_t, Stats::Histogram * > workItemStats
Definition: system.hh:542
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:401
ThreadContext * getThreadContext(ContextID tid)
Definition: system.hh:203
~System()
Definition: system.cc:185
The physical memory encapsulates all memories in the system and provides basic functionality for acce...
Definition: physical.hh:112
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:85
Addr getKernelEnd() const
Returns the address the kernel ends at.
Definition: system.hh:517
bool isAtomicMode() const
Is the system in atomic mode?
Definition: system.hh:144
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:245
int numContexts()
Definition: system.hh:208
std::list< BasicSignal > signalList
Definition: system.hh:564
std::vector< bool > activeCpus
Definition: system.hh:316
SymbolTable * kernelSymtab
kernel symbol table
Definition: system.hh:227
const Addr PageBytes
Definition: isa_traits.hh:52
uint32_t numWorkIds
Definition: system.hh:315
MasterID maxMasters()
Get the number of masters registered in the system.
Definition: system.hh:344
ThermalModel * getThermalModel() const
The thermal model used for this system (if any).
Definition: system.hh:301
static const int NumArgumentRegs M5_VAR_USED
Definition: process.cc:83
Addr memSize() const
Amount of physical memory that exists.
Definition: system.cc:359
This object is a proxy for a structural port, to be used for debug accesses.
Definition: port_proxy.hh:84
Bitfield< 9 > e
Definition: miscregs.hh:1376
ObjectFile * kernel
Object pointer for the kernel code.
Definition: system.hh:230
Addr getKernelEntry() const
Returns the address the entry point to the kernel code.
Definition: system.hh:523
Params * _params
Definition: system.hh:495
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:355
std::vector< std::string > masterIds
This array is a per-system list of all devices capable of issuing a memory system request and an asso...
Definition: system.hh:323
virtual void serializeSymtab(CheckpointOut &os) const
If needed, serialize additional symbol table entries for a specific subclass of this system...
Definition: system.hh:575
std::ostream CheckpointOut
Definition: serialize.hh:67
static int numSystemsRunning
Definition: system.hh:551
void workItemBegin(uint32_t tid, uint32_t workid)
Definition: system.hh:388
Addr getPageShift() const
Get the number of bits worth of in-page address for the ISA.
Definition: system.hh:296
Private class for the system port which is only used as a master for debug access and for non-structu...
Definition: system.hh:92
The MemObject class extends the ClockedObject with accessor functions to get its master and slave por...
Definition: mem_object.hh:60
T * addFuncEventOrPanic(const SymbolTable *symtab, const char *lbl, Args...args)
Definition: system.hh:443
A BaseMasterPort is a protocol-agnostic master port, responsible only for the structural connection t...
Definition: port.hh:115
EventQueue instEventQueue
Definition: system.hh:540
FutexMap class holds a map of all futexes used in the system.
Definition: futex_map.hh:87
PhysicalMemory & getPhysMem()
Get a pointer to access the physical memory of the system.
Definition: system.hh:266
const ContextID InvalidContextID
Definition: types.hh:176
T * addKernelFuncEvent(const char *lbl, Args...args)
Add a function-based event to a kernel symbol.
Definition: system.hh:469
void replaceThreadContext(ThreadContext *tc, ContextID context_id)
Definition: system.cc:326
MasterID getMasterId(std::string req_name)
Request an id used to create a request object in the system.
Definition: system.cc:462
uint64_t workItemsBegin
Definition: system.hh:313
std::map< std::pair< uint32_t, uint32_t >, Tick > lastWorkItemStarted
Definition: system.hh:541
std::vector< BaseRemoteGDB * > remoteGDB
Definition: system.hh:487
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:181
void printSystems()
Definition: system.cc:456
bool breakpoint()
Definition: system.cc:216
Addr loadAddrOffset
Offset that should be used for binary/symbol loading.
Definition: system.hh:254
KvmVM *const kvmVM
Definition: system.hh:305
Bitfield< 0 > p
uint64_t init_param
Definition: system.hh:220
int ContextID
Globally unique thread context ID.
Definition: types.hh:175
Addr kernelEnd
End of kernel code.
Definition: system.hh:236
uint64_t workItemsEnd
Definition: system.hh:314
Counter totalNumInsts
Definition: system.hh:539
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:420
bool isTimingMode() const
Is the system in timing mode?
Definition: system.hh:155
SystemPort(const std::string &_name, MemObject *_owner)
Create a system port with a name and an owner.
Definition: system.hh:99
Arch getArch() const
Get the architecture.
Definition: system.hh:286
A ThermalModel is the element which ties all thermal objects together and provides the thermal solver...
void setMemoryMode(Enums::MemoryMode mode)
Change the memory mode of the system.
Definition: system.cc:210
static std::vector< System * > systemList
Definition: system.hh:550

Generated on Fri Jun 9 2017 13:03:34 for gem5 by doxygen 1.8.6