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 }
31
InitParams(const std::string & params)32 void ActionCpuBig::InitParams(const std::string& params)
33 {
34 if (params == "multi-core") {
35 multiCoreflag_ = true;
36 }
37 }
38
SetStrict(bool enable)39 void ActionCpuBig::SetStrict(bool enable)
40 {
41 isStrict_ = enable;
42 }
43
SetEnableEvent(bool enable)44 void ActionCpuBig::SetEnableEvent(bool enable)
45 {
46 enableEvent_ = enable;
47 }
48
AddActionValue(std::string value)49 void ActionCpuBig::AddActionValue(std::string value)
50 {
51 if (value.empty()) {
52 return;
53 }
54 valueList_.push_back(static_cast<uint32_t>(strtol(value.c_str(), nullptr, STRTOL_FORMART_DEC)));
55 }
56
Execute()57 void ActionCpuBig::Execute()
58 {
59 auto tms = ThermalService::GetInstance();
60 THERMAL_RETURN_IF (tms == nullptr);
61 uint32_t value = GetActionValue();
62 if (value != lastValue_) {
63 if (multiCoreflag_) {
64 SocLimitRequest(LIM_CPU_BIG2_ID, value);
65 SocLimitRequest(LIM_CPU_BIG3_ID, value);
66 SocLimitRequest(LIM_CPU_BIG4_ID, value);
67 }
68 SocLimitRequest(LIM_CPU_BIG_ID, value);
69 WriteActionTriggeredHiSysEvent(enableEvent_, actionName_, value);
70 tms->GetObserver()->SetDecisionValue(actionName_, std::to_string(value));
71 lastValue_ = value;
72 THERMAL_HILOGD(COMP_SVC, "action execute: {%{public}s = %{public}u}", actionName_.c_str(), lastValue_);
73 }
74 valueList_.clear();
75 }
76
GetActionValue()77 uint32_t ActionCpuBig::GetActionValue()
78 {
79 uint32_t value = FALLBACK_VALUE_UINT_SOC;
80 if (!valueList_.empty()) {
81 if (isStrict_) {
82 value = *min_element(valueList_.begin(), valueList_.end());
83 } else {
84 value = *max_element(valueList_.begin(), valueList_.end());
85 }
86 }
87 return value;
88 }
89 } // namespace PowerMgr
90 } // namespace OHOS
91