gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
generator.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Arm Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef __MEM_RUBY_PROTOCOL_CHI_TLM_GENERATOR_HH__
39#define __MEM_RUBY_PROTOCOL_CHI_TLM_GENERATOR_HH__
40
41#include <queue>
42#include <unordered_map>
43
44#include <ARM/TLM/arm_chi.h>
45
47#include "params/TlmGenerator.hh"
48#include "sim/eventq.hh"
49#include "sim/sim_object.hh"
50
51namespace gem5 {
52
53namespace tlm::chi {
54
55class CacheController;
56
88class TlmGenerator : public SimObject
89{
90 public:
92 TlmGenerator(const Params &p);
93
115 {
116 public:
123 class Action
124 {
125 public:
126 using Callback = std::function<
127 bool(Transaction *tran)
128 >;
129
130 Action(Callback _cb, bool waiting)
131 : cb(_cb), _wait(waiting)
132 {}
133 virtual ~Action() {};
134
135 /* A basic action always returns true */
136 virtual bool
138 {
139 cb(tran);
140 return true;
141 }
142
147 bool wait() const { return _wait; }
148
149 protected:
151 bool _wait;
152 };
153
160 class Expectation : public Action
161 {
162 public:
163 Expectation(std::string exp_name, Callback _cb)
164 : Action(_cb, false), _name(exp_name)
165 {}
166
167 bool run(Transaction *tran) override;
168
169 std::string name() const { return _name; }
170
171 private:
172 std::string _name;
173 };
174
181 class Assertion : public Expectation
182 {
183 public:
184 Assertion(std::string exp_name, Callback _cb)
185 : Expectation(exp_name, _cb)
186 {}
187
188 bool run(Transaction *tran) override;
189 };
190
191 using ActionPtr = std::unique_ptr<Action>;
193
194 Transaction(const Transaction &rhs) = delete;
195 Transaction(ARM::CHI::Payload *pa, ARM::CHI::Phase &ph);
196 ~Transaction();
197
203 void setGenerator(TlmGenerator *gen);
204
205 std::string str() const;
206
207 void inject();
208
213 bool failed() const;
214
219 bool hasCallbacks() const;
220
224 void addCallback(ActionPtr &&action);
225
231 void runCallbacks();
232
233 ARM::CHI::Payload* payload() const { return _payload; }
234 ARM::CHI::Phase& phase() { return _phase; }
235
236 private:
238 bool passed;
239
241 ARM::CHI::Payload *_payload;
242 ARM::CHI::Phase _phase;
243 };
244
245 void scheduleTransaction(Tick when, Transaction *tr);
246
247 protected:
248 struct TransactionEvent : public Event
249 {
250 public:
251 struct Compare
252 {
253 bool
255 const TransactionEvent *rhs)
256 {
257 return lhs->when < rhs->when;
258 }
259 };
260
262 Tick _when)
263 : Event(), transaction(_transaction), when(_when)
264 {}
265
266 void process() override;
267
268 const char*
269 description() const override
270 {
271 return "CHI Transaction event";
272 }
273
276 };
277
278 void inject(Transaction *transaction);
279 void recv(ARM::CHI::Payload *payload, ARM::CHI::Phase *phase);
280 void passFailCheck();
281
282 protected:
284 uint8_t cpuId;
285
286 using SchedulingQueue = std::priority_queue<TransactionEvent*,
289
292
294 std::unordered_map<uint16_t, Transaction*> pendingTransactions;
295
298};
299
300} // namespace tlm::chi
301
302} // namespace gem5
303
304#endif // __MEM_RUBY_PROTOCOL_CHI_TLM_GENERATOR_HH__
Tick _when
timestamp when event should be processed
Definition eventq.hh:274
Abstract superclass for simulation objects.
SimObjectParams Params
The tlm::chi::CacheController is a ruby CacheController which acts as a bridge between the AMBA TLM 2...
Definition controller.hh:92
Action: Does something without condition checking.
Definition generator.hh:124
std::function< bool(Transaction *tran) > Callback
Definition generator.hh:128
bool wait() const
Returns true if the action dispatcher should break the dispatching loop once the action has been exec...
Definition generator.hh:147
Assertion: Will check for a specific condition and will fail if the condition is not met.
Definition generator.hh:182
Assertion(std::string exp_name, Callback _cb)
Definition generator.hh:184
Expectation: Will check for a specific condition and will warn if the condition is not met.
Definition generator.hh:161
Expectation(std::string exp_name, Callback _cb)
Definition generator.hh:163
Transaction object It stores ARM::CHI::Payload and ARM::CHI::Phase objects, and a list of action call...
Definition generator.hh:115
bool failed() const
Returns true if the transaction has failed, false otherwise.
Definition generator.cc:106
void addCallback(ActionPtr &&action)
Appends a callback to the list of actions.
Definition generator.cc:112
std::unique_ptr< Action > ActionPtr
Definition generator.hh:191
void runCallbacks()
Enters the dispatching loop and runs the callbacks in insertion order until a waiting callback is enc...
Definition generator.cc:118
ARM::CHI::Payload * payload() const
Definition generator.hh:233
Transaction(const Transaction &rhs)=delete
void setGenerator(TlmGenerator *gen)
Registers the TlmGenerator in the transaction.
Definition generator.cc:82
bool hasCallbacks() const
Returns true if the transaction has some registered callbacks, false otherwise.
Definition generator.cc:100
TlmGenerator: this class is basically a CHI-tlm traffic generator.
Definition generator.hh:89
std::unordered_map< uint16_t, Transaction * > pendingTransactions
Map of pending (injected) transactions indexed by the txn_id.
Definition generator.hh:294
void scheduleTransaction(Tick when, Transaction *tr)
Definition generator.cc:155
SchedulingQueue scheduledTransactions
PQ of transactions whose injection needs to be scheduled.
Definition generator.hh:291
void inject(Transaction *transaction)
Definition generator.cc:167
void recv(ARM::CHI::Payload *payload, ARM::CHI::Phase *phase)
Definition generator.cc:181
CacheController * controller
Pointer to the CHI-tlm controller.
Definition generator.hh:297
std::priority_queue< TransactionEvent *, std::vector< TransactionEvent * >, TransactionEvent::Compare > SchedulingQueue
Definition generator.hh:288
uint8_t cpuId
cpuId to mimic the behaviour of a CPU
Definition generator.hh:284
STL vector class.
Definition stl.hh:37
Bitfield< 39, 12 > pa
Bitfield< 0 > p
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t Tick
Tick count type.
Definition types.hh:58
bool operator()(const TransactionEvent *lhs, const TransactionEvent *rhs)
Definition generator.hh:254
TransactionEvent(Transaction *_transaction, Tick _when)
Definition generator.hh:261
const char * description() const override
Return a C string describing the event.
Definition generator.hh:269

Generated on Mon Jan 13 2025 04:28:40 for gem5 by doxygen 1.9.8