#pragma once #include "Thresholds.hpp" #include "Utils.hpp" #include #include #include #include #include #include #include #include #include #include #include #include class IntelCPUSensor : public Sensor, public std::enable_shared_from_this { public: IntelCPUSensor(const std::string& path, const std::string& objectType, sdbusplus::asio::object_server& objectServer, std::shared_ptr& conn, boost::asio::io_context& io, const std::string& sensorName, std::vector&& thresholds, const std::string& configuration, int cpuId, bool show, double dtsOffset); ~IntelCPUSensor() override; static constexpr unsigned int sensorScaleFactor = 1000; static constexpr unsigned int sensorPollMs = 1000; static constexpr size_t warnAfterErrorCount = 10; static constexpr const char* labelTcontrol = "Tcontrol"; void setupRead(); private: sdbusplus::asio::object_server& objServer; boost::asio::streambuf readBuf; boost::asio::posix::stream_descriptor inputDev; boost::asio::steady_timer waitTimer; std::string nameTcontrol; std::string path; double privTcontrol; double dtsOffset; bool show; size_t pollTime; bool loggedInterfaceDown = false; uint8_t minMaxReadCounter{0}; int fd{}; void handleResponse(const boost::system::error_code& err); void checkThresholds() override; void updateMinMaxValues(); void restartRead(); }; extern boost::container::flat_map> gCpuSensors; // this is added to intelcpusensor.hpp to avoid having every sensor have to link // against libgpiod, if another sensor needs it we may move it to utils inline bool cpuIsPresent(const SensorBaseConfigMap& gpioConfig) { static boost::container::flat_map cpuPresence; auto findName = gpioConfig.find("Name"); if (findName == gpioConfig.end()) { return false; } std::string gpioName = std::visit(VariantToStringVisitor(), findName->second); auto findIndex = cpuPresence.find(gpioName); if (findIndex != cpuPresence.end()) { return findIndex->second; } bool activeHigh = true; auto findPolarity = gpioConfig.find("Polarity"); if (findPolarity != gpioConfig.end()) { if (std::string("Low") == std::visit(VariantToStringVisitor(), findPolarity->second)) { activeHigh = false; } } auto line = gpiod::find_line(gpioName); if (!line) { std::cerr << "Error requesting gpio: " << gpioName << "\n"; return false; } bool resp = false; try { line.request({"cpusensor", gpiod::line_request::DIRECTION_INPUT, activeHigh ? 0 : gpiod::line_request::FLAG_ACTIVE_LOW}); resp = (line.get_value() != 0); } catch (const std::system_error&) { std::cerr << "Error reading gpio: " << gpioName << "\n"; return false; } cpuPresence[gpioName] = resp; return resp; }