• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H
17 #define SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H
18 
19 #include <string>
20 #include <vector>
21 #include <unordered_map>
22 #include <unistd.h>
23 #include "libxml/parser.h"
24 #include "libxml/tree.h"
25 #include "socperf_common.h"
26 #include "socperf_handler.h"
27 
28 namespace OHOS {
29 namespace SOCPERF {
30 class SocPerf {
31 public:
32     bool Init();
33     void PerfRequest(int32_t cmdId, const std::string& msg);
34     void PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg);
35     void PowerLimitBoost(bool onOffTag, const std::string& msg);
36     void ThermalLimitBoost(bool onOffTag, const std::string& msg);
37     void LimitRequest(int32_t clientId,
38         const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg);
39 
40 public:
41     SocPerf();
42     ~SocPerf();
43 
44 private:
45     std::unordered_map<int32_t, std::shared_ptr<Actions>> perfActionsInfo;
46     std::vector<std::shared_ptr<SocPerfHandler>> handlers;
47     bool handlerSwitch[MAX_HANDLER_THREADS] = { false };
48     bool enabled = false;
49 
50     std::unordered_map<int32_t, std::shared_ptr<ResNode>> resNodeInfo;
51     std::unordered_map<int32_t, std::shared_ptr<GovResNode>> govResNodeInfo;
52     std::unordered_map<std::string, int32_t> resStrToIdInfo;
53     std::vector<std::unordered_map<int32_t, int32_t>> limitRequest;
54 
55 private:
56     std::mutex mutex_;
57     std::string GetRealConfigPath(const std::string configFile);
58     std::shared_ptr<SocPerfHandler> GetHandlerByResId(int32_t resId);
59     bool LoadConfigXmlFile(std::string configFile);
60     bool CreateHandlers();
61     void InitHandlerThreads();
62     bool LoadResource(xmlNode* rootNode, std::string configFile);
63     bool LoadGovResource(xmlNode* rootNode, std::string configFile);
64     bool LoadCmd(xmlNode* rootNode, std::string configFile);
65     bool CheckResourceTag(char* id, char* name, char* pair, char* mode, std::string configFile);
66     bool CheckResourceTag(char* def, char* path, std::string configFile);
67     bool LoadResourceAvailable(std::shared_ptr<ResNode> resNode, char* node);
68     bool CheckPairResIdValid();
69     bool CheckResDefValid();
70     bool CheckGovResourceTag(char* id, char* name, std::string configFile);
71     bool LoadGovResourceAvailable(std::shared_ptr<GovResNode> govResNode, char* level, char* node);
72     bool CheckGovResDefValid();
73     bool CheckCmdTag(char* id, char* name, std::string configFile);
74     bool CheckActionResIdAndValueValid(std::string configFile);
75     void DoFreqActions(std::shared_ptr<Actions> actions, int32_t onOff, int32_t actionType);
76     void PrintCachedInfo();
77     void SendLimitRequestEvent(int32_t clientId, int32_t resId, int64_t resValue);
78     void SendLimitRequestEventOff(std::shared_ptr<SocPerfHandler> handler,
79         int32_t clientId, int32_t resId, int32_t eventId);
80     void SendLimitRequestEventOn(std::shared_ptr<SocPerfHandler> handler,
81         int32_t clientId, int32_t resId, int64_t resValue, int32_t eventId);
82 };
83 } // namespace SOCPERF
84 } // namespace OHOS
85 #endif // SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H
86