Skip to content

Commit 0ebc9db

Browse files
kostorrpippohub
authored andcommitted
Add roc-metrics tool
1 parent cb0ec79 commit 0ebc9db

File tree

13 files changed

+273
-57
lines changed

13 files changed

+273
-57
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ ENDIF ()
5656
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -fPIC")
5757

5858
# Populate the Cru/Constants.h file with the register addresses contained in CRU/cru_table.py
59-
execute_process(COMMAND python ${CMAKE_BASE_DIR}/src/Cru/cru_constants_populate.py
60-
STATUS status)
59+
execute_process(COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/src/Cru/cru_constants_populate.py
60+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/Cru
61+
RESULT_VARIABLE status)
6162
IF(NOT "${status}" EQUAL "0")
6263
MESSAGE(WARNING "Couldn't update CRU Register Addresses")
6364
ENDIF()
@@ -162,6 +163,7 @@ if(ALICEO2_READOUTCARD_PDA_ENABLED)
162163
build_util_exec(roc-flash CommandLineUtilities/ProgramFlash.cxx)
163164
build_util_exec(roc-flash-read CommandLineUtilities/ProgramFlashRead.cxx)
164165
build_util_exec(roc-list-cards CommandLineUtilities/ProgramListCards.cxx)
166+
build_util_exec(roc-metrics CommandLineUtilities/ProgramMetrics.cxx)
165167
#build_util_exec(roc-sanity-check CommandLineUtilities/ProgramSanityCheck.cxx)
166168

167169
if(DIM_FOUND)

include/ReadoutCard/BarInterface.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ class BarInterface: public virtual RegisterReadWriteInterface
4747
virtual boost::optional<std::string> getFirmwareInfo() = 0;
4848

4949
virtual boost::optional<std::string> getCardId() = 0;
50+
51+
virtual int32_t getDroppedPackets() = 0;
52+
53+
virtual uint32_t getCTPClock() = 0;
54+
55+
virtual uint32_t getLocalClock() = 0;
56+
57+
virtual int32_t getLinks() = 0;
58+
59+
virtual int32_t getLinksPerWrapper(uint32_t wrapper) = 0;
5060

5161
};
5262

src/BarInterfaceBase.h

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ class BarInterfaceBase: public BarInterface
3838
return mPdaBar->getSize();
3939
}
4040

41+
/// Default implementation for optional function
42+
virtual boost::optional<int32_t> getSerial() override
43+
{
44+
return {};
45+
}
46+
4147
/// Default implementation for optional function
4248
virtual boost::optional<float> getTemperature() override
4349
{
@@ -56,6 +62,37 @@ class BarInterfaceBase: public BarInterface
5662
return {};
5763
}
5864

65+
/// Default implementation for optional function
66+
virtual int32_t getDroppedPackets() override
67+
{
68+
return 0;
69+
}
70+
71+
/// Default implementation for optional function
72+
virtual uint32_t getCTPClock() override
73+
{
74+
return 0;
75+
}
76+
77+
/// Default implementation for optional function
78+
virtual uint32_t getLocalClock() override
79+
{
80+
return 0;
81+
}
82+
83+
/// Default implementation for optional function
84+
virtual int32_t getLinksPerWrapper(uint32_t wrapper) override
85+
{
86+
return 0;
87+
}
88+
/// Default implementation for optional function
89+
virtual int32_t getLinks() override
90+
{
91+
return 0;
92+
}
93+
94+
95+
5996

6097
protected:
6198
/// BAR index
@@ -73,10 +110,10 @@ class BarInterfaceBase: public BarInterface
73110
private:
74111
/// Inheriting classes must implement this to check whether a given read is safe.
75112
/// If it is not safe, it should throw an UnsafeReadAccess exception
76-
virtual void checkReadSafe(int index) = 0;
113+
//virtual void checkReadSafe(int index) = 0;
77114
/// Inheriting classes must implement this to check whether a given write is safe.
78115
/// If it is not safe, it should throw an UnsafeWriteAccess exception
79-
virtual void checkWriteSafe(int index, uint32_t value) = 0;
116+
//virtual void checkWriteSafe(int index, uint32_t value) = 0;
80117
};
81118

82119
} // namespace roc
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/// \file ProgramMetrics.cxx
2+
/// \brief Tool that returns current information about RoCs.
3+
///
4+
/// \author Kostas Alexopoulos ([email protected])
5+
6+
#include <iostream>
7+
#include "Cru/Constants.h"
8+
#include "ReadoutCard/ChannelFactory.h"
9+
#include "CommandLineUtilities/Options.h"
10+
#include "CommandLineUtilities/Program.h"
11+
#include "RocPciDevice.h"
12+
#include <boost/format.hpp>
13+
#include <boost/optional/optional_io.hpp>
14+
15+
using namespace AliceO2::roc::CommandLineUtilities;
16+
using namespace AliceO2::roc;
17+
using namespace AliceO2::InfoLogger;
18+
namespace po = boost::program_options;
19+
20+
class ProgramMetrics: public Program
21+
{
22+
public:
23+
24+
virtual Description getDescription()
25+
{
26+
return {"Metrics", "Return current RoC parameters",
27+
"roc-metrics\n"
28+
"roc-metrics --pci-address 42:00.0\n"};
29+
}
30+
31+
virtual void addOptions(boost::program_options::options_description& options)
32+
{
33+
options.add_options()
34+
("pci-address",
35+
po::value<std::string>(&mOptions.pciAddress)->default_value("-1"),
36+
"Card's PCI Address");
37+
}
38+
39+
virtual void run(const boost::program_options::variables_map& map)
40+
{
41+
42+
std::vector<CardDescriptor> cardsFound;
43+
if (mOptions.pciAddress != "-1")
44+
cardsFound = AliceO2::roc::RocPciDevice::findSystemDevices(mOptions.pciAddress);
45+
else
46+
cardsFound = AliceO2::roc::RocPciDevice::findSystemDevices();
47+
48+
49+
std::ostringstream table;
50+
51+
auto formatHeader = " %-3s %-6s %-10s %-10s %-19s %-20s %-19s %-8s %-17s %-17s\n";
52+
auto formatRow = " %-3s %-6s %-10s %-10s %-19s %-20s %-19s %-8s %-17s %-17s\n";
53+
auto header = (boost::format(formatHeader)
54+
% "#" % "Type" % "PCI Addr" % "Temp (C)" % "#Dropped Packets" % "CTP Clock (MHz)" % "Local Clock (MHz)"
55+
% "#links" % "#Wrapper 0 links" % "#Wrapper 1 links").str();
56+
auto lineFat = std::string(header.length(), '=') + '\n';
57+
auto lineThin = std::string(header.length(), '-') + '\n';
58+
59+
table << lineFat << header << lineThin;
60+
61+
int i = 0;
62+
for (const auto& card : cardsFound) {
63+
Parameters params = Parameters::makeParameters(card.pciAddress, 2);
64+
auto bar2 = ChannelFactory().getBar(params);
65+
66+
float temperature = bar2->getTemperature().value_or(0);
67+
int32_t dropped = bar2->getDroppedPackets();
68+
float ctp_clock = bar2->getCTPClock()/1e6;
69+
float local_clock = bar2->getLocalClock()/1e6;
70+
int32_t links = bar2->getLinks();
71+
uint32_t links0 = bar2->getLinksPerWrapper(0);
72+
uint32_t links1 = bar2->getLinksPerWrapper(1);
73+
74+
auto format = boost::format(formatRow) % i % CardType::toString(card.cardType) % card.pciAddress.toString()
75+
% temperature % dropped % ctp_clock % local_clock % links % links0 % links1;
76+
77+
table << format;
78+
i++;
79+
}
80+
81+
table << lineFat;
82+
std::cout << table.str();
83+
}
84+
85+
struct OptionsStruct
86+
{
87+
std::string pciAddress = "-1";
88+
}mOptions;
89+
90+
private:
91+
};
92+
93+
int main(int argc, char** argv)
94+
{
95+
if (argc > 2){
96+
std::cout << "Too many arguments" << std::endl;
97+
return -1;
98+
}
99+
return ProgramMetrics().execute(argc, argv);
100+
}

src/Crorc/CrorcBar.cxx

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,11 @@ CrorcBar::~CrorcBar()
1818
{
1919
}
2020

21-
void CrorcBar::checkReadSafe(int)
22-
{
23-
}
24-
25-
void CrorcBar::checkWriteSafe(int, uint32_t)
26-
{
27-
}
28-
2921
boost::optional<int32_t> CrorcBar::getSerial()
3022
{
3123
return Crorc::getSerial(*(mPdaBar.get()));
3224
}
3325

34-
35-
boost::optional<float> CrorcBar::getTemperature()
36-
{
37-
return {};
38-
}
39-
4026
boost::optional<std::string> CrorcBar::getFirmwareInfo()
4127
{
4228
uint32_t version = mPdaBar->readRegister(Rorc::RFID);
@@ -59,12 +45,5 @@ boost::optional<std::string> CrorcBar::getFirmwareInfo()
5945
return stream.str();
6046
}
6147

62-
boost::optional<std::string> CrorcBar::getCardId()
63-
{
64-
return {};
65-
}
66-
67-
68-
6948
} // namespace roc
7049
} // namespace AliceO2

src/Crorc/CrorcBar.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ class CrorcBar final : public BarInterfaceBase
2020
public:
2121
CrorcBar(const Parameters& parameters);
2222
virtual ~CrorcBar();
23-
virtual void checkReadSafe(int index) override;
24-
virtual void checkWriteSafe(int index, uint32_t value) override;
23+
//virtual void checkReadSafe(int index) override;
24+
//virtual void checkWriteSafe(int index, uint32_t value) override;
2525

2626
virtual CardType::type getCardType() override
2727
{
2828
return CardType::Crorc;
2929
}
3030

3131
virtual boost::optional<int32_t> getSerial() override;
32-
virtual boost::optional<float> getTemperature() override;
3332
virtual boost::optional<std::string> getFirmwareInfo() override;
34-
virtual boost::optional<std::string> getCardId() override;
3533
};
3634

3735
} // namespace roc

src/Cru/Constants.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,27 @@ static constexpr Register FPGA_CHIP_HIGH(0x00010014);
131131
/// Must be accessed on BAR 2
132132
static constexpr Register FPGA_CHIP_LOW(0x00010018);
133133

134+
// Register containing the number of dropped packets
135+
// Must be accessed on BAR 2
136+
//not yet in cru_tables.py//
137+
static constexpr Register NUM_DROPPED_PACKETS(0x0060001C);
138+
139+
// Register containing the CTP Clock's value
140+
// Must be accessed on BAR 2
141+
static constexpr Register CTP_CLOCK(0x00240000);
142+
143+
// Register containing the Local Clock's value
144+
// Must be accessed on BAR 2
145+
static constexpr Register LOCAL_CLOCK(0x00240004);
146+
147+
// Wrapper 0's base address
148+
// Must be accessed on BAR 2
149+
static constexpr Register WRAPPER0(0x00400000);
150+
151+
// Wrapper 1's base address
152+
// Must be accessed on BAR 2
153+
static constexpr Register WRAPPER1(0x00500000);
154+
134155
} // namespace Cru
135156
} // namespace Registers
136157
} // namespace roc

src/Cru/CruBar.cxx

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "CruBar.h"
88
#include "boost/format.hpp"
9+
#include "Utilities/Util.h"
910

1011
namespace AliceO2 {
1112
namespace roc {
@@ -27,13 +28,13 @@ CruBar::~CruBar()
2728
{
2829
}
2930

30-
void CruBar::CruBar::checkReadSafe(int)
31+
/*void CruBar::CruBar::checkReadSafe(int)
3132
{
3233
}
3334
3435
void CruBar::CruBar::checkWriteSafe(int, uint32_t)
3536
{
36-
}
37+
}*/
3738

3839
boost::optional<int32_t> CruBar::getSerial()
3940
{
@@ -137,6 +138,54 @@ FirmwareFeatures CruBar::getFirmwareFeatures()
137138
return mFeatures;
138139
}
139140

141+
/// Get number of dropped packets
142+
int32_t CruBar::getDroppedPackets()
143+
{
144+
return mPdaBar->readRegister(Cru::Registers::NUM_DROPPED_PACKETS.index);
145+
}
146+
147+
// Get CTP clock (Hz)
148+
uint32_t CruBar::getCTPClock()
149+
{
150+
return mPdaBar->readRegister(Cru::Registers::CTP_CLOCK.index);
151+
}
152+
153+
// Get local clock (Hz)
154+
uint32_t CruBar::getLocalClock()
155+
{
156+
return mPdaBar->readRegister(Cru::Registers::LOCAL_CLOCK.index);
157+
}
158+
159+
// Get total # of links per wrapper
160+
int32_t CruBar::getLinks()
161+
{
162+
int32_t links = 0;
163+
uint32_t regread = 0x0;
164+
regread = mPdaBar->readRegister((Cru::Registers::WRAPPER0.address + 0x4) / 4);
165+
links += Utilities::getBits(regread, 24, 31);
166+
regread = mPdaBar->readRegister((Cru::Registers::WRAPPER1.address + 0x4) / 4);
167+
links += Utilities::getBits(regread, 24, 31);
168+
169+
return links;
170+
171+
}
172+
173+
174+
// Get # of links per wrapper
175+
int32_t CruBar::getLinksPerWrapper(uint32_t wrapper)
176+
{
177+
uint32_t regread = 0x0;
178+
if (wrapper == 0)
179+
regread = mPdaBar->readRegister((Cru::Registers::WRAPPER0.address + 0x4) / 4);
180+
else if (wrapper == 1)
181+
regread = mPdaBar->readRegister((Cru::Registers::WRAPPER1.address + 0x4) / 4);
182+
else
183+
return 0;
184+
185+
return Utilities::getBits(regread, 24, 31);
186+
187+
}
188+
140189
/// Gets the serial number from the card.
141190
/// Note that not all firmwares have a serial number. You should make sure this firmware feature is enabled before
142191
/// calling this function, or the card may crash. See parseFirmwareFeatures().

0 commit comments

Comments
 (0)