Skip to content

Commit ae838fd

Browse files
committed
[trig-monitor] Introduce roc-trig-monitor tool
1 parent 7da5453 commit ae838fd

File tree

9 files changed

+222
-1
lines changed

9 files changed

+222
-1
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ if(PDA_FOUND)
233233
ProgramPatternPlayer.cxx
234234
ProgramSiuStatus.cxx
235235
ProgramStatus.cxx
236+
ProgramTriggerMonitor.cxx
236237
)
237238
list(APPEND EXE_NAMES
238239
roc-bar-stress
@@ -248,6 +249,7 @@ if(PDA_FOUND)
248249
roc-pat-player
249250
roc-siu-status
250251
roc-status
252+
roc-trig-monitor
251253
)
252254
endif()
253255

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file ProgramTriggerMonitor.cxx
12+
/// \brief Tool that returns monitoring information about LTU triggers.
13+
///
14+
/// \author Kostas Alexopoulos ([email protected])
15+
16+
#include <iostream>
17+
#include "Cru/CruBar.h"
18+
#include "ReadoutCard/ChannelFactory.h"
19+
#include "CommandLineUtilities/Options.h"
20+
#include "CommandLineUtilities/Program.h"
21+
#include <boost/format.hpp>
22+
#include <boost/property_tree/ptree.hpp>
23+
24+
using namespace AliceO2::roc::CommandLineUtilities;
25+
using namespace AliceO2::roc;
26+
using namespace AliceO2::InfoLogger;
27+
namespace pt = boost::property_tree;
28+
namespace po = boost::program_options;
29+
30+
class ProgramTriggerMonitor : public Program
31+
{
32+
public:
33+
virtual Description getDescription()
34+
{
35+
return { "Trigger Monitor", "Return LTU trigger monitoring information",
36+
"roc-pkt-monitor --id 42:00.0\n"
37+
"roc-pkt-monitor --id 42:00.0 --updateable\n" };
38+
}
39+
40+
virtual void addOptions(boost::program_options::options_description& options)
41+
{
42+
Options::addOptionCardId(options);
43+
options.add_options()("updateable",
44+
po::bool_switch(&mOptions.updateable),
45+
"Toggle updateable output");
46+
}
47+
48+
virtual void run(const boost::program_options::variables_map& map)
49+
{
50+
51+
auto cardId = Options::getOptionCardId(map);
52+
Parameters params;
53+
std::shared_ptr<BarInterface> bar;
54+
auto card = RocPciDevice(cardId).getCardDescriptor();
55+
auto cardType = card.cardType;
56+
57+
if (card.serialId.getSerial() == 0x7fffffff || card.serialId.getSerial() == 0x0) {
58+
std::cout << "Bad serial reported, bad card state, exiting" << std::endl;
59+
return;
60+
}
61+
62+
if (cardType == CardType::type::Crorc) {
63+
std::cout << "Only CRU supported, exiting" << std::endl;
64+
return;
65+
} else if (cardType == CardType::type::Cru) {
66+
67+
params = Parameters::makeParameters(cardId, 2); //status available on BAR2
68+
bar = ChannelFactory().getBar(params);
69+
auto cruBar2 = std::dynamic_pointer_cast<CruBar>(bar);
70+
71+
std::ostringstream table;
72+
auto formatHeader = " %-12s %-15s %-12s %-15s %-12s %-12s\n";
73+
auto formatRow = " %-12s %-15.3f %-12s %-15.3f %-12s %-12s\n";
74+
auto formatRowUpdateable = " %-12s %-15.3f %-12s %-15.3f %-12s %-12s";
75+
auto header = (boost::format(formatHeader) % "HB" % "HB rate (kHz)" % "PHY" % "PHY rate (kHz)" % "SOX" % "EOX").str();
76+
auto lineFat = std::string(header.length(), '=') + '\n';
77+
auto lineThin = std::string(header.length(), '-') + '\n';
78+
79+
table << lineFat << header << lineThin;
80+
81+
// initialize ptrees
82+
pt::ptree root;
83+
pt::ptree gbtLinks;
84+
85+
if (mOptions.updateable) {
86+
std::cout << table.str(); // header
87+
88+
while (!isSigInt()) {
89+
Cru::TriggerMonitoringInfo tmi = cruBar2->monitorTriggers(true);
90+
auto format = boost::format(formatRowUpdateable) % tmi.hbCount % tmi.hbRate % tmi.phyCount % tmi.phyRate % tmi.soxCount % tmi.eoxCount;
91+
std::cout << '\r' << format << std::flush;
92+
}
93+
94+
std::cout << std::endl << lineFat;
95+
} else {
96+
Cru::TriggerMonitoringInfo tmi = cruBar2->monitorTriggers();
97+
auto format = boost::format(formatRow) % tmi.hbCount % tmi.hbRate % tmi.phyCount % tmi.phyRate % tmi.soxCount % tmi.eoxCount;
98+
table << format << lineFat;
99+
std::cout << table.str();
100+
}
101+
102+
} else if (cardType != CardType::type::Cru) {
103+
std::cout << "Invalid card type" << std::endl;
104+
return;
105+
}
106+
}
107+
108+
private:
109+
struct OptionsStruct {
110+
bool updateable = false;
111+
} mOptions;
112+
};
113+
114+
int main(int argc, char** argv)
115+
{
116+
return ProgramTriggerMonitor().execute(argc, argv);
117+
}

src/Cru/Common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ struct PacketMonitoringInfo {
130130
std::map<int, WrapperPacketInfo> wrapperPacketInfoMap;
131131
};
132132

133+
struct TriggerMonitoringInfo {
134+
uint64_t hbCount;
135+
double hbRate;
136+
uint64_t phyCount;
137+
double phyRate;
138+
uint64_t eoxCount;
139+
uint64_t soxCount;
140+
};
141+
133142
enum TriggerMode {
134143
Manual,
135144
Periodic,

src/Cru/Constants.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static constexpr Register PON_WRAPPER_PLL(0x00224000);
193193
static constexpr Register PON_WRAPPER_TX(0x00226000);
194194
static constexpr Register PON_WRAPPER_REG(0x00222000);
195195

196-
/// Register for configuring PON TX
196+
/// Registers for configuring PON TX
197197
static constexpr Register CLOCK_ONU_FPLL(0x00248000);
198198
static constexpr Register CLOCK_PLL_CONTROL_ONU(0x00240018);
199199
static constexpr Register ONU_USER_LOGIC(0x0022a000);
@@ -203,6 +203,11 @@ static constexpr Register ONU_USER_REFGEN(0x0022c000);
203203
static constexpr Register REFGEN0_OFFSET(0x00000000);
204204
static constexpr Register REFGEN1_OFFSET(0x00000004);
205205

206+
// Registers for getting LTU info
207+
static constexpr Register LTU_HBTRIG_CNT(0x00200004);
208+
static constexpr Register LTU_PHYSTRIG_CNT(0x00200008);
209+
static constexpr Register LTU_EOX_SOX_CNT(0x0020000c);
210+
206211
//** GBT **//
207212
/// Wrapper 0's base address
208213
static constexpr Register WRAPPER0(0x00400000);

src/Cru/CruBar.cxx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,71 @@ Cru::PacketMonitoringInfo CruBar::monitorPackets()
574574
return { linkPacketInfoMap, wrapperPacketInfoMap };
575575
}
576576

577+
Cru::TriggerMonitoringInfo CruBar::monitorTriggers(bool updateable)
578+
{
579+
Ttc ttc = Ttc(mPdaBar, mSerial);
580+
581+
// previous values to calculate rate (every second)
582+
uint32_t hbCountPrev = ttc.getHbTriggerLtuCount();
583+
uint32_t phyCountPrev = ttc.getPhyTriggerLtuCount();
584+
585+
// base values to report relative counts for updateable monitoring (e.g. for a single run)
586+
static uint32_t hbCountBase = hbCountPrev;
587+
static uint32_t phyCountBase = phyCountPrev;
588+
static std::pair<uint32_t, uint32_t> statEoxSox = ttc.getEoxSoxLtuCount();
589+
static uint32_t eoxCountBase = statEoxSox.first;
590+
static uint32_t soxCountBase = statEoxSox.second;
591+
592+
std::this_thread::sleep_for(std::chrono::seconds(1));
593+
uint32_t hbCount = ttc.getHbTriggerLtuCount();
594+
uint32_t phyCount = ttc.getPhyTriggerLtuCount();
595+
std::pair<uint32_t, uint32_t> eoxSox = ttc.getEoxSoxLtuCount();
596+
uint32_t eoxCount = eoxSox.first;
597+
uint32_t soxCount = eoxSox.second;
598+
599+
// current - previous counts for rates
600+
uint64_t hbDiff;
601+
if (hbCountPrev > hbCount) {
602+
hbDiff = hbCount + pow(2, 32) - hbCountPrev;
603+
} else {
604+
hbDiff = hbCount - hbCountPrev;
605+
}
606+
607+
uint64_t phyDiff;
608+
if (phyCountPrev > phyCount) {
609+
phyDiff = phyCount + pow(2, 32) - phyCountPrev;
610+
} else {
611+
phyDiff = phyCount - phyCountPrev;
612+
}
613+
614+
// report absolute values + rates(1s)
615+
if (!updateable) {
616+
return { hbCount, hbDiff / pow(10,3),
617+
phyCount, phyDiff / pow(10,3),
618+
eoxCount, soxCount };
619+
}
620+
621+
// current - base counts for EOX/SOX
622+
uint64_t eoxDiff;
623+
if (eoxCountBase > eoxCount) {
624+
eoxDiff = eoxCount + pow(2, 32) - eoxCountBase;
625+
} else {
626+
eoxDiff = eoxCount - eoxCountBase;
627+
}
628+
629+
uint64_t soxDiff;
630+
if (soxCountBase > soxCount) {
631+
soxDiff = soxCount + pow(2, 32) - soxCountBase;
632+
} else {
633+
soxDiff = soxCount - soxCountBase;
634+
}
635+
636+
// report relative values + rates (1s)
637+
return { hbCount - hbCountBase, hbDiff / pow(10,3),
638+
phyCount - phyCountBase, phyDiff / pow(10,3),
639+
eoxDiff, soxDiff };
640+
}
641+
577642
void CruBar::checkConfigParameters()
578643
{
579644
if (mUserAndCommonLogicEnabled && !mUserLogicEnabled) {

src/Cru/CruBar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class CruBar final : public BarInterfaceBase
8282
void configure(bool force = false) override;
8383
Cru::ReportInfo report();
8484
Cru::PacketMonitoringInfo monitorPackets();
85+
Cru::TriggerMonitoringInfo monitorTriggers(bool updateable = false);
8586
void emulateCtp(Cru::CtpInfo);
8687
void patternPlayer(PatternPlayer::Info patternPlayerInfo);
8788

src/Cru/Ttc.cxx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ uint32_t Ttc::getPllClock()
236236
return clock;
237237
}
238238

239+
uint32_t Ttc::getHbTriggerLtuCount()
240+
{
241+
return mBar->readRegister(Cru::Registers::LTU_HBTRIG_CNT.index);
242+
}
243+
244+
uint32_t Ttc::getPhyTriggerLtuCount()
245+
{
246+
return mBar->readRegister(Cru::Registers::LTU_PHYSTRIG_CNT.index);
247+
}
248+
249+
std::pair<uint32_t, uint32_t> Ttc::getEoxSoxLtuCount()
250+
{
251+
uint32_t eoxSox = mBar->readRegister(Cru::Registers::LTU_EOX_SOX_CNT.index);
252+
return {(eoxSox >> 4) & 0xf, eoxSox & 0xf};
253+
}
254+
239255
/*** CTP EMULATOR METHODS ***/
240256
void Ttc::resetCtpEmulator(bool doReset)
241257
{

src/Cru/Ttc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class Ttc
3030
void selectDownstreamData(uint32_t downstreamData);
3131
uint32_t getPllClock();
3232
uint32_t getDownstreamData();
33+
uint32_t getHbTriggerLtuCount();
34+
uint32_t getPhyTriggerLtuCount();
35+
std::pair<uint32_t, uint32_t> getEoxSoxLtuCount();
3336

3437
void resetCtpEmulator(bool doReset);
3538
void setEmulatorTriggerMode(Cru::TriggerMode mode);

src/Cru/cru_constants_populate.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
'add_pon_wrapper_reg':'PON_WRAPPER_REG',
9090
'add_ttc_clkgen_onufpll':'CLOCK_ONU_FPLL',
9191
'add_ttc_clkgen_pllctrlonu':'CLOCK_PLL_CONTROL_ONU',
92+
'add_ttc_hbtrig_ltu':'LTU_HBTRIG_CNT',
93+
'add_ttc_phystrig_ltu':'LTU_PHYSTRIG_CNT',
94+
'add_ttc_eox_sox_ltu':'LTU_EOX_SOX_CNT',
9295
'add_onu_user_logic':'ONU_USER_LOGIC',
9396
'add_onu_user_refgen':'ONU_USER_REFGEN',
9497
'add_refgen0_offset':'REFGEN0_OFFSET',

0 commit comments

Comments
 (0)