| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_THERMAL_STEPWISE_CONTROLLER_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_THERMAL_STEPWISE_CONTROLLER_H_ |
| |
| #include <memory> |
| #include <string> |
| #include <utility> |
| #include <vector> |
| |
| #include "absl/base/attributes.h" |
| #include "absl/base/nullability.h" |
| #include "absl/status/statusor.h" |
| #include "absl/strings/string_view.h" |
| #include "thermal_config.pb.h" |
| #include "tlbmc/thermal/controller/algorithm/stepwise.h" |
| #include "tlbmc/thermal/controller/controller.h" |
| #include "tlbmc/thermal/zone_manager.h" |
| |
| namespace milotic_tlbmc { |
| namespace thermal { |
| |
| struct StepwiseControllerParameters { |
| std::string id; |
| ZoneManager* absl_nonnull zone_manager ABSL_REQUIRE_EXPLICIT_INIT; |
| std::unique_ptr<StepwiseThermalLoop> absl_nonnull stepwise_loop |
| ABSL_REQUIRE_EXPLICIT_INIT; |
| std::vector<std::string> input_sensors; |
| bool is_ceiling = false; |
| }; |
| |
| /** |
| * `StepwiseController` provides a connection between the thermal zone manager |
| * and the stepwise thermal loop. It will |
| * handle the sensor reading & fan output process, and the stepwise thermal loop |
| * calculations. |
| * |
| * There will be, and should be, exactly one configured stepwise thermal |
| * loop assigned to each stepwise controller object, which may be shared, |
| * however, by multiple controllers. |
| * |
| * This class is not thread-safe. |
| * |
| * This class is created based on `stepwisecontroller.*` files at |
| * https://source.corp.google.com/piper///depot/google3/third_party/openbmc_phosphor_pid_control/pid/ |
| */ |
| class StepwiseController : public ThermalController { |
| public: |
| ~StepwiseController() final = default; |
| |
| static absl::StatusOr<std::unique_ptr<StepwiseController>> Create( |
| StepwiseControllerParameters params); |
| |
| void ProcessThermalLoop() final; |
| double ProcessInput() final; |
| void ProcessOutput(double output) final; |
| |
| std::string GetId() const final { return id_; } |
| bool IsFanController() const final { return false; } |
| bool IsSupportiveController() const final { return false; } |
| const std::vector<std::string>& GetAffectedControllerIds() const final { |
| return empty_affected_controller_ids_; |
| } |
| // Stepwise controller has no setpoint to be adjusted. |
| void AdjustSetpoint([[maybe_unused]] double offset) final {} |
| |
| ZoneManager* GetZoneManager() const { return zone_owner_; } |
| |
| StepwiseThermalLoop* GetStepwiseLoop() const { return stepwise_loop_.get(); } |
| |
| void AddInputSensor(const std::string& input_sensor) { |
| input_sensors_.push_back(input_sensor); |
| } |
| const std::vector<std::string>& GetInputSensors() const { |
| return input_sensors_; |
| } |
| |
| void SetIsCeiling(bool is_ceiling) { is_ceiling_ = is_ceiling; } |
| bool GetIsCeiling() const { return is_ceiling_; } |
| |
| protected: |
| explicit StepwiseController( |
| absl::string_view id, ZoneManager* absl_nonnull zone_manager, |
| std::unique_ptr<StepwiseThermalLoop> absl_nonnull stepwise_loop, |
| std::vector<std::string> input_sensors, bool is_ceiling = false) |
| : ThermalController(), |
| id_(id), |
| zone_owner_(zone_manager), |
| stepwise_loop_(std::move(stepwise_loop)), |
| input_sensors_(std::move(input_sensors)), |
| is_ceiling_(is_ceiling) {} |
| |
| private: |
| const std::string id_; |
| ZoneManager* zone_owner_; |
| |
| std::unique_ptr<StepwiseThermalLoop> stepwise_loop_; |
| std::vector<std::string> input_sensors_; |
| bool is_ceiling_ = false; |
| // An empty vector to return by reference for `GetAffectedControllerIds`. |
| const std::vector<std::string> empty_affected_controller_ids_; |
| }; |
| |
| } // namespace thermal |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_THERMAL_STEPWISE_CONTROLLER_H_ |