| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "core/components/controls/control.h" |
| 7 | #include "core/components/controls/cpu/handlers/iepphandler.h" |
| 8 | #include "core/idatasource.h" |
| 9 | #include <memory> |
| 10 | #include <optional> |
| 11 | #include <string> |
| 12 | #include <string_view> |
| 13 | #include <vector> |
| 14 | |
| 15 | class CPUFreq : public Control |
| 16 | { |
| 17 | public: |
| 18 | static constexpr std::string_view ItemID{"CPU_CPUFREQ"}; |
| 19 | |
| 20 | class Importer : public IControl::Importer |
| 21 | { |
| 22 | public: |
| 23 | virtual std::string const &provideCPUFreqScalingGovernor() const = 0; |
| 24 | virtual std::optional<std::string> const &provideCPUFreqEPPHint() const = 0; |
| 25 | }; |
| 26 | |
| 27 | class Exporter : public IControl::Exporter |
| 28 | { |
| 29 | public: |
| 30 | virtual void takeCPUFreqScalingGovernor(std::string const &governor) = 0; |
| 31 | virtual void |
| 32 | takeCPUFreqScalingGovernors(std::vector<std::string> const &governors) = 0; |
| 33 | virtual void takeCPUFreqEPPHint(std::optional<std::string> const &hint) = 0; |
| 34 | virtual void |
| 35 | takeCPUFreqEPPHints(std::optional<std::vector<std::string>> const &hints) = 0; |
| 36 | }; |
| 37 | |
| 38 | CPUFreq(std::vector<std::string> &&scalingGovernors, |
| 39 | std::string const &defaultGovernor, |
| 40 | std::vector<std::unique_ptr<IDataSource<std::string>>> |
| 41 | &&scalingGovernorDataSources, |
| 42 | std::unique_ptr<IEPPHandler> &&eppHandler = nullptr) noexcept; |
| 43 | |
| 44 | void preInit(ICommandQueue &ctlCmds) final override; |
| 45 | void postInit(ICommandQueue &ctlCmds) final override; |
| 46 | void init() final override; |
| 47 | |
| 48 | std::string const &ID() const final override; |
| 49 | |
| 50 | protected: |
| 51 | void importControl(IControl::Importer &i) final override; |
| 52 | void exportControl(IControl::Exporter &e) const final override; |
| 53 | |
| 54 | void cleanControl(ICommandQueue &ctlCmds) final override; |
| 55 | void syncControl(ICommandQueue &ctlCmds) final override; |
| 56 | |
| 57 | std::string const &scalingGovernor() const; |
| 58 | void scalingGovernor(std::string const &governor); |
| 59 | std::vector<std::string> const &scalingGovernors() const; |
| 60 | |
| 61 | std::optional<std::string> eppHint() const; |
| 62 | std::optional<std::vector<std::string>> eppHints() const; |
| 63 | |
| 64 | private: |
| 65 | void syncScalingGovernor(std::string const &governor, ICommandQueue &ctlCmds); |
| 66 | |
| 67 | std::string const id_; |
| 68 | std::vector<std::string> const scalingGovernors_; |
| 69 | std::vector<std::unique_ptr<IDataSource<std::string>>> const |
| 70 | scalingGovernorDataSources_; |
| 71 | std::unique_ptr<IEPPHandler> eppHandler_; |
| 72 | |
| 73 | std::string const eppScalingGovernor_{"powersave"}; |
| 74 | std::string scalingGovernor_; |
| 75 | std::string dataSourceEntry_; |
| 76 | }; |