psu-ng: Remove previous input history code

As mentioned in a previous commit, the org.open_power D-Bus interfaces
that host the 30 second maximum and average input power values are no
longer necessary, and have been replaced by a single peak input power
sensor object.

Remove all of the code that dealt with them.

For now, the code remains that toggles the GPIO to sync up the input
history values between the power supplies on boots and plugs. As the
input history is used to populate the new peak sensor, its values across
power supplies will then be using the same time intervals.

Change-Id: Ide5b40e67bf3938606a75bcc0291bc57232ce8bc
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/phosphor-power-supply/average.hpp b/phosphor-power-supply/average.hpp
deleted file mode 120000
index 32555ce..0000000
--- a/phosphor-power-supply/average.hpp
+++ /dev/null
@@ -1 +0,0 @@
-../power-supply/average.hpp
\ No newline at end of file
diff --git a/phosphor-power-supply/maximum.hpp b/phosphor-power-supply/maximum.hpp
deleted file mode 120000
index ec255a0..0000000
--- a/phosphor-power-supply/maximum.hpp
+++ /dev/null
@@ -1 +0,0 @@
-../power-supply/maximum.hpp
\ No newline at end of file
diff --git a/phosphor-power-supply/meson.build b/phosphor-power-supply/meson.build
index da64bd0..3b4a052 100644
--- a/phosphor-power-supply/meson.build
+++ b/phosphor-power-supply/meson.build
@@ -7,7 +7,6 @@
     'main.cpp',
     'psu_manager.cpp',
     'power_supply.cpp',
-    'record_manager.cpp',
     'util.cpp',
     dependencies: [
         cli11_dep,
diff --git a/phosphor-power-supply/power_supply.cpp b/phosphor-power-supply/power_supply.cpp
index 6e28ca8..fa4b8e3 100644
--- a/phosphor-power-supply/power_supply.cpp
+++ b/phosphor-power-supply/power_supply.cpp
@@ -22,12 +22,6 @@
 // missing to present before running the bind command(s).
 constexpr auto bindDelay = 1000;
 
-// The number of INPUT_HISTORY records to keep on D-Bus.
-// Each record covers a 30-second span. That means two records are needed to
-// cover a minute of time. If we want one (1) hour of data, that would be 120
-// records.
-constexpr auto INPUT_HISTORY_MAX_RECORDS = 120;
-
 using namespace phosphor::logging;
 using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error;
 
@@ -94,7 +88,6 @@
 
         updatePresence();
         updateInventory();
-        setupInputHistory();
         setupSensors();
     }
 
@@ -200,7 +193,6 @@
         }
 
         setPresence(bus, invpath, present, shortName);
-        setupInputHistory();
         setupSensors();
         updateInventory();
 
@@ -679,11 +671,6 @@
             monitorSensors();
 
             checkAvailability();
-
-            if (inputHistorySupported)
-            {
-                updateHistory();
-            }
         }
         catch (const ReadFailure& e)
         {
@@ -1056,77 +1043,6 @@
     return maxPowerOut;
 }
 
-void PowerSupply::setupInputHistory()
-{
-    if (bindPath.string().find(IBMCFFPS_DD_NAME) != std::string::npos)
-    {
-        auto maxPowerOut = getMaxPowerOut();
-
-        if (maxPowerOut != phosphor::pmbus::IBM_CFFPS_1400W)
-        {
-            // Do not enable input history for power supplies that are missing
-            if (present)
-            {
-                inputHistorySupported = true;
-                log<level::INFO>(
-                    fmt::format("{} INPUT_HISTORY enabled", shortName).c_str());
-
-                std::string name{fmt::format("{}_input_power", shortName)};
-
-                historyObjectPath = std::string{INPUT_HISTORY_SENSOR_ROOT} +
-                                    '/' + name;
-
-                // If the power supply was present, we created the
-                // recordManager. If it then went missing, the recordManager is
-                // still there. If it then is reinserted, we should be able to
-                // use the recordManager that was allocated when it was
-                // initially present.
-                if (!recordManager)
-                {
-                    recordManager = std::make_unique<history::RecordManager>(
-                        INPUT_HISTORY_MAX_RECORDS);
-                }
-
-                if (!average)
-                {
-                    auto avgPath = historyObjectPath + '/' +
-                                   history::Average::name;
-                    average = std::make_unique<history::Average>(bus, avgPath);
-                    log<level::DEBUG>(
-                        fmt::format("{} avgPath: {}", shortName, avgPath)
-                            .c_str());
-                }
-
-                if (!maximum)
-                {
-                    auto maxPath = historyObjectPath + '/' +
-                                   history::Maximum::name;
-                    maximum = std::make_unique<history::Maximum>(bus, maxPath);
-                    log<level::DEBUG>(
-                        fmt::format("{} maxPath: {}", shortName, maxPath)
-                            .c_str());
-                }
-
-                log<level::DEBUG>(fmt::format("{} historyObjectPath: {}",
-                                              shortName, historyObjectPath)
-                                      .c_str());
-            }
-        }
-        else
-        {
-            log<level::INFO>(
-                fmt::format("{} INPUT_HISTORY DISABLED. max_power_out: {}",
-                            shortName, maxPowerOut)
-                    .c_str());
-            inputHistorySupported = false;
-        }
-    }
-    else
-    {
-        inputHistorySupported = false;
-    }
-}
-
 void PowerSupply::setupSensors()
 {
     setupInputPowerPeakSensor();
@@ -1176,35 +1092,6 @@
     }
 }
 
-void PowerSupply::updateHistory()
-{
-    if (!recordManager)
-    {
-        // Not enabled
-        return;
-    }
-
-    if (!present)
-    {
-        // Cannot read when not present
-        return;
-    }
-
-    // Read just the most recent average/max record
-    auto data = pmbusIntf->readBinary(INPUT_HISTORY,
-                                      pmbus::Type::HwmonDeviceDebug,
-                                      history::RecordManager::RAW_RECORD_SIZE);
-
-    // Update D-Bus only if something changed (a new record ID, or cleared
-    // out)
-    auto changed = recordManager->add(data);
-    if (changed)
-    {
-        average->values(recordManager->getAverageRecords());
-        maximum->values(recordManager->getMaximumRecords());
-    }
-}
-
 void PowerSupply::monitorSensors()
 {
     monitorPeakInputPowerSensor();
diff --git a/phosphor-power-supply/power_supply.hpp b/phosphor-power-supply/power_supply.hpp
index ec1290e..da76434 100644
--- a/phosphor-power-supply/power_supply.hpp
+++ b/phosphor-power-supply/power_supply.hpp
@@ -1,9 +1,6 @@
 #pragma once
 
-#include "average.hpp"
-#include "maximum.hpp"
 #include "pmbus.hpp"
-#include "record_manager.hpp"
 #include "types.hpp"
 #include "util.hpp"
 #include "utility.hpp"
@@ -497,42 +494,6 @@
     void checkAvailability();
 
     /**
-     * @brief Setup for power supply input history.
-     *
-     * This will setup the variables and interfaces needed to get the power
-     * supply input history data over to D-Bus. The only known support for this
-     * at this time is the INPUT_HISTORY command implemented by the IBM Common
-     * Form Factor Power Suppplies (ibm-cffps). The INPUT_HISTORY command for
-     * ibm-cffps is implemented via a manufacturing specific PMBus command.
-     */
-    void setupInputHistory();
-
-    /**
-     * @brief Returns true if this power supply has input history (supported).
-     */
-    bool hasInputHistory() const
-    {
-        return inputHistorySupported;
-    }
-
-    /**
-     * @brief Returns the number of input history records
-     *
-     * PowerSupply wrapper to getNumRecords() from RecordManager.
-     */
-    size_t getNumInputHistoryRecords() const
-    {
-        if (recordManager)
-        {
-            return recordManager->getNumRecords();
-        }
-        else
-        {
-            return 0;
-        }
-    }
-
-    /**
      * @brief Returns true when INPUT_HISTORY sync is required.
      */
     bool isSyncHistoryRequired() const
@@ -768,20 +729,6 @@
                       const std::size_t& vpdSize);
 
     /**
-     * @brief Reads the most recent input history record from the power supply
-     * and updates the average and maximum properties in D-Bus if there is a new
-     * reading available.
-     *
-     * This will still run every time analyze() is called so code can post new
-     * data as soon as possible and the timestamp will more accurately reflect
-     * the correct time.
-     *
-     * D-Bus is only updated if there is a change and the oldest record will be
-     * pruned if the property already contains the max number of records.
-     */
-    void updateHistory();
-
-    /**
      * @brief Retrieve PSU VPD keyword from D-Bus
      *
      * It retrieves PSU VPD keyword from D-Bus and assign the associated
@@ -848,14 +795,6 @@
     std::function<bool()> isPowerOn;
 
     /**
-     * @brief Set to true if INPUT_HISTORY command supported.
-     *
-     * Not all power supplies will support the INPUT_HISTORY command. The IBM
-     * Common Form Factor power supplies do support this command.
-     */
-    bool inputHistorySupported{false};
-
-    /**
      * @brief Set to true when INPUT_HISTORY sync is required.
      *
      * A power supply will need to synchronize its INPUT_HISTORY data with the
@@ -1097,27 +1036,6 @@
     size_t readFail = 0;
 
     /**
-     * @brief Class that manages the input power history records.
-     **/
-    std::unique_ptr<history::RecordManager> recordManager;
-
-    /**
-     * @brief The D-Bus object for the average input power history
-     **/
-    std::unique_ptr<history::Average> average;
-
-    /**
-     * @brief The D-Bus object for the maximum input power history
-     **/
-    std::unique_ptr<history::Maximum> maximum;
-
-    /**
-     * @brief The base D-Bus object path to use for the average and maximum
-     * objects.
-     **/
-    std::string historyObjectPath;
-
-    /**
      * @brief The D-Bus object for the input voltage rating
      *
      * It is updated at startup and power on.  If a power supply is
diff --git a/phosphor-power-supply/psu_manager.cpp b/phosphor-power-supply/psu_manager.cpp
index 4ce87c9..92492a1 100644
--- a/phosphor-power-supply/psu_manager.cpp
+++ b/phosphor-power-supply/psu_manager.cpp
@@ -42,7 +42,6 @@
 PSUManager::PSUManager(sdbusplus::bus_t& bus, const sdeventplus::Event& e) :
     bus(bus), powerSystemInputs(bus, powerSystemsInputsObjPath),
     objectManager(bus, objectManagerObjPath),
-    historyManager(bus, "/org/open_power/sensors"),
     sensorsObjManager(bus, "/xyz/openbmc_project/sensors")
 {
     // Subscribe to InterfacesAdded before doing a property read, otherwise
diff --git a/phosphor-power-supply/psu_manager.hpp b/phosphor-power-supply/psu_manager.hpp
index 0eadfea..0533a95 100644
--- a/phosphor-power-supply/psu_manager.hpp
+++ b/phosphor-power-supply/psu_manager.hpp
@@ -363,15 +363,6 @@
     sdbusplus::server::manager_t objectManager;
 
     /**
-     * @brief Implement the ObjectManager for power supply input history.
-     *
-     * Implements the org.freedesktop.DBus.ObjectManager interface used to
-     * communicate updates to the Average and Maximum interface properties on
-     * the /org/open_power/sensors root D-Bus path.
-     */
-    sdbusplus::server::manager_t historyManager;
-
-    /**
      * @brief Implement the ObjectManager for the input voltage rating.
      *
      * Implements the org.freedesktop.DBus.ObjectManager interface used to
diff --git a/phosphor-power-supply/record_manager.cpp b/phosphor-power-supply/record_manager.cpp
deleted file mode 120000
index cc2efd0..0000000
--- a/phosphor-power-supply/record_manager.cpp
+++ /dev/null
@@ -1 +0,0 @@
-../power-supply/record_manager.cpp
\ No newline at end of file
diff --git a/phosphor-power-supply/record_manager.hpp b/phosphor-power-supply/record_manager.hpp
deleted file mode 120000
index 506413d..0000000
--- a/phosphor-power-supply/record_manager.hpp
+++ /dev/null
@@ -1 +0,0 @@
-../power-supply/record_manager.hpp
\ No newline at end of file
diff --git a/phosphor-power-supply/test/meson.build b/phosphor-power-supply/test/meson.build
index 386a37e..1e5fe05 100644
--- a/phosphor-power-supply/test/meson.build
+++ b/phosphor-power-supply/test/meson.build
@@ -1,7 +1,6 @@
 test('phosphor-power-supply-tests',
      executable('phosphor-power-supply-tests',
                 'power_supply_tests.cpp',
-                '../record_manager.cpp',
                 'mock.cpp',
                 dependencies: [
                     gmock,
diff --git a/phosphor-power-supply/test/power_supply_tests.cpp b/phosphor-power-supply/test/power_supply_tests.cpp
index 74fc04c..62f8b5d 100644
--- a/phosphor-power-supply/test/power_supply_tests.cpp
+++ b/phosphor-power-supply/test/power_supply_tests.cpp
@@ -1,5 +1,4 @@
 #include "../power_supply.hpp"
-#include "../record_manager.hpp"
 #include "mock.hpp"
 
 #include <xyz/openbmc_project/Common/Device/error.hpp>
@@ -2098,7 +2097,6 @@
     auto bus = sdbusplus::bus::new_default();
     PowerSupply psu{bus,         PSUInventoryPath, 8,        0x6f,
                     "ibm-cffps", PSUGPIOLineName,  isPowerOn};
-    EXPECT_EQ(psu.hasInputHistory(), false);
     EXPECT_EQ(psu.isSyncHistoryRequired(), false);
     MockedGPIOInterface* mockPresenceGPIO =
         static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
@@ -2118,8 +2116,6 @@
         .WillRepeatedly(Return("205000"));
     EXPECT_CALL(mockedUtil, setAvailable(_, _, true));
     psu.analyze();
-    // The ibm-cffps power supply should support input history
-    EXPECT_EQ(psu.hasInputHistory(), true);
     // Missing -> Present requires history sync
     EXPECT_EQ(psu.isSyncHistoryRequired(), true);
     psu.clearSyncHistoryRequired();