Skip to content

Commit 59e90ba

Browse files
feat(V3): support for performance counter (#84)
1 parent 53aa1ef commit 59e90ba

File tree

5 files changed

+102
-32
lines changed

5 files changed

+102
-32
lines changed

dut/OpenLLC

main/Events/TLSystemEvent.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,20 @@ class TLSystemFinishEvent : public Gravity::Event<TLSystemFinishEvent>
6666
//
6767

6868

69+
/*
70+
* TL-Test TileLink subsystem finished events
71+
* -----------------------------------------------------------------------
72+
* This event is called by main routine to broadcast the finished state of
73+
* main routine and never called by TL-Test components.
74+
* It is guaranteed that all circuit activity was ended after this event.
75+
*/
76+
class TLSystemFinishedEvent : public Gravity::Event<TLSystemFinishedEvent>
77+
{ };
78+
79+
class TLSystemFailedEvent : public Gravity::Event<TLSystemFailedEvent>
80+
{ };
81+
//
82+
83+
6984
#endif // TLC_TEST_EVENTS_SYSTEM_EVENT_H
7085

main/Fuzzer/CFuzzer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ CFuzzer::CFuzzer(tl_agent::CAgent *cAgent) noexcept {
130130

131131
//
132132
Gravity::RegisterListener(
133-
Gravity::MakeListener<TLSystemFinishEvent>(
134-
Gravity::StringAppender("tltest.cfuzzer.bwprof.finish", uint64_t(this)).ToString(),
133+
Gravity::MakeListener<TLSystemFinishedEvent>(
134+
Gravity::StringAppender("tltest.cfuzzer.bwprof.finished", uint64_t(this)).ToString(),
135135
0,
136-
[this] (TLSystemFinishEvent& event) -> void {
136+
[this] (TLSystemFinishedEvent& event) -> void {
137137

138138
if (this->mode == TLSequenceMode::BWPROF_STREAM_STRIDE_READ)
139139
{

main/TLAgent/CAgent.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ namespace tl_agent {
137137
);
138138

139139
Gravity::RegisterListener(
140-
Gravity::MakeListener<TLSystemFinishEvent>(
141-
Gravity::StringAppender("tltest.cagent.l2tol1hintprof.finish@", uint64_t(this)).ToString(),
142-
0,
143-
[this] (TLSystemFinishEvent& event) -> void {
140+
Gravity::MakeListener<TLSystemFinishedEvent>(
141+
Gravity::StringAppender("tltest.cagent.l2tol1hintprof.finished@", uint64_t(this)).ToString(),
142+
1,
143+
[this] (TLSystemFinishedEvent& event) -> void {
144144

145145
uint64_t lostOrLateHint = this->lostOrLateL2ToL1Hints;
146146
uint64_t dissociatedHint = this->unconsumedL2ToL1Hints.size();

main/V3/v3_main.cpp

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
#include "../Plugins/PluginManager.hpp"
1414
#include "../System/TLSystem.hpp"
1515
#include "../PortGen/portgen_dynamic.hpp"
16+
#include "../Events/TLSystemEvent.hpp"
1617

1718
#include <verilated_fst_c.h>
1819

1920
#if TLTEST_MEMORY == 1
2021
#include "v3_memaxi.hpp"
2122
#endif
2223

23-
2424
static bool wave_enable = true;
2525
static uint64_t wave_begin = 0;
2626
static uint64_t wave_end = 0;
@@ -104,24 +104,6 @@ inline static void V3EvalPosedge(uint64_t& time, VTestTop* top)
104104
}
105105

106106

107-
void V3Finalize()
108-
{
109-
if (!initialized)
110-
return;
111-
112-
if (!finalized)
113-
{
114-
TLFinalize(&tltest, &plugins);
115-
finalized = true;
116-
}
117-
}
118-
119-
void V3SignalHandler(int signum)
120-
{
121-
V3Finalize();
122-
}
123-
124-
125107
template<typename, typename = void>
126108
struct has_port_time : std::false_type {};
127109

@@ -153,7 +135,7 @@ template<ConceptPortL2ToL1Hint T>
153135
struct has_port_l2_to_l1_hint<T, void> : std::true_type {};
154136

155137
template<ConceptPortL2ToL1Hint T>
156-
typename std::enable_if<has_port_l2_to_l1_hint<T>::value>::type V3PullL2ToL1Hint(
138+
typename std::enable_if<has_port_l2_to_l1_hint<T>::value>::type V3PushL2ToL1Hint(
157139
T* top,
158140
uint8_t& valid,
159141
uint32_t& sourceId,
@@ -165,23 +147,70 @@ typename std::enable_if<has_port_l2_to_l1_hint<T>::value>::type V3PullL2ToL1Hint
165147
}
166148

167149
template<typename T>
168-
typename std::enable_if<!has_port_l2_to_l1_hint<T>::value>::type V3PullL2ToL1Hint(
150+
typename std::enable_if<!has_port_l2_to_l1_hint<T>::value>::type V3PushL2ToL1Hint(
169151
T* top,
170152
uint8_t& valid,
171153
uint32_t& sourceId,
172154
uint8_t& isKeyword)
173155
{ }
174156

175-
void V3PullL2ToL1Hint(VTestTop* verilated, TLSequencer* tltest)
157+
void V3PushL2ToL1Hint(VTestTop* verilated, TLSequencer* tltest)
176158
{
177159
auto& io = tltest->L2ToL1Hint(0);
178160

179-
V3PullL2ToL1Hint<VTestTop>(verilated,
161+
V3PushL2ToL1Hint<VTestTop>(verilated,
180162
io.valid,
181163
io.sourceId,
182164
io.isKeyword);
183165
}
184166

167+
template<typename T>
168+
concept ConceptPortLogPerf = requires {
169+
{ std::declval<T>().log_dump } -> std::convertible_to<uint8_t>;
170+
{ std::declval<T>().log_clean } -> std::convertible_to<uint8_t>;
171+
};
172+
173+
template<typename, typename = void>
174+
struct has_port_log_perf : std::false_type {};
175+
176+
template<ConceptPortLogPerf T>
177+
struct has_port_log_perf<T, void> : std::true_type {};
178+
179+
template<ConceptPortLogPerf T>
180+
typename std::enable_if<has_port_log_perf<T>::value>::type V3PullLogPerf(
181+
T* top,
182+
uint8_t dump,
183+
uint8_t clean)
184+
{
185+
top->log_dump = dump;
186+
top->log_clean = clean;
187+
}
188+
189+
template<typename T>
190+
typename std::enable_if<!has_port_log_perf<T>::value>::type V3PullLogPerf(
191+
T* top,
192+
uint8_t dump,
193+
uint8_t clean)
194+
{ }
195+
196+
197+
void V3Finalize()
198+
{
199+
if (!initialized)
200+
return;
201+
202+
if (!finalized)
203+
{
204+
TLFinalize(&tltest, &plugins);
205+
finalized = true;
206+
}
207+
}
208+
209+
void V3SignalHandler(int signum)
210+
{
211+
V3Finalize();
212+
}
213+
185214

186215
int main(int argc, char **argv)
187216
{
@@ -210,13 +239,30 @@ int main(int argc, char **argv)
210239
else
211240
std::cout << "[V3Main] \033[31mNot accepting L2ToL1Hint from TestTop\033[0m." << std::endl;
212241

242+
if constexpr (has_port_log_perf<VTestTop>::value)
243+
std::cout << "[V3Main] \033[1;32mControlling Performance Logging of TestTop\033[0m." << std::endl;
244+
else
245+
std::cout << "[V3Main] \033[31mNot controlling Performance Logging of TestTop\033[0m." << std::endl;
246+
213247
//
214248
Verilated::commandArgs(argc, argv);
215249

216250
// initialize TL-Test subsystem
217251
TLInitialize(&tltest, &plugins, [](TLLocalConfig&) -> void {});
218252
initialized = true;
219253

254+
Gravity::RegisterListener(
255+
Gravity::MakeListener<TLSystemFinishEvent>(
256+
Gravity::StringAppender("v3main.finish").ToString(),
257+
-1,
258+
[&time] (TLSystemFinishEvent& event) -> void {
259+
260+
std::ios_base::sync_with_stdio(true);
261+
V3PullLogPerf(top, 1, 0);
262+
}
263+
)
264+
);
265+
220266
// load PortGen component
221267
# ifdef TLTEST_PORTGEN_DYNAMIC
222268
V3::PortGen::LoadDynamic(
@@ -267,6 +313,8 @@ int main(int argc, char **argv)
267313
fst->open(GetFstFileName().c_str());
268314
}
269315

316+
V3PullLogPerf(top, 0, 0);
317+
270318
V3Reset(time, top, 10);
271319
V3PushTime(top, time);
272320

@@ -280,7 +328,7 @@ int main(int argc, char **argv)
280328
V3::PortGen::PushChannelB(top, tltest);
281329
V3::PortGen::PushChannelD(top, tltest);
282330

283-
V3PullL2ToL1Hint(top, tltest);
331+
V3PushL2ToL1Hint(top, tltest);
284332

285333
#if TLTEST_MEMORY == 1
286334
V3::Memory::PushChannelAW(top, tltest);
@@ -337,15 +385,22 @@ int main(int argc, char **argv)
337385
//
338386
int error = 0;
339387

388+
std::cerr << std::flush;
389+
std::cout << std::flush;
390+
340391
//
341392
if (tltest->IsFinished())
342393
{
394+
TLSystemFinishedEvent().Fire();
395+
343396
LogInfo("test_top",
344397
Append("TL-Test TileLink subsystem FINISHED.")
345398
.EndLine());
346399
}
347400
else if (tltest->IsFailed())
348401
{
402+
TLSystemFailedEvent().Fire();
403+
349404
LogInfo("test_top",
350405
Append("TL-Test TileLink subsystem FAILED.")
351406
.EndLine());

0 commit comments

Comments
 (0)