gem5  v22.0.0.2
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 "params/StubWorkload.hh"
38 #include "params/Workload.hh"
39 #include "sim/sim_object.hh"
40 #include "sim/stats.hh"
41 
42 namespace gem5
43 {
44 
45 class BaseRemoteGDB;
46 class System;
47 class ThreadContext;
48 
49 class Workload : public SimObject
50 {
51  protected:
52  virtual Addr fixFuncEventAddr(Addr addr) const { return addr; }
53 
55  {
57  {
60 
62  : statistics::Group(parent, "inst"),
63  ADD_STAT(arm, statistics::units::Count::get(),
64  "number of arm instructions executed"),
65  ADD_STAT(quiesce, statistics::units::Count::get(),
66  "number of quiesce instructions executed")
67  {}
68 
69  } instStats;
70 
71  WorkloadStats(Workload *workload) : statistics::Group(workload),
72  instStats(workload)
73  {}
74  } stats;
75 
76  BaseRemoteGDB *gdb = nullptr;
77  bool waitForRemoteGDB = false;
78  std::set<ThreadContext *> threads;
79 
80  System *system = nullptr;
81 
82  public:
83  Workload(const WorkloadParams &params) : SimObject(params), stats(this),
84  waitForRemoteGDB(params.wait_for_remote_gdb)
85  {}
86 
87  virtual void setSystem(System *sys) { system = sys; }
88 
90  void recordArm() { stats.instStats.arm++; }
91 
92  // Once trapping into GDB is no longer a special case routed through the
93  // system object, this helper can be removed.
94  bool trapToGdb(int signal, ContextID ctx_id);
95 
96  virtual void registerThreadContext(ThreadContext *tc);
97  virtual void replaceThreadContext(ThreadContext *tc);
98 
99  void startup() override;
100 
101  virtual Addr getEntry() const = 0;
102  virtual ByteOrder byteOrder() const = 0;
103  virtual loader::Arch getArch() const = 0;
104 
105  virtual const loader::SymbolTable &symtab(ThreadContext *tc) = 0;
106  virtual bool insertSymbol(const loader::Symbol &symbol) = 0;
107 
108  virtual void
110  {
111  panic("syscall() not implemented.");
112  }
113 
114  virtual void
116  {
117  warn("Unhandled workload event.");
118  }
119 
133  template <class T, typename... Args>
134  T *
135  addFuncEvent(const loader::SymbolTable &symtab, const char *lbl,
136  const std::string &desc, Args... args)
137  {
138  auto it = symtab.find(lbl);
139  if (it == symtab.end())
140  return nullptr;
141 
142  return new T(system, desc, fixFuncEventAddr(it->address),
143  std::forward<Args>(args)...);
144  }
145 
146  template <class T>
147  T *
148  addFuncEvent(const loader::SymbolTable &symtab, const char *lbl)
149  {
150  return addFuncEvent<T>(symtab, lbl, lbl);
151  }
152 
153  template <class T, typename... Args>
154  T *
156  Args... args)
157  {
158  T *e = addFuncEvent<T>(symtab, lbl, std::forward<Args>(args)...);
159  panic_if(!e, "Failed to find symbol '%s'", lbl);
160  return e;
161  }
163 };
164 
165 class StubWorkload : public Workload
166 {
167  private:
170 
171  public:
172  StubWorkload(const StubWorkloadParams &params) : Workload(params) {}
173 
174  Addr getEntry() const override { return params().entry; }
175  ByteOrder byteOrder() const override { return params().byte_order; }
176  loader::Arch getArch() const override { return loader::UnknownArch; }
177  const loader::SymbolTable &
178  symtab(ThreadContext *tc) override
179  {
180  return _symtab;
181  }
182  bool
183  insertSymbol(const loader::Symbol &symbol) override
184  {
185  return _symtab.insert(symbol);
186  }
187 };
188 
189 } // namespace gem5
190 
191 #endif // __SIM_WORKLOAD_HH__
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1930
warn
#define warn(...)
Definition: logging.hh:246
gem5::Workload::WorkloadStats::WorkloadStats
WorkloadStats(Workload *workload)
Definition: workload.hh:71
gem5::Workload::stats
gem5::Workload::WorkloadStats stats
gem5::Workload::getEntry
virtual Addr getEntry() const =0
gem5::Workload::WorkloadStats::InstStats::InstStats
InstStats(statistics::Group *parent)
Definition: workload.hh:61
gem5::Workload::WorkloadStats::InstStats
Definition: workload.hh:56
gem5::Workload::gdb
BaseRemoteGDB * gdb
Definition: workload.hh:76
gem5::ArmISA::e
Bitfield< 9 > e
Definition: misc_types.hh:65
gem5::loader::SymbolTable::end
const_iterator end() const
Definition: symtab.hh:176
gem5::loader::SymbolTable
Definition: symtab.hh:65
gem5::StubWorkload::symtab
const loader::SymbolTable & symtab(ThreadContext *tc) override
Definition: workload.hh:178
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:135
gem5::Workload::getArch
virtual loader::Arch getArch() const =0
gem5::StubWorkload::byteOrder
ByteOrder byteOrder() const override
Definition: workload.hh:175
stats.hh
gem5::StubWorkload::_symtab
loader::SymbolTable _symtab
Definition: workload.hh:169
gem5::System
Definition: system.hh:75
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:94
gem5::Workload::event
virtual void event(ThreadContext *tc)
Definition: workload.hh:115
gem5::StubWorkload
Definition: workload.hh:165
gem5::Workload::addFuncEventOrPanic
T * addFuncEventOrPanic(const loader::SymbolTable &symtab, const char *lbl, Args... args)
Definition: workload.hh:155
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
sim_object.hh
gem5::Workload::WorkloadStats
Definition: workload.hh:54
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:174
gem5::Workload::threads
std::set< ThreadContext * > threads
Definition: workload.hh:78
gem5::Workload::waitForRemoteGDB
bool waitForRemoteGDB
Definition: workload.hh:77
gem5::Workload
Definition: workload.hh:49
gem5::StubWorkload::PARAMS
PARAMS(StubWorkload)
gem5::loader::Arch
Arch
Definition: object_file.hh:62
gem5::Workload::recordArm
void recordArm()
Definition: workload.hh:90
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::Workload::trapToGdb
bool trapToGdb(int signal, ContextID ctx_id)
Definition: workload.cc:80
gem5::StubWorkload::getArch
loader::Arch getArch() const override
Definition: workload.hh:176
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:148
gem5::loader::SymbolTable::find
const_iterator find(Addr address) const
Search for a symbol by its address.
Definition: symtab.hh:322
gem5::loader::UnknownArch
@ UnknownArch
Definition: object_file.hh:64
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:204
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:55
gem5::Workload::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: workload.cc:92
gem5::Workload::replaceThreadContext
virtual void replaceThreadContext(ThreadContext *tc)
Definition: workload.cc:54
gem5::ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
gem5::Workload::WorkloadStats::InstStats::quiesce
statistics::Scalar quiesce
Definition: workload.hh:59
gem5::loader::Symbol
Definition: symtab.hh:51
gem5::StubWorkload::insertSymbol
bool insertSymbol(const loader::Symbol &symbol) override
Definition: workload.hh:183
gem5::Workload::fixFuncEventAddr
virtual Addr fixFuncEventAddr(Addr addr) const
Definition: workload.hh:52
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
gem5::Workload::system
System * system
Definition: workload.hh:80
gem5::Workload::Workload
Workload(const WorkloadParams &params)
Definition: workload.hh:83
symtab.hh
gem5::Workload::setSystem
virtual void setSystem(System *sys)
Definition: workload.hh:87
gem5::BaseRemoteGDB
Definition: remote_gdb.hh:48
gem5::Workload::registerThreadContext
virtual void registerThreadContext(ThreadContext *tc)
Definition: workload.cc:39
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:89
object_file.hh
gem5::Workload::insertSymbol
virtual bool insertSymbol(const loader::Symbol &symbol)=0
gem5::StubWorkload::StubWorkload
StubWorkload(const StubWorkloadParams &params)
Definition: workload.hh:172
gem5::Workload::syscall
virtual void syscall(ThreadContext *tc)
Definition: workload.hh:109
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
gem5::Workload::WorkloadStats::instStats
gem5::Workload::WorkloadStats::InstStats instStats
gem5::Workload::WorkloadStats::InstStats::arm
statistics::Scalar arm
Definition: workload.hh:58
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::Workload::byteOrder
virtual ByteOrder byteOrder() const =0

Generated on Thu Jul 28 2022 13:32:25 for gem5 by doxygen 1.8.17