1 /*
2 * Copyright (c) 2022-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_big.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 }
26
ActionCpuBig(const std::string & actionName)27 ActionCpuBig::ActionCpuBig(const std::string& actionName)
28 {
29 actionName_ = actionName;
30 SocActionBase::SocSet.insert(actionName_);
31 }
32
InitParams(const std::string & params)33 void ActionCpuBig::InitParams(const std::string& params)
34 {
35 if (params == "multi-core") {
36 multiCoreflag_ = true;
37 }
38 }
39
SetStrict(bool enable)40 void ActionCpuBig::SetStrict(bool enable)
41 {
42 isStrict_ = enable;
43 }
44
SetEnableEvent(bool enable)45 void ActionCpuBig::SetEnableEvent(bool enable)
46 {
47 enableEvent_ = enable;
48 }
49
AddActionValue(uint32_t actionId,std::string value)50 void ActionCpuBig::AddActionValue(uint32_t actionId, std::string value)
51 {
52 if (value.empty()) {
53 return;
54 }
55 if (actionId > 0) {
56 auto iter = policyActionMap_.find(actionId);
57 if (iter != policyActionMap_.end()) {
58 iter->second.uintDelayValue = static_cast<uint32_t>(strtol(value.c_str(),
59 nullptr, STRTOL_FORMART_DEC));
60 }
61 } else {
62 valueList_.push_back(static_cast<uint32_t>(strtol(value.c_str(), nullptr, STRTOL_FORMART_DEC)));
63 }
64 }
65
ExecuteInner()66 void ActionCpuBig::ExecuteInner()
67 {
68 auto tms = ThermalService::GetInstance();
69 THERMAL_RETURN_IF (tms == nullptr);
70 for (auto &policyAction : policyActionMap_) {
71 if (policyAction.second.isCompleted) {
72 valueList_.push_back(policyAction.second.uintDelayValue);
73 }
74 }
75
76 uint32_t value = GetActionValue();
77 if (value != lastValue_) {
78 if (multiCoreflag_) {
79 SocLimitRequest(LIM_CPU_BIG2_ID, value);
80 SocLimitRequest(LIM_CPU_BIG3_ID, value);
81 SocLimitRequest(LIM_CPU_BIG4_ID, value);
82 }
83 SocLimitRequest(LIM_CPU_BIG_ID, value);
84 WriteActionTriggeredHiSysEvent(enableEvent_, actionName_, value);
85 tms->GetObserver()->SetDecisionValue(actionName_, std::to_string(value));
86 lastValue_ = value;
87 THERMAL_HILOGD(COMP_SVC, "action execute: {%{public}s = %{public}u}", actionName_.c_str(), lastValue_);
88 }
89 valueList_.clear();
90 }
91
ResetActionValue()92 void ActionCpuBig::ResetActionValue()
93 {
94 lastValue_ = 0;
95 }
96
GetActionValue()97 uint32_t ActionCpuBig::GetActionValue()
98 {
99 uint32_t value = FALLBACK_VALUE_UINT_SOC;
100 if (!valueList_.empty()) {
101 if (isStrict_) {
102 value = *min_element(valueList_.begin(), valueList_.end());
103 } else {
104 value = *max_element(valueList_.begin(), valueList_.end());
105 }
106 }
107 return value;
108 }
109 } // namespace PowerMgr
110 } // namespace OHOS
111