lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
Drp::MemPool Class Referenceabstract

Abstract set of buffer pools for one DRP: the DMA buffers (allocated by the driver; only counted here), the pebble buffers and the transition buffers. More...

#include <drp.hh>

Inherited by Drp::Gpu::MemPoolGpu, and Drp::MemPoolCpu.

Public Member Functions

 MemPool (const Parameters &para)
 Create the transition buffer queue (TEB_TR_BUFFERS rounded up to a power of 2) and zero the counters.
 
virtual ~MemPool ()
 Does nothing; empty body.
 
unsigned dmaCount () const
 Return the number of DMA buffers reported by the driver.
 
unsigned nDmaBuffers () const
 Return dmaCount() rounded up to a power of 2.
 
unsigned dmaSize () const
 Return the size of one DMA buffer.
 
unsigned nbuffers () const
 Return the number of pebble (L1Accept) buffers.
 
size_t bufferSize () const
 Return the size of one pebble L1Accept buffer.
 
virtual int fd () const =0
 Pure virtual: return the device file descriptor.
 
void shutdown ()
 Shut down the transition buffer queue and log how often DMA reads and returns failed.
 
Pds::EbDgram * allocateTr ()
 Pop a free transition buffer as an EbDgram pointer, or return nullptr if none is available.
 
void freeTr (Pds::EbDgram *dgram)
 Check the overrun sentinels of transition buffer dgram (logging the first overrun), then push it back onto the free queue.
 
unsigned allocateDma ()
 Count one DMA buffer allocation (the firmware does the actual allocation) and return the count before the increment.
 
ssize_t readDma (uint32_t count, int32_t *ret, uint32_t *index, uint32_t *flags, uint32_t *errors, uint32_t *dest)
 Read up to count DMA buffers with dmaReadBulkIndex() on fd(), filling the per-buffer return sizes, indices, flags, errors and destinations.
 
ssize_t freeDma (unsigned count, uint32_t *indices)
 Return count DMA buffers (by index) to the driver through the subclass and log errors; on success the frees are counted.
 
unsigned allocate ()
 Allocate the next pebble buffer index in order, blocking while all buffers are in use.
 
void freePebble (unsigned)
 Free the oldest pebble buffer (logging if the index is not the expected one), wake a blocked allocate() if the pool was full, and check that buffer's overrun sentinels.
 
void flushPebble ()
 Free pebble buffers in order until none is in use.
 
int64_t dmaInUse () const
 Return the number of DMA allocations minus frees.
 
int64_t inUse () const
 Return the number of pebble allocations minus frees.
 
int64_t trInUse () const
 Return guess_size() of the transition buffer queue.
 
void resetCounters ()
 Reset the DMA counters (only if no DMA buffer is in use, otherwise warn), the pebble counters (with a warning if buffers are still in use), the overrun flags and the error counts.
 
virtual int setMaskBytes (uint8_t laneMask, unsigned virtChan)=0
 Pure virtual: configure the driver to deliver the lanes in laneMask on virtual channel virtChan.
 
template<typename T >
T * getAs ()
 Return this pool cast with static_cast to T*.
 

Public Attributes

Pebble pebble
 Pebble holding the L1Accept and transition buffers.
 
std::vector< PGPEvent > pgpEvents
 Events being assembled, indexed by event counter modulo nDmaBuffers().
 
std::vector< Pds::EbDgram * > transitionDgrams
 Transition datagram assigned to each pebble buffer index (set for non-L1Accept events).
 
void ** dmaBuffers
 DMA buffer addresses mapped from the driver.
 

Protected Member Functions

void _initialize (const Parameters &)
 

Protected Attributes

unsigned m_nDmaBuffers
 
unsigned m_nbuffers
 
unsigned m_dmaCount
 
unsigned m_dmaSize
 
SPSCQueue< void * > m_transitionBuffers
 
std::atomic< uint64_t > m_dmaAllocs
 
std::atomic< uint64_t > m_dmaFrees
 
std::atomic< uint64_t > m_allocs
 
std::atomic< uint64_t > m_frees
 
std::mutex m_lock
 
std::condition_variable m_condition
 
uint8_t m_dmaOverrun
 
uint8_t m_l1Overrun
 
uint8_t m_trOverrun
 
uint8_t m_pad
 
unsigned m_nDmaReadErr
 
unsigned m_nDmaRetErr
 

Detailed Description

Abstract set of buffer pools for one DRP: the DMA buffers (allocated by the driver; only counted here), the pebble buffers and the transition buffers.

Subclasses open the device and provide fd(), setMaskBytes() and the release of DMA buffers.

Constructor & Destructor Documentation

◆ MemPool()

Drp::MemPool::MemPool ( const Parameters &  para)

Create the transition buffer queue (TEB_TR_BUFFERS rounded up to a power of 2) and zero the counters.

The subclass calls _initialize() once the DMA buffer count and size are known.

◆ ~MemPool()

virtual Drp::MemPool::~MemPool ( )
inlinevirtual

Does nothing; empty body.

Member Function Documentation

◆ _initialize()

void Drp::MemPool::_initialize ( const Parameters &  )
protected

◆ allocate()

unsigned Drp::MemPool::allocate ( )

Allocate the next pebble buffer index in order, blocking while all buffers are in use.

Pebble buffers must be freed in allocation order.

◆ allocateDma()

unsigned Drp::MemPool::allocateDma ( )

Count one DMA buffer allocation (the firmware does the actual allocation) and return the count before the increment.

◆ allocateTr()

Pds::EbDgram * Drp::MemPool::allocateTr ( )

Pop a free transition buffer as an EbDgram pointer, or return nullptr if none is available.

◆ bufferSize()

size_t Drp::MemPool::bufferSize ( ) const
inline

Return the size of one pebble L1Accept buffer.

◆ dmaCount()

unsigned Drp::MemPool::dmaCount ( ) const
inline

Return the number of DMA buffers reported by the driver.

◆ dmaInUse()

int64_t Drp::MemPool::dmaInUse ( ) const
inline

Return the number of DMA allocations minus frees.

◆ dmaSize()

unsigned Drp::MemPool::dmaSize ( ) const
inline

Return the size of one DMA buffer.

◆ fd()

virtual int Drp::MemPool::fd ( ) const
pure virtual

Pure virtual: return the device file descriptor.

Implemented in Drp::MemPoolCpu, and Drp::Gpu::MemPoolGpu.

◆ flushPebble()

void Drp::MemPool::flushPebble ( )

Free pebble buffers in order until none is in use.

◆ freeDma()

ssize_t Drp::MemPool::freeDma ( unsigned  count,
uint32_t *  indices 
)

Return count DMA buffers (by index) to the driver through the subclass and log errors; on success the frees are counted.

Returns the subclass result.

◆ freePebble()

void Drp::MemPool::freePebble ( unsigned  )

Free the oldest pebble buffer (logging if the index is not the expected one), wake a blocked allocate() if the pool was full, and check that buffer's overrun sentinels.

◆ freeTr()

void Drp::MemPool::freeTr ( Pds::EbDgram *  dgram)

Check the overrun sentinels of transition buffer dgram (logging the first overrun), then push it back onto the free queue.

◆ getAs()

template<typename T >
T * Drp::MemPool::getAs ( )
inline

Return this pool cast with static_cast to T*.

◆ inUse()

int64_t Drp::MemPool::inUse ( ) const
inline

Return the number of pebble allocations minus frees.

◆ nbuffers()

unsigned Drp::MemPool::nbuffers ( ) const
inline

Return the number of pebble (L1Accept) buffers.

◆ nDmaBuffers()

unsigned Drp::MemPool::nDmaBuffers ( ) const
inline

Return dmaCount() rounded up to a power of 2.

◆ readDma()

ssize_t Drp::MemPool::readDma ( uint32_t  count,
int32_t *  ret,
uint32_t *  index,
uint32_t *  flags,
uint32_t *  errors,
uint32_t *  dest 
)

Read up to count DMA buffers with dmaReadBulkIndex() on fd(), filling the per-buffer return sizes, indices, flags, errors and destinations.

Returns its result; errors are logged (the first one at error level).

◆ resetCounters()

void Drp::MemPool::resetCounters ( )

Reset the DMA counters (only if no DMA buffer is in use, otherwise warn), the pebble counters (with a warning if buffers are still in use), the overrun flags and the error counts.

◆ setMaskBytes()

virtual int Drp::MemPool::setMaskBytes ( uint8_t  laneMask,
unsigned  virtChan 
)
pure virtual

Pure virtual: configure the driver to deliver the lanes in laneMask on virtual channel virtChan.

Implemented in Drp::MemPoolCpu, and Drp::Gpu::MemPoolGpu.

◆ shutdown()

void Drp::MemPool::shutdown ( )

Shut down the transition buffer queue and log how often DMA reads and returns failed.

◆ trInUse()

int64_t Drp::MemPool::trInUse ( ) const
inline

Return guess_size() of the transition buffer queue.

That queue holds the free buffers, so despite the name this is the approximate number of free transition buffers.

Member Data Documentation

◆ dmaBuffers

void** Drp::MemPool::dmaBuffers

DMA buffer addresses mapped from the driver.

◆ m_allocs

std::atomic<uint64_t> Drp::MemPool::m_allocs
protected

◆ m_condition

std::condition_variable Drp::MemPool::m_condition
protected

◆ m_dmaAllocs

std::atomic<uint64_t> Drp::MemPool::m_dmaAllocs
protected

◆ m_dmaCount

unsigned Drp::MemPool::m_dmaCount
protected

◆ m_dmaFrees

std::atomic<uint64_t> Drp::MemPool::m_dmaFrees
protected

◆ m_dmaOverrun

uint8_t Drp::MemPool::m_dmaOverrun
protected

◆ m_dmaSize

unsigned Drp::MemPool::m_dmaSize
protected

◆ m_frees

std::atomic<uint64_t> Drp::MemPool::m_frees
protected

◆ m_l1Overrun

uint8_t Drp::MemPool::m_l1Overrun
protected

◆ m_lock

std::mutex Drp::MemPool::m_lock
protected

◆ m_nbuffers

unsigned Drp::MemPool::m_nbuffers
protected

◆ m_nDmaBuffers

unsigned Drp::MemPool::m_nDmaBuffers
protected

◆ m_nDmaReadErr

unsigned Drp::MemPool::m_nDmaReadErr
protected

◆ m_nDmaRetErr

unsigned Drp::MemPool::m_nDmaRetErr
protected

◆ m_pad

uint8_t Drp::MemPool::m_pad
protected

◆ m_transitionBuffers

SPSCQueue<void*> Drp::MemPool::m_transitionBuffers
protected

◆ m_trOverrun

uint8_t Drp::MemPool::m_trOverrun
protected

◆ pebble

Pebble Drp::MemPool::pebble

Pebble holding the L1Accept and transition buffers.

◆ pgpEvents

std::vector<PGPEvent> Drp::MemPool::pgpEvents

Events being assembled, indexed by event counter modulo nDmaBuffers().

◆ transitionDgrams

std::vector<Pds::EbDgram*> Drp::MemPool::transitionDgrams

Transition datagram assigned to each pebble buffer index (set for non-L1Accept events).


The documentation for this class was generated from the following file: