gem5  v20.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 
32 #include "base/loader/symtab.hh"
33 #include "params/Workload.hh"
34 #include "sim/sim_object.hh"
35 #include "sim/stats.hh"
36 
37 class System;
38 class ThreadContext;
39 
40 class Workload : public SimObject
41 {
42  protected:
43  virtual Addr fixFuncEventAddr(Addr addr) const { return addr; }
44 
45  struct WorkloadStats : public Stats::Group
46  {
49 
50  WorkloadStats(Workload *workload) : Stats::Group(workload),
51  arm(this, "inst.arm", "number of arm instructions executed"),
52  quiesce(this, "inst.quiesce",
53  "number of quiesce instructions executed")
54  {}
55  } stats;
56 
57  public:
58  Workload(const WorkloadParams *_params) : SimObject(_params), stats(this)
59  {}
60 
61  void recordQuiesce() { stats.quiesce++; }
62  void recordArm() { stats.arm++; }
63 
64  System *system = nullptr;
65 
66  virtual Addr getEntry() const = 0;
67  virtual Loader::Arch getArch() const = 0;
68 
69  virtual const Loader::SymbolTable &symtab(ThreadContext *tc) = 0;
70  virtual bool insertSymbol(const Loader::Symbol &symbol) = 0;
71 
85  template <class T, typename... Args>
86  T *
87  addFuncEvent(const Loader::SymbolTable &symtab, const char *lbl,
88  const std::string &desc, Args... args)
89  {
90  auto it = symtab.find(lbl);
91  if (it == symtab.end())
92  return nullptr;
93 
94  return new T(system, desc, fixFuncEventAddr(it->address),
95  std::forward<Args>(args)...);
96  }
97 
98  template <class T>
99  T *
100  addFuncEvent(const Loader::SymbolTable &symtab, const char *lbl)
101  {
102  return addFuncEvent<T>(symtab, lbl, lbl);
103  }
104 
105  template <class T, typename... Args>
106  T *
108  Args... args)
109  {
110  T *e = addFuncEvent<T>(symtab, lbl, std::forward<Args>(args)...);
111  panic_if(!e, "Failed to find symbol '%s'", lbl);
112  return e;
113  }
115 };
116 
117 #endif // __SIM_WORKLOAD_HH__
Workload::stats
Workload::WorkloadStats stats
Workload
Definition: workload.hh:40
Workload::symtab
virtual const Loader::SymbolTable & symtab(ThreadContext *tc)=0
Workload::recordQuiesce
void recordQuiesce()
Definition: workload.hh:61
Loader::SymbolTable
Definition: symtab.hh:59
Workload::WorkloadStats
Definition: workload.hh:45
Workload::WorkloadStats::arm
Stats::Scalar arm
Definition: workload.hh:47
Stats::Group::Group
Group()=delete
Workload::system
System * system
Definition: workload.hh:64
Loader::SymbolTable::find
const_iterator find(Addr address) const
Definition: symtab.hh:181
Workload::getEntry
virtual Addr getEntry() const =0
Stats::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2533
stats.hh
Workload::addFuncEventOrPanic
T * addFuncEventOrPanic(const Loader::SymbolTable &symtab, const char *lbl, Args... args)
Definition: workload.hh:107
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
Workload::WorkloadStats::WorkloadStats
WorkloadStats(Workload *workload)
Definition: workload.hh:50
sim_object.hh
System
Definition: system.hh:73
Workload::insertSymbol
virtual bool insertSymbol(const Loader::Symbol &symbol)=0
Workload::Workload
Workload(const WorkloadParams *_params)
Definition: workload.hh:58
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
ArmISA::e
Bitfield< 9 > e
Definition: miscregs_types.hh:61
Workload::getArch
virtual Loader::Arch getArch() const =0
Loader::SymbolTable::end
const_iterator end() const
Definition: symtab.hh:126
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:197
Loader::Arch
Arch
Definition: object_file.hh:44
Loader::Symbol
Definition: symtab.hh:46
Workload::fixFuncEventAddr
virtual Addr fixFuncEventAddr(Addr addr) const
Definition: workload.hh:43
SimObject::_params
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:110
Stats::Group
Statistics container.
Definition: group.hh:83
addr
ip6_addr_t addr
Definition: inet.hh:423
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:87
Stats
Definition: statistics.cc:61
symtab.hh
Workload::addFuncEvent
T * addFuncEvent(const Loader::SymbolTable &symtab, const char *lbl)
Definition: workload.hh:100
Workload::WorkloadStats::quiesce
Stats::Scalar quiesce
Definition: workload.hh:48
Workload::recordArm
void recordArm()
Definition: workload.hh:62
object_file.hh
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17