From f68b105bd9d2fb2d8e963637770a813dbde7c701 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 29 Jan 2021 04:23:50 +0700 Subject: [PATCH] Normalize DMI memory slot name. --- src/Summary.cpp | 2 +- src/hw/dmi/DmiMemory.cpp | 28 ++++++++++++++++++++++++++-- src/hw/dmi/DmiMemory.h | 4 ++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Summary.cpp b/src/Summary.cpp index 39b37ac0f..6b12e62f3 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -155,7 +155,7 @@ static void print_memory(const Config *config) if (memory.size()) { Log::print(WHITE_BOLD(" %-13s") "%s: " CYAN_BOLD("%" PRIu64) CYAN(" GB ") WHITE_BOLD("%s @ %" PRIu64 " MHz ") BLACK_BOLD("%s"), - "", memory.slot().data(), memory.size() / oneGiB, memory.type(), memory.speed() / 1000000ULL, memory.product().data()); + "", memory.id().data(), memory.size() / oneGiB, memory.type(), memory.speed() / 1000000ULL, memory.product().data()); } else if (printEmpty) { Log::print(WHITE_BOLD(" %-13s") "%s: " BLACK_BOLD(""), "", memory.slot().data()); diff --git a/src/hw/dmi/DmiMemory.cpp b/src/hw/dmi/DmiMemory.cpp index 05af09624..480ad4b39 100644 --- a/src/hw/dmi/DmiMemory.cpp +++ b/src/hw/dmi/DmiMemory.cpp @@ -20,17 +20,22 @@ #include "hw/dmi/DmiMemory.h" +#include "3rdparty/fmt/format.h" #include "3rdparty/rapidjson/document.h" #include "hw/dmi/DmiTools.h" #include #include +#include namespace xmrig { +static const char *kIdFormat = "DIMM_{}{}"; + + static inline uint16_t dmi_memory_device_width(uint16_t code) { return (code == 0xFFFF || code == 0) ? 0 : code; @@ -143,9 +148,9 @@ xmrig::DmiMemory::DmiMemory(dmi_header *h) m_size = (1024ULL * (size & 0x7FFF) * ((size & 0x8000) ? 1 : 1024ULL)); } + setId(dmi_string(h, 0x10), dmi_string(h, 0x11)); + m_formFactor = h->data[0x0E]; - m_slot = dmi_string(h, 0x10); - m_bank = dmi_string(h, 0x11); m_type = h->data[0x12]; if (!m_size || h->length < 0x17) { @@ -201,6 +206,7 @@ rapidjson::Value xmrig::DmiMemory::toJSON(rapidjson::Document &doc) const auto &allocator = doc.GetAllocator(); Value out(kObjectType); + out.AddMember("id", id().toJSON(doc), allocator); out.AddMember("slot", m_slot.toJSON(doc), allocator); out.AddMember("type", StringRef(type()), allocator); out.AddMember("form_factor", StringRef(formFactor()), allocator); @@ -217,3 +223,21 @@ rapidjson::Value xmrig::DmiMemory::toJSON(rapidjson::Document &doc) const return out; } #endif + + +void xmrig::DmiMemory::setId(const char *slot, const char *bank) +{ + m_slot = slot; + m_bank = bank; + + std::cmatch cm; + if (std::regex_match(slot, cm, std::regex("^Channel([A-Z])-DIMM(\\d+)$"))) { + m_id = fmt::format(kIdFormat, cm.str(1), cm.str(2)).c_str(); + } + else if (std::regex_search(bank, cm, std::regex("CHANNEL ([A-Z])$"))) { + std::cmatch cm2; + if (std::regex_match(slot, cm2, std::regex("^DIMM (\\d+)$"))) { + m_id = fmt::format(kIdFormat, cm.str(1), cm2.str(1)).c_str(); + } + } +} diff --git a/src/hw/dmi/DmiMemory.h b/src/hw/dmi/DmiMemory.h index badee2cfd..589b3b907 100644 --- a/src/hw/dmi/DmiMemory.h +++ b/src/hw/dmi/DmiMemory.h @@ -39,6 +39,7 @@ public: inline bool isValid() const { return !m_slot.isEmpty(); } inline const String &bank() const { return m_bank; } + inline const String &id() const { return m_id.isNull() ? m_slot : m_id; } inline const String &product() const { return m_product; } inline const String &slot() const { return m_slot; } inline const String &vendor() const { return m_vendor; } @@ -57,7 +58,10 @@ public: # endif private: + void setId(const char *slot, const char *bank); + String m_bank; + String m_id; String m_product; String m_slot; String m_vendor;