• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_INCLUDE_CORE_SOCPERF_H
17 #define SOC_PERF_INCLUDE_CORE_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 "i_socperf_service.h"
26 #include "socperf_common.h"
27 #include "socperf_handler.h"
28 
29 namespace OHOS {
30 namespace SOCPERF {
31 class SocPerf {
32 public:
33     bool Init();
34     void PerfRequest(int32_t cmdId, const std::string& msg);
35     void PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg);
36     void PowerLimitBoost(bool onOffTag, const std::string& msg);
37     void ThermalLimitBoost(bool onOffTag, const std::string& msg);
38     void LimitRequest(int32_t clientId,
39         const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg);
40 
41 public:
42     SocPerf();
43     ~SocPerf();
44 
45 private:
46     std::unordered_map<int32_t, std::shared_ptr<Actions>> perfActionsInfo;
47     std::vector<std::shared_ptr<SocPerfHandler>> handlers;
48     bool enabled = false;
49     bool debugLogEnabled = false;
50 
51     std::unordered_map<int32_t, std::shared_ptr<ResNode>> resNodeInfo;
52     std::unordered_map<int32_t, std::shared_ptr<GovResNode>> govResNodeInfo;
53     std::unordered_map<std::string, int32_t> resStrToIdInfo;
54     std::vector<std::unordered_map<int32_t, int32_t>> limitRequest;
55 
56 private:
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 };
78 } // namespace SOCPERF
79 } // namespace OHOS
80 
81 #endif // SOC_PERF_INCLUDE_CORE_SOCPERF_H
82