Skip to content

Commit b3e9ebc

Browse files
Add locking to Driver
1 parent 302ae7e commit b3e9ebc

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

src/Driver.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <Common/System.h>
1010
#include <InfoLogger/InfoLogger.hxx>
1111
#include "ReadoutCard/ParameterTypes/PciAddress.h"
12+
#include "Pda/PdaLock.h"
1213

1314
namespace AliceO2 {
1415
namespace roc {
@@ -35,6 +36,7 @@ void freeUnusedChannelBuffers()
3536
{
3637
namespace bfs = boost::filesystem;
3738
InfoLogger::InfoLogger logger;
39+
Pda::PdaLock lock(); // We're messing around with PDA buffers so we need this
3840

3941
try {
4042
std::string pciPath = "/sys/bus/pci/drivers/uio_pci_dma/";

src/Pda/PdaDmaBuffer.cxx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@
88
#include <InfoLogger/InfoLogger.hxx>
99
#include "ExceptionInternal.h"
1010
#include "InterprocessLock.h"
11+
#include "Pda/PdaLock.h"
1112

1213
namespace AliceO2 {
1314
namespace roc {
1415
namespace Pda {
15-
namespace {
16-
auto MUTEX_NAME = "AliceO2_roc_Pda_PdaDmaBuffer_Mutex";
17-
auto LOCK_FILE_PATH = "/dev/shm/alice_o2/rorc/AliceO2_roc_Pda_PdaDmaBuffer.lock";
18-
19-
20-
} // Anonymous namespace
2116

2217
PdaDmaBuffer::PdaDmaBuffer(PdaDevice::PdaPciDevice pciDevice, void* userBufferAddress, size_t userBufferSize,
2318
int dmaBufferId, bool requireHugepage) : mPciDevice(pciDevice)
2419
{
2520
// Safeguard against PDA kernel module deadlocks, since it does not like parallel buffer registration
26-
Interprocess::Lock lock {LOCK_FILE_PATH, MUTEX_NAME, true};
21+
PdaLock lock();
2722

2823
try {
2924
// Tell PDA we're using our already allocated userspace buffer.
@@ -105,7 +100,7 @@ PdaDmaBuffer::~PdaDmaBuffer()
105100
// Safeguard against PDA kernel module deadlocks, since it does not like parallel buffer registration
106101
// NOTE: not sure if necessary for deregistration as well
107102
try {
108-
Interprocess::Lock lock {LOCK_FILE_PATH, MUTEX_NAME, true};
103+
PdaLock lock();
109104
PciDevice_deleteDMABuffer(mPciDevice.get(), mDmaBuffer);
110105
} catch (std::exception& e) {
111106
// Nothing to be done?

src/Pda/PdaLock.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// \file PdaDmaBuffer.h
2+
/// \brief Definition of the PdaDmaBuffer class.
3+
///
4+
/// \author Pascal Boeschoten ([email protected])
5+
6+
#ifndef ALICEO2_SRC_READOUTCARD_PDA_PDALOCK_H_
7+
#define ALICEO2_SRC_READOUTCARD_PDA_PDALOCK_H_
8+
9+
#include "InterprocessLock.h"
10+
11+
namespace AliceO2 {
12+
namespace roc {
13+
namespace Pda {
14+
15+
/// Represents a global, system-wide lock on ReadoutCard's PDA usage. This is needed because the PDA kernel module
16+
/// will lock up if buffers are created/freed in parallel.
17+
/// Just hope nobody else uses PDA in parallel.
18+
class PdaLock
19+
{
20+
PdaLock() : mLock("/dev/shm/alice_o2/rorc/AliceO2_roc_Pda_PdaDmaBuffer.lock", "AliceO2_roc_Pda_PdaDmaBuffer_Mutex",
21+
true)
22+
{
23+
}
24+
25+
private:
26+
Interprocess::Lock mLock;
27+
};
28+
29+
} // namespace Pda
30+
} // namespace roc
31+
} // namespace AliceO2
32+
33+
#endif // ALICEO2_SRC_READOUTCARD_PDA_PDALOCK_H_

0 commit comments

Comments
 (0)