gem5  v22.1.0.0
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 
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  bool sendToGdb(std::string msg);
96 
97  virtual void registerThreadContext(ThreadContext *tc);
98  virtual void replaceThreadContext(ThreadContext *tc);
99 
100  void startup() override;
101 
102  virtual Addr getEntry() const = 0;
103  virtual ByteOrder byteOrder() const = 0;
104  virtual loader::Arch getArch() const = 0;
105 
106  virtual const loader::SymbolTable &symtab(ThreadContext *tc) = 0;
107  virtual bool insertSymbol(const loader::Symbol &symbol) = 0;
108 
109  virtual void
111  {
112  panic("syscall() not implemented.");
113  }
114 
115  virtual void
117  {
118  warn("Unhandled workload event.");
119  }
120 
134  template <class T, typename... Args>
135  T *
136  addFuncEvent(const loader::SymbolTable &symtab, const char *lbl,
137  const std::string &desc, Args... args)
138  {
139  auto it = symtab.find(lbl);
140  if (it == symtab.end())
141  return nullptr;
142 
143  return new T(system, desc, fixFuncEventAddr(it->address),
144  std::forward<Args>(args)...);
145  }
146 
147  template <class T>
148  T *
149  addFuncEvent(const loader::SymbolTable &symtab, const char *lbl)
150  {
151  return addFuncEvent<T>(symtab, lbl, lbl);
152  }
153 
154  template <class T, typename... Args>
155  T *
157  Args... args)
158  {
159  T *e = addFuncEvent<T>(symtab, lbl, std::forward<Args>(args)...);
160  panic_if(!e, "Failed to find symbol '%s'", lbl);
161  return e;
162  }
164 };
165 
166 class StubWorkload : public Workload
167 {
168  private:
171 
172  public:
173  StubWorkload(const StubWorkloadParams &params) : Workload(params) {}
174 
175  Addr getEntry() const override { return params().entry; }
176  ByteOrder byteOrder() const override { return params().byte_order; }
177  loader::Arch getArch() const override { return loader::UnknownArch; }
178  const loader::SymbolTable &
179  symtab(ThreadContext *tc) override
180  {
181  return _symtab;
182  }
183  bool
184  insertSymbol(const loader::Symbol &symbol) override
185  {
186  return _symtab.insert(symbol);
187  }
188 };
189 
190 } // namespace gem5
191 
192 #endif // __SIM_WORKLOAD_HH__
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
loader::SymbolTable _symtab
Definition: workload.hh:170
PARAMS(StubWorkload)
Addr getEntry() const override
Definition: workload.hh:175
const loader::SymbolTable & symtab(ThreadContext *tc) override
Definition: workload.hh:179
ByteOrder byteOrder() const override
Definition: workload.hh:176
loader::Arch getArch() const override
Definition: workload.hh:177
bool insertSymbol(const loader::Symbol &symbol) override
Definition: workload.hh:184
StubWorkload(const StubWorkloadParams &params)
Definition: workload.hh:173
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual void event(ThreadContext *tc)
Definition: workload.hh:116
virtual void replaceThreadContext(ThreadContext *tc)
Definition: workload.cc:51
BaseRemoteGDB * gdb
Definition: workload.hh:76
bool waitForRemoteGDB
Definition: workload.hh:77
virtual loader::Arch getArch() const =0
void startup() override
startup() is the final initialization call before simulation.
Definition: workload.cc:93
virtual const loader::SymbolTable & symtab(ThreadContext *tc)=0
void recordArm()
Definition: workload.hh:90
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:136
bool trapToGdb(int signal, ContextID ctx_id)
Definition: workload.cc:75
virtual Addr fixFuncEventAddr(Addr addr) const
Definition: workload.hh:52
T * addFuncEventOrPanic(const loader::SymbolTable &symtab, const char *lbl, Args... args)
Definition: workload.hh:156
virtual bool insertSymbol(const loader::Symbol &symbol)=0
virtual ByteOrder byteOrder() const =0
virtual void registerThreadContext(ThreadContext *tc)
Definition: workload.cc:38
virtual Addr getEntry() const =0
virtual void syscall(ThreadContext *tc)
Definition: workload.hh:110
void recordQuiesce()
Definition: workload.hh:89
virtual void setSystem(System *sys)
Definition: workload.hh:87
gem5::Workload::WorkloadStats stats
T * addFuncEvent(const loader::SymbolTable &symtab, const char *lbl)
Definition: workload.hh:149
std::set< ThreadContext * > threads
Definition: workload.hh:78
Workload(const WorkloadParams &params)
Definition: workload.hh:83
bool sendToGdb(std::string msg)
Definition: workload.cc:84
System * system
Definition: workload.hh:80
const_iterator end() const
Definition: symtab.hh:176
bool insert(const Symbol &symbol)
Insert a new symbol in the table if it does not already exist.
Definition: symtab.cc:55
const_iterator find(Addr address) const
Search for a symbol by its address.
Definition: symtab.hh:322
Statistics container.
Definition: group.hh:94
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:75
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#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
const Params & params() const
Definition: sim_object.hh:176
#define warn(...)
Definition: logging.hh:246
Bitfield< 9 > e
Definition: misc_types.hh:65
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
InstStats(statistics::Group *parent)
Definition: workload.hh:61
WorkloadStats(Workload *workload)
Definition: workload.hh:71
gem5::Workload::WorkloadStats::InstStats instStats

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