From 7e0848b7d51f8e96568865d25dde72ee09b336a5 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 28 Oct 2022 08:16:58 -0400 Subject: [PATCH] dma: throw exception in makeAccesibleFromVA instead of returning bool --- fpga/include/villas/fpga/ips/dma.hpp | 2 +- fpga/lib/ips/dma.cpp | 18 ++++++------------ fpga/tests/unit/dma.cpp | 6 ++---- fpga/tests/unit/gpu.cpp | 7 +++---- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/fpga/include/villas/fpga/ips/dma.hpp b/fpga/include/villas/fpga/ips/dma.hpp index 8783b60bf..285589dab 100644 --- a/fpga/include/villas/fpga/ips/dma.hpp +++ b/fpga/include/villas/fpga/ips/dma.hpp @@ -57,7 +57,7 @@ public: bool memcpy(const MemoryBlock &src, const MemoryBlock &dst, size_t len); - bool makeAccesibleFromVA(const MemoryBlock &mem); + void makeAccesibleFromVA(const MemoryBlock &mem); bool makeInaccesibleFromVA(const MemoryBlock &mem); inline bool diff --git a/fpga/lib/ips/dma.cpp b/fpga/lib/ips/dma.cpp index d55636abf..39b8f776d 100644 --- a/fpga/lib/ips/dma.cpp +++ b/fpga/lib/ips/dma.cpp @@ -460,28 +460,22 @@ Dma::readCompleteSimple() return bytesRead; } -bool +void Dma::makeAccesibleFromVA(const MemoryBlock &mem) { // Only symmetric mapping supported currently if (isMemoryBlockAccesible(mem, s2mmInterface) and isMemoryBlockAccesible(mem, mm2sInterface)) - return true; + return; // Try mapping via FPGA-card (VFIO) - if (not card->mapMemoryBlock(mem)) { - logger->error("Memory not accessible by DMA"); - return false; - } + if (not card->mapMemoryBlock(mem)) + throw RuntimeError("Memory not accessible by DMA"); // Sanity-check if mapping worked, this shouldn't be neccessary if (not isMemoryBlockAccesible(mem, s2mmInterface) or - not isMemoryBlockAccesible(mem, mm2sInterface)) { - logger->error("Mapping memory via card didn't work, but reported success?!"); - return false; - } - - return true; + not isMemoryBlockAccesible(mem, mm2sInterface)) + throw RuntimeError("Mapping memory via card didn't work, but reported success?!"); } bool diff --git a/fpga/tests/unit/dma.cpp b/fpga/tests/unit/dma.cpp index 7145b8305..47b9f3530 100644 --- a/fpga/tests/unit/dma.cpp +++ b/fpga/tests/unit/dma.cpp @@ -82,10 +82,8 @@ Test(fpga, dma, .description = "DMA") auto dst = HostRam::getAllocator().allocate(len); #endif // Make sure memory is accessible for DMA - cr_assert(dma->makeAccesibleFromVA(src.getMemoryBlock()), - "Source memory not accessible for DMA"); - cr_assert(dma->makeAccesibleFromVA(dst.getMemoryBlock()), - "Destination memory not accessible for DMA"); + dma->makeAccesibleFromVA(src.getMemoryBlock()); + dma->makeAccesibleFromVA(dst.getMemoryBlock()); // Get new random data const size_t lenRandom = utils::readRandom(&src, len); diff --git a/fpga/tests/unit/gpu.cpp b/fpga/tests/unit/gpu.cpp index 676fb4b68..4ee247879 100644 --- a/fpga/tests/unit/gpu.cpp +++ b/fpga/tests/unit/gpu.cpp @@ -119,10 +119,9 @@ Test(fpga, gpu_dma, .description = "GPU DMA tests") if (dma != nullptr and dma->connectLoopback()) { memcpyFuncs.push_back({ "DMA memcpy", [&]() { - if (not dma->makeAccesibleFromVA(src.getMemoryBlock()) or - not dma->makeAccesibleFromVA(dst.getMemoryBlock())) { - return; - } + dma->makeAccesibleFromVA(src.getMemoryBlock()); + dma->makeAccesibleFromVA(dst.getMemoryBlock())); + dma->memcpy(src.getMemoryBlock(), dst.getMemoryBlock(), len); }}); }