summaryrefslogtreecommitdiffstats
path: root/occ_device.hpp
diff options
context:
space:
mode:
authorEddie James <eajames@us.ibm.com>2019-03-19 20:58:53 +0000
committerEddie James <eajames@linux.ibm.com>2019-04-09 10:51:20 -0500
commit774f9af9a2d861f49c878d9eeca9830bef44127b (patch)
tree6b77eb6565e1f937403dda58296aa0d1493bbdf8 /occ_device.hpp
parent577a935e0261e7a316ec7f6ad76b72328d30d2ee (diff)
downloadopenpower-occ-control-774f9af9a2d861f49c878d9eeca9830bef44127b.tar.gz
openpower-occ-control-774f9af9a2d861f49c878d9eeca9830bef44127b.zip
Fix error attribute naming for Linux 5.0
There was a slight change to one of the error attributes as part of the OCC driver upstreaming process. This commit also adds unit tests for the error attributes. This required some refactoring to support the unit tests. Resolves openbmc/openbmc#3505 Signed-off-by: Eddie James <eajames@us.ibm.com> Change-Id: I665b46e44b18befc8a728f7246bcda82f1f1a71c
Diffstat (limited to 'occ_device.hpp')
-rw-r--r--occ_device.hpp60
1 files changed, 42 insertions, 18 deletions
diff --git a/occ_device.hpp b/occ_device.hpp
index 448253a..937c6dc 100644
--- a/occ_device.hpp
+++ b/occ_device.hpp
@@ -8,6 +8,7 @@
#include <experimental/filesystem>
#include <fstream>
+#include <org/open_power/OCC/Device/error.hpp>
namespace open_power
{
@@ -17,6 +18,7 @@ namespace occ
class Manager;
class Status;
namespace fs = std::experimental::filesystem;
+using namespace sdbusplus::org::open_power::OCC::Device::Error;
/** @class Device
* @brief Binds and unbinds the OCC driver upon request
@@ -34,25 +36,25 @@ class Device
/** @brief Constructs the Device object
*
* @param[in] event - Unique ptr reference to sd_event
- * @param[in] name - OCC instance name
+ * @param[in] path - Path to the OCC instance
* @param[in] manager - OCC manager instance
* @param[in] callback - Optional callback on errors
*/
- Device(EventPtr& event, const std::string& name, const Manager& manager,
+ Device(EventPtr& event, const fs::path& path, const Manager& manager,
Status& status, std::function<void(bool)> callBack = nullptr) :
- config(name),
- errorFile(fs::path(config) / "occ_error"), statusObject(status),
- error(event, errorFile, callBack),
- presence(event, fs::path(config) / "occs_present", manager, callBack),
+ config(getPathBack(path)),
+ devPath(path), statusObject(status),
+ error(event, path / "occ_error", callBack),
+ presence(event, path / "occs_present", manager, callBack),
throttleProcTemp(
- event, fs::path(config) / "occ_dvfs_ot",
+ event, path / "occ_dvfs_overtemp",
std::bind(std::mem_fn(&Device::throttleProcTempCallback), this,
std::placeholders::_1)),
throttleProcPower(
- event, fs::path(config) / "occ_dvfs_power",
+ event, path / "occ_dvfs_power",
std::bind(std::mem_fn(&Device::throttleProcPowerCallback), this,
std::placeholders::_1)),
- throttleMemTemp(event, fs::path(config) / "occ_mem_throttle",
+ throttleMemTemp(event, path / "occ_mem_throttle",
std::bind(std::mem_fn(&Device::throttleMemTempCallback),
this, std::placeholders::_1))
{
@@ -86,13 +88,29 @@ class Device
return fs::exists(OCC_HWMON_PATH + config);
}
- /** @brief Starts to monitor for errors */
- inline void addErrorWatch()
+ /** @brief Starts to monitor for errors
+ *
+ * @param[in] poll - Indicates whether or not the error file should
+ * actually be polled for changes. Disabling polling is
+ * necessary for error files that don't support the poll
+ * file operation.
+ */
+ inline void addErrorWatch(bool poll = true)
{
- throttleProcTemp.addWatch();
- throttleProcPower.addWatch();
- throttleMemTemp.addWatch();
- error.addWatch();
+ try
+ {
+ throttleProcTemp.addWatch(poll);
+ }
+ catch (const OpenFailure& e)
+ {
+ // try the old kernel version
+ throttleProcTemp.setFile(devPath / "occ_dvfs_ot");
+ throttleProcTemp.addWatch(poll);
+ }
+
+ throttleProcPower.addWatch(poll);
+ throttleMemTemp.addWatch(poll);
+ error.addWatch(poll);
}
/** @brief stops monitoring for errors */
@@ -101,7 +119,6 @@ class Device
// we can always safely remove watch even if we don't add it
presence.removeWatch();
error.removeWatch();
- error.removeWatch();
throttleMemTemp.removeWatch();
throttleProcPower.removeWatch();
throttleProcTemp.removeWatch();
@@ -116,12 +133,19 @@ class Device
}
}
+ /** @brief helper function to get the last part of the path
+ *
+ * @param[in] path - Path to parse
+ * @return - Last directory name in the path
+ */
+ static std::string getPathBack(const fs::path& path);
+
private:
/** @brief Config value to be used to do bind and unbind */
const std::string config;
- /** @brief This file contains 0 for success, non-zero for errors */
- const fs::path errorFile;
+ /** @brief This directory contains the error files */
+ const fs::path devPath;
/** @brief To bind the device to the OCC driver, do:
*
OpenPOWER on IntegriCloud