• 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_H
17 #define SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H
18 
19 #include <set>
20 #include "libxml/tree.h"
21 #include "socperf_thread_wrap.h"
22 #include "socperf_config.h"
23 
24 namespace OHOS {
25 namespace SOCPERF {
26 class SocPerf {
27 public:
28     bool Init();
29     void PerfRequest(int32_t cmdId, const std::string& msg);
30     void PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg);
31     void PowerLimitBoost(bool onOffTag, const std::string& msg);
32     void ThermalLimitBoost(bool onOffTag, const std::string& msg);
33     void LimitRequest(int32_t clientId,
34         const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg);
35     void SetRequestStatus(bool status, const std::string& msg);
36     void SetThermalLevel(int32_t level);
37     void RequestDeviceMode(const std::string& mode, bool status);
38     std::string RequestCmdIdCount(const std::string& msg);
39 public:
40     SocPerf();
41     ~SocPerf();
42 
43 private:
44     bool enabled_ = false;
45     std::shared_ptr<SocPerfThreadWrap> socperfThreadWrap_;
46     std::set<std::string> recordDeviceMode_;
47     std::vector<std::unordered_map<int32_t, int32_t>> limitRequest_ =
48         std::vector<std::unordered_map<int32_t, int32_t>>(ACTION_TYPE_MAX);
49     volatile bool perfRequestEnable_ = true;
50     int32_t thermalLvl_ = DEFAULT_THERMAL_LVL;
51     bool batteryLimitStatus_ = false;
52     bool powerLimitStatus_ = false;
53     SocPerfConfig &socPerfConfig_ = SocPerfConfig::GetInstance();
54     std::unordered_map<int32_t, uint32_t> boostCmdCount_;
55     std::unordered_map<int32_t, uint64_t> boostTime_;
56 private:
57     std::mutex mutex_;
58     std::mutex mutexDeviceMode_;
59     std::mutex mutexBoostCmdCount_;
60     std::mutex mutexBoostTime_;
61     bool CreateThreadWraps();
62     void InitThreadWraps();
63     void DoFreqActions(std::shared_ptr<Actions> actions, int32_t onOff, int32_t actionType);
64     std::shared_ptr<ResActionItem> DoPerfRequestThremalLvl(int32_t cmdId, std::shared_ptr<Action> originAction,
65         int32_t onOff, std::shared_ptr<ResActionItem> curItem, int64_t endTime);
66     void SendLimitRequestEvent(int32_t clientId, int32_t resId, int64_t resValue);
67     int32_t MatchDeviceModeCmd(int32_t cmdId, bool isTagOnOff);
68     void SendLimitRequestEventOff(std::shared_ptr<SocPerfThreadWrap> threadWrap,
69         int32_t clientId, int32_t resId, int32_t eventId);
70     void SendLimitRequestEventOn(std::shared_ptr<SocPerfThreadWrap> threadWrap,
71         int32_t clientId, int32_t resId, int64_t resValue, int32_t eventId);
72     void ClearAllAliveRequest();
73     void UpdateCmdIdCount(int32_t cmdId);
74     void CopyEvent(const int32_t oldCmdId, const int32_t newCmdId,
75         std::unordered_map<int32_t, std::shared_ptr<Actions>>& perfActionsInfo);
76     bool CheckTimeInterval(bool onOff, int32_t cmdId);
77     bool CompleteEvent();
78     std::string GetDeviceMode();
79     int32_t GetMatchCmdId(int32_t cmdId, bool isTagOnOff);
80     std::string MatchDeviceMode(const std::string& mode, bool status,
81         const std::vector<std::shared_ptr<SceneItem>>& items);
82     std::shared_ptr<Actions> GetActionsInfo(int32_t cmdId);
83 };
84 } // namespace SOCPERF
85 } // namespace OHOS
86 #endif // SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H
87