1 /* 2 * Copyright (c) 2022-2024 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 #ifndef SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_THREAD_WRAP_H 17 #define SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_THREAD_WRAP_H 18 19 #include "ffrt.h" 20 #include "ffrt_inner.h" 21 #include "socperf_common.h" 22 #include "socperf_config.h" 23 namespace OHOS { namespace SOCPERF { class GovResNode; } } 24 namespace OHOS { namespace SOCPERF { class ResAction; } } 25 namespace OHOS { namespace SOCPERF { class ResNode; } } 26 namespace OHOS { namespace SOCPERF { class ResStatus; } } 27 28 namespace OHOS { 29 namespace SOCPERF { 30 enum SocPerfInnerEvent : uint32_t { 31 INNER_EVENT_ID_INIT_RESOURCE_NODE_INFO = 0, 32 INNER_EVENT_ID_DO_FREQ_ACTION, 33 INNER_EVENT_ID_DO_FREQ_ACTION_PACK, 34 INNER_EVENT_ID_DO_FREQ_ACTION_DELAYED, 35 INNER_EVENT_ID_POWER_LIMIT_BOOST_FREQ, 36 INNER_EVENT_ID_THERMAL_LIMIT_BOOST_FREQ, 37 INNER_EVENT_ID_DO_FREQ_ACTION_LEVEL, 38 INNER_EVENT_ID_CLEAR_ALL_ALIVE_REQUEST 39 }; 40 41 enum RssExeEventType { 42 SOCPERF_EVENT_IVALID = 0, 43 SOCPERF_EVENT_WIRTE_NODE = 1, 44 }; 45 46 namespace { 47 const std::string QOSID_STRING = "qosId"; 48 const std::string VALUE_STRING = "value"; 49 } 50 51 class SocPerfThreadWrap { 52 public: 53 explicit SocPerfThreadWrap(); 54 ~SocPerfThreadWrap(); 55 void InitResourceNodeInfo(); 56 void DoFreqActionPack(std::shared_ptr<ResActionItem> head); 57 void UpdatePowerLimitBoostFreq(bool powerLimitBoost); 58 void UpdateThermalLimitBoostFreq(bool thermalLimitBoost); 59 void UpdateLimitStatus(int32_t eventId, std::shared_ptr<ResAction> resAction, int32_t resId); 60 void PostDelayTask(std::shared_ptr<ResActionItem> queueHead); 61 void SetWeakInteractionStatus(bool enable); 62 void ClearAllAliveRequest(); 63 public: 64 int32_t thermalLvl_ = DEFAULT_THERMAL_LVL; 65 66 private: 67 static const int32_t SCALES_OF_MILLISECONDS_TO_MICROSECONDS = 1000; 68 std::unordered_map<int32_t, std::shared_ptr<ResStatus>> resStatusInfo_; 69 SocPerfConfig &socPerfConfig_ = SocPerfConfig::GetInstance(); 70 ffrt::queue socperfQueue_; 71 bool powerLimitBoost_ = false; 72 bool thermalLimitBoost_ = false; 73 bool weakInteractionStatus_ = true; 74 int boostResCnt = 0; 75 76 private: 77 void InitResStatus(); 78 void SendResStatus(); 79 void ReportToPerfSo(std::vector<int32_t>& qosId, std::vector<int64_t>& value, std::vector<int64_t>& endTime); 80 void ReportToRssExe(std::vector<int32_t>& qosId, std::vector<int64_t>& value, std::vector<int64_t>& endTime); 81 bool GetResValueByLevel(int32_t resId, int32_t level, int64_t& resValue); 82 void UpdateResActionList(int32_t resId, std::shared_ptr<ResAction> resAction, bool delayed); 83 void UpdateResActionListByDelayedMsg(int32_t resId, int32_t type, 84 std::shared_ptr<ResAction> resAction, std::shared_ptr<ResStatus> resStatus); 85 void UpdateResActionListByInstantMsg(int32_t resId, int32_t type, 86 std::shared_ptr<ResAction> resAction, std::shared_ptr<ResStatus> resStatus); 87 void UpdateCandidatesValue(int32_t resId, int32_t type); 88 void InnerArbitrateCandidatesValue(int32_t type, std::shared_ptr<ResStatus> resStatus); 89 void ArbitrateCandidate(int32_t resId); 90 void ArbitratePairRes(int32_t resId, bool perfRequestLimit); 91 void ProcessLimitCase(int32_t resId); 92 bool ArbitratePairResInPerfLvl(int32_t resId); 93 void UpdatePairResValue(int32_t minResId, int64_t minResValue, int32_t maxResId, int64_t maxResValue); 94 void UpdateCurrentValue(int32_t resId, int64_t value); 95 bool ExistNoCandidate(int32_t resId, std::shared_ptr<ResStatus> resStatus); 96 void DoFreqAction(int32_t resId, std::shared_ptr<ResAction> resAction); 97 void DoFreqActionLevel(int32_t resId, std::shared_ptr<ResAction> resAction); 98 void HandleResAction(int32_t resId, int32_t type, 99 std::shared_ptr<ResAction> resAction, std::shared_ptr<ResStatus> resStatus); 100 void DoWeakInteraction(std::shared_ptr<Actions> actions, int32_t onOff, int32_t actionType); 101 void WeakInteraction(); 102 }; 103 } // namespace SOCPERF 104 } // namespace OHOS 105 106 #endif // SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_THREAD_WRAP_H 107