| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_THERMAL_CONTROLLER_INFO_CONTROLLER_INFO_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_THERMAL_CONTROLLER_INFO_CONTROLLER_INFO_H_ |
| |
| #include <string> |
| #include <vector> |
| |
| #include "absl/base/nullability.h" |
| #include "absl/container/flat_hash_map.h" |
| #include "absl/strings/string_view.h" |
| #include "absl/synchronization/mutex.h" |
| #include "tlbmc/thermal/controller/controller.h" |
| #include "tlbmc/thermal/thermal_control_utils.h" |
| |
| namespace milotic_tlbmc { |
| namespace thermal { |
| |
| constexpr double kDefaultSetpointValue = 0.0; |
| |
| struct ThermalControllerInfo { |
| ThermalController* thermal_controller = nullptr; |
| bool is_enabled = false; |
| double setpoint = kDefaultSetpointValue; |
| }; |
| |
| /* |
| * `ControllerInfo` stores the thermal controller related information needed by |
| * `ZoneManager`. |
| * |
| * This class is conditionally thread-safe: |
| * When tuning mode is enabled, it is thread-safe at all times. Otherwise, it is |
| * expected to be read-only after initialization, and no mutex protection will |
| * be enforced. |
| */ |
| class ControllerInfo { |
| public: |
| // `AddThermalController` adds a thermal controller to the controller info. |
| // It is thread-safe at all times. |
| void AddThermalController(absl::string_view controller_name, |
| ThermalController* absl_nonnull controller, |
| bool is_enabled); |
| |
| // `SetThermalControllerEnabled` updates the enabled-or-not status of a |
| // controller. It is thread-safe at all times. |
| void SetThermalControllerEnabled(absl::string_view controller_name, |
| bool is_enabled); |
| |
| // `IsControllerEnabled` will return true if the controller exists and is |
| // enabled, otherwise it will return false. |
| bool IsControllerEnabled(absl::string_view controller_name, |
| ThreadSafetyMode thread_safety_mode = |
| ThreadSafetyMode::DisableThreadSafety); |
| |
| // `SetThermalControllerSetpoint` updates the setpoint of a controller. It is |
| // thread-safe at all times. |
| void SetThermalControllerSetpoint(absl::string_view controller_name, |
| double setpoint); |
| |
| // `GetThermalControllerSetpoint` returns the setpoint of a controller. It is |
| // not thread-safe at all times. |
| double GetThermalControllerSetpoint(absl::string_view controller_name); |
| |
| // `GetAllThermalControllers` will return all the non-null thermal controller |
| // pointers. |
| std::vector<ThermalController*> GetAllThermalControllers( |
| ThreadSafetyMode thread_safety_mode = |
| ThreadSafetyMode::DisableThreadSafety); |
| |
| // `GetAllFanControllers` will return all the non-null thermal controller |
| // pointers. |
| std::vector<ThermalController*> GetAllFanControllers( |
| ThreadSafetyMode thread_safety_mode = |
| ThreadSafetyMode::DisableThreadSafety); |
| |
| // `GetThermalController` returns the thermal controller pointer with the |
| // given name, or nullptr if the controller does not exist. |
| ThermalController* GetThermalController( |
| absl::string_view controller_name, |
| ThreadSafetyMode thread_safety_mode = |
| ThreadSafetyMode::DisableThreadSafety); |
| |
| // `GetControllerNames` returns the names of all controllers, no matter |
| // enabled or not. |
| std::vector<std::string> GetControllerNames( |
| ThreadSafetyMode thread_safety_mode = |
| ThreadSafetyMode::DisableThreadSafety); |
| |
| // Resets setpoints of all thermal controllers. |
| void Clear(); |
| |
| private: |
| absl::Mutex controllers_mutex_; |
| // `names_` should not be updated after initialization. Therefore, no need for |
| // mutex protection at all times. |
| std::vector<std::string> controller_names_; |
| // `controllers_` should not be updated after initialization. Therefore, no |
| // need for mutex protection at all times. |
| std::vector<ThermalController*> controllers_; |
| |
| absl::Mutex name_to_info_mutex_; |
| // `name_to_info_` should not be updated after initialization, except when |
| // tuning mode is enabled. Therefore, no need for mutex protection at all |
| // times. |
| absl::flat_hash_map<std::string, ThermalControllerInfo> name_to_info_; |
| }; |
| |
| } // namespace thermal |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_THERMAL_CONTROLLER_INFO_CONTROLLER_INFO_H_ |