gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
generator.cc
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
39
41#include "debug/TLM.hh"
42
43namespace gem5 {
44
45namespace tlm::chi {
46
47bool
49{
50 auto res_print = csprintf("Checking %s...", name());
51 if (cb(tran)) {
52 inform("%s\n", res_print + " Success ");
53 return true;
54 } else {
55 inform("%s\n", res_print + " Fail ");
56 return false;
57 }
58}
59
60bool
62{
63 if (Expectation::run(tran)) {
64 return true;
65 } else {
66 panic("Failing assertion\n");
67 }
68}
69
70TlmGenerator::Transaction::Transaction(ARM::CHI::Payload *pa, ARM::CHI::Phase &ph)
71 : passed(true), parent(nullptr), _payload(pa), _phase(ph)
72{
73 _payload->ref();
74}
75
77{
78 _payload->unref();
79}
80
81void
86
87std::string
89{
90 return transactionToString(*_payload, _phase);
91}
92
93void
95{
96 parent->inject(this);
97}
98
99bool
101{
102 return !actions.empty();
103}
104
105bool
107{
108 return !passed;
109}
110
111void
113{
114 actions.push_back(std::move(action));
115}
116
117void
119{
120 // print transaction
121 auto it = actions.begin();
122 while (it != actions.end()) {
123 const bool is_passing = (*it)->run(this);
124 if (!is_passing) {
125 passed = false;
126 }
127 bool wait = (*it)->wait();
128
129 it = actions.erase(it);
130
131 if (wait) {
132 break;
133 }
134 }
135}
136
137void
139{
140 transaction->inject();
141}
142
144 : SimObject(p), cpuId(p.cpu_id), controller(p.chi_controller)
145{
146 controller->bw = [this] (ARM::CHI::Payload *payload, ARM::CHI::Phase *phase)
147 {
148 this->recv(payload, phase);
149 };
150
151 registerExitCallback([this](){ passFailCheck(); });
152}
153
154void
156{
157 transaction->setGenerator(this);
158
159 auto event = new TransactionEvent(transaction, when);
160
162
163 schedule(event, when);
164}
165
166void
168{
169 auto payload = transaction->payload();
170 ARM::CHI::Phase &phase = transaction->phase();
171
172 if (transaction->hasCallbacks())
173 pendingTransactions.insert({phase.txn_id, transaction});
174
175 DPRINTF(TLM, "[c%d] send %s\n", cpuId, transactionToString(*payload, phase));
176
177 controller->sendMsg(*payload, phase);
178}
179
180void
181TlmGenerator::recv(ARM::CHI::Payload *payload, ARM::CHI::Phase *phase)
182{
183 DPRINTF(TLM, "[c%d] rcvd %s\n", cpuId, transactionToString(*payload, *phase));
184
185 auto txn_id = phase->txn_id;
186 if (auto it = pendingTransactions.find(txn_id);
187 it != pendingTransactions.end()) {
188 // Copy the new phase
189 it->second->phase() = *phase;
190
191 // Check existing expectations
192 it->second->runCallbacks();
193 } else {
194 warn("Transaction untested\n");
195 }
196}
197
198void
200{
201 for (auto [txn_id, transaction] : pendingTransactions) {
202 // We are failing either if a condition hasn't been met,
203 // or if there are pending actions when simulation exits
204 if (transaction->failed()) {
205 inform(" Suite Fail: failed transaction ");
206 return;
207 }
208 if (transaction->hasCallbacks()) {
209 inform(" Suite Fail: non-empty action queue ");
210 return;
211 }
212 }
213 inform(" Suite Success ");
214}
215
216} // namespace tlm::chi
217
218} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
Abstract superclass for simulation objects.
SimObjectParams Params
void sendMsg(ARM::CHI::Payload &payload, ARM::CHI::Phase &phase)
std::function< void(ARM::CHI::Payload *payload, ARM::CHI::Phase *phase)> bw
Set this to send data upstream.
Definition controller.hh:98
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
TlmGenerator(const Params &p)
Definition generator.cc:143
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
uint8_t cpuId
cpuId to mimic the behaviour of a CPU
Definition generator.hh:284
void schedule(Event &event, Tick when)
Definition eventq.hh:1012
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define warn(...)
Definition logging.hh:256
#define inform(...)
Definition logging.hh:257
Bitfield< 39, 12 > pa
Bitfield< 10, 5 > event
Bitfield< 0 > p
std::string transactionToString(const Payload &payload, const Phase &phase)
Definition utils.cc:234
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t Tick
Tick count type.
Definition types.hh:58
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
void registerExitCallback(const std::function< void()> &callback)
Register an exit callback.
Definition core.cc:143

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