gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
43namespace gem5
44{
45
46class BaseRemoteGDB;
47class System;
48class ThreadContext;
49
50class 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
71
72 WorkloadStats(Workload *workload) : statistics::Group(workload),
73 instStats(workload)
74 {}
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
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;
107 virtual SimObject* getSemihosting() const { return nullptr; }
108
109 virtual const loader::SymbolTable &symtab(ThreadContext *tc) = 0;
110 virtual bool insertSymbol(const loader::Symbol &symbol) = 0;
111
112 virtual void
114 {
115 panic("syscall() not implemented.");
116 }
117
118 virtual void
120 {
121 warn("Unhandled workload event.");
122 }
123
137 template <class T, typename... Args>
138 T *
139 addFuncEvent(const loader::SymbolTable &symtab, const char *lbl,
140 const std::string &desc, Args... args)
141 {
142 auto it = symtab.find(lbl);
143 if (it == symtab.end())
144 return nullptr;
145
146 return new T(system, desc, fixFuncEventAddr(it->address()),
147 std::forward<Args>(args)...);
148 }
149
150 template <class T>
151 T *
152 addFuncEvent(const loader::SymbolTable &symtab, const char *lbl)
153 {
154 return addFuncEvent<T>(symtab, lbl, lbl);
155 }
156
157 template <class T, typename... Args>
158 T *
160 Args... args)
161 {
162 T *e = addFuncEvent<T>(symtab, lbl, std::forward<Args>(args)...);
163 panic_if(!e, "Failed to find symbol '%s'", lbl);
164 return e;
165 }
167};
168
169class StubWorkload : public Workload
170{
171 private:
174
175 public:
176 StubWorkload(const StubWorkloadParams &params) : Workload(params) {}
177
178 Addr getEntry() const override { return params().entry; }
179 ByteOrder byteOrder() const override { return params().byte_order; }
180 loader::Arch getArch() const override { return loader::UnknownArch; }
181 const loader::SymbolTable &
182 symtab(ThreadContext *tc) override
183 {
184 return _symtab;
185 }
186 bool
187 insertSymbol(const loader::Symbol &symbol) override
188 {
189 return _symtab.insert(symbol);
190 }
191};
192
193} // namespace gem5
194
195#endif // __SIM_WORKLOAD_HH__
Abstract superclass for simulation objects.
loader::SymbolTable _symtab
Definition workload.hh:173
PARAMS(StubWorkload)
Addr getEntry() const override
Definition workload.hh:178
const loader::SymbolTable & symtab(ThreadContext *tc) override
Definition workload.hh:182
ByteOrder byteOrder() const override
Definition workload.hh:179
loader::Arch getArch() const override
Definition workload.hh:180
bool insertSymbol(const loader::Symbol &symbol) override
Definition workload.hh:187
StubWorkload(const StubWorkloadParams &params)
Definition workload.hh:176
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual void event(ThreadContext *tc)
Definition workload.hh:119
virtual void replaceThreadContext(ThreadContext *tc)
Definition workload.cc:51
BaseRemoteGDB * gdb
Definition workload.hh:77
bool waitForRemoteGDB
Definition workload.hh:78
virtual const loader::SymbolTable & symtab(ThreadContext *tc)=0
virtual loader::Arch getArch() const =0
void startup() override
startup() is the final initialization call before simulation.
Definition workload.cc:93
void recordArm()
Definition workload.hh:91
T * addFuncEvent(const loader::SymbolTable &symtab, const char *lbl)
Definition workload.hh:152
virtual Addr fixFuncEventAddr(Addr addr) const
Definition workload.hh:53
virtual bool insertSymbol(const loader::Symbol &symbol)=0
T * addFuncEventOrPanic(const loader::SymbolTable &symtab, const char *lbl, Args... args)
Definition workload.hh:159
virtual ByteOrder byteOrder() const =0
virtual void registerThreadContext(ThreadContext *tc)
Definition workload.cc:38
virtual SimObject * getSemihosting() const
Returns the semihosting interface if supported by the current workload.
Definition workload.hh:107
virtual Addr getEntry() const =0
virtual void syscall(ThreadContext *tc)
Definition workload.hh:113
bool trapToGdb(GDBSignal sig, ContextID ctx_id)
Definition workload.cc:75
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:139
void recordQuiesce()
Definition workload.hh:90
virtual void setSystem(System *sys)
Definition workload.hh:88
gem5::Workload::WorkloadStats stats
std::set< ThreadContext * > threads
Definition workload.hh:79
Workload(const WorkloadParams &params)
Definition workload.hh:84
bool sendToGdb(std::string msg)
Definition workload.cc:84
System * system
Definition workload.hh:81
const_iterator end() const
Definition symtab.hh:278
bool insert(const Symbol &symbol)
Insert a new symbol in the table if it does not already exist.
Definition symtab.cc:66
const_iterator find(Addr address) const
Search for a symbol by its address.
Definition symtab.hh:435
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
#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:188
#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
const Params & params() const
#define warn(...)
Definition logging.hh:256
Bitfield< 9 > e
Definition misc_types.hh:65
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
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:62
WorkloadStats(Workload *workload)
Definition workload.hh:72
gem5::Workload::WorkloadStats::InstStats instStats

Generated on Tue Jun 18 2024 16:24:00 for gem5 by doxygen 1.11.0