Skip to content

Commit f95d891

Browse files
committed
[crorc] Update DMA interface (drops Ready & Free fifos)
1 parent 0a00f37 commit f95d891

19 files changed

+133
-725
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ set(TEST_SRCS
296296
test/TestPciAddress.cxx
297297
test/TestProgramOptions.cxx
298298
test/TestRorcException.cxx
299-
test/TestSuperpageQueue.cxx
300299
)
301300

302301
foreach (test ${TEST_SRCS})

src/ChannelPaths.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ std::string ChannelPaths::lock() const
4343
return makePath(".lock", DIR_SHAREDMEM);
4444
}
4545

46-
std::string ChannelPaths::fifo() const
46+
std::string ChannelPaths::spInfo() const
4747
{
48-
return makePath("_fifo", DIR_SHAREDMEM);
48+
return makePath("_sp_info", DIR_SHAREDMEM);
4949
}
5050

5151
std::string ChannelPaths::namedMutex() const

src/ChannelPaths.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ class ChannelPaths
3838
/// \return The path
3939
std::string lock() const;
4040

41-
/// Generates a path for the channel's shared memory FIFO object. It will be in hugetlbfs.
41+
/// Generates a path for the CRORC channel's shared memory Superpage info object.
4242
/// \return The path
43-
std::string fifo() const;
43+
std::string spInfo() const;
4444

4545
/// Generates a name for the channel's mutex
4646
/// \return The name

src/CommandLineUtilities/ProgramCleanup.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ProgramCleanup : public Program
5555
std::cout << std::endl;
5656
std::cout << "Execution of this tool will:" << std::endl;
5757
std::cout << "1. Free PDA DMA buffers" << std::endl;
58-
std::cout << "2. Clean CRORC FIFO shared memory files under /dev/shm which match AliceO2_ROC_*" << std::endl;
58+
std::cout << "2. Clean CRORC shared memory files under /dev/shm which match *_sp_info" << std::endl;
5959
std::cout << "3. Clean all hugepage resources under /var/lib/hugetlbfs/global/pagesize-{2MB, 1GB}/ which match readout* and o2-roc-bench-dma*" << std::endl;
6060
if (!mOptions.light) {
6161
std::cout << "4. Remove and reinsert the uio_pci_dma kernel module" << std::endl;
@@ -110,7 +110,7 @@ class ProgramCleanup : public Program
110110
Pda::freePdaDmaBuffers();
111111

112112
Logger::get() << "Removing CRORC FIFO shared memory files" << LogDebugDevel << endm;
113-
sysCheckRet("rm /dev/shm/AliceO2_RoC_*");
113+
sysCheckRet("rm /dev/shm/*_sp_info");
114114
Logger::get() << "Removing readout 2MB hugepage mappings" << LogDebugDevel << endm;
115115
sysCheckRet("rm /var/lib/hugetlbfs/global/pagesize-2MB/readout*");
116116
Logger::get() << "Removing readout 1GB hugepage mappings" << LogDebugDevel << endm;

src/CommandLineUtilities/ProgramDmaBench.cxx

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,13 @@ class ProgramDmaBench : public Program
508508
size_t readoutBytes = 0;
509509
auto superpageAddress = mBufferBaseAddress + superpageInfo.bufferOffset;
510510

511-
fetchAddSuperpagesReadOut();
511+
auto superpageCount = fetchAddSuperpagesReadOut();
512512

513513
bool atStartOfSuperpage = true;
514514
while ((readoutBytes < superpageInfo.effectiveSize) && !isStopDma()) {
515515
auto pageAddress = superpageAddress + readoutBytes;
516516
auto readoutCount = fetchAddDmaPagesReadOut();
517-
size_t pageSize = readoutPage(pageAddress, readoutCount, atStartOfSuperpage);
517+
size_t pageSize = readoutPage(pageAddress, readoutCount, superpageCount, atStartOfSuperpage);
518518

519519
atStartOfSuperpage = false; //Update the boolean value as soon as we move...
520520

@@ -558,15 +558,15 @@ class ProgramDmaBench : public Program
558558
auto size = mChannel->getReadyQueueSize();
559559
for (int i = 0; i < size; ++i) {
560560
auto superpage = mChannel->popSuperpage();
561-
fetchAddSuperpagesReadOut();
561+
auto superpageCount = fetchAddSuperpagesReadOut();
562562
if ((mDataSource == DataSource::Fee) || (mDataSource == DataSource::Ddg)) {
563563
auto superpageAddress = mBufferBaseAddress + superpage.getOffset();
564564
size_t readoutBytes = 0;
565565
bool atStartOfSuperpage = true;
566566
while ((readoutBytes < superpage.getReceived())) { // At least one more dma page fits in the superpage
567567
auto pageAddress = superpageAddress + readoutBytes;
568568
auto readoutCount = fetchAddDmaPagesReadOut();
569-
size_t pageSize = readoutPage(pageAddress, readoutCount, atStartOfSuperpage);
569+
size_t pageSize = readoutPage(pageAddress, readoutCount, superpageCount, atStartOfSuperpage);
570570
atStartOfSuperpage = false; // Update the boolean value as soon as we move...
571571
readoutBytes += pageSize;
572572
}
@@ -588,12 +588,23 @@ class ProgramDmaBench : public Program
588588
return payload[0];
589589
};
590590

591-
size_t readoutPage(uintptr_t pageAddress, int64_t readoutCount, bool atStartOfSuperpage)
591+
size_t readoutPage(uintptr_t pageAddress, int64_t readoutCount, int64_t superpageCount, bool atStartOfSuperpage)
592592
{
593593
size_t pageSize = (mDataSource == DataSource::Internal) ? mPageSize : DataFormat::getOffset(reinterpret_cast<const char*>(pageAddress));
594594

595+
bool isEmpty = false;
596+
if (pageSize != mPageSize) {
597+
pageSize = mPageSize;
598+
isEmpty = true;
599+
// write to file
600+
uint32_t emptySP = 0x0badf00d;
601+
for (int i = 0; i < 4; i++) { // Marker is 128bits long
602+
mReadoutStream.write(reinterpret_cast<const char*>(&emptySP), sizeof(emptySP));
603+
}
604+
}
605+
595606
// Read out to file
596-
printToFile(pageAddress, pageSize, readoutCount, atStartOfSuperpage);
607+
printToFile(pageAddress, pageSize, readoutCount, superpageCount, atStartOfSuperpage, isEmpty);
597608

598609
// Data error checking
599610
if (!mOptions.noErrorCheck) {
@@ -848,7 +859,7 @@ class ProgramDmaBench : public Program
848859
mPacketCounters[linkId] = packetCounter;
849860
}
850861

851-
if (!checkTimeFrameAlignment(pageAddress, atStartOfSuperpage)) {
862+
if (false && !checkTimeFrameAlignment(pageAddress, atStartOfSuperpage)) {
852863
// log TF not at the beginning of the superpage error
853864
mErrorCount++;
854865
if (mErrorCount < MAX_RECORDED_ERRORS) {
@@ -1015,26 +1026,38 @@ class ProgramDmaBench : public Program
10151026
}
10161027

10171028
/// Prints the page to a file in ASCII or binary format if such output is enabled
1018-
void printToFile(uintptr_t pageAddress, size_t pageSize, int64_t pageNumber, bool atStartOfSuperpage)
1029+
void printToFile(uintptr_t pageAddress, size_t pageSize, int64_t pageNumber, int64_t superpageNumber, bool atStartOfSuperpage, bool isEmpty = false)
10191030
{
10201031
auto page = reinterpret_cast<const volatile uint32_t*>(pageAddress);
10211032
auto pageSize32 = pageSize / sizeof(uint32_t);
10221033

10231034
if (mOptions.fileOutputAscii) {
10241035
if (atStartOfSuperpage && mOptions.printSuperpageChange) {
1025-
mReadoutStream << "New Superpage\n";
1036+
mReadoutStream << "Superpage #" << std::hex << "0x" << superpageNumber << '\n';
10261037
}
1027-
mReadoutStream << "Event #" << pageNumber << '\n';
1038+
// TODO: for debugging: maybe add an option here?
1039+
if (isEmpty) {
1040+
mReadoutStream << "!!EMPTY DMA PAGE!!\n";
1041+
}
1042+
mReadoutStream << "Event #" << std::hex << "0x" << pageNumber << '\n';
10281043
uint32_t perLine = 8;
10291044

10301045
for (uint32_t i = 0; i < pageSize32; i += perLine) {
10311046
for (uint32_t j = 0; j < perLine; ++j) {
1032-
mReadoutStream << page[i + j] << ' ';
1047+
mReadoutStream << std::hex << "0x" << std::setw(8) << page[i + j] << ' ';
1048+
mReadoutStream << '\t';
10331049
}
10341050
mReadoutStream << '\n';
10351051
}
10361052
mReadoutStream << '\n';
10371053
} else if (mOptions.fileOutputBin) {
1054+
// TODO: for debugging
1055+
if (isEmpty) {
1056+
uint32_t emptySP = 0xdeadbeef;
1057+
for (int i = 0; i < 4; i++) { // Marker is 128bits long
1058+
mReadoutStream.write(reinterpret_cast<const char*>(&emptySP), sizeof(emptySP));
1059+
}
1060+
}
10381061
if (atStartOfSuperpage && mOptions.printSuperpageChange) {
10391062
uint32_t newSP = 0x0badf00d;
10401063
for (int i = 0; i < 4; i++) { // Marker is 128bits long

src/Crorc/Constants.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,9 @@ static constexpr uint32_t DATA_RX_ON_OFF_BIT(0x9);
385385
static constexpr uint32_t RXSTAT_NOT_EMPTY(0x00800000);
386386
static constexpr uint32_t LOOPBACK_ON_OFF(0x00001000);
387387

388-
// Channel Receive Report Base Address
389-
static constexpr Register CHANNEL_RRBAR(0x00000034);
390-
// Channel Receive Report Base Address Extension
391-
static constexpr Register CHANNEL_RRBARX(0x00000084);
388+
// Addresses to push the DMA buffer address for SP size + count info
389+
static constexpr Register SPINFO_LOW(0x00000040);
390+
static constexpr Register SPINFO_HIGH(0x00000044);
392391

393392
// Registers to send DDL commands
394393
static constexpr Register DDL_COMMAND(0x00000018);
@@ -412,10 +411,10 @@ static constexpr Register OPT_POWER_QSFP10(0x00000144);
412411
static constexpr Register OPT_POWER_QSFP32(0x00000148);
413412
static constexpr Register OPT_POWER_QSFP54(0x00000154);
414413

415-
// Registers for RX FIFO configuration
416-
static constexpr Register RX_FIFO_ADDR_LOW(0x00000038);
417-
static constexpr Register RX_FIFO_ADDR_HIGH(0x0000003c);
418-
static constexpr Register RX_FIFO_ADDR_EXT(0x00000080);
414+
// Registers for pushing a Superpage to the CRORC
415+
static constexpr Register SP_WR_SIZE(0x00000028);
416+
static constexpr Register SP_WR_ADDR_HIGH(0x00000030);
417+
static constexpr Register SP_WR_ADDR_LOW(0x0000002c);
419418

420419
// Data transmission status word
421420
static constexpr uint32_t DTSW(0x00000082);

src/Crorc/Crorc.cxx

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -802,31 +802,6 @@ void Crorc::diuCommand(int command)
802802
ddlReadDiu(command, Ddl::RESPONSE_TIME);
803803
}
804804

805-
RxFreeFifoState Crorc::getRxFreeFifoState()
806-
{
807-
uint32_t st = read(Rorc::C_CSR);
808-
if (st & Rorc::CcsrStatus::RXAFF_FULL) {
809-
return (RxFreeFifoState::FULL);
810-
} else if (st & Rorc::CcsrStatus::RXAFF_EMPTY) {
811-
return (RxFreeFifoState::EMPTY);
812-
} else {
813-
return (RxFreeFifoState::NOT_EMPTY);
814-
}
815-
}
816-
817-
bool Crorc::isFreeFifoEmpty()
818-
{
819-
return getRxFreeFifoState() == RxFreeFifoState::EMPTY;
820-
}
821-
822-
void Crorc::assertFreeFifoEmpty()
823-
{
824-
if (!isFreeFifoEmpty()) {
825-
BOOST_THROW_EXCEPTION(CrorcFreeFifoException() << ErrorInfo::Message("Free FIFO not empty")
826-
<< ErrorInfo::PossibleCauses({ "Previous DMA did not get/free all received pages" }));
827-
}
828-
}
829-
830805
void Crorc::startDataReceiver(uintptr_t readyFifoBusAddress)
831806
{
832807
write(Rorc::C_RRBAR, (readyFifoBusAddress & 0xffffffff));

src/Crorc/Crorc.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <vector>
2424
#include <boost/optional.hpp>
2525
#include "ReadoutCard/RegisterReadWriteInterface.h"
26-
#include "RxFreeFifoState.h"
2726
#include "StWord.h"
2827

2928
namespace o2
@@ -104,12 +103,6 @@ class Crorc
104103
/// the header ddl_def.h
105104
void diuCommand(int command);
106105

107-
/// Checks if the C-RORC's Free FIFO is empty
108-
bool isFreeFifoEmpty();
109-
110-
/// Checks if the C-RORC's Free FIFO is empty
111-
void assertFreeFifoEmpty();
112-
113106
/// Starts the trigger (RDYRX or STBRD)
114107
void startTrigger(const DiuConfig& diuConfig, uint32_t command);
115108
//void startTrigger(uint32_t command);
@@ -149,8 +142,6 @@ class Crorc
149142

150143
void pushRxFreeFifo(uintptr_t blockAddress, uint32_t blockLength, uint32_t readyFifoIndex);
151144

152-
RxFreeFifoState getRxFreeFifoState();
153-
154145
static void scaInit(RegisterReadWriteInterface& bar2);
155146

156147
struct ScaWriteCommand {

src/Crorc/CrorcBar.cxx

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,17 @@ void CrorcBar::resetDevice(bool withSiu)
340340
}
341341
}
342342

343-
void CrorcBar::startDataReceiver(uintptr_t readyFifoBusAddress)
343+
void CrorcBar::startDataReceiver(uintptr_t superpageInfoBusAddress)
344344
{
345-
writeRegister(Crorc::Registers::CHANNEL_RRBAR.index, (readyFifoBusAddress & 0xffffffff));
345+
// Send the address of the DMA buffer used for writing the Superpage Info (size + count)
346+
writeRegister(Crorc::Registers::SPINFO_LOW.index, (superpageInfoBusAddress & 0xffffffff));
346347
if (sizeof(uintptr_t) > 4) {
347-
writeRegister(Crorc::Registers::CHANNEL_RRBARX.index, (readyFifoBusAddress >> 32));
348+
writeRegister(Crorc::Registers::SPINFO_HIGH.index, (superpageInfoBusAddress >> 32));
348349
} else {
349-
writeRegister(Crorc::Registers::CHANNEL_RRBARX.index, 0x0);
350+
writeRegister(Crorc::Registers::SPINFO_HIGH.index, 0x0);
350351
}
351352

353+
// Set DMA ON
352354
uint32_t CSRRegister = readRegister(Crorc::Registers::CHANNEL_CSR.index);
353355
if (!Utilities::getBit(CSRRegister, Crorc::Registers::DATA_RX_ON_OFF_BIT)) {
354356
Utilities::setBit(CSRRegister, Crorc::Registers::DATA_RX_ON_OFF_BIT, true);
@@ -366,11 +368,11 @@ void CrorcBar::stopDataReceiver()
366368
}
367369
}
368370

369-
void CrorcBar::pushRxFreeFifo(uintptr_t blockAddress, uint32_t blockLength, uint32_t readyFifoIndex)
371+
void CrorcBar::pushSuperpageAddressAndSize(uintptr_t blockAddress, uint32_t blockLength)
370372
{
371-
writeRegister(Crorc::Registers::RX_FIFO_ADDR_EXT.index, arch64() ? (blockAddress >> 32) : 0x0);
372-
writeRegister(Crorc::Registers::RX_FIFO_ADDR_HIGH.index, blockAddress & 0xffffffff);
373-
writeRegister(Crorc::Registers::RX_FIFO_ADDR_LOW.index, (blockLength << 8) | readyFifoIndex);
373+
writeRegister(Crorc::Registers::SP_WR_ADDR_HIGH.index, arch64() ? (blockAddress >> 32) : 0x0);
374+
writeRegister(Crorc::Registers::SP_WR_ADDR_LOW.index, blockAddress & 0xffffffff);
375+
writeRegister(Crorc::Registers::SP_WR_SIZE.index, blockLength);
374376
}
375377

376378
void CrorcBar::startDataGenerator()
@@ -409,21 +411,5 @@ Crorc::PacketMonitoringInfo CrorcBar::monitorPackets()
409411
return { acquisitionRate, packetsReceived };
410412
}
411413

412-
bool CrorcBar::isASuperpageAvailable()
413-
{
414-
static uint32_t previousAvailable = 0x0;
415-
uint32_t currentAvailable = readRegister(0x30 / 4);
416-
uint32_t diff;
417-
if (currentAvailable < previousAvailable) { // warped
418-
diff = (0x100000000 - 0xffffffff) + currentAvailable;
419-
} else {
420-
diff = currentAvailable - previousAvailable;
421-
}
422-
423-
previousAvailable = currentAvailable;
424-
425-
return diff > 0;
426-
}
427-
428414
} // namespace roc
429415
} // namespace o2

src/Crorc/CrorcBar.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include "Crorc/Constants.h"
2424
#include "Utilities/Util.h"
2525

26+
#include <fstream>
27+
#include <iostream>
28+
2629
namespace o2
2730
{
2831
namespace roc
@@ -54,7 +57,7 @@ class CrorcBar final : public BarInterfaceBase
5457

5558
void resetDevice(bool withSiu);
5659
void flushSuperpages();
57-
void startDataReceiver(uintptr_t readyFifoBusAddress);
60+
void startDataReceiver(uintptr_t superpageInfoBusAddress);
5861
void stopDataReceiver();
5962
void startDataGenerator();
6063
void stopDataGenerator();
@@ -63,14 +66,12 @@ class CrorcBar final : public BarInterfaceBase
6366
bool isLinkUp(int barIndex);
6467
bool checkLinkUp();
6568
void assertLinkUp();
66-
void pushRxFreeFifo(uintptr_t blockAddress, uint32_t blockLength, uint32_t readyFifoIndex);
69+
void pushSuperpageAddressAndSize(uintptr_t blockAddress, uint32_t blockLength);
6770
void setLoopback();
6871
void setDiuLoopback();
6972
void setSiuLoopback();
7073
Crorc::PacketMonitoringInfo monitorPackets();
7174

72-
bool isASuperpageAvailable();
73-
7475
private:
7576
std::map<int, Crorc::Link> initializeLinkMap();
7677

0 commit comments

Comments
 (0)