Skip to content

Commit

Permalink
[crorc] SP count as member variable instead of scoped static
Browse files Browse the repository at this point in the history
  • Loading branch information
kostorr committed Jan 10, 2022
1 parent 315abd1 commit 2966e6f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
25 changes: 16 additions & 9 deletions src/Crorc/CrorcDmaChannel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,6 @@ bool CrorcDmaChannel::pushSuperpage(Superpage superpage)
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("Could not push superpage, transfer queue was full"));
}

auto busAddress = getBusOffsetAddress(superpage.getOffset());
getBar()->pushSuperpageAddressAndSize(busAddress, superpage.getSize());

mTransferQueue.write(superpage);

return true;
Expand All @@ -262,16 +259,15 @@ auto CrorcDmaChannel::popSuperpage() -> Superpage

bool CrorcDmaChannel::isASuperpageAvailable()
{
static uint32_t count = 0xff;
uint32_t newCount = getSuperpageInfoUser()->count;
uint32_t diff;

if (newCount < count) { // handle overflow
if (newCount < mSPAvailCount) { // handle overflow
diff = ((0xff + 1) - 0xff) + newCount;
} else {
diff = newCount - count;
diff = newCount - mSPAvailCount;
}
count = newCount;
mSPAvailCount = newCount;

return diff > 0;
}
Expand All @@ -288,13 +284,24 @@ void CrorcDmaChannel::fillSuperpages()
}

// Check for arrivals & handle them
if (!mTransferQueue.isEmpty() && isASuperpageAvailable()) {
if (!mIntermediateQueue.isEmpty() && isASuperpageAvailable()) {

auto superpage = mTransferQueue.frontPtr();
auto superpage = mIntermediateQueue.frontPtr();
superpage->setReceived(getSuperpageInfoUser()->size); // length in bytes
superpage->setReady(true);
mReadyQueue.write(*superpage);
mIntermediateQueue.popFront();
}

// Push single Superpage to the firmware when available
if (mIntermediateQueue.isEmpty() && !mTransferQueue.isEmpty()) {
auto inSuperpage = mTransferQueue.frontPtr();
mTransferQueue.popFront();

auto busAddress = getBusOffsetAddress(inSuperpage->getOffset());
getBar()->pushSuperpageAddressAndSize(busAddress, inSuperpage->getSize());

mIntermediateQueue.write(*inSuperpage);
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/Crorc/CrorcDmaChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
static constexpr size_t DMA_PAGE_SIZE = 8 * 1024;

/// Max amount of superpages in the transfer queue (i.e. pending transfer).
/// CRORC FW only handles a single superpage at a time
static constexpr size_t TRANSFER_QUEUE_CAPACITY = 1;
static constexpr size_t TRANSFER_QUEUE_CAPACITY = 128;
static constexpr size_t TRANSFER_QUEUE_CAPACITY_ALLOCATIONS = TRANSFER_QUEUE_CAPACITY + 1; // folly Queue needs + 1

/// Max amount of superpages in the intermediate queue (i.e. pushed superpage).
/// CRORC FW only handles a single superpage at a time
static constexpr size_t INTERMEDIATE_QUEUE_CAPACITY = 1;
static constexpr size_t INTERMEDIATE_QUEUE_CAPACITY_ALLOCATIONS = INTERMEDIATE_QUEUE_CAPACITY + 1;

/// Max amount of superpages in the ready queue (i.e. finished transfer).
/// This is an arbitrary size, can easily be increased if more headroom is needed.
static constexpr size_t READY_QUEUE_CAPACITY = TRANSFER_QUEUE_CAPACITY;
Expand Down Expand Up @@ -120,9 +124,12 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
/// BAR used for DMA engine and configuration
std::shared_ptr<CrorcBar> crorcBar;

/// Queue for superpages that are pushed to the firmware FIFO
/// Queue for superpages that are pushed from the Readout thread
SuperpageQueue mTransferQueue{ TRANSFER_QUEUE_CAPACITY_ALLOCATIONS };

/// Queue for the superpage that is pushed to the firmware
SuperpageQueue mIntermediateQueue{ INTERMEDIATE_QUEUE_CAPACITY_ALLOCATIONS };

/// Queue for superpages that are filled
SuperpageQueue mReadyQueue{ READY_QUEUE_CAPACITY_ALLOCATIONS };

Expand Down Expand Up @@ -165,6 +172,9 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
{
return reinterpret_cast<SuperpageInfo*>(mSuperpageInfoAddressUser);
}

// Counter for the available (from the fw) superpages
uint32_t mSPAvailCount = 0xff;
};

} // namespace roc
Expand Down

0 comments on commit 2966e6f

Please sign in to comment.