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_HANDLER_H 17 #define SOC_PERF_INCLUDE_CORE_SOCPERF_HANDLER_H 18 19 #include <cstdint> // for int32_t 20 #include <memory> // for allocator 21 #include <unordered_map> // for unordered_map 22 #include <iosfwd> // for string 23 #include <memory> // for shared_ptr 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 class SocPerfHandler : public AppExecFwk::EventHandler { 35 public: 36 explicit SocPerfHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner); 37 ~SocPerfHandler() override; 38 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override; 39 40 private: 41 std::unordered_map<int32_t, std::shared_ptr<ResNode>> resNodeInfo; 42 std::unordered_map<int32_t, std::shared_ptr<GovResNode>> govResNodeInfo; 43 std::unordered_map<int32_t, std::shared_ptr<ResStatus>> resStatusInfo; 44 std::unordered_map<std::string, int32_t> fdInfo; 45 bool powerLimitBoost = false; 46 bool thermalLimitBoost = false; 47 48 private: 49 void UpdateResActionList(int32_t resId, std::shared_ptr<ResAction> resAction, bool delayed); 50 void UpdateCandidatesValue(int32_t resId, int32_t type); 51 void ArbitrateCandidate(int32_t resId); 52 void ArbitratePairRes(int32_t resId); 53 void UpdatePairResValue(int32_t minResId, int64_t minResValue, int32_t maxResId, int64_t maxResValue); 54 void UpdateCurrentValue(int32_t resId, int64_t value); 55 void WriteNode(std::string path, std::string value); 56 bool ExistNoCandidate( 57 int32_t resId, std::shared_ptr<ResStatus> resStatus, int64_t perf, int64_t power, int64_t thermal); 58 bool IsGovResId(int32_t resId); 59 bool IsResId(int32_t resId); 60 bool IsValidResId(int32_t resId); 61 int32_t GetFdForFilePath(std::string filePath); 62 }; 63 } // namespace SOCPERF 64 } // namespace OHOS 65 66 #endif 67