cpusensor: Change cpusensor to intelcpusensor
cpusensor class is specifically used for Intel CPU. The name of this
class and the build option should be changed to reflect with their
role.
The patch set https://gerrit.openbmc.org/c/openbmc/openbmc/+/56096 is
required to prevent the build error in openbmc source.
Tested:
1. No build error.
Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Change-Id: I1f941fffa10222cdac908fd763dccc866ba0e8a6
diff --git a/include/CPUSensor.hpp b/include/IntelCPUSensor.hpp
similarity index 77%
rename from include/CPUSensor.hpp
rename to include/IntelCPUSensor.hpp
index f97c71c..844c861 100644
--- a/include/CPUSensor.hpp
+++ b/include/IntelCPUSensor.hpp
@@ -16,17 +16,19 @@
#include <variant>
#include <vector>
-class CPUSensor : public Sensor, public std::enable_shared_from_this<CPUSensor>
+class IntelCPUSensor :
+ public Sensor,
+ public std::enable_shared_from_this<IntelCPUSensor>
{
public:
- CPUSensor(const std::string& path, const std::string& objectType,
- sdbusplus::asio::object_server& objectServer,
- std::shared_ptr<sdbusplus::asio::connection>& conn,
- boost::asio::io_service& io, const std::string& sensorName,
- std::vector<thresholds::Threshold>&& thresholds,
- const std::string& configuration, int cpuId, bool show,
- double dtsOffset);
- ~CPUSensor() override;
+ IntelCPUSensor(const std::string& path, const std::string& objectType,
+ sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ boost::asio::io_service& io, const std::string& sensorName,
+ std::vector<thresholds::Threshold>&& 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;
@@ -53,10 +55,10 @@
void restartRead(void);
};
-extern boost::container::flat_map<std::string, std::shared_ptr<CPUSensor>>
+extern boost::container::flat_map<std::string, std::shared_ptr<IntelCPUSensor>>
gCpuSensors;
-// this is added to cpusensor.hpp to avoid having every sensor have to link
+// 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)
{
diff --git a/meson_options.txt b/meson_options.txt
index f9d25e7..d6a8b96 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,5 +1,5 @@
option('adc', type: 'feature', value: 'enabled', description: 'Enable ADC sensor.',)
-option('cpu', type: 'feature', value: 'enabled', description: 'Enable CPU sensor.',)
+option('intel-cpu', type: 'feature', value: 'enabled', description: 'Enable CPU sensor.',)
option('exit-air', type: 'feature', value: 'enabled', description: 'Enable exit air sensor.',)
option('fan', type: 'feature', value: 'enabled', description: 'Enable fan sensor.',)
option('hwmon-temp', type: 'feature', value: 'enabled', description: 'Enable HWMON temperature sensor.',)
diff --git a/service_files/meson.build b/service_files/meson.build
index 37bb261..5f5b78c 100644
--- a/service_files/meson.build
+++ b/service_files/meson.build
@@ -1,6 +1,6 @@
unit_files = [
['adc', 'xyz.openbmc_project.adcsensor.service'],
- ['cpu', 'xyz.openbmc_project.cpusensor.service'],
+ ['intel-cpu', 'xyz.openbmc_project.intelcpusensor.service'],
['exit-air', 'xyz.openbmc_project.exitairsensor.service'],
['fan', 'xyz.openbmc_project.fansensor.service'],
['hwmon-temp', 'xyz.openbmc_project.hwmontempsensor.service'],
diff --git a/service_files/xyz.openbmc_project.adcsensor.service b/service_files/xyz.openbmc_project.adcsensor.service
index 6ca7049..bc07f6e 100644
--- a/service_files/xyz.openbmc_project.adcsensor.service
+++ b/service_files/xyz.openbmc_project.adcsensor.service
@@ -1,7 +1,7 @@
[Unit]
Description=Adc Sensor
StopWhenUnneeded=false
-Before=xyz.openbmc_project.cpusensor.service
+Before=xyz.openbmc_project.intelcpusensor.service
Requires=xyz.openbmc_project.EntityManager.service
After=xyz.openbmc_project.EntityManager.service
diff --git a/service_files/xyz.openbmc_project.cpusensor.service b/service_files/xyz.openbmc_project.intelcpusensor.service
similarity index 78%
rename from service_files/xyz.openbmc_project.cpusensor.service
rename to service_files/xyz.openbmc_project.intelcpusensor.service
index 31b7bbd..8b5be69 100644
--- a/service_files/xyz.openbmc_project.cpusensor.service
+++ b/service_files/xyz.openbmc_project.intelcpusensor.service
@@ -1,5 +1,5 @@
[Unit]
-Description=CPU Sensor
+Description=Intel CPU Sensor
StopWhenUnneeded=false
Requires=xyz.openbmc_project.EntityManager.service
After=xyz.openbmc_project.EntityManager.service
@@ -8,7 +8,7 @@
Restart=always
RestartSec=5
StartLimitBurst=10
-ExecStart=/usr/bin/cpusensor
+ExecStart=/usr/bin/intelcpusensor
[Install]
WantedBy=multi-user.target
diff --git a/src/CPUSensor.cpp b/src/IntelCPUSensor.cpp
similarity index 85%
rename from src/CPUSensor.cpp
rename to src/IntelCPUSensor.cpp
index f40c96f..79a51ed 100644
--- a/src/CPUSensor.cpp
+++ b/src/IntelCPUSensor.cpp
@@ -16,7 +16,7 @@
#include <unistd.h>
-#include <CPUSensor.hpp>
+#include <IntelCPUSensor.hpp>
#include <Utils.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
@@ -34,19 +34,20 @@
#include <string>
#include <vector>
-CPUSensor::CPUSensor(const std::string& path, const std::string& objectType,
- sdbusplus::asio::object_server& objectServer,
- std::shared_ptr<sdbusplus::asio::connection>& conn,
- boost::asio::io_service& io, const std::string& sensorName,
- std::vector<thresholds::Threshold>&& thresholdsIn,
- const std::string& sensorConfiguration, int cpuId,
- bool show, double dtsOffset) :
+IntelCPUSensor::IntelCPUSensor(
+ const std::string& path, const std::string& objectType,
+ sdbusplus::asio::object_server& objectServer,
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ boost::asio::io_service& io, const std::string& sensorName,
+ std::vector<thresholds::Threshold>&& thresholdsIn,
+ const std::string& sensorConfiguration, int cpuId, bool show,
+ double dtsOffset) :
Sensor(escapeName(sensorName), std::move(thresholdsIn), sensorConfiguration,
objectType, false, false, 0, 0, conn, PowerState::on),
objServer(objectServer), inputDev(io), waitTimer(io),
nameTcontrol("Tcontrol CPU" + std::to_string(cpuId)), path(path),
privTcontrol(std::numeric_limits<double>::quiet_NaN()),
- dtsOffset(dtsOffset), show(show), pollTime(CPUSensor::sensorPollMs)
+ dtsOffset(dtsOffset), show(show), pollTime(IntelCPUSensor::sensorPollMs)
{
if (show)
@@ -92,7 +93,7 @@
setupPowerMatch(conn);
}
-CPUSensor::~CPUSensor()
+IntelCPUSensor::~IntelCPUSensor()
{
// close the input dev to cancel async operations
inputDev.close();
@@ -110,9 +111,9 @@
}
}
-void CPUSensor::restartRead(void)
+void IntelCPUSensor::restartRead(void)
{
- std::weak_ptr<CPUSensor> weakRef = weak_from_this();
+ std::weak_ptr<IntelCPUSensor> weakRef = weak_from_this();
waitTimer.expires_from_now(boost::posix_time::milliseconds(pollTime));
waitTimer.async_wait([weakRef](const boost::system::error_code& ec) {
if (ec == boost::asio::error::operation_aborted)
@@ -120,7 +121,7 @@
std::cerr << "Failed to reschedule\n";
return;
}
- std::shared_ptr<CPUSensor> self = weakRef.lock();
+ std::shared_ptr<IntelCPUSensor> self = weakRef.lock();
if (self)
{
@@ -129,7 +130,7 @@
});
}
-void CPUSensor::setupRead(void)
+void IntelCPUSensor::setupRead(void)
{
if (readingStateGood())
{
@@ -153,10 +154,10 @@
return;
}
- std::weak_ptr<CPUSensor> weakRef = weak_from_this();
+ std::weak_ptr<IntelCPUSensor> weakRef = weak_from_this();
inputDev.async_wait(boost::asio::posix::descriptor_base::wait_read,
[weakRef](const boost::system::error_code& ec) {
- std::shared_ptr<CPUSensor> self = weakRef.lock();
+ std::shared_ptr<IntelCPUSensor> self = weakRef.lock();
if (self)
{
@@ -165,7 +166,7 @@
});
}
-void CPUSensor::updateMinMaxValues(void)
+void IntelCPUSensor::updateMinMaxValues(void)
{
const boost::container::flat_map<
std::string,
@@ -192,7 +193,7 @@
const auto& [suffix, oldValue, dbusName] = vectorItem;
auto attrPath = boost::replace_all_copy(path, fileItem, suffix);
if (auto newVal =
- readFile(attrPath, CPUSensor::sensorScaleFactor))
+ readFile(attrPath, IntelCPUSensor::sensorScaleFactor))
{
updateProperty(sensorInterface, oldValue, *newVal,
dbusName);
@@ -215,7 +216,7 @@
}
}
-void CPUSensor::handleResponse(const boost::system::error_code& err)
+void IntelCPUSensor::handleResponse(const boost::system::error_code& err)
{
if ((err == boost::system::errc::bad_file_descriptor) ||
(err == boost::asio::error::misc_errors::not_found))
@@ -231,7 +232,7 @@
std::cerr << name << " interface down!\n";
loggedInterfaceDown = true;
}
- pollTime = static_cast<size_t>(CPUSensor::sensorPollMs) * 10U;
+ pollTime = static_cast<size_t>(IntelCPUSensor::sensorPollMs) * 10U;
markFunctional(false);
}
return;
@@ -261,7 +262,7 @@
try
{
rawValue = std::stod(response);
- double nvalue = rawValue / CPUSensor::sensorScaleFactor;
+ double nvalue = rawValue / IntelCPUSensor::sensorScaleFactor;
if (show)
{
@@ -286,9 +287,9 @@
if (!thresholds.empty())
{
std::vector<thresholds::Threshold> newThresholds;
- if (parseThresholdsFromAttr(newThresholds, path,
- CPUSensor::sensorScaleFactor,
- dtsOffset))
+ if (parseThresholdsFromAttr(
+ newThresholds, path,
+ IntelCPUSensor::sensorScaleFactor, dtsOffset))
{
if (!std::equal(thresholds.begin(), thresholds.end(),
newThresholds.begin(),
@@ -322,7 +323,7 @@
restartRead();
}
-void CPUSensor::checkThresholds(void)
+void IntelCPUSensor::checkThresholds(void)
{
if (show)
{
diff --git a/src/CPUSensorMain.cpp b/src/IntelCPUSensorMain.cpp
similarity index 98%
rename from src/CPUSensorMain.cpp
rename to src/IntelCPUSensorMain.cpp
index e9e6433..7ca6bc1 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/IntelCPUSensorMain.cpp
@@ -16,7 +16,7 @@
#include <fcntl.h>
-#include <CPUSensor.hpp>
+#include <IntelCPUSensor.hpp>
#include <Utils.hpp>
#include <VariantVisitors.hpp>
#include <boost/algorithm/string/predicate.hpp>
@@ -53,7 +53,8 @@
static constexpr bool debug = false;
-boost::container::flat_map<std::string, std::shared_ptr<CPUSensor>> gCpuSensors;
+boost::container::flat_map<std::string, std::shared_ptr<IntelCPUSensor>>
+ gCpuSensors;
boost::container::flat_map<std::string,
std::shared_ptr<sdbusplus::asio::dbus_interface>>
inventoryIfaces;
@@ -93,7 +94,7 @@
"xyz.openbmc_project.Configuration.";
static constexpr auto sensorTypes{std::to_array<const char*>({"XeonCPU"})};
static constexpr auto hiddenProps{std::to_array<const char*>(
- {CPUSensor::labelTcontrol, "Tthrottle", "Tjmax"})};
+ {IntelCPUSensor::labelTcontrol, "Tthrottle", "Tjmax"})};
void detectCpuAsync(
boost::asio::deadline_timer& pingTimer,
@@ -372,7 +373,7 @@
if (sensorThresholds.empty())
{
if (!parseThresholdsFromAttr(sensorThresholds, inputPathStr,
- CPUSensor::sensorScaleFactor,
+ IntelCPUSensor::sensorScaleFactor,
dtsOffset))
{
std::cerr << "error populating thresholds for "
@@ -382,7 +383,7 @@
auto& sensorPtr = gCpuSensors[sensorName];
// make sure destructor fires before creating a new one
sensorPtr = nullptr;
- sensorPtr = std::make_shared<CPUSensor>(
+ sensorPtr = std::make_shared<IntelCPUSensor>(
inputPathStr, sensorType, objectServer, dbusConnection, io,
sensorName, std::move(sensorThresholds), *interfacePath, cpuId,
show, dtsOffset);
@@ -776,7 +777,7 @@
matches.emplace_back(std::move(match));
}
- systemBus->request_name("xyz.openbmc_project.CPUSensor");
+ systemBus->request_name("xyz.openbmc_project.IntelCPUSensor");
setupManufacturingModeMatch(*systemBus);
io.run();
diff --git a/src/meson.build b/src/meson.build
index 4c3d61c..e420b27 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -21,11 +21,11 @@
)
endif
-if get_option('cpu').enabled()
+if get_option('intel-cpu').enabled()
executable(
- 'cpusensor',
- 'CPUSensorMain.cpp',
- 'CPUSensor.cpp',
+ 'intelcpusensor',
+ 'IntelCPUSensorMain.cpp',
+ 'IntelCPUSensor.cpp',
dependencies: [
default_deps,
gpiodcxx,