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_HANDLER_H 17 #define SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_HANDLER_H 18 19 20 #include <memory> // for shared_ptr 21 #include <string> // for string 22 #include <unordered_map> // for unordered_map 23 #include <stdint.h> // for uint32_t 24 #include "event_handler.h" // for EventHandler 25 #include "event_runner.h" 26 #include "inner_event.h" // for InnerEvent, InnerEvent::Pointer 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_RES_NODE_INFO = 0, 36 INNER_EVENT_ID_INIT_GOV_RES_NODE_INFO, 37 INNER_EVENT_ID_DO_FREQ_ACTION, 38 INNER_EVENT_ID_DO_FREQ_ACTION_PACK, 39 INNER_EVENT_ID_DO_FREQ_ACTION_DELAYED, 40 INNER_EVENT_ID_POWER_LIMIT_BOOST_FREQ, 41 INNER_EVENT_ID_THERMAL_LIMIT_BOOST_FREQ, 42 INNER_EVENT_ID_DO_FREQ_ACTION_LEVEL, 43 }; 44 45 class SocPerfHandler : public AppExecFwk::EventHandler { 46 public: 47 explicit SocPerfHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner); 48 ~SocPerfHandler() override; 49 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override; 50 51 private: 52 std::unordered_map<int32_t, std::shared_ptr<ResNode>> resNodeInfo; 53 std::unordered_map<int32_t, std::shared_ptr<GovResNode>> govResNodeInfo; 54 std::unordered_map<int32_t, std::shared_ptr<ResStatus>> resStatusInfo; 55 std::unordered_map<std::string, int32_t> fdInfo; 56 bool powerLimitBoost = false; 57 bool thermalLimitBoost = false; 58 59 private: 60 void HandleDoFreqActionLevel(int32_t resId, std::shared_ptr<ResAction> resAction); 61 bool GetResValueByLevel(int32_t resId, int32_t level, int64_t& resValue); 62 void UpdateResActionList(int32_t resId, std::shared_ptr<ResAction> resAction, bool delayed); 63 void UpdateCandidatesValue(int32_t resId, int32_t type); 64 void ArbitrateCandidate(int32_t resId); 65 void ArbitratePairRes(int32_t resId); 66 void UpdatePairResValue(int32_t minResId, int64_t minResValue, int32_t maxResId, int64_t maxResValue); 67 void UpdateCurrentValue(int32_t resId, int64_t value); 68 void WriteNode(std::string path, std::string value); 69 bool ExistNoCandidate( 70 int32_t resId, std::shared_ptr<ResStatus> resStatus, int64_t perf, int64_t power, int64_t thermal); 71 bool IsGovResId(int32_t resId); 72 bool IsResId(int32_t resId); 73 bool IsValidResId(int32_t resId); 74 int32_t GetFdForFilePath(std::string filePath); 75 }; 76 } // namespace SOCPERF 77 } // namespace OHOS 78 79 #endif // SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_HANDLER_H 80