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