Skip to content

Commit 91745c6

Browse files
committed
[crorc] Use folly instead of boost queue
1 parent bfba739 commit 91745c6

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

src/Crorc/CrorcDmaChannel.cxx

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ void CrorcDmaChannel::deviceStartDma()
130130
mFreeFifoFront = 0;
131131
mFreeFifoBack = 0;
132132
mFreeFifoSize = 0;
133-
mReadyQueue.clear();
134-
mTransferQueue.clear();
133+
while (!mReadyQueue.isEmpty()) {
134+
mReadyQueue.popFront();
135+
}
136+
while (!mTransferQueue.isEmpty()) {
137+
mTransferQueue.popFront();
138+
}
135139
mPendingDmaStart = true;
136140
}
137141

@@ -141,7 +145,7 @@ void CrorcDmaChannel::startPendingDma()
141145
return;
142146
}
143147

144-
if (mTransferQueue.empty()) { // We should never end up in here
148+
if (mTransferQueue.isEmpty()) { // We should never end up in here
145149
log("Insufficient superpages to start pending DMA");
146150
return;
147151
}
@@ -189,12 +193,12 @@ void CrorcDmaChannel::deviceStopDma()
189193
fillSuperpages();
190194

191195
// Return any superpages that have been pushed up in the meantime but won't get filled
192-
while (mTransferQueue.size()) {
193-
auto superpage = mTransferQueue.front();
194-
superpage.setReceived(0);
195-
superpage.setReady(false);
196-
mReadyQueue.push_back(superpage);
197-
mTransferQueue.pop_front();
196+
while (mTransferQueue.sizeGuess()) {
197+
auto superpage = mTransferQueue.frontPtr();
198+
superpage->setReceived(0);
199+
superpage->setReady(false);
200+
mReadyQueue.write(*superpage);
201+
mTransferQueue.popFront();
198202
}
199203
}
200204

@@ -324,20 +328,20 @@ void CrorcDmaChannel::startDataReceiving()
324328

325329
int CrorcDmaChannel::getTransferQueueAvailable()
326330
{
327-
return TRANSFER_QUEUE_CAPACITY - mTransferQueue.size();
331+
return TRANSFER_QUEUE_CAPACITY - mTransferQueue.sizeGuess();
328332
}
329333

330334
int CrorcDmaChannel::getReadyQueueSize()
331335
{
332-
return mReadyQueue.size();
336+
return mReadyQueue.sizeGuess();
333337
}
334338

335339
auto CrorcDmaChannel::getSuperpage() -> Superpage
336340
{
337-
if (mReadyQueue.empty()) {
341+
if (mReadyQueue.isEmpty()) {
338342
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("Could not get superpage, ready queue was empty"));
339343
}
340-
return mReadyQueue.front();
344+
return *mReadyQueue.frontPtr();
341345
}
342346

343347
bool CrorcDmaChannel::pushSuperpage(Superpage superpage)
@@ -348,7 +352,7 @@ bool CrorcDmaChannel::pushSuperpage(Superpage superpage)
348352

349353
checkSuperpage(superpage);
350354

351-
if (mTransferQueue.size() >= TRANSFER_QUEUE_CAPACITY) {
355+
if (mTransferQueue.sizeGuess() >= TRANSFER_QUEUE_CAPACITY) {
352356
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("Could not push superpage, transfer queue was full"));
353357
}
354358

@@ -362,25 +366,25 @@ bool CrorcDmaChannel::pushSuperpage(Superpage superpage)
362366
mFreeFifoSize++;
363367
mFreeFifoFront = (mFreeFifoFront + 1) % MAX_SUPERPAGE_DESCRIPTORS;
364368

365-
mTransferQueue.push_back(superpage);
369+
mTransferQueue.write(superpage);
366370

367371
return true;
368372
}
369373

370374
auto CrorcDmaChannel::popSuperpage() -> Superpage
371375
{
372-
if (mReadyQueue.empty()) {
376+
if (mReadyQueue.isEmpty()) {
373377
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("Could not pop superpage, ready queue was empty"));
374378
}
375-
auto superpage = mReadyQueue.front();
376-
mReadyQueue.pop_front();
377-
return superpage;
379+
auto superpage = mReadyQueue.frontPtr();
380+
mReadyQueue.popFront();
381+
return *superpage;
378382
}
379383

380384
void CrorcDmaChannel::fillSuperpages()
381385
{
382386
if (mPendingDmaStart) {
383-
if (!mTransferQueue.empty()) {
387+
if (!mTransferQueue.isEmpty()) {
384388
startPendingDma();
385389
} else {
386390
// Waiting on enough superpages to start DMA...
@@ -389,7 +393,7 @@ void CrorcDmaChannel::fillSuperpages()
389393
}
390394

391395
// Check for arrivals & handle them
392-
if (!mTransferQueue.empty()) { // i.e. If something is pushed to the CRORC
396+
if (!mTransferQueue.isEmpty()) { // i.e. If something is pushed to the CRORC
393397
auto isArrived = [&](int descriptorIndex) { return dataArrived(descriptorIndex) == DataArrivalStatus::WholeArrived; };
394398
auto resetDescriptor = [&](int descriptorIndex) { getReadyFifoUser()->entries[descriptorIndex].reset(); };
395399
auto getLength = [&](int descriptorIndex) { return getReadyFifoUser()->entries[descriptorIndex].length * 4; }; // length in 4B words
@@ -404,11 +408,11 @@ void CrorcDmaChannel::fillSuperpages()
404408
mFreeFifoBack = (mFreeFifoBack + 1) % MAX_SUPERPAGE_DESCRIPTORS;
405409

406410
// Push Superpage
407-
auto superpage = mTransferQueue.front();
408-
superpage.setReceived(superpageFilled);
409-
superpage.setReady(true);
410-
mReadyQueue.push_back(superpage);
411-
mTransferQueue.pop_front();
411+
auto superpage = mTransferQueue.frontPtr();
412+
superpage->setReceived(superpageFilled);
413+
superpage->setReady(true);
414+
mReadyQueue.write(*superpage);
415+
mTransferQueue.popFront();
412416
} else {
413417
// If the back one hasn't arrived yet, the next ones will certainly not have arrived either...
414418
break;
@@ -421,14 +425,14 @@ void CrorcDmaChannel::fillSuperpages()
421425
// The transfer queue is empty when all its slots are available
422426
bool CrorcDmaChannel::isTransferQueueEmpty()
423427
{
424-
return mTransferQueue.empty();
428+
return mTransferQueue.isEmpty();
425429
}
426430

427431
// Return a boolean that denotes whether the ready queue is full
428432
// The ready queue is full when the CRORC has filled it up
429433
bool CrorcDmaChannel::isReadyQueueFull()
430434
{
431-
return mReadyQueue.size() == READY_QUEUE_CAPACITY;
435+
return mReadyQueue.sizeGuess() == READY_QUEUE_CAPACITY;
432436
}
433437

434438
int32_t CrorcDmaChannel::getDroppedPackets()

src/Crorc/CrorcDmaChannel.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#include <mutex>
2121
#include <unordered_map>
22-
#include <boost/circular_buffer.hpp>
2322
#include <boost/scoped_ptr.hpp>
2423
#include "DmaChannelPdaBase.h"
2524
#include "Crorc.h"
2625
#include "CrorcBar.h"
2726
#include "ReadoutCard/Parameters.h"
2827
#include "ReadyFifo.h"
28+
#include "folly/ProducerConsumerQueue.h"
2929

3030
namespace AliceO2
3131
{
@@ -77,16 +77,18 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
7777

7878
/// Max amount of superpages in the transfer queue (i.e. pending transfer).
7979
static constexpr size_t TRANSFER_QUEUE_CAPACITY = MAX_SUPERPAGE_DESCRIPTORS;
80+
static constexpr size_t TRANSFER_QUEUE_CAPACITY_ALLOCATIONS = TRANSFER_QUEUE_CAPACITY + 1; // folly Queue needs + 1
8081

8182
/// Max amount of superpages in the ready queue (i.e. finished transfer).
8283
/// This is an arbitrary size, can easily be increased if more headroom is needed.
8384
static constexpr size_t READY_QUEUE_CAPACITY = TRANSFER_QUEUE_CAPACITY;
85+
static constexpr size_t READY_QUEUE_CAPACITY_ALLOCATIONS = TRANSFER_QUEUE_CAPACITY_ALLOCATIONS;
8486

8587
/// Minimum number of superpages needed to bootstrap DMA
8688
//static constexpr size_t DMA_START_REQUIRED_SUPERPAGES = 1;
8789
//static constexpr size_t DMA_START_REQUIRED_SUPERPAGES = READYFIFO_ENTRIES;
8890

89-
using SuperpageQueue = boost::circular_buffer<Superpage>;
91+
using SuperpageQueue = folly::ProducerConsumerQueue<Superpage>;
9092

9193
/// Namespace for enum describing the status of a page's arrival
9294
struct DataArrivalStatus {
@@ -164,10 +166,10 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
164166
int mFreeFifoSize = 0;
165167

166168
/// Queue for superpages that are pushed to the firmware FIFO
167-
SuperpageQueue mTransferQueue{ TRANSFER_QUEUE_CAPACITY };
169+
SuperpageQueue mTransferQueue{ TRANSFER_QUEUE_CAPACITY_ALLOCATIONS };
168170

169171
/// Queue for superpages that are filled
170-
SuperpageQueue mReadyQueue{ READY_QUEUE_CAPACITY };
172+
SuperpageQueue mReadyQueue{ READY_QUEUE_CAPACITY_ALLOCATIONS };
171173

172174
/// Address of DMA buffer in userspace
173175
uintptr_t mDmaBufferUserspace = 0;

src/Cru/CruDmaChannel.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ void CruDmaChannel::deviceStartDma()
131131

132132
// Initialize link queues
133133
for (auto& link : mLinks) {
134-
//link.queue->clear();
135134
while (!link.queue->isEmpty()) {
136135
link.queue->popFront();
137136
}

0 commit comments

Comments
 (0)