summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYong Li <yong.b.li@linux.intel.com>2019-11-19 13:25:01 +0300
committerLi, Yong B <yong.b.li@intel.com>2019-11-22 07:22:23 +0300
commit62d865faae2c183a64455abed5114d67aa61b311 (patch)
treebda3d55ad6f802977b76d944003fbe45e83c7a75
parentd095ccea8df74f9de228ab83b658d80b4fb79460 (diff)
downloadprovingground-62d865faae2c183a64455abed5114d67aa61b311.tar.xz
Sync configuration data between settings and PSU redundancy service
Add support for reading configuration from settings service, and store all these data into dbus; Rank order configuration needs to be queried from PSU redundancy service, since it will be changed from time to time. Tested: Applied https://gerrit.openbmc-project.xyz/#/c/openbmc/intel-ipmi-oem/+/27220/, With two PSUs, AC cycle the board, // two PSUs available ipmitool raw 0x30 0x2E 0x05 05 02 // Return the default order 0,0, instead of the default settings is 0 root@intel-obmc:~# ipmitool raw 0x30 0x2E 0x03 03 01 00 00 Wait for 2 minutes, the order will be changed to ascending order, and start the rotation ipmitool raw 0x30 0x2e 0x3 03 00 01 02 // Set a new order 1,2 root@intel-obmc:~# ipmitool raw 0x30 0x2d 0x03 0x01 0x01 0x02 00 // Return the new order root@intel-obmc:~# ipmitool raw 0x30 0x2E 0x03 03 01 01 02 Signed-off-by: Yong Li <yong.b.li@linux.intel.com> Change-Id: I50c469ae7b2f089d3e7cc70932e5eed4f7164f74
-rw-r--r--psu-manager/include/cold_redundancy.hpp9
-rw-r--r--psu-manager/include/utility.hpp6
-rw-r--r--psu-manager/src/cold_redundancy.cpp120
-rw-r--r--psu-manager/src/utility.cpp2
4 files changed, 108 insertions, 29 deletions
diff --git a/psu-manager/include/cold_redundancy.hpp b/psu-manager/include/cold_redundancy.hpp
index cd7a5f6..81c56d1 100644
--- a/psu-manager/include/cold_redundancy.hpp
+++ b/psu-manager/include/cold_redundancy.hpp
@@ -21,7 +21,6 @@
const constexpr char* psuInterface =
"/xyz/openbmc_project/inventory/system/powersupply/";
const constexpr int secondsInOneDay = 86400;
-const constexpr uint8_t bmcSpecific = 0;
using Association = std::tuple<std::string, std::string, std::string>;
@@ -47,14 +46,10 @@ class ColdRedundancy
private:
bool crSupported = true;
- bool crEnabled = true;
- bool rotationEnabled = true;
- std::string rotationAlgo =
- "xyz.openbmc_project.Control.PowerSupplyRedundancy.Algo.bmcSpecific";
uint8_t psOrder;
uint8_t numberOfPSU = 0;
- uint32_t rotationPeriod = 7 * secondsInOneDay;
uint8_t redundancyPSURequire = 1;
+ std::vector<uint8_t> settingsOrder = {};
void startRotateCR(void);
void startCRCheck(void);
@@ -91,7 +86,7 @@ class PowerSupply
{
public:
PowerSupply(
- std::string name, uint8_t bus, uint8_t address,
+ std::string& name, uint8_t bus, uint8_t address, uint8_t order,
const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
~PowerSupply();
std::string name;
diff --git a/psu-manager/include/utility.hpp b/psu-manager/include/utility.hpp
index d0df858..33bca75 100644
--- a/psu-manager/include/utility.hpp
+++ b/psu-manager/include/utility.hpp
@@ -28,9 +28,9 @@ static const constexpr std::array<const char*, 1> psuEventInterface = {
"xyz.openbmc_project.State.Decorator.OperationalStatus"};
using BasicVariantType =
- std::variant<std::vector<std::string>, std::vector<uint64_t>, std::string,
- int64_t, uint64_t, double, int32_t, uint32_t, int16_t,
- uint16_t, uint8_t, bool>;
+ std::variant<std::vector<std::string>, std::vector<uint64_t>,
+ std::vector<uint8_t>, std::string, int64_t, uint64_t, double,
+ int32_t, uint32_t, int16_t, uint16_t, uint8_t, bool>;
using PropertyMapType =
boost::container::flat_map<std::string, BasicVariantType>;
diff --git a/psu-manager/src/cold_redundancy.cpp b/psu-manager/src/cold_redundancy.cpp
index bc902ab..9a15a7a 100644
--- a/psu-manager/src/cold_redundancy.cpp
+++ b/psu-manager/src/cold_redundancy.cpp
@@ -73,6 +73,54 @@ ColdRedundancy::ColdRedundancy(
std::cerr << "error initializing assoc interface\n";
}
+ // set default configuration
+ powerSupplyRedundancyEnabled(true);
+ rotationEnabled(true);
+ periodOfRotation(7 * secondsInOneDay);
+ rotationAlgorithm(Algo::bmcSpecific);
+
+ // read configuration from settings service
+ systemBus->async_method_call(
+ [this](const boost::system::error_code ec, PropertyMapType& propMap) {
+ if (ec)
+ {
+ std::cerr << "Exception happened when get all properties\n";
+ return;
+ }
+ auto period = std::get_if<uint32_t>(&propMap["PeriodOfRotation"]);
+ auto redundancyEnabled =
+ std::get_if<bool>(&propMap["ColdRedundancyEnabled"]);
+ auto algorithm =
+ std::get_if<std::string>(&propMap["RotationAlgorithm"]);
+ auto enabled = std::get_if<bool>(&propMap["RotationEnabled"]);
+ auto rankOrder = std::get_if<std::vector<uint8_t>>(
+ &propMap["RotationRankOrder"]);
+
+ if (period == nullptr || redundancyEnabled == nullptr ||
+ algorithm == nullptr || enabled == nullptr ||
+ rankOrder == nullptr)
+ {
+ std::cerr << "error reading configuration data\n";
+ return;
+ }
+
+ periodOfRotation(*period);
+ powerSupplyRedundancyEnabled(*redundancyEnabled);
+ rotationAlgorithm(convertAlgoFromString(*algorithm));
+ rotationEnabled(*enabled);
+ rotationRankOrder(*rankOrder);
+
+ ColdRedundancy::configCR(false);
+ timerRotation.cancel();
+ startRotateCR();
+
+ // cache the rank order configuration
+ settingsOrder.assign(rankOrder->begin(), rankOrder->end());
+ },
+ "xyz.openbmc_project.Settings", coldRedundancyPath,
+ "org.freedesktop.DBus.Properties", "GetAll",
+ "xyz.openbmc_project.Control.PowerSupplyRedundancy");
+
io.post([this, &io, &objectServer, &systemBus]() {
createPSU(io, objectServer, systemBus);
});
@@ -115,7 +163,7 @@ ColdRedundancy::ColdRedundancy(
bool* pCREnabled = std::get_if<bool>(&(value.second));
if (pCREnabled != nullptr)
{
- crEnabled = *pCREnabled;
+ powerSupplyRedundancyEnabled(*pCREnabled);
ColdRedundancy::configCR(false);
}
continue;
@@ -125,7 +173,7 @@ ColdRedundancy::ColdRedundancy(
bool* pRotationEnabled = std::get_if<bool>(&(value.second));
if (pRotationEnabled != nullptr)
{
- rotationEnabled = *pRotationEnabled;
+ rotationEnabled(*pRotationEnabled);
ColdRedundancy::configCR(false);
}
continue;
@@ -136,7 +184,7 @@ ColdRedundancy::ColdRedundancy(
std::get_if<std::string>(&(value.second));
if (pAlgo != nullptr)
{
- rotationAlgo = *pAlgo;
+ rotationAlgorithm(convertAlgoFromString(*pAlgo));
}
continue;
}
@@ -150,6 +198,11 @@ ColdRedundancy::ColdRedundancy(
}
uint8_t rankSize = pRank->size();
uint8_t index = 0;
+
+ // cache the rank order configuration
+ settingsOrder.assign(pRank->begin(), pRank->end());
+
+ // apply the order to all psus
for (auto& psu : powerSupplies)
{
if (index < rankSize)
@@ -162,7 +215,11 @@ ColdRedundancy::ColdRedundancy(
}
index++;
}
+
+ // store the settings data into dbus
+ rotationRankOrder(settingsOrder);
ColdRedundancy::configCR(false);
+
continue;
}
if (value.first == "PeriodOfRotation")
@@ -170,13 +227,14 @@ ColdRedundancy::ColdRedundancy(
uint32_t* pPeriod = std::get_if<uint32_t>(&(value.second));
if (pPeriod != nullptr)
{
- rotationPeriod = *pPeriod;
+ periodOfRotation(*pPeriod);
timerRotation.cancel();
startRotateCR();
}
continue;
}
- std::cerr << "Unused property changed\n";
+ std::cerr << "Unused property [" << value.first
+ << "] changed\n";
}
};
@@ -257,9 +315,11 @@ ColdRedundancy::ColdRedundancy(
matches.emplace_back(std::move(eventMatch));
}
+ // monitor data change from settings service
auto configParamMatch = std::make_unique<sdbusplus::bus::match::match>(
static_cast<sdbusplus::bus::bus&>(*systemBus),
- "type='signal',member='PropertiesChanged',path_namespace='" +
+ "type='signal',member='PropertiesChanged',sender='xyz.openbmc_project."
+ "Settings', path_namespace='" +
std::string(coldRedundancyPath) + "',arg0namespace='" +
redundancyInterface + "'",
paramConfig);
@@ -475,13 +535,27 @@ void ColdRedundancy::createPSU(
}
}
+ uint8_t order = 0;
+
+ if (numberOfPSU < settingsOrder.size())
+ {
+ order = settingsOrder[numberOfPSU];
+ }
+
powerSupplies.emplace_back(
std::make_unique<PowerSupply>(
*configName,
static_cast<uint8_t>(*configBus),
static_cast<uint8_t>(*configAddress),
- conn));
+ order, conn));
+
numberOfPSU++;
+ std::vector<uint8_t> orders = {};
+ for (auto& psu : powerSupplies)
+ {
+ orders.push_back(psu->order);
+ }
+ rotationRankOrder(orders);
},
serviceName.c_str(), pathName.c_str(),
"org.freedesktop.DBus.Properties", "GetAll",
@@ -522,10 +596,10 @@ uint8_t ColdRedundancy::pSUNumber() const
}
PowerSupply::PowerSupply(
- std::string name, uint8_t bus, uint8_t address,
+ std::string& name, uint8_t bus, uint8_t address, uint8_t order,
const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection) :
name(name),
- bus(bus), address(address)
+ bus(bus), address(address), order(order)
{
getPSUEvent(psuEventInterface, dbusConnection, name, state);
if (debug)
@@ -541,8 +615,10 @@ PowerSupply::PowerSupply(
void ColdRedundancy::reRanking(void)
{
uint8_t index = 1;
- if (rotationAlgo ==
- "xyz.openbmc_project.Control.PowerSupplyRedundancy.Algo.bmcSpecific")
+ uint8_t psuNumber = 0;
+ std::vector<uint8_t> orders = rotationRankOrder();
+
+ if (rotationAlgorithm() == Algo::bmcSpecific)
{
for (auto& psu : powerSupplies)
{
@@ -554,7 +630,9 @@ void ColdRedundancy::reRanking(void)
{
psu->order = 0;
}
+ orders[psuNumber++] = psu->order;
}
+ rotationRankOrder(orders);
}
else
{
@@ -562,8 +640,7 @@ void ColdRedundancy::reRanking(void)
{
if (psu->state == PSUState::acLost)
{
- rotationAlgo = "xyz.openbmc_project.Control."
- "PowerSupplyRedundancy.Algo.bmcSpecific";
+ rotationAlgorithm(Algo::bmcSpecific);
reRanking();
return;
}
@@ -573,7 +650,7 @@ void ColdRedundancy::reRanking(void)
void ColdRedundancy::configCR(bool reConfig)
{
- if (!crSupported || !crEnabled)
+ if (!crSupported || !powerSupplyRedundancyEnabled())
{
return;
}
@@ -616,7 +693,7 @@ void ColdRedundancy::checkCR(void)
{
return;
}
- if (!crEnabled)
+ if (!powerSupplyRedundancyEnabled())
{
putWarmRedundant();
return;
@@ -665,7 +742,7 @@ void ColdRedundancy::startCRCheck()
// rank order. And the PSU with last rank order will become the rank order 1
void ColdRedundancy::rotateCR(void)
{
- if (!crSupported || !crEnabled)
+ if (!crSupported || !powerSupplyRedundancyEnabled())
{
return;
}
@@ -708,12 +785,19 @@ void ColdRedundancy::rotateCR(void)
std::cerr << "Failed to change PSU Cold Redundancy order\n";
}
}
+
+ std::vector<uint8_t> orders = {};
+ for (auto& psu : powerSupplies)
+ {
+ orders.push_back(psu->order);
+ }
+ rotationRankOrder(orders);
});
}
void ColdRedundancy::startRotateCR()
{
- timerRotation.expires_after(std::chrono::seconds(rotationPeriod));
+ timerRotation.expires_after(std::chrono::seconds(periodOfRotation()));
timerRotation.async_wait([this](const boost::system::error_code& ec) {
if (ec == boost::asio::error::operation_aborted)
{
@@ -723,7 +807,7 @@ void ColdRedundancy::startRotateCR()
{
std::cerr << "timer error\n";
}
- if (crSupported && rotationEnabled)
+ if (crSupported && rotationEnabled())
{
rotateCR();
}
diff --git a/psu-manager/src/utility.cpp b/psu-manager/src/utility.cpp
index 5446dd9..dc5573c 100644
--- a/psu-manager/src/utility.cpp
+++ b/psu-manager/src/utility.cpp
@@ -252,7 +252,7 @@ void getPSUEvent(const std::array<const char*, 1>& configTypes,
if (ec)
{
std::cerr << "Exception happened when get "
- "functional propert\n";
+ "functional property\n";
return;
}