| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/components/controls/cpu/cpufreq.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "cpufreq.h"cxx . . $ `<file>/src/core/components/controls/cpu/cpufreq.h`/ |
| 5 | |
| 6 | #include "core/icommandqueue.h"cxx . . $ `<file>/src/core/icommandqueue.h`/ |
| 7 | #include <algorithm> |
| 8 | #include <cassert> |
| 9 | #include <utility> |
| 10 | |
| 11 | CPUFreqcxx . . $ CPUFreq#::CPUFreqcxx . . $ CPUFreq#CPUFreq(b0ad3956e833d53d).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> &&scalingGovernors, |
| 12 | stdcxx . . $ std/::stringcxx . . $ std/string# const &defaultGovernor, |
| 13 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IDataSourcecxx . . $ IDataSource#<stdcxx . . $ std/::stringcxx . . $ std/string#>>> |
| 14 | &&scalingGovernorDataSources, |
| 15 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IEPPHandlercxx . . $ IEPPHandler#> &&eppHandler) noexcept |
| 16 | : Controlcxx . . $ Control#(true) |
| 17 | , id_cxx . . $ CPUFreq#id_.(CPUFreqcxx . . $ CPUFreq#::ItemIDcxx . . $ CPUFreq#ItemID.) |
| 18 | , scalingGovernors_cxx . . $ CPUFreq#scalingGovernors_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(scalingGovernors)) |
| 19 | , scalingGovernorDataSources_cxx . . $ CPUFreq#scalingGovernorDataSources_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(scalingGovernorDataSources)) |
| 20 | , eppHandler_cxx . . $ CPUFreq#eppHandler_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(eppHandler)) |
| 21 | { |
| 22 | scalingGovernorcxx . . $ CPUFreq#scalingGovernor(9c546c94e5fcce4e).(defaultGovernor); |
| 23 | if (scalingGovernor_cxx . . $ CPUFreq#scalingGovernor_..emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 24 | scalingGovernorcxx . . $ CPUFreq#scalingGovernor(9c546c94e5fcce4e).(scalingGovernors_cxx . . $ CPUFreq#scalingGovernors_..frontcxx . . $ std/vector#front(af0004c3ce7cab93).()); |
| 25 | } |
| 26 | |
| 27 | void CPUFreqcxx . . $ CPUFreq#::preInitcxx . . $ CPUFreq#preInit(151e9138769f295e).(ICommandQueuecxx . . $ ICommandQueue# &ctlCmds) |
| 28 | { |
| 29 | if (eppHandler_cxx . . $ CPUFreq#eppHandler_.) |
| 30 | // We need to set the EPP scaling governor as the current scaling governor |
| 31 | // before the initialization of the EPP handler. |
| 32 | syncScalingGovernorcxx . . $ CPUFreq#syncScalingGovernor(64a8914dcf7b3242).(eppScalingGovernor_cxx . . $ CPUFreq#eppScalingGovernor_., ctlCmds); |
| 33 | } |
| 34 | |
| 35 | void CPUFreqcxx . . $ CPUFreq#::postInitcxx . . $ CPUFreq#postInit(151e9138769f295e).(ICommandQueuecxx . . $ ICommandQueue# &) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | void CPUFreqcxx . . $ CPUFreq#::initcxx . . $ CPUFreq#init(49f6e7a06ebc5aa8).() |
| 40 | { |
| 41 | if (eppHandler_cxx . . $ CPUFreq#eppHandler_.) |
| 42 | eppHandler_cxx . . $ CPUFreq#eppHandler_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).initcxx . . $ IEPPHandler#init(49f6e7a06ebc5aa8).(); |
| 43 | } |
| 44 | |
| 45 | stdcxx . . $ std/::stringcxx . . $ std/string# const &CPUFreqcxx . . $ CPUFreq#::IDcxx . . $ CPUFreq#ID(f4fff0029955a25f).() const |
| 46 | { |
| 47 | return id_cxx . . $ CPUFreq#id_.; |
| 48 | } |
| 49 | |
| 50 | void CPUFreqcxx . . $ CPUFreq#::importControlcxx . . $ CPUFreq#importControl(4f796e3ecd5dcd94).(IControlcxx . . $ IControl#::Importercxx . . $ IControl#Importer# &i) |
| 51 | { |
| 52 | auto &importer = dynamic_cast<CPUFreqcxx . . $ CPUFreq#::Importercxx . . $ CPUFreq#Importer# &>(i); |
| 53 | scalingGovernorcxx . . $ CPUFreq#scalingGovernor(9c546c94e5fcce4e).(importer.provideCPUFreqScalingGovernorcxx . . $ CPUFreq#Importer#provideCPUFreqScalingGovernor(f4fff0029955a25f).()); |
| 54 | |
| 55 | if (eppHandler_cxx . . $ CPUFreq#eppHandler_.) { |
| 56 | auto hint = importer.provideCPUFreqEPPHintcxx . . $ CPUFreq#Importer#provideCPUFreqEPPHint(f34183478aa9387b).(); |
| 57 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(hint.has_value()); |
| 58 | eppHandler_cxx . . $ CPUFreq#eppHandler_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).hintcxx . . $ IEPPHandler#hint(9c546c94e5fcce4e).(*cxx . . $ std/optional#`operator*`(47e1a15210ec6306).hint); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void CPUFreqcxx . . $ CPUFreq#::exportControlcxx . . $ CPUFreq#exportControl(40299682ab9c8676).(IControlcxx . . $ IControl#::Exportercxx . . $ IControl#Exporter# &e) const |
| 63 | { |
| 64 | auto &exporter = dynamic_cast<CPUFreqcxx . . $ CPUFreq#::Exportercxx . . $ CPUFreq#Exporter# &>(e); |
| 65 | exporter.takeCPUFreqScalingGovernorscxx . . $ CPUFreq#Exporter#takeCPUFreqScalingGovernors(eb4a68411a16b7e7).(scalingGovernorscxx . . $ CPUFreq#scalingGovernors(f5f2959be38ccc08).()); |
| 66 | exporter.takeCPUFreqEPPHintscxx . . $ CPUFreq#Exporter#takeCPUFreqEPPHints(2ecf63ce205bf0f4).(eppHintscxx . . $ CPUFreq#eppHints(a019dd56d320b4d4).()); |
| 67 | exporter.takeCPUFreqScalingGovernorcxx . . $ CPUFreq#Exporter#takeCPUFreqScalingGovernor(9c546c94e5fcce4e).(scalingGovernorcxx . . $ CPUFreq#scalingGovernor(f4fff0029955a25f).()); |
| 68 | exporter.takeCPUFreqEPPHintcxx . . $ CPUFreq#Exporter#takeCPUFreqEPPHint(d049417f242f31d7).(eppHintcxx . . $ CPUFreq#eppHint(5ce91bc52c9d8e1).()); |
| 69 | } |
| 70 | |
| 71 | void CPUFreqcxx . . $ CPUFreq#::cleanControlcxx . . $ CPUFreq#cleanControl(151e9138769f295e).(ICommandQueuecxx . . $ ICommandQueue# &) |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | void CPUFreqcxx . . $ CPUFreq#::syncControlcxx . . $ CPUFreq#syncControl(151e9138769f295e).(ICommandQueuecxx . . $ ICommandQueue# &ctlCmds) |
| 76 | { |
| 77 | syncScalingGovernorcxx . . $ CPUFreq#syncScalingGovernor(64a8914dcf7b3242).(scalingGovernorcxx . . $ CPUFreq#scalingGovernor(f4fff0029955a25f).(), ctlCmds); |
| 78 | if (eppHandler_cxx . . $ CPUFreq#eppHandler_. && scalingGovernorcxx . . $ CPUFreq#scalingGovernor(f4fff0029955a25f).() ==cxx . . $ std/`operator==`(5ea818b58063a774). eppScalingGovernor_cxx . . $ CPUFreq#eppScalingGovernor_.) |
| 79 | eppHandler_cxx . . $ CPUFreq#eppHandler_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).synccxx . . $ IDataSourceHandler#sync(151e9138769f295e).(ctlCmds); |
| 80 | } |
| 81 | |
| 82 | stdcxx . . $ std/::stringcxx . . $ std/string# const &CPUFreqcxx . . $ CPUFreq#::scalingGovernorcxx . . $ CPUFreq#scalingGovernor(f4fff0029955a25f).() const |
| 83 | { |
| 84 | return scalingGovernor_cxx . . $ CPUFreq#scalingGovernor_.; |
| 85 | } |
| 86 | |
| 87 | void CPUFreqcxx . . $ CPUFreq#::scalingGovernorcxx . . $ CPUFreq#scalingGovernor(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const &scalingGovernor) |
| 88 | { |
| 89 | // only assign known scalingGovernors |
| 90 | auto iter = stdcxx . . $ std/::find_ifcxx . . $ std/find_if(f0a0a4f94ee5cb00).(scalingGovernorscxx . . $ CPUFreq#scalingGovernors(f5f2959be38ccc08).().cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), |
| 91 | scalingGovernorscxx . . $ CPUFreq#scalingGovernors(f5f2959be38ccc08).().cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), |
| 92 | [&](auto const &availableScalingGovernor) { |
| 93 | return scalingGovernor == availableScalingGovernor; |
| 94 | }); |
| 95 | if (iter != scalingGovernorscxx . . $ CPUFreq#scalingGovernors(f5f2959be38ccc08).().cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).()) |
| 96 | scalingGovernor_cxx . . $ CPUFreq#scalingGovernor_. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). scalingGovernor; |
| 97 | } |
| 98 | |
| 99 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> const &CPUFreqcxx . . $ CPUFreq#::scalingGovernorscxx . . $ CPUFreq#scalingGovernors(f5f2959be38ccc08).() const |
| 100 | { |
| 101 | return scalingGovernors_cxx . . $ CPUFreq#scalingGovernors_.; |
| 102 | } |
| 103 | |
| 104 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::stringcxx . . $ std/string#> CPUFreqcxx . . $ CPUFreq#::eppHintcxx . . $ CPUFreq#eppHint(5ce91bc52c9d8e1).() const |
| 105 | { |
| 106 | return eppHandler_cxx . . $ CPUFreq#eppHandler_. ? stdcxx . . $ std/::make_optionalcxx . . $ std/make_optional(e412eef0971c0904).(eppHandler_cxx . . $ CPUFreq#eppHandler_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).hintcxx . . $ IEPPHandler#hint(f4fff0029955a25f).()) : stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.; |
| 107 | } |
| 108 | |
| 109 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#>> CPUFreqcxx . . $ CPUFreq#::eppHintscxx . . $ CPUFreq#eppHints(a019dd56d320b4d4).() const |
| 110 | { |
| 111 | return eppHandler_cxx . . $ CPUFreq#eppHandler_. ? stdcxx . . $ std/::make_optionalcxx . . $ std/make_optional(e412eef0971c0904).(eppHandler_cxx . . $ CPUFreq#eppHandler_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).hintscxx . . $ IEPPHandler#hints(f5f2959be38ccc08).()) : stdcxx . . $ std/optional#optional(eb2253fdec8870b5).::nulloptcxx . . $ std/nullopt.; |
| 112 | } |
| 113 | |
| 114 | void CPUFreqcxx . . $ CPUFreq#::syncScalingGovernorcxx . . $ CPUFreq#syncScalingGovernor(64a8914dcf7b3242).(stdcxx . . $ std/::stringcxx . . $ std/string# const &governor, |
| 115 | ICommandQueuecxx . . $ ICommandQueue# &ctlCmds) |
| 116 | { |
| 117 | for (auto &scalingGovernorDataSource : scalingGovernorDataSources_cxx . . $ CPUFreq#scalingGovernorDataSources_.) |
| 118 | if (scalingGovernorDataSource->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).readcxx . . $ IDataSource#read(ad81cd1bcc32f58b).(dataSourceEntry_cxx . . $ CPUFreq#dataSourceEntry_.)) { |
| 119 | if (dataSourceEntry_cxx . . $ CPUFreq#dataSourceEntry_. != governor) |
| 120 | ctlCmds.addcxx . . $ ICommandQueue#add(358a66d3ce188717).({cxx . . $ std/pair#pair(62e1774a2dc03c82).scalingGovernorDataSource->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).sourcecxx . . $ IDataSource#source(219584694fe2b248).(), governor}); |
| 121 | } |
| 122 | } |