Normalize DMI memory slot name.

This commit is contained in:
XMRig 2021-01-29 04:23:50 +07:00
parent 9ca1a6129b
commit f68b105bd9
No known key found for this signature in database
GPG key ID: 446A53638BE94409
3 changed files with 31 additions and 3 deletions

View file

@ -155,7 +155,7 @@ static void print_memory(const Config *config)
if (memory.size()) { if (memory.size()) {
Log::print(WHITE_BOLD(" %-13s") "%s: " CYAN_BOLD("%" PRIu64) CYAN(" GB ") WHITE_BOLD("%s @ %" PRIu64 " MHz ") BLACK_BOLD("%s"), 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) { else if (printEmpty) {
Log::print(WHITE_BOLD(" %-13s") "%s: " BLACK_BOLD("<empty>"), "", memory.slot().data()); Log::print(WHITE_BOLD(" %-13s") "%s: " BLACK_BOLD("<empty>"), "", memory.slot().data());

View file

@ -20,17 +20,22 @@
#include "hw/dmi/DmiMemory.h" #include "hw/dmi/DmiMemory.h"
#include "3rdparty/fmt/format.h"
#include "3rdparty/rapidjson/document.h" #include "3rdparty/rapidjson/document.h"
#include "hw/dmi/DmiTools.h" #include "hw/dmi/DmiTools.h"
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <regex>
namespace xmrig { namespace xmrig {
static const char *kIdFormat = "DIMM_{}{}";
static inline uint16_t dmi_memory_device_width(uint16_t code) static inline uint16_t dmi_memory_device_width(uint16_t code)
{ {
return (code == 0xFFFF || code == 0) ? 0 : 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)); m_size = (1024ULL * (size & 0x7FFF) * ((size & 0x8000) ? 1 : 1024ULL));
} }
setId(dmi_string(h, 0x10), dmi_string(h, 0x11));
m_formFactor = h->data[0x0E]; m_formFactor = h->data[0x0E];
m_slot = dmi_string(h, 0x10);
m_bank = dmi_string(h, 0x11);
m_type = h->data[0x12]; m_type = h->data[0x12];
if (!m_size || h->length < 0x17) { if (!m_size || h->length < 0x17) {
@ -201,6 +206,7 @@ rapidjson::Value xmrig::DmiMemory::toJSON(rapidjson::Document &doc) const
auto &allocator = doc.GetAllocator(); auto &allocator = doc.GetAllocator();
Value out(kObjectType); Value out(kObjectType);
out.AddMember("id", id().toJSON(doc), allocator);
out.AddMember("slot", m_slot.toJSON(doc), allocator); out.AddMember("slot", m_slot.toJSON(doc), allocator);
out.AddMember("type", StringRef(type()), allocator); out.AddMember("type", StringRef(type()), allocator);
out.AddMember("form_factor", StringRef(formFactor()), allocator); out.AddMember("form_factor", StringRef(formFactor()), allocator);
@ -217,3 +223,21 @@ rapidjson::Value xmrig::DmiMemory::toJSON(rapidjson::Document &doc) const
return out; return out;
} }
#endif #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();
}
}
}

View file

@ -39,6 +39,7 @@ public:
inline bool isValid() const { return !m_slot.isEmpty(); } inline bool isValid() const { return !m_slot.isEmpty(); }
inline const String &bank() const { return m_bank; } 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 &product() const { return m_product; }
inline const String &slot() const { return m_slot; } inline const String &slot() const { return m_slot; }
inline const String &vendor() const { return m_vendor; } inline const String &vendor() const { return m_vendor; }
@ -57,7 +58,10 @@ public:
# endif # endif
private: private:
void setId(const char *slot, const char *bank);
String m_bank; String m_bank;
String m_id;
String m_product; String m_product;
String m_slot; String m_slot;
String m_vendor; String m_vendor;