Skip to content

Commit 7680b0b

Browse files
committed
[bench-dma] Improve TF checks
1 parent 256ab4c commit 7680b0b

File tree

1 file changed

+46
-39
lines changed

1 file changed

+46
-39
lines changed

src/CommandLineUtilities/ProgramDmaBench.cxx

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -730,26 +730,12 @@ class ProgramDmaBench : public Program
730730
mPacketCounters[linkId] = packetCounter; // same as = (mPacketCounters + mErrorCheckFrequency) % mMaxRdhPacketCounter
731731
}
732732

733-
// check that the TimeFrame starts at the beginning of the superpage
734-
const auto triggerType = DataFormat::getTriggerType(reinterpret_cast<const char*>(pageAddress));
735-
const auto orbit = DataFormat::getOrbit(reinterpret_cast<const char*>(pageAddress));
736-
//const auto pagesCounter = DataFormat::getPagesCounter(reinterpret_cast<const char*>(pageAddress));
737-
738-
//std::cout << atStartOfSuperpage << " 0x" << std::hex << orbit << " 0x" << std::hex << mNextTFOrbit << std::endl;
739-
740-
if (Utilities::getBit(triggerType, 9) == 0x1 || Utilities::getBit(triggerType, 7) == 0x1) { // If SOX, use current orbit as the first one
741-
mNextTFOrbit = (orbit + mTimeFrameLength) % (0x100000000);
742-
} else if (orbit == mNextTFOrbit) {
743-
// next orbit should be previous orbit + time frame length
744-
if (!atStartOfSuperpage) {
745-
// log TF not at the beginning of the superpage error
746-
mErrorCount++;
747-
if (mErrorCount < MAX_RECORDED_ERRORS) {
748-
mErrorStream << b::format("[RDHERR]\tevent:%1% l:%2% payloadBytes:%3% size:%4% packet_cnt:%5% orbit:%6$#x nextTForbit:%7$#x atSPStart:%8% TF unaligned w/ start of superpage\n") % eventNumber % linkId % memBytes % pageSize % packetCounter % orbit % mNextTFOrbit % atStartOfSuperpage;
749-
}
733+
if (!checkTimeFrameAlignment(pageAddress, atStartOfSuperpage)) {
734+
// log TF not at the beginning of the superpage error
735+
mErrorCount++;
736+
if (mErrorCount < MAX_RECORDED_ERRORS) {
737+
mErrorStream << b::format("[RDHERR]\tevent:%1% l:%2% payloadBytes:%3% size:%4% packet_cnt:%5% orbit:%6$#x nextTForbit:%7$#x atSPStart:%8% TF unaligned w/ start of superpage\n") % eventNumber % linkId % memBytes % pageSize % packetCounter % mOrbit % mNextTFOrbit % atStartOfSuperpage;
750738
}
751-
// Update next TF orbit expected
752-
mNextTFOrbit = (orbit + mTimeFrameLength) % (0x100000000);
753739
}
754740

755741
// Skip data check if fast check enabled or FEE data source selected
@@ -801,6 +787,39 @@ class ProgramDmaBench : public Program
801787
return foundError;
802788
}
803789

790+
bool checkTimeFrameAlignment(uintptr_t pageAddress, bool atStartOfSuperpage)
791+
{
792+
static bool overflowGuard = false;
793+
static uint32_t mNextTFOrbit = 0x0;
794+
static uint32_t prevOrbit = 0x0;
795+
796+
// check that the TimeFrame starts at the beginning of the superpage
797+
const auto triggerType = DataFormat::getTriggerType(reinterpret_cast<const char*>(pageAddress));
798+
//const auto orbit = DataFormat::getOrbit(reinterpret_cast<const char*>(pageAddress));
799+
mOrbit = DataFormat::getOrbit(reinterpret_cast<const char*>(pageAddress));
800+
//const auto pagesCounter = DataFormat::getPagesCounter(reinterpret_cast<const char*>(pageAddress));
801+
802+
//std::cout << atStartOfSuperpage << " 0x" << std::hex << orbit << " 0x" << std::hex << mNextTFOrbit << std::endl;
803+
if (prevOrbit > mOrbit) { // orbit overflown, remove guard
804+
overflowGuard = false;
805+
}
806+
prevOrbit = mOrbit;
807+
808+
if (Utilities::getBit(triggerType, 9) == 0x1 || Utilities::getBit(triggerType, 7) == 0x1) { // If SOX, use current orbit as the first one
809+
mNextTFOrbit = mOrbit + mTimeFrameLength;
810+
} else if (!overflowGuard && mOrbit >= mNextTFOrbit) {
811+
// next orbit should be previous orbit + time frame length
812+
if (!atStartOfSuperpage) {
813+
return false;
814+
}
815+
// Update next TF orbit expected
816+
overflowGuard = (mNextTFOrbit + mTimeFrameLength) & 0x100000000; // next TF orbit overflown, need to wait for orbit to overflow as well
817+
mNextTFOrbit = mNextTFOrbit + mTimeFrameLength;
818+
}
819+
820+
return true;
821+
}
822+
804823
void addError(int64_t eventNumber, int linkId, int index, uint32_t generatorCounter, uint32_t expectedValue,
805824
uint32_t actualValue, uint32_t payloadBytes)
806825
{
@@ -837,27 +856,12 @@ class ProgramDmaBench : public Program
837856
mPacketCounters[linkId] = packetCounter;
838857
}
839858

840-
// check that the TimeFrame starts at the beginning of the superpage
841-
const auto triggerType = DataFormat::getTriggerType(reinterpret_cast<const char*>(pageAddress));
842-
const auto orbit = DataFormat::getOrbit(reinterpret_cast<const char*>(pageAddress));
843-
//const auto pagesCounter = DataFormat::getPagesCounter(reinterpret_cast<const char*>(pageAddress));
844-
//const auto bunchCrossing = DataFormat::getBunchCrossing(reinterpret_cast<const char*>(pageAddress));
845-
846-
//std::cout << atStartOfSuperpage << " 0x" << std::hex << orbit << " 0x" << std::hex << mNextTFOrbit << std::endl;
847-
848-
if (Utilities::getBit(triggerType, 9) == 0x1 || Utilities::getBit(triggerType, 7) == 0x1) { // If SOX, use current orbit as the first one
849-
mNextTFOrbit = (orbit + mTimeFrameLength) % (0x100000000);
850-
} else if (orbit >= mNextTFOrbit) {
851-
// next orbit should be previous orbit + time frame length
852-
if (!atStartOfSuperpage) {
853-
// log TF not at the beginning of the superpage error
854-
mErrorCount++;
855-
if (mErrorCount < MAX_RECORDED_ERRORS) {
856-
mErrorStream << b::format("[RDHERR]\tevent:%1% l:%2% payloadBytes:%3% size:%4% packet_cnt:%5% orbit:%6$#x nextTForbit:%7$#x atSPStart:%8% TF unaligned w/ start of superpage\n") % eventNumber % linkId % memBytes % pageSize % packetCounter % orbit % mNextTFOrbit % atStartOfSuperpage;
857-
}
859+
if (!checkTimeFrameAlignment(pageAddress, atStartOfSuperpage)) {
860+
// log TF not at the beginning of the superpage error
861+
mErrorCount++;
862+
if (mErrorCount < MAX_RECORDED_ERRORS) {
863+
mErrorStream << b::format("[RDHERR]\tevent:%1% l:%2% payloadBytes:%3% size:%4% packet_cnt:%5% orbit:%6$#x nextTForbit:%7$#x atSPStart:%8% TF unaligned w/ start of superpage\n") % eventNumber % linkId % memBytes % pageSize % packetCounter % mOrbit % mNextTFOrbit % atStartOfSuperpage;
858864
}
859-
// Update next TF orbit expected
860-
mNextTFOrbit = (orbit + mTimeFrameLength) % (0x100000000);
861865
}
862866

863867
if (mFastCheckEnabled) {
@@ -1260,6 +1264,9 @@ class ProgramDmaBench : public Program
12601264
/// Data Source
12611265
DataSource::type mDataSource;
12621266

1267+
/// Current orbit
1268+
uint32_t mOrbit = 0x0;
1269+
12631270
/// The orbit number that coincides with the next TimeFrame
12641271
uint32_t mNextTFOrbit = 0x0;
12651272

0 commit comments

Comments
 (0)