Commit 14dc3da8 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

log: remove static logger instances

parent 9bed48ae
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
using DistSink = std::shared_ptr<spdlog::sinks::dist_sink_mt>; using DistSink = std::shared_ptr<spdlog::sinks::dist_sink_mt>;
protected: protected:
Logger logger = logging.get("log"); Logger logger;
DistSink sinks; DistSink sinks;
Level level; Level level;
......
...@@ -96,9 +96,10 @@ class MemoryManager { ...@@ -96,9 +96,10 @@ class MemoryManager {
private: private:
// This is a singleton, so private constructor ... // This is a singleton, so private constructor ...
MemoryManager() : MemoryManager() :
memoryGraph("memory:graph"), memoryGraph("memory:graph")
logger(logging.get("memory:manager"))
{ {
logger = logging.get("memory:manager");
pathCheckFunc = [&](const MemoryGraph::Path& path) { pathCheckFunc = [&](const MemoryGraph::Path& path) {
return this->pathCheck(path); return this->pathCheck(path);
}; };
......
...@@ -42,10 +42,10 @@ namespace villas { ...@@ -42,10 +42,10 @@ namespace villas {
namespace kernel { namespace kernel {
namespace rt { namespace rt {
static Logger logger = logging.get("kernel:rt");
int init(int priority, int affinity) int init(int priority, int affinity)
{ {
Logger logger = logging.get("kernel:rt");
logger->info("Initialize sub-system"); logger->info("Initialize sub-system");
#ifdef __linux__ #ifdef __linux__
...@@ -96,6 +96,8 @@ int setAffinity(int affinity) ...@@ -96,6 +96,8 @@ int setAffinity(int affinity)
char isolcpus[255]; char isolcpus[255];
int is_isol, ret; int is_isol, ret;
Logger logger = logging.get("kernel:rt");
/* Pin threads to CPUs by setting the affinity */ /* Pin threads to CPUs by setting the affinity */
CpuSet cset_pin, cset_isol, cset_non_isol; CpuSet cset_pin, cset_isol, cset_non_isol;
...@@ -131,6 +133,8 @@ int setPriority(int priority) ...@@ -131,6 +133,8 @@ int setPriority(int priority)
.sched_priority = priority .sched_priority = priority
}; };
Logger logger = logging.get("kernel:rt");
ret = sched_setscheduler(0, SCHED_FIFO, &param); ret = sched_setscheduler(0, SCHED_FIFO, &param);
if (ret) if (ret)
throw SystemError("Failed to set real time priority"); throw SystemError("Failed to set real time priority");
......
...@@ -46,8 +46,6 @@ ...@@ -46,8 +46,6 @@
using namespace villas; using namespace villas;
static Logger logger = logging.get("kernel:vfio");
static const char *vfio_pci_region_names[] = { static const char *vfio_pci_region_names[] = {
"PCI_BAR0", // VFIO_PCI_BAR0_REGION_INDEX, "PCI_BAR0", // VFIO_PCI_BAR0_REGION_INDEX,
"PCI_BAR1", // VFIO_PCI_BAR1_REGION_INDEX, "PCI_BAR1", // VFIO_PCI_BAR1_REGION_INDEX,
...@@ -75,6 +73,8 @@ VfioContainer::VfioContainer() ...@@ -75,6 +73,8 @@ VfioContainer::VfioContainer()
: iova_next(0) : iova_next(0)
{ {
Logger logger = logging.get("kernel:vfio");
static constexpr const char* requiredKernelModules[] = { static constexpr const char* requiredKernelModules[] = {
"vfio", "vfio_pci", "vfio_iommu_type1" "vfio", "vfio_pci", "vfio_iommu_type1"
}; };
...@@ -133,6 +133,8 @@ VfioContainer::VfioContainer() ...@@ -133,6 +133,8 @@ VfioContainer::VfioContainer()
VfioContainer::~VfioContainer() VfioContainer::~VfioContainer()
{ {
Logger logger = logging.get("kernel:vfio");
logger->debug("Clean up container with fd {}", fd); logger->debug("Clean up container with fd {}", fd);
/* Release memory and close fds */ /* Release memory and close fds */
...@@ -157,6 +159,8 @@ VfioContainer::create() ...@@ -157,6 +159,8 @@ VfioContainer::create()
void void
VfioContainer::dump() VfioContainer::dump()
{ {
Logger logger = logging.get("kernel:vfio");
logger->info("File descriptor: {}", fd); logger->info("File descriptor: {}", fd);
logger->info("Version: {}", version); logger->info("Version: {}", version);
logger->info("Extensions: 0x{:x}", extensions); logger->info("Extensions: 0x{:x}", extensions);
...@@ -210,6 +214,8 @@ VfioContainer::dump() ...@@ -210,6 +214,8 @@ VfioContainer::dump()
VfioDevice& VfioDevice&
VfioContainer::attachDevice(const char* name, int index) VfioContainer::attachDevice(const char* name, int index)
{ {
Logger logger = logging.get("kernel:vfio");
VfioGroup& group = getOrAttachGroup(index); VfioGroup& group = getOrAttachGroup(index);
auto device = std::make_unique<VfioDevice>(name, group); auto device = std::make_unique<VfioDevice>(name, group);
...@@ -285,6 +291,8 @@ VfioContainer::attachDevice(const pci_device* pdev) ...@@ -285,6 +291,8 @@ VfioContainer::attachDevice(const pci_device* pdev)
char name[32]; char name[32];
static constexpr const char* kernelDriver = "vfio-pci"; static constexpr const char* kernelDriver = "vfio-pci";
Logger logger = logging.get("kernel:vfio");
/* Load PCI bus driver for VFIO */ /* Load PCI bus driver for VFIO */
if (kernel_module_load("vfio_pci")) { if (kernel_module_load("vfio_pci")) {
logger->error("Failed to load kernel driver: vfio_pci"); logger->error("Failed to load kernel driver: vfio_pci");
...@@ -333,7 +341,9 @@ VfioContainer::memoryMap(uintptr_t virt, uintptr_t phys, size_t length) ...@@ -333,7 +341,9 @@ VfioContainer::memoryMap(uintptr_t virt, uintptr_t phys, size_t length)
{ {
int ret; int ret;
if(not hasIommu) { Logger logger = logging.get("kernel:vfio");
if (not hasIommu) {
logger->error("DMA mapping not supported without IOMMU"); logger->error("DMA mapping not supported without IOMMU");
return UINTPTR_MAX; return UINTPTR_MAX;
} }
...@@ -382,9 +392,10 @@ VfioContainer::memoryUnmap(uintptr_t phys, size_t length) ...@@ -382,9 +392,10 @@ VfioContainer::memoryUnmap(uintptr_t phys, size_t length)
{ {
int ret; int ret;
if(not hasIommu) { Logger logger = logging.get("kernel:vfio");
if (not hasIommu)
return true; return true;
}
struct vfio_iommu_type1_dma_unmap dmaUnmap; struct vfio_iommu_type1_dma_unmap dmaUnmap;
dmaUnmap.argsz = sizeof(struct vfio_iommu_type1_dma_unmap); dmaUnmap.argsz = sizeof(struct vfio_iommu_type1_dma_unmap);
...@@ -405,8 +416,10 @@ VfioContainer::memoryUnmap(uintptr_t phys, size_t length) ...@@ -405,8 +416,10 @@ VfioContainer::memoryUnmap(uintptr_t phys, size_t length)
VfioGroup& VfioGroup&
VfioContainer::getOrAttachGroup(int index) VfioContainer::getOrAttachGroup(int index)
{ {
Logger logger = logging.get("kernel:vfio");
// search if group with index already exists // search if group with index already exists
for(auto& group : groups) { for (auto& group : groups) {
if(group->index == index) { if(group->index == index) {
return *group; return *group;
} }
...@@ -414,7 +427,7 @@ VfioContainer::getOrAttachGroup(int index) ...@@ -414,7 +427,7 @@ VfioContainer::getOrAttachGroup(int index)
// group not yet part of this container, so acquire ownership // group not yet part of this container, so acquire ownership
auto group = VfioGroup::attach(*this, index); auto group = VfioGroup::attach(*this, index);
if(not group) { if (not group) {
logger->error("Failed to attach to IOMMU group: {}", index); logger->error("Failed to attach to IOMMU group: {}", index);
throw std::exception(); throw std::exception();
} else { } else {
...@@ -430,6 +443,8 @@ VfioContainer::getOrAttachGroup(int index) ...@@ -430,6 +443,8 @@ VfioContainer::getOrAttachGroup(int index)
VfioDevice::~VfioDevice() VfioDevice::~VfioDevice()
{ {
Logger logger = logging.get("kernel:vfio");
logger->debug("Clean up device {} with fd {}", this->name, this->fd); logger->debug("Clean up device {} with fd {}", this->name, this->fd);
for(auto& region : regions) { for(auto& region : regions) {
...@@ -476,6 +491,8 @@ VfioDevice::regionUnmap(size_t index) ...@@ -476,6 +491,8 @@ VfioDevice::regionUnmap(size_t index)
int ret; int ret;
struct vfio_region_info *r = &regions[index]; struct vfio_region_info *r = &regions[index];
Logger logger = logging.get("kernel:vfio");
if (!mappings[index]) if (!mappings[index])
return false; /* was not mapped */ return false; /* was not mapped */
...@@ -494,6 +511,8 @@ VfioDevice::regionUnmap(size_t index) ...@@ -494,6 +511,8 @@ VfioDevice::regionUnmap(size_t index)
size_t size_t
VfioDevice::regionGetSize(size_t index) 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()); logger->error("Index out of range: {} >= {}", index, regions.size());
throw std::out_of_range("Index out of range"); throw std::out_of_range("Index out of range");
...@@ -533,6 +552,8 @@ VfioDevice::pciEnable() ...@@ -533,6 +552,8 @@ VfioDevice::pciEnable()
bool bool
VfioDevice::pciHotReset() VfioDevice::pciHotReset()
{ {
Logger logger = logging.get("kernel:vfio");
/* Check if this is really a vfio-pci device */ /* Check if this is really a vfio-pci device */
if (not isVfioPciDevice()) if (not isVfioPciDevice())
return false; return false;
...@@ -722,6 +743,8 @@ VfioDevice::isVfioPciDevice() const ...@@ -722,6 +743,8 @@ VfioDevice::isVfioPciDevice() const
VfioGroup::~VfioGroup() VfioGroup::~VfioGroup()
{ {
Logger logger = logging.get("kernel:vfio");
logger->debug("Clean up group {} with fd {}", this->index, this->fd); logger->debug("Clean up group {} with fd {}", this->index, this->fd);
/* Release memory and close fds */ /* Release memory and close fds */
...@@ -746,6 +769,8 @@ VfioGroup::~VfioGroup() ...@@ -746,6 +769,8 @@ VfioGroup::~VfioGroup()
std::unique_ptr<VfioGroup> std::unique_ptr<VfioGroup>
VfioGroup::attach(VfioContainer& container, int groupIndex) VfioGroup::attach(VfioContainer& container, int groupIndex)
{ {
Logger logger = logging.get("kernel:vfio");
std::unique_ptr<VfioGroup> group { new VfioGroup(groupIndex) }; std::unique_ptr<VfioGroup> group { new VfioGroup(groupIndex) };
group->container = &container; group->container = &container;
......
...@@ -37,7 +37,9 @@ Log villas::logging; ...@@ -37,7 +37,9 @@ Log villas::logging;
Log::Log(Level lvl) : Log::Log(Level lvl) :
level(lvl) level(lvl)
{ } {
logger = logging.get("log");
}
void Log::init() void Log::init()
{ {
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
using namespace villas; using namespace villas;
Logger logger = logging.get("default");
int log_get_width() int log_get_width()
{ {
return logging.getWidth(); return logging.getWidth();
...@@ -46,6 +44,8 @@ void debug(long long, const char *fmt, ...) ...@@ -46,6 +44,8 @@ void debug(long long, const char *fmt, ...)
vasprintf(&buf, fmt, ap); vasprintf(&buf, fmt, ap);
va_end(ap); va_end(ap);
Logger logger = logging.get("default");
logger->debug(buf); logger->debug(buf);
free(buf); free(buf);
...@@ -61,6 +61,8 @@ void info(const char *fmt, ...) ...@@ -61,6 +61,8 @@ void info(const char *fmt, ...)
vasprintf(&buf, fmt, ap); vasprintf(&buf, fmt, ap);
va_end(ap); va_end(ap);
Logger logger = logging.get("default");
logger->info(buf); logger->info(buf);
free(buf); free(buf);
...@@ -76,6 +78,8 @@ void warning(const char *fmt, ...) ...@@ -76,6 +78,8 @@ void warning(const char *fmt, ...)
vasprintf(&buf, fmt, ap); vasprintf(&buf, fmt, ap);
va_end(ap); va_end(ap);
Logger logger = logging.get("default");
logger->warn(buf); logger->warn(buf);
free(buf); free(buf);
...@@ -91,6 +95,8 @@ void stats(const char *fmt, ...) ...@@ -91,6 +95,8 @@ void stats(const char *fmt, ...)
vasprintf(&buf, fmt, ap); vasprintf(&buf, fmt, ap);
va_end(ap); va_end(ap);
Logger logger = logging.get("default");
logger->info(buf); logger->info(buf);
free(buf); free(buf);
...@@ -106,6 +112,8 @@ void error(const char *fmt, ...) ...@@ -106,6 +112,8 @@ void error(const char *fmt, ...)
vasprintf(&buf, fmt, ap); vasprintf(&buf, fmt, ap);
va_end(ap); va_end(ap);
Logger logger = logging.get("default");
logger->error(buf); logger->error(buf);
free(buf); free(buf);
...@@ -124,6 +132,8 @@ void serror(const char *fmt, ...) ...@@ -124,6 +132,8 @@ void serror(const char *fmt, ...)
vasprintf(&buf, fmt, ap); vasprintf(&buf, fmt, ap);
va_end(ap); va_end(ap);
Logger logger = logging.get("default");
logger->error(buf); logger->error(buf);
free(buf); free(buf);
...@@ -142,6 +152,8 @@ void jerror(json_error_t *err, const char *fmt, ...) ...@@ -142,6 +152,8 @@ void jerror(json_error_t *err, const char *fmt, ...)
vasprintf(&buf, fmt, ap); vasprintf(&buf, fmt, ap);
va_end(ap); va_end(ap);
Logger logger = logging.get("default");
logger->error("{}:", buf); logger->error("{}:", buf);
logger->error(" {} in {}:{}:{}", err->text, err->source, err->line, err->column); logger->error(" {} in {}:{}:{}", err->text, err->source, err->line, err->column);
......
...@@ -190,6 +190,7 @@ MemoryTranslation& ...@@ -190,6 +190,7 @@ MemoryTranslation&
MemoryTranslation::operator+=(const MemoryTranslation& other) MemoryTranslation::operator+=(const MemoryTranslation& other)
{ {
Logger logger = logging.get("MemoryTranslation"); Logger logger = logging.get("MemoryTranslation");
// set level to debug to enable debug output // set level to debug to enable debug output
logger->set_level(spdlog::level::info); logger->set_level(spdlog::level::info);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment