gem5  v21.1.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 "params/Workload.hh"
37 #include "sim/sim_object.hh"
38 #include "sim/stats.hh"
39 
40 namespace gem5
41 {
42 
43 class BaseRemoteGDB;
44 class System;
45 class ThreadContext;
46 
47 class Workload : public SimObject
48 {
49  protected:
50  virtual Addr fixFuncEventAddr(Addr addr) const { return addr; }
51 
53  {
55  {
58 
60  : statistics::Group(parent, "inst"),
61  ADD_STAT(arm, statistics::units::Count::get(),
62  "number of arm instructions executed"),
63  ADD_STAT(quiesce, statistics::units::Count::get(),
64  "number of quiesce instructions executed")
65  {}
66 
67  } instStats;
68 
69  WorkloadStats(Workload *workload) : statistics::Group(workload),
70  instStats(workload)
71  {}
72  } stats;
73 
74  BaseRemoteGDB *gdb = nullptr;
75  bool waitForRemoteGDB = false;
76  std::set<ThreadContext *> threads;
77 
78  System *system = nullptr;
79 
80  public:
81  Workload(const WorkloadParams &params) : SimObject(params), stats(this),
82  waitForRemoteGDB(params.wait_for_remote_gdb)
83  {}
84 
85  virtual void setSystem(System *sys) { system = sys; }
86 
88  void recordArm() { stats.instStats.arm++; }
89 
90  // Once trapping into GDB is no longer a special case routed through the
91  // system object, this helper can be removed.
92  bool trapToGdb(int signal, ContextID ctx_id);
93 
94  virtual void registerThreadContext(ThreadContext *tc);
95  virtual void replaceThreadContext(ThreadContext *tc);
96 
97  void startup() override;
98 
99  virtual Addr getEntry() const = 0;
100  virtual loader::Arch getArch() const = 0;
101 
102  virtual const loader::SymbolTable &symtab(ThreadContext *tc) = 0;
103  virtual bool insertSymbol(const loader::Symbol &symbol) = 0;
104 
105  virtual void
107  {
108  panic("syscall() not implemented.");
109  }
110 
111  virtual void
113  {
114  warn("Unhandled workload event.");
115  }
116 
130  template <class T, typename... Args>
131  T *
132  addFuncEvent(const loader::SymbolTable &symtab, const char *lbl,
133  const std::string &desc, Args... args)
134  {
135  auto it = symtab.find(lbl);
136  if (it == symtab.end())
137  return nullptr;
138 
139  return new T(system, desc, fixFuncEventAddr(it->address),
140  std::forward<Args>(args)...);
141  }
142 
143  template <class T>
144  T *
145  addFuncEvent(const loader::SymbolTable &symtab, const char *lbl)
146  {
147  return addFuncEvent<T>(symtab, lbl, lbl);
148  }
149 
150  template <class T, typename... Args>
151  T *
153  Args... args)
154  {
155  T *e = addFuncEvent<T>(symtab, lbl, std::forward<Args>(args)...);
156  panic_if(!e, "Failed to find symbol '%s'", lbl);
157  return e;
158  }
160 };
161 
162 } // namespace gem5
163 
164 #endif // __SIM_WORKLOAD_HH__
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1927
warn
#define warn(...)
Definition: logging.hh:245
gem5::Workload::WorkloadStats::WorkloadStats
WorkloadStats(Workload *workload)
Definition: workload.hh:69
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:59
gem5::Workload::WorkloadStats::InstStats
Definition: workload.hh:54
gem5::Workload::gdb
BaseRemoteGDB * gdb
Definition: workload.hh:74
gem5::ArmISA::e
Bitfield< 9 > e
Definition: misc_types.hh:64
gem5::loader::SymbolTable::end
const_iterator end() const
Definition: symtab.hh:176
gem5::loader::SymbolTable
Definition: symtab.hh:65
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:132
gem5::Workload::getArch
virtual loader::Arch getArch() const =0
stats.hh
gem5::System
Definition: system.hh:77
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:93
gem5::Workload::event
virtual void event(ThreadContext *tc)
Definition: workload.hh:112
gem5::Workload::addFuncEventOrPanic
T * addFuncEventOrPanic(const loader::SymbolTable &symtab, const char *lbl, Args... args)
Definition: workload.hh:152
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
sim_object.hh
gem5::Workload::WorkloadStats
Definition: workload.hh:52
ADD_STAT
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:75
gem5::Workload::threads
std::set< ThreadContext * > threads
Definition: workload.hh:76
gem5::Workload::waitForRemoteGDB
bool waitForRemoteGDB
Definition: workload.hh:75
gem5::Workload
Definition: workload.hh:47
gem5::loader::Arch
Arch
Definition: object_file.hh:50
gem5::Workload::recordArm
void recordArm()
Definition: workload.hh:88
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::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:145
gem5::loader::SymbolTable::find
const_iterator find(Addr address) const
Search for a symbol by its address.
Definition: symtab.hh:322
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:203
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:246
gem5::Workload::WorkloadStats::InstStats::quiesce
statistics::Scalar quiesce
Definition: workload.hh:57
gem5::loader::Symbol
Definition: symtab.hh:51
gem5::Workload::fixFuncEventAddr
virtual Addr fixFuncEventAddr(Addr addr) const
Definition: workload.hh:50
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
gem5::Workload::system
System * system
Definition: workload.hh:78
gem5::Workload::Workload
Workload(const WorkloadParams &params)
Definition: workload.hh:81
symtab.hh
gem5::Workload::setSystem
virtual void setSystem(System *sys)
Definition: workload.hh:85
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: decoder.cc:40
gem5::Workload::recordQuiesce
void recordQuiesce()
Definition: workload.hh:87
object_file.hh
gem5::Workload::insertSymbol
virtual bool insertSymbol(const loader::Symbol &symbol)=0
gem5::Workload::syscall
virtual void syscall(ThreadContext *tc)
Definition: workload.hh:106
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::Workload::WorkloadStats::instStats
gem5::Workload::WorkloadStats::InstStats instStats
gem5::Workload::WorkloadStats::InstStats::arm
statistics::Scalar arm
Definition: workload.hh:56
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Tue Sep 21 2021 12:25:48 for gem5 by doxygen 1.8.17