Skip to content

Commit 9f5386e

Browse files
committed
[cru] Add support for Run Statistics links
1 parent e1d1f94 commit 9f5386e

File tree

12 files changed

+104
-38
lines changed

12 files changed

+104
-38
lines changed

cru_template.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ gbtEnabled=true
5050
# [true | false]
5151
userLogicEnabled=false
5252

53+
# [true | false]
54+
runStatsEnabled=true
55+
5356
#############################################
5457
# links
5558
#############################################

include/ReadoutCard/Parameters.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class Parameters
119119
/// Type for the User Logic enabled parameter
120120
using UserLogicEnabledType = bool;
121121

122+
/// Type for the Run Statistics enabled parameter
123+
using RunStatsEnabledType = bool;
124+
122125
/// Type for the GBT enabled parameter
123126
using GbtEnabledType = bool;
124127

@@ -228,6 +231,14 @@ class Parameters
228231
/// \return Reference to this object for chaining calls
229232
auto setUserLogicEnabled(UserLogicEnabledType value) -> Parameters&;
230233

234+
/// Sets the RunStatsEnabled parameter
235+
///
236+
/// If enabled the Run Statistics link is enabled
237+
///
238+
/// \param value The value to set
239+
/// \return Reference to this object for chaining calls
240+
auto setRunStatsEnabled(RunStatsEnabledType value) -> Parameters&;
241+
231242
/// Sets the OnuAddress parameter
232243
///
233244
/// \param value The value to set
@@ -432,6 +443,10 @@ class Parameters
432443
/// \return The value wrapped in an optional if it is present, or an empty optional if it was not
433444
auto getUserLogicEnabled() const -> boost::optional<UserLogicEnabledType>;
434445

446+
/// Gets the RunStatsEnabled parameter
447+
/// \return The value wrapped in an optional if it is present, or an empty optional if it was not
448+
auto getRunStatsEnabled() const -> boost::optional<RunStatsEnabledType>;
449+
435450
/// Gets the OnuAddress parameter
436451
/// \return The value wrapped in an optional if it is present, or an empty optional if it was not
437452
auto getOnuAddress() const -> boost::optional<OnuAddressType>;
@@ -539,6 +554,11 @@ class Parameters
539554
/// \return The value
540555
auto getUserLogicEnabledRequired() const -> UserLogicEnabledType;
541556

557+
/// Gets the RunStatsEnabled parameter
558+
/// \exception ParameterException The parameter was not present
559+
/// \return The value
560+
auto getRunStatsEnabledRequired() const -> RunStatsEnabledType;
561+
542562
/// Gets the OnuAddress parameter
543563
/// \exception ParameterException The parameter was not present
544564
/// \return The value

src/CardConfigurator.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void CardConfigurator::parseConfigUriCru(std::string configUri, Parameters& para
9292
uint32_t triggerWindowSize = 1000;
9393
bool gbtEnabled = false;
9494
bool userLogicEnabled = false;
95+
bool runStatsEnabled = false;
9596

9697
bool enabled = false;
9798
std::string gbtMux = "ttc";
@@ -143,6 +144,7 @@ void CardConfigurator::parseConfigUriCru(std::string configUri, Parameters& para
143144

144145
gbtEnabled = subtree.get<bool>("gbtEnabled");
145146
userLogicEnabled = subtree.get<bool>("userLogicEnabled");
147+
runStatsEnabled = subtree.get<bool>("runStatsEnabled");
146148

147149
parameters.setClock(clock);
148150
parameters.setDatapathMode(datapathMode);
@@ -157,7 +159,7 @@ void CardConfigurator::parseConfigUriCru(std::string configUri, Parameters& para
157159
parameters.setTriggerWindowSize(triggerWindowSize);
158160
parameters.setGbtEnabled(gbtEnabled);
159161
parameters.setUserLogicEnabled(userLogicEnabled);
160-
162+
parameters.setRunStatsEnabled(runStatsEnabled);
161163
} else if (group == "links") { // Configure all links with default values
162164

163165
enabled = subtree.get<bool>("enabled");

src/CommandLineUtilities/ProgramConfig.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ class ProgramConfig : public Program
111111
options.add_options()("user-logic",
112112
po::bool_switch(&mOptions.userLogicEnabled),
113113
"Flag to enable the User Logic link");
114+
options.add_options()("run-stats",
115+
po::bool_switch(&mOptions.runStatsEnabled),
116+
"Flag to enable the Run Statistics link");
114117
Options::addOptionCardId(options);
115118
}
116119

@@ -171,6 +174,7 @@ class ProgramConfig : public Program
171174
params.setTriggerWindowSize(mOptions.triggerWindowSize);
172175
params.setGbtEnabled(!mOptions.noGbt);
173176
params.setUserLogicEnabled(mOptions.userLogicEnabled);
177+
params.setRunStatsEnabled(mOptions.runStatsEnabled);
174178
params.setTimeFrameLength(mOptions.timeFrameLength);
175179
params.setTimeFrameDetectionEnabled(!mOptions.timeFrameDetectionDisabled);
176180

@@ -247,6 +251,7 @@ class ProgramConfig : public Program
247251
uint32_t timeFrameLength = 0x100;
248252
bool timeFrameDetectionDisabled = false;
249253
bool userLogicEnabled = false;
254+
bool runStatsEnabled = false;
250255
bool noGbt = false;
251256
} mOptions;
252257

src/CommandLineUtilities/ProgramPacketMonitor.cxx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class ProgramPacketMonitor : public Program
8888
// initialize ptrees
8989
pt::ptree root;
9090
pt::ptree gbtLinks;
91-
pt::ptree ulLink;
9291

9392
/* TABLE */
9493
for (const auto& el : packetMonitoringInfo.linkPacketInfoMap) {
@@ -98,20 +97,6 @@ class ProgramPacketMonitor : public Program
9897
uint32_t rejected = linkMonitoringInfoMap.rejected;
9998
uint32_t forced = linkMonitoringInfoMap.forced;
10099

101-
/* UL HEADER */
102-
if (globalId == 15) {
103-
auto uLHeader = (boost::format(formatHeader) % "ULL ID " % "Accepted" % "Rejected" % "Forced").str();
104-
105-
if (mOptions.jsonOut) {
106-
107-
} else if (mOptions.csvOut) {
108-
auto uLHeader = "Link ID,Accepted,Rejected,Forced\n";
109-
std::cout << uLHeader;
110-
} else {
111-
table << lineFat << uLHeader << lineThin;
112-
}
113-
}
114-
115100
if (mOptions.jsonOut) {
116101
pt::ptree linkNode;
117102

@@ -121,12 +106,7 @@ class ProgramPacketMonitor : public Program
121106
linkNode.put("rejected", std::to_string(rejected));
122107
linkNode.put("forced", std::to_string(forced));
123108

124-
// append to the links (or UL link)
125-
if (globalId == 15) {
126-
ulLink.add_child(std::to_string(globalId), linkNode);
127-
} else {
128-
gbtLinks.add_child(std::to_string(globalId), linkNode);
129-
}
109+
gbtLinks.add_child(std::to_string(globalId), linkNode);
130110
} else if (mOptions.csvOut) {
131111
auto csvLine = std::to_string(globalId) + "," + std::to_string(accepted) + "," + std::to_string(rejected) + "," + std::to_string(forced) + "\n";
132112
std::cout << csvLine;
@@ -138,7 +118,6 @@ class ProgramPacketMonitor : public Program
138118

139119
// add links nodes to the tree
140120
root.add_child("gbtLinks", gbtLinks);
141-
root.add_child("userLogicLink", ulLink);
142121

143122
/* PRINT */
144123
if (!mOptions.csvOut) {

src/CommandLineUtilities/ProgramStatus.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class ProgramStatus : public Program
181181
auto cruBar2 = std::dynamic_pointer_cast<CruBar>(bar2);
182182

183183
if (mOptions.csvOut) {
184-
auto csvHeader = "Link ID,GBT Mode,Loopback,GBT Mux,Datapath Mode,Datapath,RX Freq(MHz),TX Freq(MHz),Status,Optical Power(uW),Clock,Offset,UserLogic\n";
184+
auto csvHeader = "Link ID,GBT Mode,Loopback,GBT Mux,Datapath Mode,Datapath,RX Freq(MHz),TX Freq(MHz),Status,Optical Power(uW),Clock,Offset,UserLogic,RunStats\n";
185185
std::cout << csvHeader;
186186
} else if (!mOptions.jsonOut) {
187187
table << lineFat << header << lineThin;
@@ -192,6 +192,7 @@ class ProgramStatus : public Program
192192
std::string clock = (reportInfo.ttcClock == 0 ? "TTC" : "Local");
193193
std::string offset = (reportInfo.dynamicOffset ? "Dynamic" : "Fixed");
194194
std::string userLogic = (reportInfo.userLogicEnabled ? "Enabled" : "Disabled");
195+
std::string runStats = (reportInfo.runStatsEnabled ? "Enabled" : "Disabled");
195196

196197
/* GENERAL PARAMETERS */
197198
if (mOptions.monitoring) {
@@ -200,20 +201,23 @@ class ProgramStatus : public Program
200201
.addValue(clock, "clock")
201202
.addValue(reportInfo.dynamicOffset, "dynamicOffset")
202203
.addValue(reportInfo.userLogicEnabled, "userLogic")
204+
.addValue(reportInfo.runStatsEnabled, "runStats")
203205
.addTag(tags::Key::ID, card.sequenceId)
204206
.addTag(tags::Key::Type, tags::Value::CRU));
205207
} else if (mOptions.jsonOut) {
206208
root.put("clock", clock);
207209
root.put("offset", offset);
208210
root.put("userLogic", userLogic);
211+
root.put("runStats", runStats);
209212
} else if (mOptions.csvOut) {
210-
auto csvLine = ",,,,,,,,,," + clock + "," + offset + "," + userLogic + "\n";
213+
auto csvLine = ",,,,,,,,,," + clock + "," + offset + "," + userLogic + "," + runStats + "\n";
211214
std::cout << csvLine;
212215
} else {
213216
std::cout << "----------------------------" << std::endl;
214217
std::cout << clock << " clock | ";
215218
std::cout << offset << " offset" << std::endl;
216219
std::cout << "User Logic " << userLogic << std::endl;
220+
std::cout << "Run statistics " << runStats << std::endl;
217221
std::cout << "----------------------------" << std::endl;
218222
}
219223

src/Cru/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct ReportInfo {
9191
uint32_t triggerWindowSize;
9292
bool gbtEnabled;
9393
bool userLogicEnabled;
94+
bool runStatsEnabled;
9495
};
9596

9697
struct OnuStatus {

src/Cru/CruBar.cxx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ CruBar::CruBar(const Parameters& parameters, std::unique_ptr<RocPciDevice> rocPc
5454
mDynamicOffset(parameters.getDynamicOffsetEnabled().get_value_or(false)),
5555
mTriggerWindowSize(parameters.getTriggerWindowSize().get_value_or(1000)),
5656
mGbtEnabled(parameters.getGbtEnabled().get_value_or(true)),
57-
mUserLogicEnabled(parameters.getUserLogicEnabled().get_value_or(false))
57+
mUserLogicEnabled(parameters.getUserLogicEnabled().get_value_or(false)),
58+
mRunStatsEnabled(parameters.getRunStatsEnabled().get_value_or(false))
5859
{
5960
if (getIndex() == 0) {
6061
mFeatures = parseFirmwareFeatures();
@@ -494,9 +495,13 @@ Cru::ReportInfo CruBar::report()
494495
Link userLogicLink;
495496
userLogicLink.dwrapper = mEndpoint;
496497
userLogicLink.dwrapperId = 15;
497-
498498
bool userLogicEnabled = datapathWrapper.getLinkEnabled(userLogicLink);
499499

500+
Link runStatsLink;
501+
runStatsLink.dwrapper = mEndpoint;
502+
runStatsLink.dwrapperId = (mEndpoint == 0) ? 13 : 14;
503+
bool runStatsEnabled = datapathWrapper.getLinkEnabled(runStatsLink);
504+
500505
Cru::ReportInfo reportInfo = {
501506
linkMap,
502507
clock,
@@ -507,7 +512,8 @@ Cru::ReportInfo CruBar::report()
507512
dynamicOffset,
508513
triggerWindowSize,
509514
gbtEnabled,
510-
userLogicEnabled
515+
userLogicEnabled,
516+
runStatsEnabled
511517
};
512518

513519
return reportInfo;
@@ -527,14 +533,23 @@ Cru::PacketMonitoringInfo CruBar::monitorPackets()
527533
linkPacketInfoMap.insert({ el.first, { accepted, rejected, forced } });
528534
}
529535

536+
// Insert the Run Statistics link
537+
Link runStatsLink = {};
538+
runStatsLink.dwrapper = mEndpoint;
539+
runStatsLink.dwrapperId = (mEndpoint == 0) ? 13 : 14;
540+
uint32_t accepted = datapathWrapper.getAcceptedPackets(runStatsLink);
541+
uint32_t rejected = datapathWrapper.getRejectedPackets(runStatsLink);
542+
uint32_t forced = datapathWrapper.getForcedPackets(runStatsLink);
543+
linkPacketInfoMap.insert({ runStatsLink.dwrapperId, { accepted, rejected, forced } });
544+
530545
// Insert the UL link at 15
531546
Link uLLink = {};
532547
// dwrapper 0 on endpoint 0, dwrapper 1 on endpoint 1
533548
uLLink.dwrapper = mEndpoint;
534549
uLLink.dwrapperId = 15;
535-
uint32_t accepted = datapathWrapper.getAcceptedPackets(uLLink);
536-
uint32_t rejected = datapathWrapper.getRejectedPackets(uLLink);
537-
uint32_t forced = datapathWrapper.getForcedPackets(uLLink);
550+
accepted = datapathWrapper.getAcceptedPackets(uLLink);
551+
rejected = datapathWrapper.getRejectedPackets(uLLink);
552+
forced = datapathWrapper.getForcedPackets(uLLink);
538553
linkPacketInfoMap.insert({ 15, { accepted, rejected, forced } });
539554

540555
int wrapper = mEndpoint;
@@ -561,6 +576,7 @@ void CruBar::configure(bool force)
561576
mDynamicOffset == reportInfo.dynamicOffset &&
562577
mTriggerWindowSize == reportInfo.triggerWindowSize &&
563578
mUserLogicEnabled == reportInfo.userLogicEnabled &&
579+
mRunStatsEnabled == reportInfo.runStatsEnabled &&
564580
mGbtEnabled == reportInfo.gbtEnabled &&
565581
!force) {
566582
log("No need to reconfigure further");
@@ -608,6 +624,7 @@ void CruBar::configure(bool force)
608624
// Disable all links
609625
datapathWrapper.setLinksEnabled(mEndpoint, 0x0);
610626
toggleUserLogicLink(reportInfo.userLogicEnabled); // Make sure the user logic link retains its state
627+
toggleRunStatsLink(reportInfo.runStatsEnabled); // Make sure the run stats link retains its state
611628
} else if (mGbtEnabled && (!std::equal(mLinkMap.begin(), mLinkMap.end(), reportInfo.linkMap.begin()) || force)) {
612629
/* BSP */
613630
disableDataTaking();
@@ -647,6 +664,12 @@ void CruBar::configure(bool force)
647664
toggleUserLogicLink(mUserLogicEnabled);
648665
}
649666

667+
/* RUN STATS */
668+
if (mRunStatsEnabled != reportInfo.runStatsEnabled || force) {
669+
log("Toggling the Run Statistics link");
670+
toggleRunStatsLink(mRunStatsEnabled);
671+
}
672+
650673
/* BSP */
651674
if (mCruId != reportInfo.cruId || force) {
652675
log("Setting the CRU ID");
@@ -915,6 +938,20 @@ void CruBar::toggleUserLogicLink(bool userLogicEnabled)
915938
datapathWrapper.setDatapathMode(userLogicLink, mDatapathMode);
916939
}
917940

941+
void CruBar::toggleRunStatsLink(bool runStatsLinkEnabled)
942+
{
943+
Link runStatsLink;
944+
runStatsLink.dwrapper = mEndpoint;
945+
runStatsLink.dwrapperId = (mEndpoint == 0) ? 13 : 14;
946+
947+
DatapathWrapper datapathWrapper = DatapathWrapper(mPdaBar);
948+
if (runStatsLinkEnabled) {
949+
datapathWrapper.setLinkEnabled(runStatsLink);
950+
} else {
951+
datapathWrapper.setLinkDisabled(runStatsLink);
952+
}
953+
}
954+
918955
boost::optional<std::string> CruBar::getUserLogicVersion()
919956
{
920957
uint32_t firmwareHash = readRegister(Cru::Registers::USERLOGIC_GIT_HASH.index);

src/Cru/CruBar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class CruBar final : public BarInterfaceBase
9292
bool getDebugModeEnabled();
9393

9494
void toggleUserLogicLink(bool mUserLogicEnabled);
95+
void toggleRunStatsLink(bool mRunStatsLinkEnabled);
9596
boost::optional<std::string> getUserLogicVersion();
9697

9798
Cru::OnuStatus reportOnuStatus();
@@ -148,6 +149,7 @@ class CruBar final : public BarInterfaceBase
148149
uint32_t mTriggerWindowSize;
149150
bool mGbtEnabled;
150151
bool mUserLogicEnabled;
152+
bool mRunStatsEnabled;
151153

152154
int mEndpoint;
153155

src/Cru/CruDmaChannel.cxx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,27 @@ CruDmaChannel::CruDmaChannel(const Parameters& parameters)
7474
DatapathWrapper dwrapper = DatapathWrapper(getBar2()->getPdaBar());
7575
auto linkMap = getBar2()->initializeLinkMap();
7676

77-
std::stringstream stream;
78-
stream << "Using link(s): ";
77+
int endpoint = getBar()->getEndpointNumber();
78+
79+
Cru::Link newLink;
80+
newLink.dwrapper = endpoint;
7981

80-
Cru::Link userLogicLink;
81-
userLogicLink.dwrapper = getBar()->getEndpointNumber();
82-
userLogicLink.dwrapperId = 15;
83-
if (dwrapper.getLinkEnabled(userLogicLink)) {
84-
linkMap.insert({ 15, userLogicLink });
82+
// Insert UL link
83+
newLink.dwrapperId = 15;
84+
if (dwrapper.getLinkEnabled(newLink)) {
85+
linkMap.insert({ 15, newLink });
8586
}
8687

88+
// Insert Run Statistics link
89+
newLink.dwrapperId = (endpoint == 0) ? 13 : 14;
90+
91+
if (dwrapper.getLinkEnabled(newLink)) {
92+
linkMap.insert({ newLink.dwrapperId, newLink });
93+
}
94+
95+
std::stringstream stream;
96+
stream << "Using link(s): ";
97+
8798
for (const auto& el : linkMap) {
8899
auto id = el.first;
89100
auto link = el.second;

0 commit comments

Comments
 (0)