1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "action_cpu_boost.h"
17
18 #include "constants.h"
19 #include "thermal_hisysevent.h"
20 #include "thermal_service.h"
21
22 namespace OHOS {
23 namespace PowerMgr {
24 namespace {
25 constexpr int32_t BOOST_DISABLE_VALUE = 100;
26 }
27
ActionCpuBoost(const std::string & actionName)28 ActionCpuBoost::ActionCpuBoost(const std::string& actionName)
29 {
30 actionName_ = actionName;
31 }
32
InitParams(const std::string & params)33 void ActionCpuBoost::InitParams(const std::string& params)
34 {
35 (void)params;
36 }
37
SetStrict(bool enable)38 void ActionCpuBoost::SetStrict(bool enable)
39 {
40 isStrict_ = enable;
41 }
42
SetEnableEvent(bool enable)43 void ActionCpuBoost::SetEnableEvent(bool enable)
44 {
45 enableEvent_ = enable;
46 }
47
AddActionValue(std::string value)48 void ActionCpuBoost::AddActionValue(std::string value)
49 {
50 if (value.empty()) {
51 return;
52 }
53 valueList_.push_back(static_cast<uint32_t>(atoi(value.c_str())));
54 }
55
Execute()56 void ActionCpuBoost::Execute()
57 {
58 auto tms = ThermalService::GetInstance();
59 THERMAL_RETURN_IF (tms == nullptr);
60 uint32_t value = GetActionValue();
61 if (value != lastValue_) {
62 if (value == BOOST_DISABLE_VALUE) {
63 SetBoostEnable(false);
64 } else {
65 SetBoostEnable(true);
66 SetSocPerfThermalLevel(value);
67 }
68 WriteActionTriggeredHiSysEvent(enableEvent_, actionName_, value);
69 tms->GetObserver()->SetDecisionValue(actionName_, std::to_string(value));
70 lastValue_ = value;
71 THERMAL_HILOGD(COMP_SVC, "action execute: {%{public}s = %{public}d}", actionName_.c_str(), lastValue_);
72 }
73 valueList_.clear();
74 }
75
GetActionValue()76 uint32_t ActionCpuBoost::GetActionValue()
77 {
78 uint32_t value = FALLBACK_VALUE_UINT_ZERO;
79 if (!valueList_.empty()) {
80 if (isStrict_) {
81 value = *min_element(valueList_.begin(), valueList_.end());
82 } else {
83 value = *max_element(valueList_.begin(), valueList_.end());
84 }
85 }
86 return value;
87 }
88 } // namespace PowerMgr
89 } // namespace OHOS
90