diff --git a/common/include/villas/graph/directed.hpp b/common/include/villas/graph/directed.hpp index 87f58ec93..326f1098a 100644 --- a/common/include/villas/graph/directed.hpp +++ b/common/include/villas/graph/directed.hpp @@ -57,7 +57,7 @@ public: std::shared_ptr getVertex(VertexIdentifier vertexId) const { - if(vertexId >= lastVertexId) + if (vertexId >= lastVertexId) throw std::invalid_argument("vertex doesn't exist"); // cannot use [] operator, because creates non-existing elements @@ -68,11 +68,11 @@ public: template VertexIdentifier findVertex(UnaryPredicate p) { - for(auto& v : vertices) { + for (auto& v : vertices) { auto& vertexId = v.first; auto& vertex = v.second; - if(p(vertex)) { + if (p(vertex)) { return vertexId; } } @@ -82,7 +82,7 @@ public: std::shared_ptr getEdge(EdgeIdentifier edgeId) const { - if(edgeId >= lastEdgeId) + if (edgeId >= lastEdgeId) throw std::invalid_argument("edge doesn't exist"); // cannot use [] operator, because creates non-existing elements @@ -155,13 +155,13 @@ public: { // delete every edge that start or ends at this vertex auto it = edges.begin(); - while(it != edges.end()) { + while (it != edges.end()) { auto& edgeId = it->first; auto& edge = it->second; bool removeEdge = false; - if(edge->to == vertexId) { + if (edge->to == vertexId) { logger->debug("Remove edge {} from vertex {}'s edge list", edgeId, edge->from); @@ -171,7 +171,7 @@ public: startVertex->edges.remove(edge->id); } - if((edge->from == vertexId) or removeEdge) { + if ((edge->from == vertexId) or removeEdge) { logger->debug("Remove edge {}", edgeId); // remove edge from global edge list it = edges.erase(it); @@ -200,26 +200,26 @@ public: Path& path, check_path_fn pathCheckFunc = checkPath) { - if(fromVertexId == toVertexId) { + if (fromVertexId == toVertexId) { // arrived at the destination return true; } else { auto fromVertex = getVertex(fromVertexId); - for(auto& edgeId : fromVertex->edges) { + for (auto& edgeId : fromVertex->edges) { auto edgeOfFromVertex = getEdge(edgeId); // loop detection bool loop = false; - for(auto& edgeIdInPath : path) { + for (auto& edgeIdInPath : path) { auto edgeInPath = getEdge(edgeIdInPath); - if(edgeInPath->from == edgeOfFromVertex->to) { + if (edgeInPath->from == edgeOfFromVertex->to) { loop = true; break; } } - if(loop) { + if (loop) { logger->debug("Loop detected via edge {}", edgeId); continue; } @@ -228,7 +228,7 @@ public: path.push_back(edgeId); // recursive, depth-first search - if(getPath(edgeOfFromVertex->to, toVertexId, path, pathCheckFunc) and + if (getPath(edgeOfFromVertex->to, toVertexId, path, pathCheckFunc) and pathCheckFunc(path)) { // path found, we're done return true; @@ -245,12 +245,12 @@ public: void dump(const std::string& fileName = "") { logger->info("Vertices:"); - for(auto& v : vertices) { + for (auto& v : vertices) { auto& vertex = v.second; // format connected vertices into a list std::stringstream ssEdges; - for(auto& edge : vertex->edges) { + for (auto& edge : vertex->edges) { ssEdges << getEdge(edge)->to << " "; } @@ -258,16 +258,16 @@ public: } std::fstream s(fileName, s.out | s.trunc); - if(s.is_open()) { + if (s.is_open()) { s << "digraph memgraph {" << std::endl; } logger->info("Edges:"); - for(auto& e : edges) { + for (auto& e : edges) { auto& edge = e.second; logger->info(" {}: {} -> {}", *edge, edge->from, edge->to); - if(s.is_open()) { + if (s.is_open()) { auto from = getVertex(edge->from); auto to = getVertex(edge->to); @@ -277,7 +277,7 @@ public: } } - if(s.is_open()) { + if (s.is_open()) { s << "}" << std::endl; s.close(); } diff --git a/common/include/villas/memory.hpp b/common/include/villas/memory.hpp index 465a9aa87..7bdd0d9a0 100644 --- a/common/include/villas/memory.hpp +++ b/common/include/villas/memory.hpp @@ -107,7 +107,7 @@ public: const MemoryBlock& getMemoryBlock() const - { if(not memoryBlock) throw std::bad_alloc(); else return *memoryBlock; } + { if (not memoryBlock) throw std::bad_alloc(); else return *memoryBlock; } private: /// cached memory translation for fast access @@ -159,7 +159,7 @@ public: MemoryAccessor allocate(size_t num) { - if(num == 0) { + if (num == 0) { // doesn't make sense to allocate an empty block logger->error("Trying to allocate empty memory"); throw std::bad_alloc(); @@ -173,10 +173,10 @@ public: // speed up testing. MemoryAccessor byteAccessor(*mem); size_t idx = 0; - for(int i = 0; idx < mem->getSize(); i++, idx = (1 << i)) { + for (int i = 0; idx < mem->getSize(); i++, idx = (1 << i)) { auto val = static_cast(i); byteAccessor[idx] = val; - if(byteAccessor[idx] != val) { + if (byteAccessor[idx] != val) { logger->error("Cannot access allocated memory"); throw std::bad_alloc(); } diff --git a/common/include/villas/utils.hpp b/common/include/villas/utils.hpp index 45d320c6d..19240d132 100644 --- a/common/include/villas/utils.hpp +++ b/common/include/villas/utils.hpp @@ -77,7 +77,7 @@ auto &_y = y; \ x = _y; \ y = _x; \ -} while(0) +} while (0) /** Round-up integer division */ #define CEIL(x, y) (((x) + (y) - 1) / (y)) diff --git a/common/lib/base64.cpp b/common/lib/base64.cpp index 77a960031..b96c3fed4 100644 --- a/common/lib/base64.cpp +++ b/common/lib/base64.cpp @@ -81,8 +81,8 @@ std::vector decode(const std::string& input) std::size_t padding{}; if (input.length()) { - if(input[input.length() - 1] == kPadCharacter) padding++; - if(input[input.length() - 2] == kPadCharacter) padding++; + if (input[input.length() - 1] == kPadCharacter) padding++; + if (input[input.length() - 2] == kPadCharacter) padding++; } std::vector decoded; diff --git a/common/lib/kernel/pci.cpp b/common/lib/kernel/pci.cpp index 7e56a2f10..3f074dc7f 100644 --- a/common/lib/kernel/pci.cpp +++ b/common/lib/kernel/pci.cpp @@ -291,7 +291,7 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions) for (int i = 0; i < 3; i++) { char* end; tokens[i] = strtoull(s, &end, 16); - if(s == end) { + if (s == end) { printf("Error parsing line %d of %s\n", region + 1, sysfs); tokens[0] = tokens[1] = 0; /* Mark invalid */ break; diff --git a/common/lib/kernel/vfio.cpp b/common/lib/kernel/vfio.cpp index 7174ae25b..b5649d771 100644 --- a/common/lib/kernel/vfio.cpp +++ b/common/lib/kernel/vfio.cpp @@ -121,8 +121,8 @@ VfioContainer::VfioContainer() hasIommu = false; - if(not (extensions & (1 << VFIO_NOIOMMU_IOMMU))) { - if(not (extensions & (1 << VFIO_TYPE1_IOMMU))) { + if (not (extensions & (1 << VFIO_NOIOMMU_IOMMU))) { + if (not (extensions & (1 << VFIO_TYPE1_IOMMU))) { logger->error("No supported IOMMU extension found"); throw std::exception(); } else { @@ -170,14 +170,14 @@ VfioContainer::dump() logger->info("Version: {}", version); logger->info("Extensions: 0x{:x}", extensions); - for(auto& group : groups) { + for (auto& group : groups) { logger->info("VFIO Group {}, viable={}, container={}", group->index, (group->status.flags & VFIO_GROUP_FLAGS_VIABLE) > 0, (group->status.flags & VFIO_GROUP_FLAGS_CONTAINER_SET) > 0 ); - for(auto& device : group->devices) { + for (auto& device : group->devices) { logger->info("Device {}: regions={}, irqs={}, flags={}", device->name, device->info.num_regions, @@ -319,7 +319,7 @@ VfioContainer::attachDevice(const pci_device* pdev) int index = isIommuEnabled() ? pci_get_iommu_group(pdev) : 0; if (index < 0) { ret = kernel::get_cmdline_param("intel_iommu", iommu_state, sizeof(iommu_state)); - if(ret != 0 || strcmp("on", iommu_state) != 0) + if (ret != 0 || strcmp("on", iommu_state) != 0) logger->warn("Kernel booted without command line parameter " "'intel_iommu' set to 'on'. Please check documentation " "(https://villas.fein-aachen.org/doc/fpga-setup.html) " @@ -339,7 +339,7 @@ VfioContainer::attachDevice(const pci_device* pdev) device.pci_device = pdev; /* Check if this is really a vfio-pci device */ - if(not device.isVfioPciDevice()) { + if (not device.isVfioPciDevice()) { logger->error("Device is not a vfio-pci device"); throw std::exception(); } @@ -433,7 +433,7 @@ VfioContainer::getOrAttachGroup(int index) /* Search if group with index already exists */ for (auto& group : groups) { - if(group->index == index) { + if (group->index == index) { return *group; } } @@ -460,7 +460,7 @@ VfioDevice::~VfioDevice() logger->debug("Clean up device {} with fd {}", this->name, this->fd); - for(auto& region : regions) { + for (auto& region : regions) { regionUnmap(region.index); } @@ -531,7 +531,7 @@ VfioDevice::regionGetSize(size_t index) { Logger logger = logging.get("kernel:vfio"); - if(index >= regions.size()) { + if (index >= regions.size()) { logger->error("Index out of range: {} >= {}", index, regions.size()); throw std::out_of_range("Index out of range"); } @@ -619,7 +619,7 @@ VfioDevice::pciHotReset() delete[] reset_buf; - if(not success and not group.container->isIommuEnabled()) { + if (not success and not group.container->isIommuEnabled()) { logger->info("PCI hot reset failed, but this is expected without IOMMU"); return true; } @@ -632,7 +632,7 @@ int VfioDevice::pciMsiInit(int efds[]) { /* Check if this is really a vfio-pci device */ - if(not isVfioPciDevice()) + if (not isVfioPciDevice()) return -1; const size_t irqCount = irqs[VFIO_PCI_MSI_IRQ_INDEX].count; @@ -641,7 +641,7 @@ VfioDevice::pciMsiInit(int efds[]) auto *irqSetBuf = new char[irqSetSize]; auto *irqSet = reinterpret_cast(irqSetBuf); - if(irqSet == nullptr) + if (irqSet == nullptr) return -1; irqSet->argsz = irqSetSize; @@ -661,7 +661,7 @@ VfioDevice::pciMsiInit(int efds[]) memcpy(irqSet->data, efds, sizeof(int) * irqCount); - if(ioctl(fd, VFIO_DEVICE_SET_IRQS, irqSet) != 0) { + if (ioctl(fd, VFIO_DEVICE_SET_IRQS, irqSet) != 0) { delete[] irqSetBuf; return -1; } @@ -676,7 +676,7 @@ int VfioDevice::pciMsiDeinit(int efds[]) { /* Check if this is really a vfio-pci device */ - if(not isVfioPciDevice()) + if (not isVfioPciDevice()) return -1; const size_t irqCount = irqs[VFIO_PCI_MSI_IRQ_INDEX].count; @@ -685,7 +685,7 @@ VfioDevice::pciMsiDeinit(int efds[]) auto *irqSetBuf = new char[irqSetSize]; auto *irqSet = reinterpret_cast(irqSetBuf); - if(irqSet == nullptr) + if (irqSet == nullptr) return -1; irqSet->argsz = irqSetSize; @@ -770,7 +770,7 @@ VfioGroup::~VfioGroup() /* Release memory and close fds */ devices.clear(); - if(fd < 0) { + if (fd < 0) { logger->debug("Destructing group that has not been attached"); } else { int ret = ioctl(fd, VFIO_GROUP_UNSET_CONTAINER); diff --git a/common/lib/memory.cpp b/common/lib/memory.cpp index 6adc066d2..93208221c 100644 --- a/common/lib/memory.cpp +++ b/common/lib/memory.cpp @@ -47,7 +47,7 @@ HostRam::HostRamAllocator::allocateBlock(size_t size) const int mmap_protection = PROT_READ | PROT_WRITE; const void* addr = mmap(nullptr, size, mmap_protection, mmap_flags, 0, 0); - if(addr == nullptr) { + if (addr == nullptr) { throw std::bad_alloc(); } @@ -79,7 +79,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId allocationCount(0) { /* Make sure to start at aligned offset, reduce size in case we need padding */ - if(const size_t paddingBytes = getAlignmentPadding(internalOffset)) { + if (const size_t paddingBytes = getAlignmentPadding(internalOffset)) { assert(paddingBytes < memorySize); internalOffset += paddingBytes; @@ -94,7 +94,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId removeMemoryBlock(*mem); allocationCount--; - if(allocationCount == 0) { + if (allocationCount == 0) { logger->debug("All allocations are deallocated now, freeing memory"); /* All allocations have been deallocated, free all memory */ @@ -111,7 +111,7 @@ LinearAllocator::getName() const { std::stringstream name; name << "LinearAlloc" << getAddrSpaceId(); - if(internalOffset != 0) { + if (internalOffset != 0) { name << "@0x" << std::hex << internalOffset; } @@ -122,7 +122,7 @@ LinearAllocator::getName() const std::unique_ptr LinearAllocator::allocateBlock(size_t size) { - if(size > getAvailableMemory()) { + if (size > getAvailableMemory()) { throw std::bad_alloc(); } @@ -133,7 +133,7 @@ LinearAllocator::allocateBlock(size_t size) nextFreeAddress += size; /* Make sure it is aligned */ - if(const size_t paddingBytes = getAlignmentPadding(nextFreeAddress)) { + if (const size_t paddingBytes = getAlignmentPadding(nextFreeAddress)) { nextFreeAddress += paddingBytes; /* If next free address is outside this block due to padding, cap it */ @@ -174,7 +174,7 @@ HostRam::HostRamAllocator::HostRamAllocator() : BaseAllocator(MemoryManager::get().getProcessAddressSpace()) { free = [&](MemoryBlock* mem) { - if(::munmap(reinterpret_cast(mem->getOffset()), mem->getSize()) != 0) { + if (::munmap(reinterpret_cast(mem->getOffset()), mem->getSize()) != 0) { logger->warn("munmap() failed for {:#x} of size {:#x}", mem->getOffset(), mem->getSize()); } @@ -194,7 +194,7 @@ HostDmaRam::HostDmaRamAllocator::HostDmaRamAllocator(int num) : auto& mm = MemoryManager::get(); logger = logging.get(getName()); - if(getSize() == 0) { + if (getSize() == 0) { logger->error("Zero-sized DMA buffer not supported, is the kernel module loaded?"); throw std::bad_alloc(); } @@ -206,11 +206,11 @@ HostDmaRam::HostDmaRamAllocator::HostDmaRamAllocator(int num) : const auto bufPath = std::string("/dev/") + getUdmaBufName(num); const int bufFd = open(bufPath.c_str(), O_RDWR | O_SYNC); - if(bufFd != -1) { + if (bufFd != -1) { void* buf = mmap(nullptr, getSize(), PROT_READ|PROT_WRITE, MAP_SHARED, bufFd, 0); close(bufFd); - if(buf != MAP_FAILED) { + if (buf != MAP_FAILED) { mm.createMapping(reinterpret_cast(buf), 0, getSize(), getName() + "-VA", mm.getProcessAddressSpace(), getAddrSpaceId()); @@ -240,7 +240,7 @@ HostDmaRam::HostDmaRamAllocator::~HostDmaRamAllocator() logger->debug("Unmapping {}", getName()); /* Try to unmap it */ - if(::munmap(baseVirt, getSize()) != 0) { + if (::munmap(baseVirt, getSize()) != 0) { logger->warn("munmap() failed for {:p} of size {:#x}", baseVirt, getSize()); } @@ -267,9 +267,9 @@ size_t HostDmaRam::getUdmaBufBufSize(int num) { std::fstream s(getUdmaBufBasePath(num) + "size", s.in); - if(s.is_open()) { + if (s.is_open()) { std::string line; - if(std::getline(s, line)) { + if (std::getline(s, line)) { return std::strtoul(line.c_str(), nullptr, 10); } } @@ -281,9 +281,9 @@ uintptr_t HostDmaRam::getUdmaBufPhysAddr(int num) { std::fstream s(getUdmaBufBasePath(num) + "phys_addr", s.in); - if(s.is_open()) { + if (s.is_open()) { std::string line; - if(std::getline(s, line)) { + if (std::getline(s, line)) { return std::strtoul(line.c_str(), nullptr, 16); } } @@ -294,7 +294,7 @@ HostDmaRam::getUdmaBufPhysAddr(int num) HostDmaRam::HostDmaRamAllocator&HostDmaRam::getAllocator(int num) { auto& allocator = allocators[num]; - if(not allocator) { + if (not allocator) { allocator = std::make_unique(num); } diff --git a/common/lib/memory_manager.cpp b/common/lib/memory_manager.cpp index 887c4c92e..316abe07b 100644 --- a/common/lib/memory_manager.cpp +++ b/common/lib/memory_manager.cpp @@ -37,7 +37,7 @@ MemoryManager::instance = nullptr; MemoryManager& MemoryManager::get() { - if(instance == nullptr) { + if (instance == nullptr) { instance = new MemoryManager; } @@ -106,7 +106,7 @@ MemoryManager::findPath(MemoryManager::AddressSpaceId fromAddrSpaceId, /* Find a path through the memory graph */ MemoryGraph::Path pathGraph; - if(not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, pathGraph, pathCheckFunc)) { + if (not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, pathGraph, pathCheckFunc)) { logger->debug("No translation found from ({}) to ({})", *fromAddrSpace, *toAddrSpace); @@ -114,7 +114,7 @@ MemoryManager::findPath(MemoryManager::AddressSpaceId fromAddrSpaceId, throw std::out_of_range("no translation found"); } - for(auto& mappingId : pathGraph) { + for (auto& mappingId : pathGraph) { auto mapping = memoryGraph.getEdge(mappingId); path.push_back(mapping->getVertexTo()); } @@ -128,7 +128,7 @@ MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId, { /* Find a path through the memory graph */ MemoryGraph::Path path; - if(not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, path, pathCheckFunc)) { + if (not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, path, pathCheckFunc)) { auto fromAddrSpace = memoryGraph.getVertex(fromAddrSpaceId); auto toAddrSpace = memoryGraph.getVertex(toAddrSpaceId); @@ -142,7 +142,7 @@ MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId, MemoryTranslation translation(0, 0, SIZE_MAX); /* Iterate through path and merge all mappings into a single translation */ - for(auto& mappingId : path) { + for (auto& mappingId : path) { auto mapping = memoryGraph.getEdge(mappingId); translation += getTranslationFromMapping(*mapping); } @@ -159,7 +159,7 @@ MemoryManager::pathCheck(const MemoryGraph::Path& path) /* Try to add all mappings together to a common translation. If this fails * there is a non-overlapping window. */ - for(auto& mappingId : path) { + for (auto& mappingId : path) { auto mapping = memoryGraph.getEdge(mappingId); try { translation += getTranslationFromMapping(*mapping); @@ -237,7 +237,7 @@ MemoryTranslation::operator+=(const MemoryTranslation& other) /* The source stays the same and can only increase with merged translations */ //this->src = this->src; - if(otherSrcIsSmaller) { + if (otherSrcIsSmaller) { /* Other mapping starts at lower addresses, so we actually arrive at * higher addresses */