From f703aec64fc2d6dc7e30d5cc0b2617f770c2b9f1 Mon Sep 17 00:00:00 2001 From: Nikita Kosenkov Date: Mon, 29 Aug 2022 18:26:59 +0300 Subject: Refactor CPU class --- include/cpu.hpp | 33 ++++++++++++----------------- src/cpu.cpp | 66 ++++++++++++++++++--------------------------------------- 2 files changed, 35 insertions(+), 64 deletions(-) diff --git a/include/cpu.hpp b/include/cpu.hpp index 4f31c93..231d5f4 100644 --- a/include/cpu.hpp +++ b/include/cpu.hpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace phosphor { @@ -37,8 +38,9 @@ using asset = sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Ass using location = sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::LocationCode; using connector = sdbusplus::xyz::openbmc_project::Inventory::Connector::server::Slot; using processor = sdbusplus::xyz::openbmc_project::Inventory::Item::server::Cpu; -using Item = sdbusplus::xyz::openbmc_project::Inventory::server::Item; +using item = sdbusplus::xyz::openbmc_project::Inventory::server::Item; using association = sdbusplus::xyz::openbmc_project::Association::server::Definitions; +using operstatus = sdbusplus::xyz::openbmc_project::State::Decorator::server::OperationalStatus; // Definition follow smbios spec DSP0134 3.0.0 static const std::map familyTable = { @@ -95,8 +97,9 @@ static const std::array, 16> std::nullopt, std::nullopt}; -class Cpu : sdbusplus::server::object_t +class Cpu : + sdbusplus::server::object_t { public: Cpu() = delete; @@ -110,19 +113,13 @@ class Cpu : sdbusplus::server::object_t(bus, objPath.c_str()), + Item, association, operstatus>(bus, objPath.c_str()), cpuNum(cpuId), regionS(region) { - processorInfoUpdate(); + infoUpdate(); } - void processorInfoUpdate(void); - - std::string processorSocket(std::string value); - uint32_t processorId(uint32_t value); - uint16_t processorMaxSpeed(uint16_t value); - uint16_t processorCoreCount(uint16_t value); - uint16_t processorThreadCount(uint16_t value); + void infoUpdate(void); private: /** @brief Path of the group instance */ @@ -163,13 +160,11 @@ class Cpu : sdbusplus::server::object_t::const_iterator it = familyTable.find(value); if (it == familyTable.end()) @@ -55,7 +50,7 @@ void Cpu::cpuFamily(uint8_t value) } } -void Cpu::cpuManufacturer(uint8_t positionNum, uint8_t structLen, +void Cpu::manufacturer(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn) { std::string result; @@ -65,12 +60,7 @@ void Cpu::cpuManufacturer(uint8_t positionNum, uint8_t structLen, asset::manufacturer(result); } -uint32_t Cpu::processorId(uint32_t value) -{ - return processor::id(value); -} - -void Cpu::cpuVersion(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn) +void Cpu::version(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn) { std::string result; @@ -80,12 +70,7 @@ void Cpu::cpuVersion(uint8_t positionNum, uint8_t structLen, uint8_t *dataIn) rev::version(result); } -uint16_t Cpu::processorMaxSpeed(uint16_t value) -{ - return processor::maxSpeedInMhz(value); -} - -void Cpu::cpuCharacteristics(uint16_t value) +void Cpu::characteristics(uint16_t value) { std::vector result; std::optional cap; @@ -105,18 +90,8 @@ void Cpu::cpuCharacteristics(uint16_t value) processor::characteristics(result); } -uint16_t Cpu::processorCoreCount(uint16_t value) -{ - return processor::coreCount(value); -} - -uint16_t Cpu::processorThreadCount(uint16_t value) -{ - return processor::threadCount(value); -} - static constexpr uint8_t maxOldVersionCount = 0xff; -void Cpu::processorInfoUpdate(void) +void Cpu::infoUpdate(void) { uint8_t *dataIn = regionS[0].regionData; @@ -146,37 +121,38 @@ void Cpu::processorInfoUpdate(void) if ((cpuInfo->status & socketPopulatedMask) == 0) { // Don't attempt to fill in any other details if the CPU is not present. - present(false); + item::present(false); return; } - present(true); - - cpuSocket(cpuInfo->socketDesignation, cpuInfo->length, dataIn); // offset 4h - cpuFamily(cpuInfo->family); // offset 6h - cpuManufacturer(cpuInfo->manufacturer, cpuInfo->length, dataIn);// offset 7h - processorId(cpuInfo->id); // offset 8h - cpuVersion(cpuInfo->version, cpuInfo->length, dataIn); // offset 10h - processorMaxSpeed(cpuInfo->maxSpeed); // offset 14h + item::present(true); + operstatus::functional(true); + + socket(cpuInfo->socketDesignation, cpuInfo->length, dataIn); // offset 4h + family(cpuInfo->family); // offset 6h + manufacturer(cpuInfo->manufacturer, cpuInfo->length, dataIn);// offset 7h + processor::id(cpuInfo->id); // offset 8h + version(cpuInfo->version, cpuInfo->length, dataIn); // offset 10h + processor::maxSpeedInMhz(cpuInfo->maxSpeed); // offset 14h if (cpuInfo->coreCount < maxOldVersionCount) // offset 23h or 2Ah { - processorCoreCount((uint16_t)cpuInfo->coreCount); + processor::coreCount((uint16_t)cpuInfo->coreCount); } else { - processorCoreCount(cpuInfo->coreCount2); + processor::coreCount(cpuInfo->coreCount2); } if (cpuInfo->threadCount < maxOldVersionCount) // offset 25h or 2Eh) { - processorThreadCount((uint16_t)cpuInfo->threadCount); + processor::coreCount((uint16_t)cpuInfo->threadCount); } else { - processorThreadCount(cpuInfo->threadCount2); + processor::coreCount(cpuInfo->threadCount2); } - cpuCharacteristics(cpuInfo->characteristics); // offset 26h + characteristics(cpuInfo->characteristics); // offset 26h } } // namespace smbios -- cgit v1.2.3