gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
workload.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Google Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __SIM_WORKLOAD_HH__
29 #define __SIM_WORKLOAD_HH__
30 
31 #include <set>
32 #include <tuple>
33 
35 #include "base/loader/symtab.hh"
36 #include "enums/ByteOrder.hh"
37 #include "gdbremote/signals.hh"
38 #include "params/StubWorkload.hh"
39 #include "params/Workload.hh"
40 #include "sim/sim_object.hh"
41 #include "sim/stats.hh"
42 
43 namespace gem5
44 {
45 
46 class BaseRemoteGDB;
47 class System;
48 class ThreadContext;
49 
50 class Workload : public SimObject
51 {
52  protected:
53  virtual Addr fixFuncEventAddr(Addr addr) const { return addr; }
54 
56  {
58  {
61 
63  : statistics::Group(parent, "inst"),
64  ADD_STAT(arm, statistics::units::Count::get(),
65  "number of arm instructions executed"),
66  ADD_STAT(quiesce, statistics::units::Count::get(),
67  "number of quiesce instructions executed")
68  {}
69 
70  } instStats;
71 
72  WorkloadStats(Workload *workload) : statistics::Group(workload),
73  instStats(workload)
74  {}
75  } stats;
76 
77  BaseRemoteGDB *gdb = nullptr;
78  bool waitForRemoteGDB = false;
79  std::set<ThreadContext *> threads;
80 
81  System *system = nullptr;
82 
83  public:
84  Workload(const WorkloadParams &params) : SimObject(params), stats(this),
85  waitForRemoteGDB(params.wait_for_remote_gdb)
86  {}
87 
88  virtual void setSystem(System *sys) { system = sys; }
89 
91  void recordArm() { stats.instStats.arm++; }
92 
93  // Once trapping into GDB is no longer a special case routed through the
94  // system object, this helper can be removed.
95  bool trapToGdb(GDBSignal sig, ContextID ctx_id);
96  bool sendToGdb(std::string msg);
97 
98  virtual void registerThreadContext(ThreadContext *tc);
99  virtual void replaceThreadContext(ThreadContext *tc);
100 
101  void startup() override;
102 
103  virtual Addr getEntry() const = 0;
104  virtual ByteOrder byteOrder() const = 0;
105  virtual loader::Arch getArch() const = 0;
106 
107  virtual const loader::SymbolTable &symtab(ThreadContext *tc) = 0;
108  virtual bool insertSymbol(const loader::Symbol &symbol) = 0;
109 
110  virtual void
112  {
113  panic("syscall() not implemented.");
114  }
115 
116  virtual void
118  {
119  warn("Unhandled workload event.");
120  }
121 
135  template <class T, typename... Args>
136  T *
137  addFuncEvent(const loader::SymbolTable &symtab, const char *lbl,
138  const std::string &desc, Args... args)
139  {
140  auto it = symtab.find(lbl);
141  if (it == symtab.end())
142  return nullptr;
143 
144  return new T(system, desc, fixFuncEventAddr(it->address),
145  std::forward<Args>(args)...);
146  }
147 
148  template <class T>
149  T *
150  addFuncEvent(const loader::SymbolTable &symtab, const char *lbl)
151  {
152  return addFuncEvent<T>(symtab, lbl, lbl);
153  }
154 
155  template <class T, typename... Args>
156  T *
158  Args... args)
159  {
160  T *e = addFuncEvent<T>(symtab, lbl, std::forward<Args>(args)...);
161  panic_if(!e, "Failed to find symbol '%s'", lbl);
162  return e;
163  }
165 };
166 
167 class StubWorkload : public Workload
168 {
169  private:
172 
173  public:
174  StubWorkload(const StubWorkloadParams &params) : Workload(params) {}
175 
176  Addr getEntry() const override { return params().entry; }
177  ByteOrder byteOrder() const override { return params().byte_order; }
178  loader::Arch getArch() const override { return loader::UnknownArch; }
179  const loader::SymbolTable &
180  symtab(ThreadContext *tc) override
181  {
182  return _symtab;
183  }
184  bool
185  insertSymbol(const loader::Symbol &symbol) override
186  {
187  return _symtab.insert(symbol);
188  }
189 };
190 
191 } // namespace gem5
192 
193 #endif // __SIM_WORKLOAD_HH__
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1929
warn
#define warn(...)
Definition: logging.hh:256
gem5::Workload::WorkloadStats::WorkloadStats
WorkloadStats(Workload *workload)
Definition: workload.hh:72
gem5::Workload::stats
gem5::Workload::WorkloadStats stats
gem5::Workload::getEntry
virtual Addr getEntry() const =0
gem5::MipsISA::misc_reg::Count
@ Count
Definition: misc.hh:94
gem5::Workload::WorkloadStats::InstStats::InstStats
InstStats(statistics::Group *parent)
Definition: workload.hh:62
gem5::Workload::WorkloadStats::InstStats
Definition: workload.hh:57
gem5::Workload::gdb
BaseRemoteGDB * gdb
Definition: workload.hh:77
gem5::ArmISA::e
Bitfield< 9 > e
Definition: misc_types.hh:65
gem5::loader::SymbolTable::end
const_iterator end() const
Definition: symtab.hh:175
gem5::loader::SymbolTable
Definition: symtab.hh:64
gem5::StubWorkload::symtab
const loader::SymbolTable & symtab(ThreadContext *tc) override
Definition: workload.hh:180
gem5::Workload::addFuncEvent
T * addFuncEvent(const loader::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: workload.hh:137
gem5::Workload::trapToGdb
bool trapToGdb(GDBSignal sig, ContextID ctx_id)
Definition: workload.cc:75
gem5::Workload::getArch
virtual loader::Arch getArch() const =0
gem5::StubWorkload::byteOrder
ByteOrder byteOrder() const override
Definition: workload.hh:177
stats.hh
gem5::StubWorkload::_symtab
loader::SymbolTable _symtab
Definition: workload.hh:171
gem5::System
Definition: system.hh:74
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
gem5::Workload::event
virtual void event(ThreadContext *tc)
Definition: workload.hh:117
gem5::StubWorkload
Definition: workload.hh:167
gem5::Workload::addFuncEventOrPanic
T * addFuncEventOrPanic(const loader::SymbolTable &symtab, const char *lbl, Args... args)
Definition: workload.hh:157
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
sim_object.hh
gem5::Workload::WorkloadStats
Definition: workload.hh:55
ADD_STAT
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:75
gem5::StubWorkload::getEntry
Addr getEntry() const override
Definition: workload.hh:176
gem5::Workload::threads
std::set< ThreadContext * > threads
Definition: workload.hh:79
gem5::Workload::waitForRemoteGDB
bool waitForRemoteGDB
Definition: workload.hh:78
gem5::Workload
Definition: workload.hh:50
gem5::StubWorkload::PARAMS
PARAMS(StubWorkload)
gem5::loader::Arch
Arch
Definition: object_file.hh:61
gem5::Workload::recordArm
void recordArm()
Definition: workload.hh:91
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::Workload::sendToGdb
bool sendToGdb(std::string msg)
Definition: workload.cc:84
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::StubWorkload::getArch
loader::Arch getArch() const override
Definition: workload.hh:178
gem5::Workload::symtab
virtual const loader::SymbolTable & symtab(ThreadContext *tc)=0
gem5::Workload::addFuncEvent
T * addFuncEvent(const loader::SymbolTable &symtab, const char *lbl)
Definition: workload.hh:150
gem5::loader::SymbolTable::find
const_iterator find(Addr address) const
Search for a symbol by its address.
Definition: symtab.hh:321
gem5::loader::UnknownArch
@ UnknownArch
Definition: object_file.hh:63
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:214
gem5::loader::SymbolTable::insert
bool insert(const Symbol &symbol)
Insert a new symbol in the table if it does not already exist.
Definition: symtab.cc:54
gem5::Workload::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: workload.cc:93
gem5::Workload::replaceThreadContext
virtual void replaceThreadContext(ThreadContext *tc)
Definition: workload.cc:51
gem5::ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
gem5::Workload::WorkloadStats::InstStats::quiesce
statistics::Scalar quiesce
Definition: workload.hh:60
gem5::loader::Symbol
Definition: symtab.hh:50
gem5::StubWorkload::insertSymbol
bool insertSymbol(const loader::Symbol &symbol) override
Definition: workload.hh:185
gem5::Workload::fixFuncEventAddr
virtual Addr fixFuncEventAddr(Addr addr) const
Definition: workload.hh:53
gem5::statistics::Group
Statistics container.
Definition: group.hh:92
gem5::Workload::system
System * system
Definition: workload.hh:81
gem5::Workload::Workload
Workload(const WorkloadParams &params)
Definition: workload.hh:84
symtab.hh
gem5::Workload::setSystem
virtual void setSystem(System *sys)
Definition: workload.hh:88
gem5::BaseRemoteGDB
Definition: remote_gdb.hh:48
gem5::Workload::registerThreadContext
virtual void registerThreadContext(ThreadContext *tc)
Definition: workload.cc:38
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::Workload::recordQuiesce
void recordQuiesce()
Definition: workload.hh:90
object_file.hh
gem5::Workload::insertSymbol
virtual bool insertSymbol(const loader::Symbol &symbol)=0
gem5::StubWorkload::StubWorkload
StubWorkload(const StubWorkloadParams &params)
Definition: workload.hh:174
gem5::Workload::syscall
virtual void syscall(ThreadContext *tc)
Definition: workload.hh:111
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
gem5::Workload::WorkloadStats::instStats
gem5::Workload::WorkloadStats::InstStats instStats
gem5::Workload::WorkloadStats::InstStats::arm
statistics::Scalar arm
Definition: workload.hh:59
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::Workload::byteOrder
virtual ByteOrder byteOrder() const =0

Generated on Sun Jul 30 2023 01:56:50 for gem5 by doxygen 1.8.17