• 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_H
17 #define SOC_PERF_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(int cmdId, const std::string& msg);
35     void PerfRequestEx(int cmdId, bool onOffTag, const std::string& msg);
36     void PowerRequest(int cmdId, const std::string& msg);
37     void PowerRequestEx(int cmdId, bool onOffTag, const std::string& msg);
38     void PowerLimitBoost(bool onOffTag, const std::string& msg);
39     void ThermalRequest(int cmdId, const std::string& msg);
40     void ThermalRequestEx(int cmdId, bool onOffTag, const std::string& msg);
41     void ThermalLimitBoost(bool onOffTag, const std::string& msg);
42 
43 public:
44     SocPerf();
45     ~SocPerf();
46 
47 private:
48     std::unordered_map<int, std::shared_ptr<Action>> perfActionInfo;
49     std::unordered_map<int, std::shared_ptr<Action>> powerActionInfo;
50     std::unordered_map<int, std::shared_ptr<Action>> thermalActionInfo;
51     std::vector<std::shared_ptr<SocPerfHandler>> handlers;
52     bool enabled = false;
53 
54     std::unordered_map<int, std::shared_ptr<ResNode>> resNodeInfo;
55     std::unordered_map<int, std::shared_ptr<GovResNode>> govResNodeInfo;
56     std::unordered_map<std::string, int> resStrToIdInfo;
57 
58 private:
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 DoFreqAction(std::shared_ptr<Action> action, int onOff, int actionType);
76     void PrintCachedInfo();
77 };
78 } // namespace SOCPERF
79 } // namespace OHOS
80 
81 #endif // SOC_PERF_H