Skip to content

Commit 0ff4a1e

Browse files
RoC: Add mutex as workaround for PDA kernel deadlocks on simultaneous DMA buffer construction/destruction
1 parent fb1fd83 commit 0ff4a1e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Pda/PdaDmaBuffer.cxx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,27 @@
44
/// \author Pascal Boeschoten ([email protected])
55

66
#include "PdaDmaBuffer.h"
7+
#include <boost/interprocess/sync/scoped_lock.hpp>
8+
#include <boost/interprocess/sync/named_mutex.hpp>
79
#include <pda.h>
810
#include "ExceptionInternal.h"
911

1012
namespace AliceO2 {
1113
namespace roc {
1214
namespace Pda {
15+
namespace {
16+
using Mutex = boost::interprocess::named_mutex;
17+
using Lock = boost::interprocess::scoped_lock<Mutex>;
18+
auto MUTEX_NAME = "AliceO2_roc_Pda_PdaDmaBuffer_Mutex";
19+
} // Anonymous namespace
1320

1421
PdaDmaBuffer::PdaDmaBuffer(PdaDevice::PdaPciDevice pciDevice, void* userBufferAddress, size_t userBufferSize,
1522
int dmaBufferId) : mPciDevice(pciDevice)
1623
{
24+
// Safeguard against PDA kernel module deadlocks
25+
Mutex mutex {boost::interprocess::open_or_create, MUTEX_NAME};
26+
Lock lock {mutex};
27+
1728
try {
1829
// Tell PDA we're using our already allocated userspace buffer.
1930
if (PciDevice_registerDMABuffer(pciDevice.get(), dmaBufferId, userBufferAddress, userBufferSize,
@@ -86,6 +97,10 @@ PdaDmaBuffer::PdaDmaBuffer(PdaDevice::PdaPciDevice pciDevice, void* userBufferAd
8697

8798
PdaDmaBuffer::~PdaDmaBuffer()
8899
{
100+
// Safeguard against PDA kernel module deadlocks
101+
Mutex mutex {boost::interprocess::open_or_create, MUTEX_NAME};
102+
Lock lock {mutex};
103+
89104
PciDevice_deleteDMABuffer(mPciDevice.get(), mDmaBuffer);
90105
}
91106

0 commit comments

Comments
 (0)