diff --git a/CODEOWNERS b/CODEOWNERS index ef7dc9ef1..2dec02cc1 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -35,5 +35,5 @@ fpga @n-eiling # VFIO related files /common/lib/kernel/pci.cpp @n-eiling /common/lib/kernel/vfi_*.cpp @n-eiling -/common/include/villas/kernel/pci.hpp @n-eiling +/common/include/villas/kernel/devices/* @n-eiling /common/include/villas/kernel/vfio_*.hpp @n-eiling diff --git a/common/include/villas/graph/directed.hpp b/common/include/villas/graph/directed.hpp index ce19ef0db..9b4ea8328 100644 --- a/common/include/villas/graph/directed.hpp +++ b/common/include/villas/graph/directed.hpp @@ -31,7 +31,7 @@ public: using Path = std::list; DirectedGraph(const std::string &name = "DirectedGraph") - : lastVertexId(0), lastEdgeId(0), logger(logging.get(name)) {} + : lastVertexId(0), lastEdgeId(0), logger(Log::get(name)) {} std::shared_ptr getVertex(VertexIdentifier vertexId) const { // Cannot use [] operator, because creates non-existing elements diff --git a/common/include/villas/kernel/pci.hpp b/common/include/villas/kernel/devices/pci_device.hpp similarity index 78% rename from common/include/villas/kernel/pci.hpp rename to common/include/villas/kernel/devices/pci_device.hpp index 2002ba7a2..65794644b 100644 --- a/common/include/villas/kernel/pci.hpp +++ b/common/include/villas/kernel/devices/pci_device.hpp @@ -17,7 +17,7 @@ namespace villas { namespace kernel { -namespace pci { +namespace devices { #define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) #define PCI_FUNC(devfn) ((devfn) & 0x07) @@ -58,15 +58,15 @@ struct Region { unsigned long long flags; }; -class Device { +class PciDevice { public: - Device(Id i, Slot s) : id(i), slot(s), log(logging.get("kernel:pci")) {} + PciDevice(Id i, Slot s) : id(i), slot(s), log(Log::get("kernel:pci")) {} - Device(Id i) : id(i), log(logging.get("kernel:pci")) {} + PciDevice(Id i) : id(i), log(Log::get("kernel:pci")) {} - Device(Slot s) : slot(s), log(logging.get("kernel:pci")) {} + PciDevice(Slot s) : slot(s), log(Log::get("kernel:pci")) {} - bool operator==(const Device &other); + bool operator==(const PciDevice &other); // Get currently loaded driver for device std::string getDriver() const; @@ -106,25 +106,25 @@ protected: std::ios_base::out) const; }; -class DeviceList : public std::list> { +class PciDeviceList : public std::list> { private: // Initialize Linux PCI handle. // // This search for all available PCI devices under /sys/bus/pci - DeviceList(); - DeviceList &operator=(const DeviceList &); - static DeviceList *instance; + PciDeviceList(); + PciDeviceList &operator=(const PciDeviceList &); + static PciDeviceList *instance; public: - static DeviceList *getInstance(); + static PciDeviceList *getInstance(); - DeviceList::value_type lookupDevice(const Slot &s); + PciDeviceList::value_type lookupDevice(const Slot &s); - DeviceList::value_type lookupDevice(const Id &i); + PciDeviceList::value_type lookupDevice(const Id &i); - DeviceList::value_type lookupDevice(const Device &f); + PciDeviceList::value_type lookupDevice(const PciDevice &f); }; -} // namespace pci +} // namespace devices } // namespace kernel } // namespace villas diff --git a/common/include/villas/kernel/vfio_container.hpp b/common/include/villas/kernel/vfio_container.hpp index 08c747dd6..2165092da 100644 --- a/common/include/villas/kernel/vfio_container.hpp +++ b/common/include/villas/kernel/vfio_container.hpp @@ -35,8 +35,7 @@ static constexpr size_t EXTENSION_SIZE = VFIO_NOIOMMU_IOMMU + 1; class Container { public: - Container(std::vector required_modules = {"vfio", "vfio_pci", - "vfio_iommu_type1"}); + Container(std::vector required_modules = {"vfio"}); // No copying allowed because we manage the vfio state in constructor and destructors Container(Container const &) = delete; @@ -47,9 +46,10 @@ public: void dump(); void attachGroup(std::shared_ptr group); + std::shared_ptr getOrAttachGroup(int index); std::shared_ptr attachDevice(const std::string &name, int groupIndex); - std::shared_ptr attachDevice(pci::Device &pdev); + std::shared_ptr attachDevice(devices::PciDevice &pdev); // Map VM to an IOVA, which is accessible by devices in the container // @@ -65,8 +65,6 @@ public: bool isIommuEnabled() const { return this->hasIommu; } private: - std::shared_ptr getOrAttachGroup(int index); - int fd; int version; diff --git a/common/include/villas/kernel/vfio_device.hpp b/common/include/villas/kernel/vfio_device.hpp index 9f8c51a7c..ca49c2e1f 100644 --- a/common/include/villas/kernel/vfio_device.hpp +++ b/common/include/villas/kernel/vfio_device.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include namespace villas { @@ -29,7 +29,7 @@ namespace vfio { class Device { public: Device(const std::string &name, int groupFileDescriptor, - const kernel::pci::Device *pci_device = nullptr); + const kernel::devices::PciDevice *pci_device = nullptr); ~Device(); // No copying allowed because we manage the vfio state in constructor and destructors @@ -68,6 +68,8 @@ public: void setAttachedToGroup() { this->attachedToGroup = true; } + int getNumberIrqs() const { return this->info.num_irqs; } + private: // Name of the device as listed under // /sys/kernel/iommu_groups/[vfio_group::index]/devices/ @@ -89,7 +91,7 @@ private: std::vector mappings; // libpci handle of the device - const kernel::pci::Device *pci_device; + const kernel::devices::PciDevice *pci_device; Logger log; }; diff --git a/common/include/villas/kernel/vfio_group.hpp b/common/include/villas/kernel/vfio_group.hpp index 7c4fca580..5f990c46c 100644 --- a/common/include/villas/kernel/vfio_group.hpp +++ b/common/include/villas/kernel/vfio_group.hpp @@ -48,7 +48,7 @@ public: std::shared_ptr attachDevice(std::shared_ptr device); std::shared_ptr attachDevice(const std::string &name, - const kernel::pci::Device *pci_device = nullptr); + const kernel::devices::PciDevice *pci_device = nullptr); bool checkStatus(); void dump(); diff --git a/common/include/villas/log.hpp b/common/include/villas/log.hpp index 0cc62775e..459939499 100644 --- a/common/include/villas/log.hpp +++ b/common/include/villas/log.hpp @@ -20,12 +20,7 @@ namespace villas { // Forward declarations -class Log; - using Logger = std::shared_ptr; - -extern Log logging; - class Log { public: @@ -64,7 +59,19 @@ public: void parse(json_t *json); - Logger get(const std::string &name); + static Log &getInstance() { + // This will "leak" memory. Because we don't have a complex destructor it's okay + // that this will be cleaned up implicitly on program exit. + static auto log = new Log(); + return *log; + }; + + Logger getNewLogger(const std::string &name); + + static Logger get(const std::string &name) { + static auto &log = getInstance(); + return log.getNewLogger(name); + } void setFormatter(const std::string &pattern, const std::string &pfx = ""); void setLevel(Level lvl); diff --git a/common/include/villas/memory.hpp b/common/include/villas/memory.hpp index 526ac4ec5..a98556d4d 100644 --- a/common/include/villas/memory.hpp +++ b/common/include/villas/memory.hpp @@ -116,7 +116,7 @@ public: // CRTP derivedAlloc = static_cast(this); std::string loggerName = fmt::format("memory:", derivedAlloc->getName()); - logger = logging.get(loggerName); + logger = Log::get(loggerName); // Default deallocation callback free = [&](MemoryBlock *mem) { @@ -249,10 +249,12 @@ public: allocateBlock(size_t size); }; - static HostRamAllocator &getAllocator() { return allocator; } - -private: - static HostRamAllocator allocator; + static HostRamAllocator &getAllocator() { + // This will "leak" memory. Because we don't have a complex destructor it's okay + // that this will be cleaned up implicitly on program exit. + static auto allocator = new HostRamAllocator(); + return *allocator; + } }; class HostDmaRam { diff --git a/common/include/villas/memory_manager.hpp b/common/include/villas/memory_manager.hpp index cfed69b84..60f61c96c 100644 --- a/common/include/villas/memory_manager.hpp +++ b/common/include/villas/memory_manager.hpp @@ -65,7 +65,7 @@ class MemoryManager { private: // This is a singleton, so private constructor ... MemoryManager() - : memoryGraph("memory:graph"), logger(logging.get("memory:manager")) { + : memoryGraph("memory:graph"), logger(Log::get("memory:manager")) { pathCheckFunc = [&](const MemoryGraph::Path &path) { return this->pathCheck(path); }; diff --git a/common/include/villas/plugin.hpp b/common/include/villas/plugin.hpp index f52bb594e..41a0f18d5 100644 --- a/common/include/villas/plugin.hpp +++ b/common/include/villas/plugin.hpp @@ -41,7 +41,7 @@ protected: List registries; public: - Logger getLogger() { return logging.get("plugin:registry"); } + Logger getLogger() { return Log::get("plugin:registry"); } void add(Plugin *p) { plugins.push_back(p); } @@ -126,7 +126,7 @@ public: virtual Logger getLogger() { if (!logger) { auto name = fmt::format("{}:{}", getType(), getName()); - logger = logging.get(name); + logger = Log::get(name); } return logger; diff --git a/common/include/villas/utils.hpp b/common/include/villas/utils.hpp index 6ca28736d..a65fb6cba 100644 --- a/common/include/villas/utils.hpp +++ b/common/include/villas/utils.hpp @@ -52,7 +52,7 @@ #ifdef ALIGN #undef ALIGN #endif -#define ALIGN(x, a) ALIGN_MASK(x, (uintptr_t)(a)-1) +#define ALIGN(x, a) ALIGN_MASK(x, (uintptr_t)(a) - 1) #define ALIGN_MASK(x, m) (((uintptr_t)(x) + (m)) & ~(m)) #define IS_ALIGNED(x, a) (ALIGN(x, a) == (uintptr_t)x) @@ -64,13 +64,13 @@ } while (0) // Round-up integer division -#define CEIL(x, y) (((x) + (y)-1) / (y)) +#define CEIL(x, y) (((x) + (y) - 1) / (y)) // Get nearest up-rounded power of 2 -#define LOG2_CEIL(x) (1 << (villas::utils::log2i((x)-1) + 1)) +#define LOG2_CEIL(x) (1 << (villas::utils::log2i((x) - 1) + 1)) // Check if the number is a power of 2 -#define IS_POW2(x) (((x) != 0) && !((x) & ((x)-1))) +#define IS_POW2(x) (((x) != 0) && !((x) & ((x) - 1))) // Calculate the number of elements in an array. #define ARRAY_LEN(a) (sizeof(a) / sizeof(a)[0]) diff --git a/common/lib/CMakeLists.txt b/common/lib/CMakeLists.txt index 7927fc0f4..116d786e6 100644 --- a/common/lib/CMakeLists.txt +++ b/common/lib/CMakeLists.txt @@ -39,7 +39,7 @@ endif() if(CMAKE_SYSTEM_NAME STREQUAL Linux) target_sources(villas-common PRIVATE - kernel/pci.cpp + kernel/devices/pci_device.cpp kernel/vfio_device.cpp kernel/vfio_group.cpp kernel/vfio_container.cpp diff --git a/common/lib/kernel/pci.cpp b/common/lib/kernel/devices/pci_device.cpp similarity index 87% rename from common/lib/kernel/pci.cpp rename to common/lib/kernel/devices/pci_device.cpp index c999f77e2..ef8a8b5d0 100644 --- a/common/lib/kernel/pci.cpp +++ b/common/lib/kernel/devices/pci_device.cpp @@ -18,23 +18,23 @@ #include #include -#include +#include #include -using namespace villas::kernel::pci; +using namespace villas::kernel::devices; #define PCI_BASE_ADDRESS_N(n) (PCI_BASE_ADDRESS_0 + sizeof(uint32_t) * (n)) -DeviceList *DeviceList::instance = nullptr; +PciDeviceList *PciDeviceList::instance = nullptr; -DeviceList *DeviceList::getInstance() { +PciDeviceList *PciDeviceList::getInstance() { if (instance == nullptr) { - instance = new DeviceList(); + instance = new PciDeviceList(); } return instance; }; -DeviceList::DeviceList() { +PciDeviceList::PciDeviceList() { struct dirent *e; DIR *dp; FILE *f; @@ -82,27 +82,28 @@ DeviceList::DeviceList() { if (ret != 4) throw RuntimeError("Failed to parse PCI slot number: {}", e->d_name); - emplace_back(std::make_shared(id, slot)); + emplace_back(std::make_shared(id, slot)); } closedir(dp); } -DeviceList::value_type DeviceList::lookupDevice(const Slot &s) { - return *std::find_if(begin(), end(), [s](const DeviceList::value_type &d) { +PciDeviceList::value_type PciDeviceList::lookupDevice(const Slot &s) { + return *std::find_if(begin(), end(), [s](const PciDeviceList::value_type &d) { return d->slot == s; }); } -DeviceList::value_type DeviceList::lookupDevice(const Id &i) { - return *std::find_if(begin(), end(), [i](const DeviceList::value_type &d) { +PciDeviceList::value_type PciDeviceList::lookupDevice(const Id &i) { + return *std::find_if(begin(), end(), [i](const PciDeviceList::value_type &d) { return d->id == i; }); } -DeviceList::value_type DeviceList::lookupDevice(const Device &d) { - auto dev = std::find_if( - begin(), end(), [d](const DeviceList::value_type &e) { return *e == d; }); +PciDeviceList::value_type PciDeviceList::lookupDevice(const PciDevice &d) { + auto dev = + std::find_if(begin(), end(), + [d](const PciDeviceList::value_type &e) { return *e == d; }); return dev == end() ? value_type() : *dev; } @@ -247,11 +248,11 @@ bool Slot::operator==(const Slot &s) { return true; } -bool Device::operator==(const Device &f) { +bool PciDevice::operator==(const PciDevice &f) { return id == f.id && slot == f.slot; } -std::list Device::getRegions() const { +std::list PciDevice::getRegions() const { FILE *f; char sysfs[1024]; @@ -311,7 +312,7 @@ std::list Device::getRegions() const { return regions; } -std::string Device::getDriver() const { +std::string PciDevice::getDriver() const { int ret; char sysfs[1024], syml[1024]; memset(syml, 0, sizeof(syml)); @@ -331,7 +332,7 @@ std::string Device::getDriver() const { return basename(syml); } -bool Device::attachDriver(const std::string &driver) const { +bool PciDevice::attachDriver(const std::string &driver) const { FILE *f; char fn[1024]; @@ -363,7 +364,7 @@ bool Device::attachDriver(const std::string &driver) const { return true; } -uint32_t Device::readHostBar(unsigned barNum) const { +uint32_t PciDevice::readHostBar(unsigned barNum) const { auto file = openSysFs("resource", std::ios_base::in); std::string line; @@ -389,7 +390,7 @@ uint32_t Device::readHostBar(unsigned barNum) const { return start; } -void Device::rewriteBar(unsigned barNum) { +void PciDevice::rewriteBar(unsigned barNum) { auto hostBar = readHostBar(barNum); auto configBar = readBar(barNum); @@ -405,7 +406,7 @@ void Device::rewriteBar(unsigned barNum) { writeBar(hostBar, barNum); } -uint32_t Device::readBar(unsigned barNum) const { +uint32_t PciDevice::readBar(unsigned barNum) const { uint32_t addr; auto file = openSysFs("config", std::ios_base::in); @@ -415,14 +416,14 @@ uint32_t Device::readBar(unsigned barNum) const { return addr; } -void Device::writeBar(uint32_t addr, unsigned barNum) { +void PciDevice::writeBar(uint32_t addr, unsigned barNum) { auto file = openSysFs("config", std::ios_base::out); file.seekp(PCI_BASE_ADDRESS_N(barNum)); file.write(reinterpret_cast(&addr), sizeof(addr)); } -int Device::getIommuGroup() const { +int PciDevice::getIommuGroup() const { int ret; char *group; @@ -443,8 +444,8 @@ int Device::getIommuGroup() const { return atoi(group); } -std::fstream Device::openSysFs(const std::string &subPath, - std::ios_base::openmode mode) const { +std::fstream PciDevice::openSysFs(const std::string &subPath, + std::ios_base::openmode mode) const { std::fstream file; auto sysFsFilename = diff --git a/common/lib/kernel/kernel.cpp b/common/lib/kernel/kernel.cpp index 70100da1e..902b67130 100644 --- a/common/lib/kernel/kernel.cpp +++ b/common/lib/kernel/kernel.cpp @@ -119,7 +119,7 @@ int villas::kernel::setModuleParam(const char *module, const char *param, throw RuntimeError("Failed set parameter {} for kernel module {} to {}", module, param, value); - auto logger = logging.get("kernel"); + auto logger = Log::get("kernel"); logger->debug("Set parameter {} of kernel module {} to {}", module, param, value); @@ -134,7 +134,7 @@ int villas::kernel::loadModule(const char *module) { ret = isModuleLoaded(module); if (!ret) { - auto logger = logging.get("kernel"); + auto logger = Log::get("kernel"); logger->debug("Kernel module {} already loaded...", module); return 0; } @@ -193,7 +193,7 @@ int villas::kernel::getCmdlineParam(const char *param, char *buf, size_t len) { do { ret = sscanf(tok, "%127[^=]=%127s", key, value); if (ret >= 1) { - auto logger = logging.get("kernel"); + auto logger = Log::get("kernel"); if (ret >= 2) logger->debug("Found kernel param: {}={}", key, value); else @@ -220,7 +220,7 @@ int villas::kernel::getNrHugepages() { f = fopen(PROCFS_PATH "/sys/vm/nr_hugepages", "r"); if (!f) { - auto logger = logging.get("kernel"); + auto logger = Log::get("kernel"); logger->error("Failed to open {}: {}", PROCFS_PATH "/sys/vm/nr_hugepages", strerror(errno)); return -1; diff --git a/common/lib/kernel/rt.cpp b/common/lib/kernel/rt.cpp index 14887fde1..6f1ec22d8 100644 --- a/common/lib/kernel/rt.cpp +++ b/common/lib/kernel/rt.cpp @@ -26,7 +26,7 @@ namespace kernel { namespace rt { void init(int priority, int affinity) { - Logger logger = logging.get("kernel:rt"); + Logger logger = Log::get("kernel:rt"); logger->info("Initialize sub-system"); @@ -82,7 +82,7 @@ void setProcessAffinity(int affinity) { assert(affinity != 0); - Logger logger = logging.get("kernel:rt"); + Logger logger = Log::get("kernel:rt"); // Pin threads to CPUs by setting the affinity CpuSet cset_pin(affinity); @@ -101,7 +101,7 @@ void setThreadAffinity(pthread_t thread, int affinity) { assert(affinity != 0); - Logger logger = logging.get("kernel:rt"); + Logger logger = Log::get("kernel:rt"); CpuSet cset_pin(affinity); @@ -119,7 +119,7 @@ void setPriority(int priority) { struct sched_param param; param.sched_priority = priority; - Logger logger = logging.get("kernel:rt"); + Logger logger = Log::get("kernel:rt"); ret = sched_setscheduler(0, SCHED_FIFO, ¶m); if (ret) diff --git a/common/lib/kernel/vfio_container.cpp b/common/lib/kernel/vfio_container.cpp index 79a101aaf..76923aa08 100644 --- a/common/lib/kernel/vfio_container.cpp +++ b/common/lib/kernel/vfio_container.cpp @@ -68,7 +68,7 @@ static std::array VFIO_EXTENSION_STR = Container::Container(std::vector required_modules) : fd(-1), version(0), extensions(), iova_next(0), hasIommu(false), groups(), - log(logging.get("kernel:vfio:container")) { + log(Log::get("kernel:vfio:container")) { for (auto module : required_modules) { if (kernel::loadModule(module.c_str()) != 0) { throw RuntimeError("Kernel module '{}' required but could not be loaded. " @@ -187,7 +187,7 @@ std::shared_ptr Container::attachDevice(const std::string &name, return device; } -std::shared_ptr Container::attachDevice(pci::Device &pdev) { +std::shared_ptr Container::attachDevice(devices::PciDevice &pdev) { int ret; char name[32], iommu_state[4]; static constexpr const char *kernelDriver = "vfio-pci"; diff --git a/common/lib/kernel/vfio_device.cpp b/common/lib/kernel/vfio_device.cpp index 02da4c898..ff70f3cb7 100644 --- a/common/lib/kernel/vfio_device.cpp +++ b/common/lib/kernel/vfio_device.cpp @@ -53,10 +53,10 @@ static const char *vfio_pci_irq_names[] = { }; Device::Device(const std::string &name, int groupFileDescriptor, - const kernel::pci::Device *pci_device) + const kernel::devices::PciDevice *pci_device) : name(name), fd(-1), attachedToGroup(false), groupFd(groupFileDescriptor), info(), irqs(), regions(), mappings(), pci_device(pci_device), - log(logging.get("kernel:vfio:device")) { + log(Log::get("kernel:vfio:device")) { if (groupFileDescriptor < 0) throw RuntimeError("Invalid group file descriptor"); @@ -293,8 +293,8 @@ int Device::pciMsiInit(int efds[]) { } int Device::pciMsiDeinit(int efds[]) { - logging.get("Device")->debug("Deinitializing MSI interrupts for device {}", - name); + Log::get("Device")->debug("Deinitializing MSI interrupts for device {}", + name); // Check if this is really a vfio-pci device if (not isVfioPciDevice()) return -1; diff --git a/common/lib/kernel/vfio_group.cpp b/common/lib/kernel/vfio_group.cpp index aae4781e9..512460c20 100644 --- a/common/lib/kernel/vfio_group.cpp +++ b/common/lib/kernel/vfio_group.cpp @@ -38,7 +38,7 @@ using namespace villas::kernel::vfio; Group::Group(int index, bool iommuEnabled) : fd(-1), index(index), attachedToContainer(false), status(), devices(), - log(logging.get("kernel:vfio:group")) { + log(Log::get("kernel:vfio:group")) { // Open group fd std::stringstream groupPath; groupPath << VFIO_PATH << (iommuEnabled ? "" : "noiommu-") << index; @@ -68,7 +68,7 @@ std::shared_ptr Group::attachDevice(std::shared_ptr device) { std::shared_ptr Group::attachDevice(const std::string &name, - const kernel::pci::Device *pci_device) { + const kernel::devices::PciDevice *pci_device) { auto device = std::make_shared(name, fd, pci_device); return attachDevice(device); } diff --git a/common/lib/log.cpp b/common/lib/log.cpp index 708b5b83b..3320eb579 100644 --- a/common/lib/log.cpp +++ b/common/lib/log.cpp @@ -20,9 +20,6 @@ using namespace villas; -// The global log instance -Log villas::logging; - static std::map levelNames = { {spdlog::level::trace, "trc"}, {spdlog::level::debug, "dbg"}, {spdlog::level::info, "info"}, {spdlog::level::warn, "warn"}, @@ -69,7 +66,7 @@ int Log::getWidth() { return width; } -Logger Log::get(const std::string &name) { +Logger Log::getNewLogger(const std::string &name) { Logger logger = spdlog::get(name); if (not logger) { diff --git a/common/lib/memory.cpp b/common/lib/memory.cpp index bb5b23656..205d8c70f 100644 --- a/common/lib/memory.cpp +++ b/common/lib/memory.cpp @@ -143,8 +143,6 @@ LinearAllocator::allocateBlock(size_t size) { return mem; } -HostRam::HostRamAllocator HostRam::allocator; - HostRam::HostRamAllocator::HostRamAllocator() : BaseAllocator(MemoryManager::get().getProcessAddressSpace()) { free = [&](MemoryBlock *mem) { @@ -167,7 +165,7 @@ HostDmaRam::HostDmaRamAllocator::HostDmaRamAllocator(int num) getUdmaBufBufSize(num)), num(num) { auto &mm = MemoryManager::get(); - logger = logging.get(getName()); + logger = Log::get(getName()); if (getSize() == 0) { logger->error( diff --git a/common/lib/memory_manager.cpp b/common/lib/memory_manager.cpp index 9e2976121..61f641b95 100644 --- a/common/lib/memory_manager.cpp +++ b/common/lib/memory_manager.cpp @@ -164,7 +164,7 @@ MemoryTranslation::getForeignAddr(uintptr_t addrInLocalAddrSpace) const { MemoryTranslation & MemoryTranslation::operator+=(const MemoryTranslation &other) { - Logger logger = logging.get("MemoryTranslation"); + Logger logger = Log::get("MemoryTranslation"); // Set level to debug to enable debug output logger->set_level(spdlog::level::info); diff --git a/common/lib/table.cpp b/common/lib/table.cpp index dd4d6dcac..8c1b50002 100644 --- a/common/lib/table.cpp +++ b/common/lib/table.cpp @@ -57,8 +57,8 @@ int Table::resize(int w) { } void Table::header() { - if (width != logging.getWidth()) - resize(logging.getWidth()); + if (width != Log::getInstance().getWidth()) + resize(Log::getInstance().getWidth()); char *line1 = nullptr; char *line2 = nullptr; @@ -107,8 +107,8 @@ void Table::header() { } void Table::row(int count, ...) { - if (width != logging.getWidth()) { - resize(logging.getWidth()); + if (width != Log::getInstance().getWidth()) { + resize(Log::getInstance().getWidth()); header(); } diff --git a/common/lib/terminal.cpp b/common/lib/terminal.cpp index 4ab4ce244..cb6540262 100644 --- a/common/lib/terminal.cpp +++ b/common/lib/terminal.cpp @@ -23,7 +23,7 @@ Terminal::Terminal() { isTty = isatty(STDERR_FILENO); - Logger logger = logging.get("terminal"); + Logger logger = Log::get("terminal"); if (isTty) { struct sigaction sa_resize; @@ -57,7 +57,7 @@ void Terminal::resize(int, siginfo_t *, void *) { if (!current) current = new Terminal(); - Logger logger = logging.get("terminal"); + Logger logger = Log::get("terminal"); int ret; diff --git a/common/lib/tool.cpp b/common/lib/tool.cpp index adb21e553..c84bc1a45 100644 --- a/common/lib/tool.cpp +++ b/common/lib/tool.cpp @@ -33,7 +33,7 @@ Tool::Tool(int ac, char *av[], const std::string &nme, : argc(ac), argv(av), name(nme), handlerSignals(sigs) { current_tool = this; - logger = logging.get(name); + logger = Log::get(name); } int Tool::run() { diff --git a/common/lib/utils.cpp b/common/lib/utils.cpp index 87e148f8c..f495d8121 100644 --- a/common/lib/utils.cpp +++ b/common/lib/utils.cpp @@ -87,7 +87,7 @@ int signalsInit(void (*cb)(int signal, siginfo_t *sinfo, void *ctx), std::list cbSignals, std::list ignoreSignals) { int ret; - Logger logger = logging.get("signals"); + Logger logger = Log::get("signals"); logger->info("Initialize subsystem"); diff --git a/common/tests/unit/graph.cpp b/common/tests/unit/graph.cpp index 4c27c772e..2c7cf7408 100644 --- a/common/tests/unit/graph.cpp +++ b/common/tests/unit/graph.cpp @@ -18,7 +18,7 @@ using namespace villas; TestSuite(graph, .description = "Graph library"); Test(graph, basic, .description = "DirectedGraph") { - Logger logger = logging.get("test:graph:basic"); + Logger logger = Log::get("test:graph:basic"); villas::graph::DirectedGraph<> g("test:graph:basic"); logger->info("Testing basic graph construction and modification"); @@ -48,7 +48,7 @@ Test(graph, basic, .description = "DirectedGraph") { } Test(graph, path, .description = "Find path") { - Logger logger = logging.get("test:graph:path"); + Logger logger = Log::get("test:graph:path"); logger->info("Testing path finding algorithm"); using Graph = villas::graph::DirectedGraph<>; @@ -109,7 +109,7 @@ Test(graph, path, .description = "Find path") { } Test(graph, memory_manager, .description = "Global Memory Manager") { - Logger logger = logging.get("test:graph:mm"); + Logger logger = Log::get("test:graph:mm"); auto &mm = villas::MemoryManager::get(); logger->info("Create address spaces"); diff --git a/flake.lock b/flake.lock index 447a49cc0..53b45cc18 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1712666087, - "narHash": "sha256-WwjUkWsjlU8iUImbivlYxNyMB1L5YVqE8QotQdL9jWc=", + "lastModified": 1723320709, + "narHash": "sha256-DeKCsLQsS58D8TB/cTjXs2x8XMvsyv2JVxcF0Hu6pu8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a76c4553d7e741e17f289224eda135423de0491d", + "rev": "e1d92cda6fd1bcec60e4938ce92fcee619eea793", "type": "github" }, "original": { diff --git a/fpga/gpu/src/gpu.cpp b/fpga/gpu/src/gpu.cpp index 4c6b426f9..f80a9521e 100644 --- a/fpga/gpu/src/gpu.cpp +++ b/fpga/gpu/src/gpu.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include @@ -47,7 +47,7 @@ std::string villas::gpu::GpuAllocator::getName() const { } GpuFactory::GpuFactory() - : logger(villas::logging.get("gpu:factory")), + : logger(villas::Log::get("gpu:factory")), Plugin("cuda", "CUDA capable GPUs") {} // Required to be defined here for PIMPL to compile @@ -67,8 +67,8 @@ std::string Gpu::getName() const { cudaDeviceProp deviceProp; if (cudaGetDeviceProperties(&deviceProp, gpuId) != cudaSuccess) { // Logger not yet availabe - villas::logging.get("gpu")->error("Cannot retrieve properties for GPU {}", - gpuId); + villas::Log::get("gpu")->error("Cannot retrieve properties for GPU {}", + gpuId); throw std::exception(); } @@ -404,7 +404,7 @@ GpuAllocator::allocateBlock(size_t size) { } Gpu::Gpu(int gpuId) : pImpl{std::make_unique()}, gpuId(gpuId) { - logger = villas::logging.get(getName()); + logger = villas::Log::get(getName()); pImpl->gdr = gdr_open(); if (pImpl->gdr == nullptr) { diff --git a/fpga/include/villas/fpga/core.hpp b/fpga/include/villas/fpga/core.hpp index 3968b5841..089aaf8e7 100644 --- a/fpga/include/villas/fpga/core.hpp +++ b/fpga/include/villas/fpga/core.hpp @@ -107,6 +107,7 @@ protected: virtual std::list getMemoryBlocks() const { return {}; } public: + size_t getBaseaddr() const { return baseaddr; } const std::string &getInstanceName() const { return id.getName(); } // Operators @@ -201,6 +202,8 @@ protected: // AXI bus master interfaces to access memory somewhere std::map busMasterInterfaces; + + size_t baseaddr = 0; }; class CoreFactory : public plugin::Plugin { @@ -225,14 +228,12 @@ protected: IRQ, }; - Logger getLogger() { return villas::logging.get(getName()); } + Logger getLogger() { return villas::Log::get(getName()); } // Configure IP instance from JSON config virtual void parse(Core &, json_t *) {} - static Logger getStaticLogger() { - return villas::logging.get("core:factory"); - } + static Logger getStaticLogger() { return villas::Log::get("core:factory"); } private: virtual void configurePollingMode(Core &, PollingMode) {} diff --git a/fpga/include/villas/fpga/ips/i2c.hpp b/fpga/include/villas/fpga/ips/i2c.hpp index 800ea7ce8..3c3ce2cff 100644 --- a/fpga/include/villas/fpga/ips/i2c.hpp +++ b/fpga/include/villas/fpga/ips/i2c.hpp @@ -19,8 +19,7 @@ namespace fpga { namespace ip { #define I2C_SWTICH_ADDR 0x70 -#define I2C_SWITCH_CHANNEL_MAP \ - { 0x20, 0x80, 0x02, 0x08, 0x10, 0x40, 0x01, 0x04 } +#define I2C_SWITCH_CHANNEL_MAP {0x20, 0x80, 0x02, 0x08, 0x10, 0x40, 0x01, 0x04} #define I2C_IOEXT_ADDR 0x20 #define I2C_IOEXT_REG_DIR 0x03 #define I2C_IOEXT_REG_OUT 0x01 @@ -45,10 +44,9 @@ public: class Switch { public: - Switch(I2c *i2c, uint8_t address, - Logger logger = villas::logging.get("i2c")) + Switch(I2c *i2c, uint8_t address, Logger logger = villas::Log::get("i2c")) : i2c(i2c), address(address), channel(0), readOnce(false), switchLock(), - logger(logger){}; + logger(logger) {}; Switch(const Switch &other) = delete; Switch &operator=(const Switch &other) = delete; void setChannel(uint8_t channel); diff --git a/fpga/include/villas/fpga/pcie_card.hpp b/fpga/include/villas/fpga/pcie_card.hpp index 76fa6f5ff..aff1b23fb 100644 --- a/fpga/include/villas/fpga/pcie_card.hpp +++ b/fpga/include/villas/fpga/pcie_card.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include @@ -55,10 +55,10 @@ public: // TODO: make this private bool doReset; // Reset VILLASfpga during startup? int affinity; // Affinity for MSI interrupts - std::shared_ptr pdev; // PCI device handle + std::shared_ptr pdev; // PCI device handle protected: - Logger getLogger() const { return villas::logging.get(name); } + Logger getLogger() const { return villas::Log::get(name); } }; class PCIeCardFactory : public plugin::Plugin { @@ -71,7 +71,7 @@ public: static PCIeCard *make() { return new PCIeCard(); } static Logger getStaticLogger() { - return villas::logging.get("pcie:card:factory"); + return villas::Log::get("pcie:card:factory"); } virtual std::string getName() const { return "pcie"; } diff --git a/fpga/include/villas/fpga/utils.hpp b/fpga/include/villas/fpga/utils.hpp index 42f3afbb5..b078936fb 100644 --- a/fpga/include/villas/fpga/utils.hpp +++ b/fpga/include/villas/fpga/utils.hpp @@ -89,7 +89,7 @@ protected: BufferedSampleFormatter(const size_t bufSamples, const size_t bufSampleSize) : buf(bufSamples * bufSampleSize + 1), // Leave room for a final `\0' bufSamples(bufSamples), bufSampleSize(bufSampleSize), - currentBufLoc(0){}; + currentBufLoc(0) {}; BufferedSampleFormatter() = delete; BufferedSampleFormatter(const BufferedSampleFormatter &) = delete; virtual char *nextBufPos() { return &buf[(currentBufLoc++) * bufSampleSize]; } @@ -98,7 +98,7 @@ protected: class BufferedSampleFormatterShort : public BufferedSampleFormatter { public: BufferedSampleFormatterShort(size_t bufSizeInSamples) - : BufferedSampleFormatter(bufSizeInSamples, formatStringSize){}; + : BufferedSampleFormatter(bufSizeInSamples, formatStringSize) {}; virtual void format(float value) override { size_t chars; @@ -119,7 +119,7 @@ class BufferedSampleFormatterLong : public BufferedSampleFormatter { public: BufferedSampleFormatterLong(size_t bufSizeInSamples) : BufferedSampleFormatter(bufSizeInSamples, formatStringSize), - sampleCnt(0){}; + sampleCnt(0) {}; virtual void format(float value) override { if (std::snprintf(nextBufPos(), formatStringSize + 1, formatString, diff --git a/fpga/lib/core.cpp b/fpga/lib/core.cpp index d8ee767e8..0a1f8de1f 100644 --- a/fpga/lib/core.cpp +++ b/fpga/lib/core.cpp @@ -126,10 +126,20 @@ CoreFactory::configureIps(std::list orderedIps, json_t *json_ips, // Setup generic IP type properties ip->card = card; ip->id = id; - ip->logger = villas::logging.get(id.getName()); + ip->logger = villas::Log::get(id.getName()); json_t *json_ip = json_object_get(json_ips, id.getName().c_str()); + // parse ip baseadress + json_t *json_parameters = json_object_get(json_ip, "parameters"); + if (json_is_object(json_parameters)) { + json_int_t c_baseaddr = 0; + int baseaddress_found = + json_unpack(json_parameters, "{ s?: I }", "c_baseaddr", &c_baseaddr); + if (baseaddress_found == 0) + ip->baseaddr = c_baseaddr; + } + json_t *json_irqs = json_object_get(json_ip, "irqs"); if (json_is_object(json_irqs)) { logger->debug("Parse IRQs of {}", *ip); diff --git a/fpga/lib/dma.cpp b/fpga/lib/dma.cpp index 0afebfdc2..7ce10b2b5 100644 --- a/fpga/lib/dma.cpp +++ b/fpga/lib/dma.cpp @@ -21,8 +21,8 @@ using namespace villas; -static std::shared_ptr pciDevices; -static auto logger = villas::logging.get("villasfpga_dma"); +static std::shared_ptr pciDevices; +static auto logger = villas::Log::get("villasfpga_dma"); struct villasfpga_handle_t { std::shared_ptr card; @@ -40,7 +40,7 @@ villasfpga_handle villasfpga_init(const char *configFile) { bool dumpAuroraChannels = true; try { // Logging setup - logging.setLevel(spdlog::level::debug); + Log::getInstance().setLevel(spdlog::level::debug); fpga::setupColorHandling(); if (configFile == nullptr || configFile[0] == '\0') { diff --git a/fpga/lib/ips/dino.cpp b/fpga/lib/ips/dino.cpp index 6ab463a33..64e158af7 100644 --- a/fpga/lib/ips/dino.cpp +++ b/fpga/lib/ips/dino.cpp @@ -1,7 +1,7 @@ /* Driver for wrapper around standard Xilinx Aurora (xilinx.com:ip:aurora_8b10b) * - * Author: Steffen Vogel - * SPDX-FileCopyrightText: 2017 Institute for Automation of Complex Power Systems, RWTH Aachen University + * Author: Niklas Eiling + * SPDX-FileCopyrightText: 2023-2024 Niklas Eiling * SPDX-License-Identifier: Apache-2.0 */ @@ -141,23 +141,42 @@ void DinoAdc::setRegisterConfig(std::shared_ptr reg, double sampleRate) { constexpr double dinoClk = 25e6; // Dino is clocked with 25 Mhz constexpr size_t dinoRegisterTimer = 0; - constexpr size_t dinoRegisterScale = 1; - constexpr size_t dinoRegisterOffset = 2; + constexpr size_t dinoRegisterAdcScale = 1; + constexpr size_t dinoRegisterAdcOffset = 2; + constexpr size_t dinoRegisterDacExternalTrig = 4; + constexpr size_t dinoRegisterStsActive = 5; + constexpr size_t dinoRegisterDacScale = 6; + constexpr size_t dinoRegisterDacOffset = 7; uint32_t dinoTimerVal = static_cast(dinoClk / sampleRate); double rateError = dinoClk / dinoTimerVal - sampleRate; reg->setRegister( dinoRegisterTimer, dinoTimerVal); // Timer value for generating ADC trigger signal - reg->setRegister(dinoRegisterScale, - -0.001615254F); // Scale factor for ADC value - reg->setRegister(dinoRegisterOffset, 10.8061F); // Offset for ADC value - uint32_t rate = reg->getRegister(0); - float scale = reg->getRegisterFloat(1); - float offset = reg->getRegisterFloat(2); - logging.get("Dino")->info("Check: Register configuration: Rate: {}, Scale: " - "{}, Offset: {}, Rate-Error: {} Hz", - rate, scale, offset, rateError); + // The following are calibration values for the ADC and DAC. Scale + // sets an factor to be multiplied with the input value. This is the + // raw 16 bit ADC value for the ADC and the float value from VILLAS for + // the DAC. Offset is a value to be added to the result of the multiplication. + // All values are IEE 754 single precision floating point values. + reg->setRegister(dinoRegisterAdcScale, + -0.001615254F); // Scale factor for ADC value + reg->setRegister(dinoRegisterAdcOffset, 10.8061F); // Offset for ADC value + reg->setRegister(dinoRegisterDacScale, + 3448.53852516F); // Scale factor for DAC value + reg->setRegister(dinoRegisterDacOffset, 32767.5F); // Offset for DAC value + uint32_t rate = reg->getRegister(dinoRegisterTimer); + float adcScale = reg->getRegisterFloat(dinoRegisterAdcScale); + float adcOffset = reg->getRegisterFloat(dinoRegisterAdcOffset); + float dacScale = reg->getRegisterFloat(dinoRegisterDacScale); + float dacOffset = reg->getRegisterFloat(dinoRegisterDacOffset); + uint32_t dacExternalTrig = reg->getRegister(dinoRegisterDacExternalTrig); + uint32_t stsActive = reg->getRegister(dinoRegisterStsActive); + Log::get("Dino")->info( + "Check: Register configuration: TimerThresh: {}, Rate-Error: {} Hz, ADC " + "Scale: {}, ADC Offset: {}, DAC Scale: {}, DAC Offset: {}, DAC External " + "Trig: {:#x}, STS Active: {:#x}", + rate, rateError, adcScale, adcOffset, dacScale, dacOffset, + dacExternalTrig, stsActive); } DinoDac::DinoDac() : Dino() {} diff --git a/fpga/lib/ips/dma.cpp b/fpga/lib/ips/dma.cpp index 91ba36a9d..b8e9c7213 100644 --- a/fpga/lib/ips/dma.cpp +++ b/fpga/lib/ips/dma.cpp @@ -477,7 +477,7 @@ XAxiDma_Bd *Dma::readScatterGatherSetupBd(void *buf, size_t len) { (uintptr_t)buf, (uintptr_t)bd, ret); } - ret = XAxiDma_BdSetLength(curBd, readMsgSize, rxRing->MaxTransferLen); + ret = XAxiDma_BdSetLength(curBd, len, rxRing->MaxTransferLen); if (ret != XST_SUCCESS) { hwReadLock.unlock(); throw RuntimeError("Rx set length {} on BD {:x} failed {}", len, @@ -491,7 +491,7 @@ XAxiDma_Bd *Dma::readScatterGatherSetupBd(void *buf, size_t len) { // TODO: Check if we really need this XAxiDma_BdSetId(curBd, (uintptr_t)buf); - curBuf += readMsgSize; + curBuf += len; curBd = (XAxiDma_Bd *)XAxiDma_BdRingNext(rxRing, curBd); } return bd; diff --git a/fpga/lib/pcie_card.cpp b/fpga/lib/pcie_card.cpp index 5bd58c0ce..a43632f97 100644 --- a/fpga/lib/pcie_card.cpp +++ b/fpga/lib/pcie_card.cpp @@ -13,7 +13,8 @@ #include #include #include -#include +#include +#include #include #include @@ -23,8 +24,8 @@ using namespace villas::fpga; // Instantiate factory to register static PCIeCardFactory PCIeCardFactoryInstance; -static const kernel::pci::Device - defaultFilter((kernel::pci::Id(FPGA_PCI_VID_XILINX, FPGA_PCI_PID_VFPGA))); +static const kernel::devices::PciDevice defaultFilter( + (kernel::devices::Id(FPGA_PCI_VID_XILINX, FPGA_PCI_PID_VFPGA))); std::shared_ptr PCIeCardFactory::make(json_t *json_card, std::string card_name, @@ -32,6 +33,10 @@ PCIeCardFactory::make(json_t *json_card, std::string card_name, const std::filesystem::path &searchPath) { auto logger = getStaticLogger(); + // make sure the vfio container has the required modules + kernel::loadModule("vfio_pci"); + kernel::loadModule("vfio_iommu_type1"); + json_t *json_ips = nullptr; json_t *json_paths = nullptr; const char *pci_slot = nullptr; @@ -58,15 +63,16 @@ PCIeCardFactory::make(json_t *json_card, std::string card_name, card->doReset = do_reset != 0; card->polling = (polling != 0); - kernel::pci::Device filter = defaultFilter; + kernel::devices::PciDevice filter = defaultFilter; if (pci_id) - filter.id = kernel::pci::Id(pci_id); + filter.id = kernel::devices::Id(pci_id); if (pci_slot) - filter.slot = kernel::pci::Slot(pci_slot); + filter.slot = kernel::devices::Slot(pci_slot); // Search for FPGA card - card->pdev = kernel::pci::DeviceList::getInstance()->lookupDevice(filter); + card->pdev = + kernel::devices::PciDeviceList::getInstance()->lookupDevice(filter); if (!card->pdev) { logger->warn("Failed to find PCI device"); return nullptr; diff --git a/fpga/lib/utils.cpp b/fpga/lib/utils.cpp index 723947183..be0f20b8a 100644 --- a/fpga/lib/utils.cpp +++ b/fpga/lib/utils.cpp @@ -31,7 +31,7 @@ using namespace villas; -static auto logger = villas::logging.get("streamer"); +static auto logger = villas::Log::get("streamer"); std::shared_ptr>> fpga::getAuroraChannels(std::shared_ptr card) { @@ -52,7 +52,7 @@ fpga::getAuroraChannels(std::shared_ptr card) { } fpga::ConnectString::ConnectString(std::string &connectString, int maxPortNum) - : log(villas::logging.get("ConnectString")), maxPortNum(maxPortNum), + : log(villas::Log::get("ConnectString")), maxPortNum(maxPortNum), bidirectional(false), invert(false), srcType(ConnectType::LOOPBACK), dstType(ConnectType::LOOPBACK), srcAsInt(-1), dstAsInt(-1) { parseString(connectString); diff --git a/fpga/src/villas-fpga-ctrl.cpp b/fpga/src/villas-fpga-ctrl.cpp index b4c7076b9..6232ac782 100644 --- a/fpga/src/villas-fpga-ctrl.cpp +++ b/fpga/src/villas-fpga-ctrl.cpp @@ -34,8 +34,8 @@ using namespace villas; -static std::shared_ptr pciDevices; -static auto logger = villas::logging.get("ctrl"); +static std::shared_ptr pciDevices; +static auto logger = villas::Log::get("ctrl"); void writeToDmaFromStdIn(std::shared_ptr dma) { auto &alloc = villas::HostRam::getAllocator(); @@ -203,7 +203,7 @@ int main(int argc, char *argv[]) { // Logging setup - logging.setLevel(spdlog::level::trace); + Log::getInstance().setLevel(spdlog::level::trace); logger->set_level(spdlog::level::trace); fpga::setupColorHandling(); diff --git a/fpga/src/villas-fpga-pipe.cpp b/fpga/src/villas-fpga-pipe.cpp index edb8ce9e5..b059501c0 100644 --- a/fpga/src/villas-fpga-pipe.cpp +++ b/fpga/src/villas-fpga-pipe.cpp @@ -27,8 +27,8 @@ using namespace villas; -static std::shared_ptr pciDevices; -static auto logger = villas::logging.get("streamer"); +static std::shared_ptr pciDevices; +static auto logger = villas::Log::get("streamer"); int main(int argc, char *argv[]) { // Command Line Parser diff --git a/fpga/tests/unit/dma.cpp b/fpga/tests/unit/dma.cpp index f17515bd4..6700266dd 100644 --- a/fpga/tests/unit/dma.cpp +++ b/fpga/tests/unit/dma.cpp @@ -20,7 +20,7 @@ using namespace villas; // cppcheck-suppress unknownMacro Test(fpga, dma, .description = "DMA") { - auto logger = logging.get("unit-test:dma"); + auto logger = Log::get("unit-test:dma"); std::list> dmaIps; diff --git a/fpga/tests/unit/fifo.cpp b/fpga/tests/unit/fifo.cpp index 958e3ccc9..f875aa30d 100644 --- a/fpga/tests/unit/fifo.cpp +++ b/fpga/tests/unit/fifo.cpp @@ -23,7 +23,7 @@ Test(fpga, fifo, .description = "FIFO") { char src[255], dst[255]; size_t count = 0; - auto logger = logging.get("unit-test:fifo"); + auto logger = Log::get("unit-test:fifo"); for (auto &ip : state.cards.front()->ips) { // Skip non-fifo IPs diff --git a/fpga/tests/unit/fpga.cpp b/fpga/tests/unit/fpga.cpp index d6ad32478..587cc0264 100644 --- a/fpga/tests/unit/fpga.cpp +++ b/fpga/tests/unit/fpga.cpp @@ -27,7 +27,7 @@ using namespace villas; -static kernel::pci::DeviceList *pciDevices; +static kernel::devices::PciDeviceList *pciDevices; FpgaState state; @@ -40,7 +40,7 @@ static void init() { plugin::registry->dump(); - pciDevices = kernel::pci::DeviceList::getInstance(); + pciDevices = kernel::devices::PciDeviceList::getInstance(); auto vfioContainer = std::make_shared(); diff --git a/fpga/tests/unit/gpu.cpp b/fpga/tests/unit/gpu.cpp index ef249eedb..e9bbfe194 100644 --- a/fpga/tests/unit/gpu.cpp +++ b/fpga/tests/unit/gpu.cpp @@ -26,7 +26,7 @@ using namespace villas; // cppcheck-suppress unknownMacro Test(fpga, gpu_dma, .description = "GPU DMA tests") { - auto logger = logging.get("unit-test:dma"); + auto logger = Log::get("unit-test:dma"); auto &card = state.cards.front(); diff --git a/fpga/tests/unit/logging.cpp b/fpga/tests/unit/logging.cpp index 2d7727c6d..46abafdbc 100644 --- a/fpga/tests/unit/logging.cpp +++ b/fpga/tests/unit/logging.cpp @@ -41,7 +41,7 @@ static int format_msg(char *buf, size_t buflen, const char *msg, va_list args) { } void criterion_log_noformat(enum criterion_severity severity, const char *msg) { - auto logger = villas::logging.get("criterion"); + auto logger = villas::Log::get("criterion"); switch (severity) { case CR_LOG_INFO: @@ -67,7 +67,7 @@ void criterion_vlog(enum criterion_logging_level level, const char *msg, format_msg(formatted_msg, sizeof(formatted_msg), msg, args); - auto logger = villas::logging.get("criterion"); + auto logger = villas::Log::get("criterion"); logger->info(formatted_msg); } @@ -85,7 +85,7 @@ void criterion_plog(enum criterion_logging_level level, format_msg(formatted_msg, sizeof(formatted_msg), msg, args); va_end(args); - auto logger = villas::logging.get("criterion"); + auto logger = villas::Log::get("criterion"); if (strstr(formatted_msg, "Warning")) logger->warn(formatted_msg); diff --git a/fpga/tests/unit/main.cpp b/fpga/tests/unit/main.cpp index db8385218..8aeb32d7d 100644 --- a/fpga/tests/unit/main.cpp +++ b/fpga/tests/unit/main.cpp @@ -35,7 +35,7 @@ static bool suite_enabled(struct criterion_test_set *tests, const char *name) { // Limit number of parallel jobs to 1 in case we use the FPGA ReportHook(PRE_ALL)(struct criterion_test_set *tests) { if (suite_enabled(tests, "fpga")) { - auto logger = villas::logging.get("unittest"); + auto logger = villas::Log::get("unittest"); logger->info("FPGA tests enabled. Only 1 job is executed in parallel!."); criterion_options.jobs = 1; diff --git a/fpga/tests/unit/rtds.cpp b/fpga/tests/unit/rtds.cpp index c3f64df4a..b5728667b 100644 --- a/fpga/tests/unit/rtds.cpp +++ b/fpga/tests/unit/rtds.cpp @@ -29,7 +29,7 @@ using namespace villas::fpga::ip; // cppcheck-suppress unknownMacro Test(fpga, rtds, .description = "RTDS") { - auto logger = villas::logging.get("unit-test:rtds"); + auto logger = villas::Log::get("unit-test:rtds"); std::list rtdsIps; std::list dmaIps; diff --git a/fpga/tests/unit/rtds2gpu.cpp b/fpga/tests/unit/rtds2gpu.cpp index a1f9ffcd2..20ba0890a 100644 --- a/fpga/tests/unit/rtds2gpu.cpp +++ b/fpga/tests/unit/rtds2gpu.cpp @@ -52,7 +52,7 @@ static void dumpMem(const uint32_t *addr, size_t len) { // cppcheck-suppress unknownMacro Test(fpga, rtds2gpu_loopback_dma, .description = "Rtds2Gpu") { - auto logger = logging.get("unit-test:rtds2gpu"); + auto logger = Log::get("unit-test:rtds2gpu"); for (auto &ip : state.cards.front()->ips) { if (*ip != fpga::Vlnv("acs.eonerc.rwth-aachen.de:hls:rtds2gpu:")) @@ -158,7 +158,7 @@ Test(fpga, rtds2gpu_loopback_dma, .description = "Rtds2Gpu") { // cppcheck-suppress unknownMacro Test(fpga, rtds2gpu_rtt_cpu, .description = "Rtds2Gpu RTT via CPU") { - auto logger = logging.get("unit-test:rtds2gpu"); + auto logger = Log::get("unit-test:rtds2gpu"); // Collect neccessary IPs auto gpu2rtds = std::dynamic_pointer_cast( @@ -233,7 +233,7 @@ void gpu_rtds_rtt_stop(); // cppcheck-suppress unknownMacro Test(fpga, rtds2gpu_rtt_gpu, .description = "Rtds2Gpu RTT via GPU") { - auto logger = logging.get("unit-test:rtds2gpu"); + auto logger = Log::get("unit-test:rtds2gpu"); // Collect neccessary IPs auto gpu2rtds = std::dynamic_pointer_cast( diff --git a/fpga/tests/unit/timer.cpp b/fpga/tests/unit/timer.cpp index 23e518643..37e3e87cc 100644 --- a/fpga/tests/unit/timer.cpp +++ b/fpga/tests/unit/timer.cpp @@ -16,7 +16,7 @@ // cppcheck-suppress unknownMacro Test(fpga, timer, .description = "Timer Counter") { - auto logger = villas::logging.get("unit-test:timer"); + auto logger = villas::Log::get("unit-test:timer"); size_t count = 0; for (auto &ip : state.cards.front()->ips) { diff --git a/include/villas/api.hpp b/include/villas/api.hpp index ff3f53f86..8e13cdd22 100644 --- a/include/villas/api.hpp +++ b/include/villas/api.hpp @@ -14,8 +14,6 @@ #include #include -#include - #include #include #include diff --git a/include/villas/formats/protobuf.hpp b/include/villas/formats/protobuf.hpp index 09048ad72..ee7e3804a 100644 --- a/include/villas/formats/protobuf.hpp +++ b/include/villas/formats/protobuf.hpp @@ -7,13 +7,8 @@ #pragma once -#include - #include -// Generated message descriptors by protoc -#include - namespace villas { namespace node { @@ -22,9 +17,6 @@ struct Sample; class ProtobufFormat : public BinaryFormat { -protected: - enum SignalType detect(const Villas__Node__Value *val); - public: using BinaryFormat::BinaryFormat; diff --git a/include/villas/nodes/ethercat.hpp b/include/villas/nodes/ethercat.hpp index bd16c7b65..0476ac1da 100644 --- a/include/villas/nodes/ethercat.hpp +++ b/include/villas/nodes/ethercat.hpp @@ -18,22 +18,17 @@ #include #include -namespace villas { -namespace node { +// Include hard-coded Ethercat Bus configuration +#include + +#define DEFAULT_ETHERCAT_QUEUE_LENGTH (DEFAULT_QUEUE_LENGTH * 64) + +namespace villas::node { // Forward declarations class NodeCompat; class SuperNode; -// Include hard-coded Ethercat Bus configuration -#include - -extern "C" { -#include -} - -#define DEFAULT_ETHERCAT_QUEUE_LENGTH (DEFAULT_QUEUE_LENGTH * 64) - // Internal data per ethercat node struct ethercat { // Settings @@ -91,5 +86,4 @@ int ethercat_read(NodeCompat *n, struct Sample *const smps[], unsigned cnt); int ethercat_write(NodeCompat *n, struct Sample *const smps[], unsigned cnt); -} // namespace node -} // namespace villas +} // namespace villas::node diff --git a/include/villas/nodes/ethercat_config.hpp b/include/villas/nodes/ethercat_config.hpp index 4b1c2816f..819adfde2 100644 --- a/include/villas/nodes/ethercat_config.hpp +++ b/include/villas/nodes/ethercat_config.hpp @@ -25,6 +25,8 @@ #define ETHERCAT_PID_EL3008 0x0bc03052 #define ETHERCAT_PID_FC1100 0x044c0c62 +namespace villas::node { + // TODO: Make PDO entry tables configurable /* Master 0, Slave 3, "EL4038" @@ -168,3 +170,5 @@ static ec_sync_info_t slave_4_syncs[] = { {2, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE}, {3, EC_DIR_INPUT, 8, slave_4_pdos + 0, EC_WD_DISABLE}, {0xff}}; + +} // namespace villas::node diff --git a/include/villas/nodes/fpga.hpp b/include/villas/nodes/fpga.hpp index c8a3f034a..98a0fc9f3 100644 --- a/include/villas/nodes/fpga.hpp +++ b/include/villas/nodes/fpga.hpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -61,7 +62,11 @@ protected: std::shared_ptr card; std::shared_ptr dma; std::shared_ptr blockRx; + std::shared_ptr> accessorRxInt; + std::shared_ptr> accessorRxFloat; std::shared_ptr blockTx; + std::shared_ptr> accessorTxInt; + std::shared_ptr> accessorTxFloat; // Non-public methods virtual int fastRead(Sample *smps[], unsigned cnt); diff --git a/include/villas/nodes/iec61850.hpp b/include/villas/nodes/iec61850.hpp index bbb1afc0f..85c008c2f 100644 --- a/include/villas/nodes/iec61850.hpp +++ b/include/villas/nodes/iec61850.hpp @@ -20,8 +20,7 @@ #include #ifndef CONFIG_GOOSE_DEFAULT_DST_ADDRESS -#define CONFIG_GOOSE_DEFAULT_DST_ADDRESS \ - { 0x01, 0x0c, 0xcd, 0x01, 0x00, 0x01 } +#define CONFIG_GOOSE_DEFAULT_DST_ADDRESS {0x01, 0x0c, 0xcd, 0x01, 0x00, 0x01} #endif namespace villas { diff --git a/include/villas/nodes/test_rtt.hpp b/include/villas/nodes/test_rtt.hpp index c33db2d8c..fd5c55d4d 100644 --- a/include/villas/nodes/test_rtt.hpp +++ b/include/villas/nodes/test_rtt.hpp @@ -58,7 +58,7 @@ protected: : node(n), id(id), rate(rate), warmup(warmup), cooldown(cooldown), values(values), count(count), sent(0), received(0), missed(0), count_warmup(count_warmup), sent_warmup(0), received_warmup(0), - missed_warmup(0), filename(filename){}; + missed_warmup(0), filename(filename) {}; int start(); int stop(); @@ -96,7 +96,7 @@ public: : Node(id, name), task(CLOCK_MONOTONIC), formatter(nullptr), stream(nullptr), shutdown(false) {} - virtual ~TestRTT(){}; + virtual ~TestRTT() {}; virtual int prepare(); diff --git a/lib/api.cpp b/lib/api.cpp index c53bd47bb..ac7c92942 100644 --- a/lib/api.cpp +++ b/lib/api.cpp @@ -24,7 +24,7 @@ InvalidMethod::InvalidMethod(Request *req) Session::methodToString(req->method)) {} Api::Api(SuperNode *sn) - : logger(logging.get("api")), state(State::INITIALIZED), super_node(sn) {} + : logger(Log::get("api")), state(State::INITIALIZED), super_node(sn) {} Api::~Api() { if (state == State::STARTED) diff --git a/lib/api/requests/restart.cpp b/lib/api/requests/restart.cpp index 8fc489ccf..cf29f76e9 100644 --- a/lib/api/requests/restart.cpp +++ b/lib/api/requests/restart.cpp @@ -28,7 +28,7 @@ protected: const char *argv[] = {"villas-node", cfg, nullptr}; - Logger logger = logging.get("api:restart"); + Logger logger = Log::get("api:restart"); if (cfg) logger->info("Restarting instance: config={}", cfg); diff --git a/lib/api/response.cpp b/lib/api/response.cpp index 62914191e..175d75419 100644 --- a/lib/api/response.cpp +++ b/lib/api/response.cpp @@ -12,7 +12,7 @@ using namespace villas::node::api; Response::Response(Session *s, int c, const std::string &ct, const Buffer &b) - : session(s), logger(logging.get("api:response")), buffer(b), code(c), + : session(s), logger(Log::get("api:response")), buffer(b), code(c), contentType(ct), headers{{"Server:", HTTP_USER_AGENT}, {"Access-Control-Allow-Origin:", "*"}, diff --git a/lib/api/session.cpp b/lib/api/session.cpp index 331f6a1dc..0494aa10b 100644 --- a/lib/api/session.cpp +++ b/lib/api/session.cpp @@ -21,7 +21,7 @@ using namespace villas::node; using namespace villas::node::api; Session::Session(lws *w) - : version(Version::VERSION_2), wsi(w), logger(logging.get("api:session")) { + : version(Version::VERSION_2), wsi(w), logger(Log::get("api:session")) { lws_context *ctx = lws_get_context(wsi); void *user_ctx = lws_context_user(ctx); diff --git a/lib/config.cpp b/lib/config.cpp index 59f795534..433197426 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -27,7 +27,7 @@ using namespace villas; using namespace villas::node; -Config::Config() : logger(logging.get("config")), root(nullptr) {} +Config::Config() : logger(Log::get("config")), root(nullptr) {} Config::Config(const std::string &u) : Config() { root = load(u); } diff --git a/lib/dumper.cpp b/lib/dumper.cpp index 7b0862605..5d00d9439 100644 --- a/lib/dumper.cpp +++ b/lib/dumper.cpp @@ -20,7 +20,7 @@ using namespace villas::node; Dumper::Dumper() : active(false), socketFd(0), socketPath(""), supressRepeatedWarning(true), - warningCounter(0), logger(logging.get("dumper")) {} + warningCounter(0), logger(Log::get("dumper")) {} Dumper::~Dumper() { closeSocket(); } diff --git a/lib/formats/CMakeLists.txt b/lib/formats/CMakeLists.txt index 67afa3cbc..44af099cf 100644 --- a/lib/formats/CMakeLists.txt +++ b/lib/formats/CMakeLists.txt @@ -25,6 +25,9 @@ if(DEFINED PROTOBUFC_COMPILER AND PROTOBUFC_FOUND) COMMAND ${PROTOBUFC_COMPILER} --c_out=${CMAKE_CURRENT_BINARY_DIR} villas.proto + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_BINARY_DIR}/villas.pb-c.h + ${CMAKE_BINARY_DIR}/include/villas/formats/villas.pb-c.h MAIN_DEPENDENCY villas.proto WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) diff --git a/lib/formats/protobuf.cpp b/lib/formats/protobuf.cpp index 5000fbb9c..c34913bcc 100644 --- a/lib/formats/protobuf.cpp +++ b/lib/formats/protobuf.cpp @@ -11,9 +11,12 @@ #include #include +// Generated message descriptors by protoc +#include + using namespace villas::node; -enum SignalType ProtobufFormat::detect(const Villas__Node__Value *val) { +static enum SignalType detect(const Villas__Node__Value *val) { switch (val->value_case) { case VILLAS__NODE__VALUE__VALUE_F: return SignalType::FLOAT; diff --git a/lib/hook.cpp b/lib/hook.cpp index 61a6f59bc..feb61efa2 100644 --- a/lib/hook.cpp +++ b/lib/hook.cpp @@ -22,7 +22,7 @@ using namespace villas; using namespace villas::node; Hook::Hook(Path *p, Node *n, int fl, int prio, bool en) - : logger(logging.get("hook")), factory(nullptr), + : logger(Log::get("hook")), factory(nullptr), state(fl & (int)Hook::Flags::BUILTIN ? State::CHECKED : State::INITIALIZED), // We dont need to parse builtin hooks diff --git a/lib/hooks/dp.cpp b/lib/hooks/dp.cpp index 06df2bb81..f41b85b25 100644 --- a/lib/hooks/dp.cpp +++ b/lib/hooks/dp.cpp @@ -27,7 +27,6 @@ protected: char *signal_name; unsigned signal_index; - int offset; int inverse; double f0; @@ -43,7 +42,7 @@ protected: void step(double *in, std::complex *out) { int N = window.size(); - __attribute__((unused)) std::complex om_k, corr; + std::complex om_k, corr; double newest = *in; __attribute__((unused)) double oldest = window.update(newest); @@ -97,8 +96,8 @@ protected: public: DPHook(Path *p, Node *n, int fl, int prio, bool en = true) : Hook(p, n, fl, prio, en), signal_name(nullptr), signal_index(0), - offset(0), inverse(0), f0(50.0), timestep(50e-6), time(), steps(0), - coeffs(), fharmonics(), fharmonics_len(0) {} + inverse(0), f0(50.0), timestep(50e-6), time(), steps(0), coeffs(), + fharmonics(), fharmonics_len(0) {} virtual ~DPHook() { // Release memory @@ -122,6 +121,10 @@ public: coeffs[i] = 0; window = dsp::Window((1.0 / f0) / timestep, 0.0); + if (window.size() == 0) { + throw RuntimeError( + "Windows size is 0: f0 * timestep < 1.0 not satisfied"); + } state = State::STARTED; } @@ -221,7 +224,7 @@ public: if (!new_sig) throw RuntimeError("Failed to create signal"); - signals->insert(signals->begin() + offset, new_sig); + signals->insert(signals->begin() + signal_index, new_sig); } else { auto orig_sig = signals->getByIndex(signal_index); if (!orig_sig) @@ -240,7 +243,7 @@ public: if (!new_sig) throw RuntimeError("Failed to create new signal"); - signals->insert(signals->begin() + offset, new_sig); + signals->insert(signals->begin() + signal_index, new_sig); } } @@ -277,7 +280,7 @@ public: istep(coeffs, &signal); sample_data_remove(smp, signal_index, fharmonics_len); - sample_data_insert(smp, (union SignalData *)&signal, offset, 1); + sample_data_insert(smp, (union SignalData *)&signal, signal_index, 1); } else { double signal = smp->data[signal_index].f; std::complex coeffs[fharmonics_len]; @@ -285,7 +288,7 @@ public: step(&signal, coeffs); sample_data_remove(smp, signal_index, 1); - sample_data_insert(smp, (union SignalData *)coeffs, offset, + sample_data_insert(smp, (union SignalData *)coeffs, signal_index, fharmonics_len); } diff --git a/lib/kernel/if.cpp b/lib/kernel/if.cpp index 08aca8255..98477bfab 100644 --- a/lib/kernel/if.cpp +++ b/lib/kernel/if.cpp @@ -32,7 +32,7 @@ using namespace villas::kernel; Interface::Interface(struct rtnl_link *link, int aff) : nl_link(link), tc_qdisc(nullptr), affinity(aff) { - logger = logging.get(fmt::format("kernel:if:{}", getName())); + logger = Log::get(fmt::format("kernel:if:{}", getName())); int n = getIRQs(); if (n) @@ -118,7 +118,7 @@ std::string Interface::getName() const { Interface *Interface::getEgress(struct sockaddr *sa, SuperNode *sn) { struct rtnl_link *link; - Logger logger = logging.get("kernel:if"); + Logger logger = Log::get("kernel:if"); auto &interfaces = sn->getInterfaces(); auto affinity = sn->getAffinity(); diff --git a/lib/kernel/tc.cpp b/lib/kernel/tc.cpp index fd43d65e0..08cf3eb81 100644 --- a/lib/kernel/tc.cpp +++ b/lib/kernel/tc.cpp @@ -50,7 +50,7 @@ int villas::kernel::tc::prio(Interface *i, struct rtnl_qdisc **qd, *qd = q; - auto logger = logging.get("kernel"); + auto logger = Log::get("kernel"); logger->debug("Added prio qdisc with {} bands to interface '{}'", bands, rtnl_link_get_name(i->nl_link)); @@ -80,7 +80,7 @@ int villas::kernel::tc::mark(Interface *i, struct rtnl_cls **cls, *cls = c; - auto logger = logging.get("kernel"); + auto logger = Log::get("kernel"); logger->debug("Added fwmark classifier with mark {} to interface '{}'", mark, rtnl_link_get_name(i->nl_link)); diff --git a/lib/kernel/tc_netem.cpp b/lib/kernel/tc_netem.cpp index 0b9ab2625..1f4f3cc17 100644 --- a/lib/kernel/tc_netem.cpp +++ b/lib/kernel/tc_netem.cpp @@ -277,7 +277,7 @@ int villas::kernel::tc::netem(Interface *i, struct rtnl_qdisc **qd, *qd = q; - auto logger = logging.get("kernel"); + auto logger = Log::get("kernel"); logger->debug("Added netem qdisc to interface '{}'", rtnl_link_get_name(i->nl_link)); diff --git a/lib/memory.cpp b/lib/memory.cpp index 9475dc5fa..fb1cae4fd 100644 --- a/lib/memory.cpp +++ b/lib/memory.cpp @@ -31,7 +31,7 @@ static Logger logger; int villas::node::memory::init(int hugepages) { int ret; - logger = logging.get("memory"); + logger = Log::get("memory"); logger->info("Initialize memory sub-system: #hugepages={}", hugepages); diff --git a/lib/memory/ib.cpp b/lib/memory/ib.cpp index 5a2bce3c0..9dc7a96e3 100644 --- a/lib/memory/ib.cpp +++ b/lib/memory/ib.cpp @@ -42,7 +42,7 @@ static struct Allocation *ib_alloc(size_t len, size_t alignment, ma->address = ma->parent->address; if (!mi->pd) { - auto logger = logging.get("memory:ib"); + auto logger = Log::get("memory:ib"); logger->error("Protection domain is not registered!"); } diff --git a/lib/memory/managed.cpp b/lib/memory/managed.cpp index 8ffc1cdbf..3b3c5c412 100644 --- a/lib/memory/managed.cpp +++ b/lib/memory/managed.cpp @@ -145,7 +145,7 @@ struct Type *villas::node::memory::managed(void *ptr, size_t len) { char *cptr = (char *)ptr; if (len < sizeof(struct Type) + sizeof(struct Block)) { - auto logger = logging.get("memory:managed"); + auto logger = Log::get("memory:managed"); logger->info("Passed region is too small"); return nullptr; } diff --git a/lib/memory/mmap.cpp b/lib/memory/mmap.cpp index f4060eaaf..65efb0b0d 100644 --- a/lib/memory/mmap.cpp +++ b/lib/memory/mmap.cpp @@ -36,7 +36,7 @@ static size_t hugepgsz = -1; static Logger logger; int villas::node::memory::mmap_init(int hugepages) { - logger = logging.get("memory:mmap"); + logger = Log::get("memory:mmap"); pgsz = kernel::getPageSize(); if (pgsz < 0) diff --git a/lib/node.cpp b/lib/node.cpp index ebdf331b9..20b280e62 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -40,7 +40,7 @@ using namespace villas::node; using namespace villas::utils; Node::Node(const uuid_t &id, const std::string &name) - : logger(logging.get("node")), sequence_init(0), sequence(0), + : logger(Log::get("node")), sequence_init(0), sequence(0), in(NodeDirection::Direction::IN, this), out(NodeDirection::Direction::OUT, this), configPath(), #ifdef __linux__ diff --git a/lib/node_list.cpp b/lib/node_list.cpp index 86b8397e6..0859cb788 100644 --- a/lib/node_list.cpp +++ b/lib/node_list.cpp @@ -37,7 +37,7 @@ int NodeList::parse(json_t *json, NodeList &all) { size_t index; json_t *elm; - auto logger = logging.get("node"); + auto logger = Log::get("node"); switch (json_typeof(json)) { case JSON_STRING: diff --git a/lib/nodes/ethercat.cpp b/lib/nodes/ethercat.cpp index 3b2944637..11dbba864 100644 --- a/lib/nodes/ethercat.cpp +++ b/lib/nodes/ethercat.cpp @@ -125,7 +125,7 @@ int villas::node::ethercat_type_start(villas::node::SuperNode *sn) { } int villas::node::ethercat_type_stop() { - auto logger = logging.get("node:ethercat"); + auto logger = Log::get("node:ethercat"); logger->info("Releasing EtherCAT master"); diff --git a/lib/nodes/fpga.cpp b/lib/nodes/fpga.cpp index bac7e9e04..3e12653c2 100644 --- a/lib/nodes/fpga.cpp +++ b/lib/nodes/fpga.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -36,7 +37,9 @@ static std::shared_ptr vfioContainer; FpgaNode::FpgaNode(const uuid_t &id, const std::string &name) : Node(id, name), cardName(""), connectStrings(), lowLatencyMode(false), - timestep(10e-3), card(nullptr), dma(), blockRx(), blockTx() {} + timestep(10e-3), card(nullptr), dma(), blockRx(), accessorRxInt(nullptr), + accessorRxFloat(nullptr), blockTx(), accessorTxInt(nullptr), + accessorTxFloat(nullptr) {} FpgaNode::~FpgaNode() {} @@ -74,7 +77,7 @@ int FpgaNode::prepare() { if (reg != nullptr && card->lookupIp(fpga::Vlnv("xilinx.com:module_ref:dinoif_fast:"))) { - fpga::ip::DinoAdc::setRegisterConfigTimestep(reg, 10e-3); + fpga::ip::DinoAdc::setRegisterConfigTimestep(reg, timestep); } else { logger->warn("No DinoAdc or no Register found on FPGA."); } @@ -90,8 +93,10 @@ int FpgaNode::prepare() { blockRx = alloc.allocateBlock(0x200 * sizeof(float)); blockTx = alloc.allocateBlock(0x200 * sizeof(float)); - villas::MemoryAccessor memRx = *blockRx; - villas::MemoryAccessor memTx = *blockTx; + accessorRxInt = std::make_shared>(*blockRx); + accessorTxInt = std::make_shared>(*blockTx); + accessorRxFloat = std::make_shared>(*blockRx); + accessorTxFloat = std::make_shared>(*blockTx); dma->makeAccesibleFromVA(blockRx); dma->makeAccesibleFromVA(blockTx); @@ -183,12 +188,22 @@ const std::string &FpgaNode::getDetails() { int FpgaNode::check() { return Node::check(); } int FpgaNode::start() { - if (getOutputSignalsMaxCount() * sizeof(float) > blockRx->getSize()) { + if (getOutputSignalsMaxCount() * sizeof(float) > blockTx->getSize()) { + logger->error("Output signals exceed block size."); + throw villas ::RuntimeError("Output signals exceed block size."); + } + if (getInputSignalsMaxCount() * sizeof(float) > blockRx->getSize()) { logger->error("Output signals exceed block size."); throw villas ::RuntimeError("Output signals exceed block size."); } if (lowLatencyMode) { - dma->readScatterGatherPrepare(*blockRx, blockRx->getSize()); + if (getInputSignalsMaxCount() != 0) { + dma->readScatterGatherPrepare(*blockRx, + getInputSignalsMaxCount() * sizeof(float)); + } else { + logger->warn("No input signals defined. Not preparing read buffer - " + "reads will not work."); + } if (getOutputSignalsMaxCount() != 0) { dma->writeScatterGatherPrepare(*blockTx, getOutputSignalsMaxCount() * sizeof(float)); @@ -209,23 +224,18 @@ int FpgaNode::fastWrite(Sample *smps[], unsigned cnt) { assert(cnt == 1 && smps != nullptr && smps[0] != nullptr); - auto mem = MemoryAccessor(*blockTx); - float scaled; - for (unsigned i = 0; i < smp->length; i++) { if (smp->signals->getByIndex(i)->type == SignalType::FLOAT) { - scaled = smp->data[i].f; - if (scaled > 10.) { - scaled = 10.; - } else if (scaled < -10.) { - scaled = -10.; - } - mem[i] = (scaled + 10.) * ((float)0xFFFF / 20.); + (*accessorTxFloat)[i] = static_cast(smp->data[i].f); + ; } else { - mem[i] = smp->data[i].i; + (*accessorTxInt)[i] = static_cast(smp->data[i].i); } } + logger->trace("Writing sample: {}, {}, {:#x}", smp->data[0].f, + signalTypeToString(smp->signals->getByIndex(0)->type), + smp->data[0].i); dma->writeScatterGatherFast(); auto written = dma->writeScatterGatherPoll() / sizeof(float); // The number of samples written @@ -243,18 +253,37 @@ int FpgaNode::fastWrite(Sample *smps[], unsigned cnt) { // what we have received. fastRead is thus capable of partial reads. int FpgaNode::fastRead(Sample *smps[], unsigned cnt) { Sample *smp = smps[0]; - auto mem = MemoryAccessor(*blockRx); smp->flags = (int)SampleFlags::HAS_DATA; smp->signals = in.signals; - dma->readScatterGatherFast(); - auto read = dma->readScatterGatherPoll(true); + size_t to_read = in.signals->size() * sizeof(uint32_t); + size_t read; + do { + dma->readScatterGatherFast(); + read = dma->readScatterGatherPoll(true); + if (read < to_read) { + logger->warn("Read only {} bytes, but {} were expected", read, to_read); + } + } while (read < to_read); + // when we read less than expected we don't know what we missed so the data is + // useless. Thus, we discard what we read and try again. + // We assume a lot without checking at this point. All for the latency! smp->length = 0; - for (unsigned i = 0; i < MIN(read / sizeof(float), smp->capacity); i++) { - smp->data[i].f = static_cast(mem[i]); + for (unsigned i = 0; i < MIN(read / sizeof(uint32_t), smp->capacity); i++) { + if (i >= in.signals->size()) { + logger->warn( + "Received more data than expected. Maybe the descriptor cache needs " + "to be invalidated?. Ignoring the rest of the data."); + break; + } + if (in.signals->getByIndex(i)->type == SignalType::INTEGER) { + smp->data[i].i = static_cast((*accessorRxInt)[i]); + } else { + smp->data[i].f = static_cast((*accessorRxFloat)[i]); + } smp->length++; } @@ -312,17 +341,10 @@ int FpgaNode::slowWrite(Sample *smps[], unsigned cnt) { assert(cnt == 1 && smps != nullptr && smps[0] != nullptr); - auto mem = MemoryAccessor(*blockTx); - float scaled; + auto mem = MemoryAccessor(*blockTx); for (unsigned i = 0; i < smps[0]->length; i++) { - scaled = smps[0]->data[i].f; - if (scaled > 10.) { - scaled = 10.; - } else if (scaled < -10.) { - scaled = -10.; - } - mem[i] = (scaled + 10.) * ((float)0xFFFF / 20.); + mem[i] = smps[0]->data[i].f; } bool state = dma->write(*blockTx, smp->length * sizeof(float)); diff --git a/lib/nodes/iec61850_sv.cpp b/lib/nodes/iec61850_sv.cpp index a4f98ef9d..def34ffce 100644 --- a/lib/nodes/iec61850_sv.cpp +++ b/lib/nodes/iec61850_sv.cpp @@ -77,14 +77,9 @@ static void iec61850_sv_listener(SVSubscriber subscriber, void *ctx, const char *sv_id = SVSubscriber_ASDU_getSvId(asdu); int smp_cnt = SVSubscriber_ASDU_getSmpCnt(asdu); - int smp_mod = SVSubscriber_ASDU_getSmpMod(asdu); - int smp_synch = SVSubscriber_ASDU_getSmpSynch(asdu); - int conf_rev = SVSubscriber_ASDU_getConfRev(asdu); size_t data_size = (size_t)SVSubscriber_ASDU_getDataSize(asdu); - n->logger->debug("Received sample: sv_id={}, smp_mod={}, smp_sync={}, " - "smp_cnt={}, conf_rev={}", - sv_id, smp_mod, smp_synch, smp_cnt, conf_rev); + n->logger->debug("Received sample: sv_id={}, smp_cnt={}", sv_id, smp_cnt); smp = sample_alloc(&i->in.pool); if (!smp) { @@ -335,8 +330,7 @@ int villas::node::iec61850_sv_start(NodeCompat *n) { i->interface, i->in.check_dst_address); i->in.receiver = r->sv; - i->in.subscriber = - SVSubscriber_create(i->dst_address.ether_addr_octet, i->app_id); + i->in.subscriber = SVSubscriber_create(nullptr, i->app_id); // Install a callback handler for the subscriber SVSubscriber_setListener(i->in.subscriber, iec61850_sv_listener, n); @@ -473,23 +467,21 @@ int villas::node::iec61850_sv_write(NodeCompat *n, struct Sample *const smps[], unsigned off = 0; for (unsigned k = 0; k < i->out.asdu_length; k++) { - struct iec61850_type_descriptor *td = - (struct iec61850_type_descriptor *)list_at(&i->out.signals, k); + auto *td = (struct iec61850_type_descriptor *)list_at(&i->out.signals, k); + auto sig = smp->signals->getByIndex(k); - int i_val = 0; - double f_val = 0; + SignalData data; switch (td->iec_type) { case IEC61850Type::INT8: case IEC61850Type::INT32: - i_val = sample_format(smp, k) == SignalType::FLOAT ? smp->data[k].f - : smp->data[k].i; + case IEC61850Type::INT64: + data = smp->data[k].cast(sig->type, SignalType::INTEGER); break; case IEC61850Type::FLOAT32: case IEC61850Type::FLOAT64: - f_val = sample_format(smp, k) == SignalType::FLOAT ? smp->data[k].f - : smp->data[k].i; + data = smp->data[k].cast(sig->type, SignalType::FLOAT); break; default: { @@ -497,20 +489,28 @@ int villas::node::iec61850_sv_write(NodeCompat *n, struct Sample *const smps[], } switch (td->iec_type) { + case IEC61850Type::BOOLEAN: + SVPublisher_ASDU_setINT8(i->out.asdu, off, data.b); + break; + case IEC61850Type::INT8: - SVPublisher_ASDU_setINT8(i->out.asdu, off, i_val); + SVPublisher_ASDU_setINT8(i->out.asdu, off, data.i); break; case IEC61850Type::INT32: - SVPublisher_ASDU_setINT32(i->out.asdu, off, i_val); + SVPublisher_ASDU_setINT32(i->out.asdu, off, data.i); + break; + + case IEC61850Type::INT64: + SVPublisher_ASDU_setINT64(i->out.asdu, off, data.i); break; case IEC61850Type::FLOAT32: - SVPublisher_ASDU_setFLOAT(i->out.asdu, off, f_val); + SVPublisher_ASDU_setFLOAT(i->out.asdu, off, data.f); break; case IEC61850Type::FLOAT64: - SVPublisher_ASDU_setFLOAT64(i->out.asdu, off, f_val); + SVPublisher_ASDU_setFLOAT64(i->out.asdu, off, data.f); break; default: { @@ -524,8 +524,7 @@ int villas::node::iec61850_sv_write(NodeCompat *n, struct Sample *const smps[], SVPublisher_ASDU_setSmpCnt(i->out.asdu, smp->sequence); if (smp->flags & (int)SampleFlags::HAS_TS_ORIGIN) { - uint64_t t = - smp->ts.origin.tv_sec * 1000000000 + smp->ts.origin.tv_nsec; + uint64_t t = smp->ts.origin.tv_sec * 1000000000 + smp->ts.origin.tv_nsec; SVPublisher_ASDU_setRefrTmNs(i->out.asdu, t); } diff --git a/lib/nodes/kafka.cpp b/lib/nodes/kafka.cpp index 7eceda0dc..c41551e8c 100644 --- a/lib/nodes/kafka.cpp +++ b/lib/nodes/kafka.cpp @@ -470,7 +470,7 @@ int villas::node::kafka_stop(NodeCompat *n) { int villas::node::kafka_type_start(villas::node::SuperNode *sn) { int ret; - logger = logging.get("node:kafka"); + logger = Log::get("node:kafka"); ret = list_init(&clients); if (ret) diff --git a/lib/nodes/loopback_internal.cpp b/lib/nodes/loopback_internal.cpp index b30030a9f..eceed8424 100644 --- a/lib/nodes/loopback_internal.cpp +++ b/lib/nodes/loopback_internal.cpp @@ -35,7 +35,7 @@ InternalLoopbackNode::InternalLoopbackNode(Node *src, unsigned id, unsigned ql) auto logger_name = fmt::format("node:{}", getNameShort()); - logger = logging.get(logger_name); + logger = Log::get(logger_name); in.signals = source->getInputSignals(false); diff --git a/lib/nodes/mqtt.cpp b/lib/nodes/mqtt.cpp index 9860c9e2f..d76704ff0 100644 --- a/lib/nodes/mqtt.cpp +++ b/lib/nodes/mqtt.cpp @@ -412,7 +412,7 @@ int villas::node::mqtt_type_start(villas::node::SuperNode *sn) { return 0; mosquitto_error: - auto logger = logging.get("node:mqtt"); + auto logger = Log::get("node:mqtt"); logger->warn("{}", mosquitto_strerror(ret)); return ret; @@ -428,7 +428,7 @@ int villas::node::mqtt_type_stop() { return 0; mosquitto_error: - auto logger = logging.get("node:mqtt"); + auto logger = Log::get("node:mqtt"); logger->warn("{}", mosquitto_strerror(ret)); return ret; diff --git a/lib/nodes/ngsi.cpp b/lib/nodes/ngsi.cpp index aeb00d7f0..8fed2e405 100644 --- a/lib/nodes/ngsi.cpp +++ b/lib/nodes/ngsi.cpp @@ -41,7 +41,7 @@ using namespace villas::utils; static pthread_mutex_t *mutex_buf = NULL; static void handle_error(const char *file, int lineno, const char *msg) { - auto logger = logging.get("curl"); + auto logger = Log::get("curl"); logger->error("** {}:{} {}", file, lineno, msg); @@ -550,7 +550,7 @@ int villas::node::ngsi_type_start(villas::node::SuperNode *sn) { CRYPTO_set_id_callback(curl_ssl_thread_id_function); CRYPTO_set_locking_callback(curl_ssl_locking_function); - auto logger = logging.get("curl"); + auto logger = Log::get("curl"); logger->info("Setup libcurl/openssl locking primitives"); #endif // CURL_SSL_REQUIRES_LOCKING diff --git a/lib/nodes/opal.cpp b/lib/nodes/opal.cpp index a60ea7725..f7e76fef2 100644 --- a/lib/nodes/opal.cpp +++ b/lib/nodes/opal.cpp @@ -124,7 +124,7 @@ int villas::node::opal_type_start(villas::node::SuperNode *sn) { if (err != EOK) throw RuntimeError("Failed to get list of recv ids ({})", err); - auto logger = logging.get("node:opal"); + auto logger = Log::get("node:opal"); logger->info("Started as OPAL Asynchronous process"); logger->info("This is VILLASnode %s (built on %s, %s)", PROJECT_BUILD_ID, __DATE__, __TIME__); @@ -141,7 +141,7 @@ int villas::node::opal_type_stop() { if (err != EOK) throw RuntimeError("Failed to close shared memory area ({})", err); - auto logger = logging.get("node:opal"); + auto logger = Log::get("node:opal"); logger->debug("Closing OPAL shared memory mapping"); err = OpalSystemCtrl_UnRegister((char *)printShmemName.c_str()); @@ -155,7 +155,7 @@ int villas::node::opal_type_stop() { } static int opal_print_global() { - auto logger = logging.get("node:opal"); + auto logger = Log::get("node:opal"); logger->debug("Controller ID: {}", params.controllerID); std::stringstream sss, rss; diff --git a/lib/nodes/redis.cpp b/lib/nodes/redis.cpp index 8b38684d7..0c33f5d78 100644 --- a/lib/nodes/redis.cpp +++ b/lib/nodes/redis.cpp @@ -35,7 +35,7 @@ static std::unordered_map RedisConnection::RedisConnection(const sw::redis::ConnectionOptions &opts) : context(opts), subscriber(context.subscriber()), - logger(logging.get("nodes:redis")) { + logger(Log::get("nodes:redis")) { // Enable keyspace notifications context.command("config", "set", "notify-keyspace-events", "K$h"); diff --git a/lib/nodes/rtp.cpp b/lib/nodes/rtp.cpp index be2ad20a0..503978691 100644 --- a/lib/nodes/rtp.cpp +++ b/lib/nodes/rtp.cpp @@ -76,7 +76,7 @@ static int rtp_aimd(NodeCompat *n, double loss_frac) { int villas::node::rtp_init(NodeCompat *n) { auto *r = n->getData(); - n->logger = villas::logging.get("node:rtp"); + n->logger = villas::Log::get("node:rtp"); // Default values r->aimd.a = 10; diff --git a/lib/nodes/temper.cpp b/lib/nodes/temper.cpp index da0138908..53289c8ab 100644 --- a/lib/nodes/temper.cpp +++ b/lib/nodes/temper.cpp @@ -168,7 +168,7 @@ bool TEMPer1Device::match(struct libusb_device *dev) { struct libusb_device_descriptor desc; int ret = libusb_get_device_descriptor(dev, &desc); if (ret < 0) { - logging.get("node:temper") + Log::get("node:temper") ->warn("Could not get USB device descriptor: {}", libusb_strerror((enum libusb_error)ret)); return false; @@ -185,7 +185,7 @@ bool TEMPer2Device::match(struct libusb_device *dev) { struct libusb_device_descriptor desc; ret = libusb_get_device_descriptor(dev, &desc); if (ret < 0) { - logging.get("node:temper") + Log::get("node:temper") ->warn("Could not get USB device descriptor: {}", libusb_strerror((enum libusb_error)ret)); return false; @@ -193,7 +193,7 @@ bool TEMPer2Device::match(struct libusb_device *dev) { ret = libusb_open(dev, &handle); if (ret < 0) { - logging.get("node:temper") + Log::get("node:temper") ->warn("Failed to open USB device: {}", libusb_strerror((enum libusb_error)ret)); return false; @@ -202,7 +202,7 @@ bool TEMPer2Device::match(struct libusb_device *dev) { ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, product, sizeof(product)); if (ret < 0) { - logging.get("node:temper") + Log::get("node:temper") ->warn("Could not get USB string descriptor: {}", libusb_strerror((enum libusb_error)ret)); return false; @@ -217,7 +217,7 @@ bool TEMPerHUMDevice::match(struct libusb_device *dev) { struct libusb_device_descriptor desc; int ret = libusb_get_device_descriptor(dev, &desc); if (ret < 0) { - logging.get("node:temper") + Log::get("node:temper") ->warn("Could not get USB device descriptor: {}", libusb_strerror((enum libusb_error)ret)); return false; @@ -229,7 +229,7 @@ bool TEMPerHUMDevice::match(struct libusb_device *dev) { int villas::node::temper_type_start(villas::node::SuperNode *sn) { context = usb::get_context(); - logger = logging.get("node:temper"); + logger = Log::get("node:temper"); // Enumerate temper devices devices.clear(); diff --git a/lib/nodes/uldaq.cpp b/lib/nodes/uldaq.cpp index ad442eecd..9fba87861 100644 --- a/lib/nodes/uldaq.cpp +++ b/lib/nodes/uldaq.cpp @@ -194,7 +194,7 @@ int villas::node::uldaq_type_start(villas::node::SuperNode *sn) { if (err != ERR_NO_ERROR) throw RuntimeError("Failed to retrieve DAQ device list"); - auto logger = logging.get("node:uldaq"); + auto logger = Log::get("node:uldaq"); logger->info("Found {} DAQ devices", num_devs); for (unsigned i = 0; i < num_devs; i++) { DaqDeviceDescriptor *desc = &descriptors[i]; diff --git a/lib/nodes/webrtc/peer_connection.cpp b/lib/nodes/webrtc/peer_connection.cpp index f8b50be73..79e83dddd 100644 --- a/lib/nodes/webrtc/peer_connection.cpp +++ b/lib/nodes/webrtc/peer_connection.cpp @@ -32,7 +32,7 @@ PeerConnection::PeerConnection(const std::string &server, rtc::DataChannelInit d) : web(w), extraServers({}), dataChannelInit(d), defaultConfig(cfg), conn(nullptr), chan(nullptr), out_signals(out_signals), - logger(logging.get("webrtc:pc")), stopStartup(false), + logger(Log::get("webrtc:pc")), stopStartup(false), warnNotConnected(false), standby(true), first(false), firstID(INT_MAX), secondID(INT_MAX), onMessageCallback(nullptr) { client = std::make_shared(server, session, peer, web); diff --git a/lib/nodes/webrtc/signaling_client.cpp b/lib/nodes/webrtc/signaling_client.cpp index f6d4cb53f..b00b9f5bc 100644 --- a/lib/nodes/webrtc/signaling_client.cpp +++ b/lib/nodes/webrtc/signaling_client.cpp @@ -24,7 +24,7 @@ SignalingClient::SignalingClient(const std::string &server, const std::string &session, const std::string &peer, Web *w) : retry_count(0), web(w), running(false), - logger(logging.get("webrtc:signal")) { + logger(Log::get("webrtc:signal")) { int ret; const char *prot, *a, *p; diff --git a/lib/nodes/websocket.cpp b/lib/nodes/websocket.cpp index f63178c9d..39da203fa 100644 --- a/lib/nodes/websocket.cpp +++ b/lib/nodes/websocket.cpp @@ -29,7 +29,7 @@ static std::list static std::mutex connections_lock; static villas::node::Web *web; -static villas::Logger logger = logging.get("websocket"); +static villas::Logger logger = Log::get("websocket"); // Forward declarations static NodeCompatType p; diff --git a/lib/path.cpp b/lib/path.cpp index 904fedafb..e9ff9bcbd 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -113,7 +113,7 @@ Path::Path() rate(0), // Disabled affinity(0), enabled(true), poll(-1), reversed(false), builtin(true), original_sequence_no(-1), queuelen(DEFAULT_QUEUE_LENGTH), - logger(logging.get(fmt::format("path:{}", id++))) { + logger(Log::get(fmt::format("path:{}", id++))) { uuid_clear(uuid); pool.state = State::DESTROYED; diff --git a/lib/pool.cpp b/lib/pool.cpp index f3c4c0465..612108a79 100644 --- a/lib/pool.cpp +++ b/lib/pool.cpp @@ -17,7 +17,7 @@ using namespace villas; int villas::node::pool_init(struct Pool *p, size_t cnt, size_t blocksz, struct memory::Type *m) { int ret; - auto logger = logging.get("pool"); + auto logger = Log::get("pool"); // Make sure that we use a block size that is aligned to the size of a cache line p->alignment = kernel::getCachelineSize(); diff --git a/lib/queue.cpp b/lib/queue.cpp index eb1f96407..966d62eb3 100644 --- a/lib/queue.cpp +++ b/lib/queue.cpp @@ -46,7 +46,7 @@ int villas::node::queue_init(struct CQueue *q, size_t size, size_t old_size = size; size = LOG2_CEIL(size); - auto logger = logging.get("queue"); + auto logger = Log::get("queue"); logger->warn("A queue size was changed from {} to {}", old_size, size); } diff --git a/lib/sample.cpp b/lib/sample.cpp index c8d81f9ba..d865f6f14 100644 --- a/lib/sample.cpp +++ b/lib/sample.cpp @@ -311,7 +311,15 @@ void villas::node::sample_data_insert(struct Sample *smp, void villas::node::sample_data_remove(struct Sample *smp, size_t offset, size_t len) { - size_t sz = sizeof(smp->data[0]) * len; + if (offset + len > smp->length) { + if (offset > smp->length) { + return; + } else { + len = smp->length - offset; + } + } + + size_t sz = sizeof(smp->data[0]) * (smp->length - offset - len); memmove(&smp->data[offset], &smp->data[offset + len], sz); diff --git a/lib/stats.cpp b/lib/stats.cpp index f4f8dad06..7a0aa780c 100644 --- a/lib/stats.cpp +++ b/lib/stats.cpp @@ -93,7 +93,7 @@ enum Stats::Type Stats::lookupType(const std::string &str) { throw std::invalid_argument("Invalid stats type"); } -Stats::Stats(int buckets, int warmup) : logger(logging.get("stats")) { +Stats::Stats(int buckets, int warmup) : logger(Log::get("stats")) { for (auto m : metrics) { histograms.emplace(std::piecewise_construct, std::forward_as_tuple(m.first), std::forward_as_tuple(buckets, warmup)); @@ -133,7 +133,7 @@ void Stats::printHeader(enum Format fmt) { void Stats::setupTable() { if (!table) { - auto logger = logging.get("stats"); + auto logger = Log::get("stats"); table = std::make_shared(logger, columns); } } diff --git a/lib/super_node.cpp b/lib/super_node.cpp index 32a4999e8..a4284bddb 100644 --- a/lib/super_node.cpp +++ b/lib/super_node.cpp @@ -56,7 +56,7 @@ SuperNode::SuperNode() kernel::nl::init(); // Fill link cache #endif // WITH_NETEM - logger = logging.get("super_node"); + logger = Log::get("super_node"); } void SuperNode::parse(const std::string &u) { @@ -111,7 +111,7 @@ void SuperNode::parse(json_t *root) { #endif // WITH_WEB if (json_logging) - logging.parse(json_logging); + Log::getInstance().parse(json_logging); // Parse nodes if (json_nodes) { diff --git a/lib/usb.cpp b/lib/usb.cpp index 6c3f3dd79..1580e24ef 100644 --- a/lib/usb.cpp +++ b/lib/usb.cpp @@ -78,7 +78,7 @@ struct libusb_context *villas::usb::init() { int ret; struct libusb_context *ctx; - logger = logging.get("usb"); + logger = Log::get("usb"); ret = libusb_init(&ctx); if (ret) diff --git a/lib/web.cpp b/lib/web.cpp index b3e6d2251..b3b2be629 100644 --- a/lib/web.cpp +++ b/lib/web.cpp @@ -101,7 +101,7 @@ void Web::lwsLogger(int lws_lvl, const char *msg) { if (strstr(msg, "Unable to open") == msg) lws_lvl = LLL_WARN; - Logger logger = logging.get("lws"); + Logger logger = Log::get("lws"); switch (lws_lvl) { case LLL_ERR: @@ -162,9 +162,9 @@ void Web::worker() { } Web::Web(Api *a) - : state(State::INITIALIZED), logger(logging.get("web")), context(nullptr), + : state(State::INITIALIZED), logger(Log::get("web")), context(nullptr), vhost(nullptr), port(getuid() > 0 ? 8080 : 80), api(a) { - lws_set_log_level(lwsLogLevel(logging.getLevel()), lwsLogger); + lws_set_log_level(lwsLogLevel(Log::getInstance().getLevel()), lwsLogger); } Web::~Web() { diff --git a/src/villas-compare.cpp b/src/villas-compare.cpp index 71c0e6b6b..ef88da2b3 100644 --- a/src/villas-compare.cpp +++ b/src/villas-compare.cpp @@ -165,7 +165,7 @@ protected: exit(EXIT_SUCCESS); case 'd': - logging.setLevel(optarg); + Log::getInstance().setLevel(optarg); break; case 'h': diff --git a/src/villas-convert.cpp b/src/villas-convert.cpp index 89b28166e..944af0dba 100644 --- a/src/villas-convert.cpp +++ b/src/villas-convert.cpp @@ -88,7 +88,7 @@ protected: break; case 'd': - logging.setLevel(optarg); + Log::getInstance().setLevel(optarg); break; case 'h': diff --git a/src/villas-hook.cpp b/src/villas-hook.cpp index 0a3985b91..d9b0c868b 100644 --- a/src/villas-hook.cpp +++ b/src/villas-hook.cpp @@ -144,7 +144,7 @@ protected: goto check; case 'd': - logging.setLevel(optarg); + Log::getInstance().setLevel(optarg); break; case 'o': diff --git a/src/villas-node.cpp b/src/villas-node.cpp index 5bb432fc9..3a13d46e3 100644 --- a/src/villas-node.cpp +++ b/src/villas-node.cpp @@ -155,7 +155,7 @@ protected: exit(EXIT_SUCCESS); case 'd': - logging.setLevel(optarg); + Log::getInstance().setLevel(optarg); break; case 'C': diff --git a/src/villas-pipe.cpp b/src/villas-pipe.cpp index 68f375f1b..053d90ba2 100644 --- a/src/villas-pipe.cpp +++ b/src/villas-pipe.cpp @@ -57,7 +57,7 @@ public: : node(n), formatter(fmt), stop(false), enabled(en), limit(lim), count(0) { auto loggerName = fmt::format("pipe:{}", name); - logger = logging.get(loggerName); + logger = Log::get(loggerName); // Initialize memory unsigned pool_size = @@ -372,7 +372,7 @@ protected: break; case 'd': - logging.setLevel(optarg); + Log::getInstance().setLevel(optarg); break; case 'h': @@ -404,7 +404,7 @@ protected: json_t *json_format; json_error_t err; - logger->info("Logging level: {}", logging.getLevelName()); + logger->info("Logging level: {}", Log::getInstance().getLevelName()); if (!uri.empty()) sn.parse(uri); diff --git a/src/villas-relay.cpp b/src/villas-relay.cpp index 8d2a71f14..d9e134ebe 100644 --- a/src/villas-relay.cpp +++ b/src/villas-relay.cpp @@ -36,7 +36,7 @@ namespace tools { RelaySession::RelaySession(Relay *r, Identifier sid) : identifier(sid), connects(0) { auto loggerName = fmt::format("relay:{}", sid); - logger = villas::logging.get(loggerName); + logger = villas::Log::get(loggerName); logger->info("Session created: {}", identifier); @@ -76,7 +76,7 @@ RelaySession *RelaySession::get(Relay *r, lws *wsi) { return rs; } else { - auto logger = logging.get("villas-relay"); + auto logger = Log::get("villas-relay"); logger->info("Found existing session: {}", sid); return it->second; @@ -198,7 +198,8 @@ Relay::Relay(int argc, char *argv[]) throw RuntimeError("Failed to initialize memory"); // Initialize logging - lws_set_log_level(Web::lwsLogLevel(logging.getLevel()), Web::lwsLogger); + lws_set_log_level(Web::lwsLogLevel(Log::getInstance().getLevel()), + Web::lwsLogger); protocols = {{.name = "http", .callback = lws_callback_http_dummy, @@ -354,8 +355,9 @@ void Relay::parse() { while ((c = getopt(argc, argv, "hVp:P:ld:u:")) != -1) { switch (c) { case 'd': - logging.setLevel(optarg); - lws_set_log_level(Web::lwsLogLevel(logging.getLevel()), Web::lwsLogger); + Log::getInstance().setLevel(optarg); + lws_set_log_level(Web::lwsLogLevel(Log::getInstance().getLevel()), + Web::lwsLogger); break; case 'p': @@ -422,7 +424,7 @@ int Relay::main() { ctx_info.mounts = &mount; ctx_info.user = (void *)this; - auto lwsLogger = logging.get("lws"); + auto lwsLogger = Log::get("lws"); context = lws_create_context(&ctx_info); if (context == nullptr) { diff --git a/src/villas-signal.cpp b/src/villas-signal.cpp index 9dc7afac2..82e20548d 100644 --- a/src/villas-signal.cpp +++ b/src/villas-signal.cpp @@ -159,7 +159,7 @@ protected: goto check; case 'd': - logging.setLevel(optarg); + Log::getInstance().setLevel(optarg); break; case 'V': diff --git a/tests/unit/format.cpp b/tests/unit/format.cpp index c05590ccf..d788dc9bc 100644 --- a/tests/unit/format.cpp +++ b/tests/unit/format.cpp @@ -240,7 +240,7 @@ ParameterizedTest(Param *p, format, lowlevel, .init = init_memory) { char buf[8192]; size_t wbytes, rbytes; - Logger logger = logging.get("test:format:lowlevel"); + Logger logger = Log::get("test:format:lowlevel"); logger->info("Running test for format={}, cnt={}", p->fmt, p->cnt); @@ -330,7 +330,7 @@ ParameterizedTest(Param *p, format, highlevel, .init = init_memory) { int ret, cnt; char *retp; - Logger logger = logging.get("test:format:highlevel"); + Logger logger = Log::get("test:format:highlevel"); logger->info("Running test for format={}, cnt={}", p->fmt, p->cnt); diff --git a/tests/unit/pool.cpp b/tests/unit/pool.cpp index de98f8a88..c78550f72 100644 --- a/tests/unit/pool.cpp +++ b/tests/unit/pool.cpp @@ -46,7 +46,7 @@ ParameterizedTest(struct param *p, pool, basic, .init = init_memory) { struct Pool pool; void *ptr, *ptrs[p->pool_size]; - logging.setLevel("trace"); + Log::getInstance().setLevel("trace"); if (!utils::isPrivileged() && p->mt == &memory::mmap_hugetlb) cr_skip_test("Skipping memory_mmap_hugetlb tests allocatpr because we are " diff --git a/tests/unit/queue.cpp b/tests/unit/queue.cpp index 4c21fef4c..c3f213fba 100644 --- a/tests/unit/queue.cpp +++ b/tests/unit/queue.cpp @@ -260,7 +260,7 @@ ParameterizedTest(struct param *p, queue, multi_threaded, .timeout = 20, int ret, cycpop; struct Tsc tsc; - Logger logger = logging.get("test:queue:multi_threaded"); + Logger logger = Log::get("test:queue:multi_threaded"); if (!utils::isPrivileged() && p->mt == &memory::mmap_hugetlb) cr_skip_test("Skipping memory_mmap_hugetlb tests allocatpr because we are " diff --git a/tests/unit/queue_signalled.cpp b/tests/unit/queue_signalled.cpp index 3f440e523..ca831eb63 100644 --- a/tests/unit/queue_signalled.cpp +++ b/tests/unit/queue_signalled.cpp @@ -93,15 +93,15 @@ void *polled_consumer(void *ctx) { ParameterizedTestParameters(queue_signalled, simple) { static struct param params[] = { - {QueueSignalledMode::AUTO, 0, false}, - {QueueSignalledMode::PTHREAD, 0, false}, - {QueueSignalledMode::PTHREAD, 0, false}, - {QueueSignalledMode::PTHREAD, (int)QueueSignalledFlags::PROCESS_SHARED, - false}, - {QueueSignalledMode::POLLING, 0, false}, + {QueueSignalledMode::AUTO, 0, false}, + {QueueSignalledMode::PTHREAD, 0, false}, + {QueueSignalledMode::PTHREAD, 0, false}, + {QueueSignalledMode::PTHREAD, (int)QueueSignalledFlags::PROCESS_SHARED, + false}, + {QueueSignalledMode::POLLING, 0, false}, #if defined(__linux__) && defined(HAS_EVENTFD) - {QueueSignalledMode::EVENTFD, 0, false}, - {QueueSignalledMode::EVENTFD, 0, true} + {QueueSignalledMode::EVENTFD, 0, false}, + {QueueSignalledMode::EVENTFD, 0, true} #endif }; diff --git a/tools/hwdef-parse.py b/tools/hwdef-parse.py index aa87c6619..510ef0e48 100755 --- a/tools/hwdef-parse.py +++ b/tools/hwdef-parse.py @@ -46,6 +46,7 @@ whitelist = [ ["xilinx.com", "ip", "xdma"], ["xilinx.com", "ip", "axi_iic"], ["xilinx.com", "module_ref", "dinoif_fast"], + ["xilinx.com", "module_ref", "dinoif_fast_nologic"], ["xilinx.com", "module_ref", "dinoif_dac"], ["xilinx.com", "module_ref", "axi_pcie_intc"], ["xilinx.com", "module_ref", "registerif"], @@ -175,6 +176,8 @@ for module in modules: value = int(value, 0) except ValueError: pass + except TypeError: + pass p[name] = value