Skip to content

Commit 886fb31

Browse files
committed
Stay within the link superpage queue's limits
1 parent d6c0ad2 commit 886fb31

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/CommandLineUtilities/ProgramDmaBench.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ class ProgramDmaBench: public Program
563563
auto size = mChannel->getReadyQueueSize();
564564
for (int i = 0; i < size; ++i) {
565565
auto superpage = mChannel->popSuperpage();
566-
if (mOptions.loopbackModeString == "NONE") { //if it's ddg
566+
if (mOptions.loopbackModeString == "NONE" || mOptions.loopbackModeString == "DDG") { // TODO: CRORC?
567567
int pages = mSuperpageSize / mPageSize;
568568
for (int i = 0; i < pages; ++i) {
569569
auto readoutCount = fetchAddReadoutCount();

src/Cru/CruDmaChannel.cxx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ CruDmaChannel::~CruDmaChannel()
9696
{
9797
setBufferNonReady();
9898
if (mReadyQueue.size() > 0) {
99-
log((format("Remaining superpages in the ready queue: %1%") % mReadyQueue.size()).str());
100-
}
99+
log((format("Remaining superpages in the ready queue: %1%") % mReadyQueue.size()).str()); }
101100
}
102101

103102
void CruDmaChannel::deviceStartDma()
@@ -169,12 +168,14 @@ void CruDmaChannel::deviceStopDma()
169168
int32_t superpageCount = getBar()->getSuperpageCount(link.id);
170169
uint32_t amountAvailable = superpageCount - link.superpageCounter;
171170
//log((format("superpageCount %1% amountAvailable %2%") % superpageCount % amountAvailable).str());
172-
for (uint32_t i = 0; i < (amountAvailable + 1); ++i) {
171+
for (uint32_t i = 0; i < (amountAvailable + 1); ++i) { // get an extra, possibly partly filled superpage
173172
if (mReadyQueue.size() >= READY_QUEUE_CAPACITY) {
174173
break;
175174
}
176-
transferSuperpageFromLinkToReady(link);
177-
moved++;
175+
if (!link.queue.empty()) { // care for the extra filled superpage
176+
transferSuperpageFromLinkToReady(link);
177+
moved++;
178+
}
178179
}
179180
assert(link.queue.empty());
180181
}
@@ -271,12 +272,16 @@ void CruDmaChannel::pushSuperpageToLink(Link& link, const Superpage& superpage)
271272

272273
void CruDmaChannel::transferSuperpageFromLinkToReady(Link& link)
273274
{
275+
if (link.queue.empty()) {
276+
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("Could not transfer Superpage from link to ready queue, link queue is empty"));
277+
}
278+
274279
link.queue.front().setReady(true);
275280
link.queue.front().setReceived(link.queue.front().getSize());
276281
mReadyQueue.push_back(link.queue.front());
277-
mLinkQueuesTotalAvailable++;
278282
link.queue.pop_front();
279283
link.superpageCounter++;
284+
mLinkQueuesTotalAvailable++;
280285
}
281286

282287
void CruDmaChannel::fillSuperpages()

0 commit comments

Comments
 (0)