From 6ac874e1a1752e29ef4756d9c7e7d33baee9f9d5 Mon Sep 17 00:00:00 2001 From: Andrew Geissler Date: Mon, 10 Jul 2017 15:54:58 -0500 Subject: Notify OCC of pcap setting changes Resolves openbmc/openbmc#948 Change-Id: I03193b07ddaf380468bd0c0e62a41220bdeaecce Signed-off-by: Andrew Geissler --- configure.ac | 4 ++++ powercap.cpp | 33 ++++++++++++++++++++++++++++++--- powercap.hpp | 6 ++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index efc29d8..daff49a 100644 --- a/configure.ac +++ b/configure.ac @@ -83,6 +83,10 @@ AC_ARG_VAR(OCC_NAME, [The OCC object name]) AS_IF([test "x$OCC_NAME" == "x"], [OCC_NAME="occ"]) AC_DEFINE_UNQUOTED([OCC_NAME], ["$OCC_NAME"], [The OCC object name]) +AC_ARG_VAR(OCC_MASTER_NAME, [The OCC master object name]) +AS_IF([test "x$OCC_MASTER_NAME" == "x"], [OCC_MASTER_NAME="occ-dev0"]) +AC_DEFINE_UNQUOTED([OCC_MASTER_NAME], ["$OCC_MASTER_NAME"], [The OCC master object name]) + AC_ARG_VAR(OCC_HWMON_PATH, [The OCC hwmon path]) AS_IF([test "x$OCC_HWMON_PATH" == "x"], [OCC_HWMON_PATH="/sys/bus/platform/drivers/occ-hwmon/"]) AC_DEFINE_UNQUOTED([OCC_HWMON_PATH], ["$OCC_HWMON_PATH"], [The OCC hwmon path]) diff --git a/powercap.cpp b/powercap.cpp index 7e8c0db..0aca3e4 100644 --- a/powercap.cpp +++ b/powercap.cpp @@ -113,6 +113,34 @@ bool PowerCap::getPcapEnabled() return pcapEnabled.get(); } +void PowerCap::writeOcc(uint32_t pcapValue) +{ + // Create path out to master occ hwmon entry + std::unique_ptr fileName = + std::make_unique(OCC_HWMON_PATH); + *fileName /= OCC_MASTER_NAME; + *fileName /= "/hwmon/"; + + // Need to get the hwmonXX directory name, there better only be 1 dir + assert(std::distance(fs::directory_iterator(*fileName), + fs::directory_iterator{}) == 1); + // Now set our path to this full path, including this hwmonXX directory + fileName = std::make_unique(*fs::directory_iterator(*fileName)); + // Append on the hwmon string where we write the user power cap + *fileName /= "/caps1_user"; + + auto pcapString {std::to_string(pcapValue)}; + + log("Writing pcap value to hwmon", + entry("PCAP_PATH=%s",*fileName), + entry("PCAP_VALUE=%s",pcapString.c_str())); + // Open the hwmon file and write the power cap + std::ofstream file(*fileName, std::ios::out); + file << pcapString; + file.close(); + return; +} + void PowerCap::pcapChanged(sdbusplus::message::message& msg) { if (!occStatus.occActive()) @@ -157,12 +185,11 @@ void PowerCap::pcapChanged(sdbusplus::message::message& msg) entry("PCAP_ENABLED=%u",pcapEnabled)); // Determine desired action to write to occ + auto occInput = getOccInput(pcap, pcapEnabled); - log("Writing new power cap setting to OCC", - entry("OCC_PCAP_VAL=%u",occInput)); // Write action to occ - // TODO + writeOcc(occInput); return; } diff --git a/powercap.hpp b/powercap.hpp index efd0729..ddf2a74 100644 --- a/powercap.hpp +++ b/powercap.hpp @@ -91,6 +91,12 @@ private: */ bool getPcapEnabled(); + /** @brief Write the input power cap to the occ hwmon entry + * + * @param[in] pcapValue - Power cap value to write to OCC + */ + void writeOcc(uint32_t pcapValue); + /** @brief Reference to sdbus **/ sdbusplus::bus::bus& bus; -- cgit v1.2.1