regulators: Add phase faults to ActionEnvironment
Enhance the ActionEnvironment class to support detecting and logging
redundant phase fault errors.
Add gtests to test the new functions/methods.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: Id87d811374dd3da616cdeeb780b3575ef96ffbb7
diff --git a/phosphor-regulators/src/actions/action_environment.hpp b/phosphor-regulators/src/actions/action_environment.hpp
index 72aa8f4..7f6c402 100644
--- a/phosphor-regulators/src/actions/action_environment.hpp
+++ b/phosphor-regulators/src/actions/action_environment.hpp
@@ -16,10 +16,13 @@
#pragma once
#include "id_map.hpp"
+#include "phase_fault.hpp"
#include "services.hpp"
#include <cstddef> // for size_t
+#include <map>
#include <optional>
+#include <set>
#include <stdexcept>
#include <string>
@@ -40,6 +43,9 @@
* - current volts value (if any)
* - mapping from device and rule IDs to the corresponding objects
* - rule call stack depth (to detect infinite recursion)
+ * - reference to system services
+ * - faults detected by actions (if any)
+ * - additional error data captured by actions (if any)
*/
class ActionEnvironment
{
@@ -72,6 +78,33 @@
}
/**
+ * Adds the specified key/value pair to the map of additional error data
+ * that has been captured.
+ *
+ * This data provides more information about an error and will be stored in
+ * the error log.
+ *
+ * @param key key name
+ * @param value value expressed as a string
+ */
+ void addAdditionalErrorData(const std::string& key,
+ const std::string& value)
+ {
+ additionalErrorData.emplace(key, value);
+ }
+
+ /**
+ * Adds the specified phase fault to the set of faults that have been
+ * detected.
+ *
+ * @param type phase fault type
+ */
+ void addPhaseFault(PhaseFaultType type)
+ {
+ phaseFaults.emplace(type);
+ }
+
+ /**
* Decrements the rule call stack depth by one.
*
* Should be used when a call to a rule returns. Does nothing if depth is
@@ -86,6 +119,16 @@
}
/**
+ * Returns the additional error data that has been captured (if any).
+ *
+ * @return additional error data
+ */
+ const std::map<std::string, std::string>& getAdditionalErrorData() const
+ {
+ return additionalErrorData;
+ }
+
+ /**
* Returns the device with the current device ID.
*
* Throws invalid_argument if no device is found with current ID.
@@ -108,6 +151,16 @@
}
/**
+ * Returns the set of phase faults that have been detected (if any).
+ *
+ * @return phase faults detected
+ */
+ const std::set<PhaseFaultType>& getPhaseFaults() const
+ {
+ return phaseFaults;
+ }
+
+ /**
* Returns the rule with the specified ID.
*
* Throws invalid_argument if no rule is found with specified ID.
@@ -218,6 +271,16 @@
* Rule call stack depth.
*/
size_t ruleDepth{0};
+
+ /**
+ * Redundant phase faults that have been detected.
+ */
+ std::set<PhaseFaultType> phaseFaults{};
+
+ /**
+ * Additional error data that has been captured.
+ */
+ std::map<std::string, std::string> additionalErrorData{};
};
} // namespace phosphor::power::regulators
diff --git a/phosphor-regulators/src/phase_fault.hpp b/phosphor-regulators/src/phase_fault.hpp
new file mode 100644
index 0000000..fbcb255
--- /dev/null
+++ b/phosphor-regulators/src/phase_fault.hpp
@@ -0,0 +1,74 @@
+/**
+ * Copyright © 2021 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <string>
+
+namespace phosphor::power::regulators
+{
+
+/**
+ * Redundant phase fault type.
+ *
+ * A voltage regulator is sometimes called a "phase controller" because it
+ * controls one or more phases that perform the actual voltage regulation.
+ *
+ * A regulator may have redundant phases. If a redundant phase fails, the
+ * regulator will continue to provide the desired output voltage. However, a
+ * phase fault error should be logged warning the user that the regulator has
+ * lost redundancy.
+ */
+enum class PhaseFaultType : unsigned char
+{
+ /**
+ * N phase fault type.
+ *
+ * Regulator has lost all redundant phases. The regulator is now at
+ * redundancy level N.
+ */
+ n,
+
+ /**
+ * N+1 phase fault type.
+ *
+ * An "N+2" regulator has lost one redundant phase. The regulator is now at
+ * redundancy level "N+1".
+ */
+ n_plus_1
+};
+
+/**
+ * Returns the name of the specified PhaseFaultType.
+ *
+ * @param type phase fault type
+ * @return phase fault type name
+ */
+inline std::string toString(PhaseFaultType type)
+{
+ std::string name{};
+ switch (type)
+ {
+ case PhaseFaultType::n:
+ name = "n";
+ break;
+ case PhaseFaultType::n_plus_1:
+ name = "n+1";
+ break;
+ }
+ return name;
+}
+
+} // namespace phosphor::power::regulators