powermode.cpp (1be4337b390fbcb951ee3c5c15f1a5a54a2dd205) powermode.cpp (cde7bea3d41e51204dad61761d46af70b34a787a)
1#include "powermode.hpp"
2
3#include <fmt/core.h>
4
5#include <com/ibm/Host/Target/server.hpp>
6#include <phosphor-logging/log.hpp>
7#include <xyz/openbmc_project/Control/Power/Mode/server.hpp>
8

--- 181 unchanged lines hidden (view full) ---

190 persistedData.updateMode(currentMode, 0);
191
192 // Write default mode to DBus
193 updateDbusMode(currentMode);
194 }
195
196 if (!persistedData.ipsAvailable())
197 {
1#include "powermode.hpp"
2
3#include <fmt/core.h>
4
5#include <com/ibm/Host/Target/server.hpp>
6#include <phosphor-logging/log.hpp>
7#include <xyz/openbmc_project/Control/Power/Mode/server.hpp>
8

--- 181 unchanged lines hidden (view full) ---

190 persistedData.updateMode(currentMode, 0);
191
192 // Write default mode to DBus
193 updateDbusMode(currentMode);
194 }
195
196 if (!persistedData.ipsAvailable())
197 {
198 // Read the default IPS parameters
199 bool ipsEnabled;
200 uint8_t enterUtil, exitUtil;
201 uint16_t enterTime, exitTime;
202 if (!getDefaultIPSParms(ipsEnabled, enterUtil, enterTime, exitUtil,
203 exitTime))
204 {
205 // Unable to read defaults
206 return false;
207 }
208 log<level::INFO>(
209 fmt::format(
210 "PowerMode::initPersistentData: Using default IPS parms: Enabled: {}, EnterUtil: {}%, EnterTime: {}s, ExitUtil: {}%, ExitTime: {}s",
211 ipsEnabled, enterUtil, enterTime, exitUtil, exitTime)
212 .c_str());
213
214 // Save IPS
215 persistedData.updateIPS(ipsEnabled, enterUtil, enterTime, exitUtil,
216 exitTime);
217
218 // Write default IPS data to DBus
219 updateDbusIPS(ipsEnabled, enterUtil, enterTime, exitUtil, exitTime);
198 // Read the default IPS parameters, write persistent file and update
199 // DBus
200 return useDefaultIPSParms();
220 }
221 return true;
222}
223
224// Get the requested power mode and return true if successful
225bool PowerMode::getMode(SysPwrMode& currentMode, uint16_t& oemModeData)
226{
227 currentMode = SysPwrMode::NO_CHANGE;

--- 140 unchanged lines hidden (view full) ---

368 status = CmdStatus::FAILURE;
369 }
370
371 return status;
372}
373
374void PowerMode::ipsChanged(sdbusplus::message::message& msg)
375{
201 }
202 return true;
203}
204
205// Get the requested power mode and return true if successful
206bool PowerMode::getMode(SysPwrMode& currentMode, uint16_t& oemModeData)
207{
208 currentMode = SysPwrMode::NO_CHANGE;

--- 140 unchanged lines hidden (view full) ---

349 status = CmdStatus::FAILURE;
350 }
351
352 return status;
353}
354
355void PowerMode::ipsChanged(sdbusplus::message::message& msg)
356{
376 if (!masterActive || !masterOccSet)
377 {
378 // Nothing to do
379 return;
380 }
381
382 bool parmsChanged = false;
383 std::string interface;
384 std::map<std::string, std::variant<bool, uint8_t, uint64_t>>
385 ipsProperties{};
386 msg.read(interface, ipsProperties);
387
388 // Read persisted values
389 bool ipsEnabled;

--- 48 unchanged lines hidden (view full) ---

438 log<level::INFO>(
439 fmt::format("Idle Power Saver change: Exit Time={}sec", exitTime)
440 .c_str());
441 parmsChanged = true;
442 }
443
444 if (parmsChanged)
445 {
357 bool parmsChanged = false;
358 std::string interface;
359 std::map<std::string, std::variant<bool, uint8_t, uint64_t>>
360 ipsProperties{};
361 msg.read(interface, ipsProperties);
362
363 // Read persisted values
364 bool ipsEnabled;

--- 48 unchanged lines hidden (view full) ---

413 log<level::INFO>(
414 fmt::format("Idle Power Saver change: Exit Time={}sec", exitTime)
415 .c_str());
416 parmsChanged = true;
417 }
418
419 if (parmsChanged)
420 {
446 // Update persistant data with new DBus values
447 persistedData.updateIPS(ipsEnabled, enterUtil, enterTime, exitUtil,
448 exitTime);
421 if (exitUtil == 0)
422 {
423 // Setting the exitUtil to 0 will force restoring the default IPS
424 // parmeters (0 is not valid exit utilization)
425 log<level::INFO>(
426 "Idle Power Saver Exit Utilization is 0%. Restoring default parameters");
427 // Read the default IPS parameters, write persistent file and update
428 // DBus
429 useDefaultIPSParms();
430 }
431 else
432 {
433 // Update persistant data with new DBus values
434 persistedData.updateIPS(ipsEnabled, enterUtil, enterTime, exitUtil,
435 exitTime);
436 }
449
450 // Trigger IPS data to get sent to the OCC
451 sendIpsData();
452 }
453
454 return;
455}
456

--- 138 unchanged lines hidden (view full) ---

595 log<level::ERR>(
596 "PowerMode::sendIpsData: SET_CFG_DATA[IPS] FAILED!");
597 }
598 }
599
600 return status;
601}
602
437
438 // Trigger IPS data to get sent to the OCC
439 sendIpsData();
440 }
441
442 return;
443}
444

--- 138 unchanged lines hidden (view full) ---

583 log<level::ERR>(
584 "PowerMode::sendIpsData: SET_CFG_DATA[IPS] FAILED!");
585 }
586 }
587
588 return status;
589}
590
591// Print the current values
603void OccPersistData::print()
604{
605 if (modeData.modeInitialized)
606 {
607 log<level::INFO>(
608 fmt::format(
609 "OccPersistData: Mode: 0x{:02X}, OEM Mode Data: {} (0x{:04X})",
610 modeData.mode, modeData.oemModeData, modeData.oemModeData)

--- 22 unchanged lines hidden (view full) ---

633 std::filesystem::create_directory(opath.parent_path());
634 }
635
636 log<level::DEBUG>(
637 fmt::format(
638 "OccPersistData::save: Writing Power Mode persisted data to {}",
639 opath.c_str())
640 .c_str());
592void OccPersistData::print()
593{
594 if (modeData.modeInitialized)
595 {
596 log<level::INFO>(
597 fmt::format(
598 "OccPersistData: Mode: 0x{:02X}, OEM Mode Data: {} (0x{:04X})",
599 modeData.mode, modeData.oemModeData, modeData.oemModeData)

--- 22 unchanged lines hidden (view full) ---

622 std::filesystem::create_directory(opath.parent_path());
623 }
624
625 log<level::DEBUG>(
626 fmt::format(
627 "OccPersistData::save: Writing Power Mode persisted data to {}",
628 opath.c_str())
629 .c_str());
641 print();
630 // print();
642
643 std::ofstream stream{opath.c_str()};
644 cereal::JSONOutputArchive oarchive{stream};
645
646 oarchive(modeData);
647}
648
649// Loads the OEM mode data in the filesystem using cereal.

--- 27 unchanged lines hidden (view full) ---

677 log<level::ERR>(
678 fmt::format("OccPersistData::load: failed to read {}, errno={}",
679 ipath.c_str(), error)
680 .c_str());
681 modeData.modeInitialized = false;
682 modeData.ipsInitialized = false;
683 }
684
631
632 std::ofstream stream{opath.c_str()};
633 cereal::JSONOutputArchive oarchive{stream};
634
635 oarchive(modeData);
636}
637
638// Loads the OEM mode data in the filesystem using cereal.

--- 27 unchanged lines hidden (view full) ---

666 log<level::ERR>(
667 fmt::format("OccPersistData::load: failed to read {}, errno={}",
668 ipath.c_str(), error)
669 .c_str());
670 modeData.modeInitialized = false;
671 modeData.ipsInitialized = false;
672 }
673
685 print();
674 // print();
686}
687
688// Called when PowerModeProperties defaults are available on DBus
689void PowerMode::defaultsReady(sdbusplus::message::message& msg)
690{
691 std::map<std::string, std::variant<std::string>> properties{};
692 std::string interface;
693 msg.read(interface, properties);

--- 160 unchanged lines hidden (view full) ---

854 enterUtil, exitUtil)
855 .c_str());
856 enterUtil = exitUtil;
857 }
858
859 return true;
860}
861
675}
676
677// Called when PowerModeProperties defaults are available on DBus
678void PowerMode::defaultsReady(sdbusplus::message::message& msg)
679{
680 std::map<std::string, std::variant<std::string>> properties{};
681 std::string interface;
682 msg.read(interface, properties);

--- 160 unchanged lines hidden (view full) ---

843 enterUtil, exitUtil)
844 .c_str());
845 enterUtil = exitUtil;
846 }
847
848 return true;
849}
850
851/* Read default IPS parameters, save them to the persistent file and update
852 DBus. Return true if successful */
853bool PowerMode::useDefaultIPSParms()
854{
855 // Read the default IPS parameters
856 bool ipsEnabled;
857 uint8_t enterUtil, exitUtil;
858 uint16_t enterTime, exitTime;
859 if (!getDefaultIPSParms(ipsEnabled, enterUtil, enterTime, exitUtil,
860 exitTime))
861 {
862 // Unable to read defaults
863 return false;
864 }
865 log<level::INFO>(
866 fmt::format(
867 "PowerMode::useDefaultIPSParms: Using default IPS parms: Enabled: {}, EnterUtil: {}%, EnterTime: {}s, ExitUtil: {}%, ExitTime: {}s",
868 ipsEnabled, enterUtil, enterTime, exitUtil, exitTime)
869 .c_str());
870
871 // Save IPS parms to the persistent file
872 persistedData.updateIPS(ipsEnabled, enterUtil, enterTime, exitUtil,
873 exitTime);
874
875 // Write IPS parms to DBus
876 return updateDbusIPS(ipsEnabled, enterUtil, enterTime, exitUtil, exitTime);
877}
878
862} // namespace powermode
863
864} // namespace occ
865
866} // namespace open_power
879} // namespace powermode
880
881} // namespace occ
882
883} // namespace open_power