From b7cad5016f3bdb2d3bfd9fca483381eafee9b74d Mon Sep 17 00:00:00 2001 From: liuchungang Date: Wed, 17 Jul 2024 15:30:43 +0800 Subject: [PATCH] Add fps offset for power mode Signed-off-by: liuchungang --- common/src/config_reader.cpp | 30 +++++++++++-------- services/include/concurrent_task_controller.h | 2 +- services/src/concurrent_task_controller.cpp | 8 ++--- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/common/src/config_reader.cpp b/common/src/config_reader.cpp index 26c46a6..bdc3e8a 100644 --- a/common/src/config_reader.cpp +++ b/common/src/config_reader.cpp @@ -36,6 +36,10 @@ namespace { const std::string XML_TAG_SWITCH = "switch"; const std::string XML_TAG_FPS = "fps"; const std::string XML_TAG_DEGRADATION_FPS = "degradationfps"; + const std::string XML_TAG_FPS_HIGH = "120"; + const std::string XML_TAG_FPS_MEDIUM = "90"; + const std::string XML_TAG_FPS_STANDARD = "60"; + constexpr int FPS_OFFSET = 10000; } bool ConfigReader::IsValidNode(const xmlNode* currNode) @@ -122,7 +126,7 @@ void ConfigReader::ParsePowerMode(const xmlNode* currNode) xmlNodePtr currNodePtr = currNode->xmlChildrenNode; for (; currNodePtr; currNodePtr = currNodePtr->next) { if (xmlStrcmp(currNodePtr->name, reinterpret_cast(XML_TAG_SWITCH.c_str())) == 0) { - char* switchValue = reinterpret_cast(xmlNodeGetContent(currNode)); + char* switchValue = reinterpret_cast(xmlNodeGetContent(currNodePtr)); if (!switchValue) { CONCUR_LOGE("ParsePowerMode:: switch is null!"); continue; @@ -140,18 +144,18 @@ void ConfigReader::ParsePowerMode(const xmlNode* currNode) if (xmlStrcmp(currNodePtr->name, reinterpret_cast(XML_TAG_DEGRADATION_FPS.c_str())) == 0) { char* fpsValue = reinterpret_cast(xmlGetProp(currNodePtr, reinterpret_cast(XML_TAG_FPS.c_str()))); - char* deFpsValue = reinterpret_cast(xmlNodeGetContent(currNode)); - if (!fpsValue || !deFpsValue) { - CONCUR_LOGE("ParsePowerMode:: fps is null!"); - continue; - } - if (IsValidFps(fpsValue) && IsPositiveInt(deFpsValue)) { + char* deFpsValue = reinterpret_cast(xmlNodeGetContent(currNodePtr)); + if (fpsValue && deFpsValue && IsValidFps(fpsValue) && IsPositiveInt(deFpsValue)) { degradationFpsMap_.insert(std::make_pair(atoi(fpsValue), atoi(deFpsValue))); } else { - CONCUR_LOGE("ParsePowerMode:: invalid fps value!"); + CONCUR_LOGE("ParsePowerMode:: fps is null or invalid!"); + } + if (fpsValue) { + xmlFree(fpsValue); + } + if (deFpsValue) { + xmlFree(deFpsValue); } - xmlFree(fpsValue); - xmlFree(deFpsValue); } } } @@ -234,18 +238,18 @@ int ConfigReader::GetDegratationFps(int fps) if (degradationFpsMap_.find(fps) == degradationFpsMap_.end()) { return fps; } - return degradationFpsMap_[fps]; + return degradationFpsMap_[fps] + FPS_OFFSET; } bool ConfigReader::IsValidFps(const std::string& fps) { - if (fps == "120" || fps == "90" || fps == "60") { + if (fps == XML_TAG_FPS_HIGH || fps == XML_TAG_FPS_MEDIUM || fps == XML_TAG_FPS_STANDARD) { return true; } return false; } -bool ConfigReader::IsPositiveInt(const std::string& intStr) +bool ConfigReader::IsPositiveInt(const std::string& intStr) { int num = 0; try { diff --git a/services/include/concurrent_task_controller.h b/services/include/concurrent_task_controller.h index 4d6e2e6..4789874 100644 --- a/services/include/concurrent_task_controller.h +++ b/services/include/concurrent_task_controller.h @@ -79,7 +79,7 @@ private: void SetAppRate(const Json::Value& payload); int FindRateFromInfo(int uiTid, const Json::Value& payload); void SetRenderServiceRate(const Json::Value& payload); - void SetAppAndRenderServicRate(int appRate, int rsRate); + void SetAppAndRenderServiceRate(int appRate, int rsRate); bool CheckJsonValid(const Json::Value& payload); void SetFrameRate(int rtgId, int rate); std::list::iterator GetRecordOfPid(int pid); diff --git a/services/src/concurrent_task_controller.cpp b/services/src/concurrent_task_controller.cpp index 9d6f030..0846fcf 100644 --- a/services/src/concurrent_task_controller.cpp +++ b/services/src/concurrent_task_controller.cpp @@ -551,7 +551,7 @@ void TaskController::NewForeground(int uid, int pid) void TaskController::NewForegroundAppRecord(int pid, int uiTid, bool ddlEnabled) { - auto appRecord = foregroundApp_.emplace_back(pid, uiTid, pid != curGamePid_); + ForegroundAppRecord& appRecord = foregroundApp_.emplace_back(pid, uiTid, pid != curGamePid_); if (foregroundApp_.size() <= 0 || appRecord.GetPid() != pid) { CONCUR_LOGE("pid %{public}d create app record failed", pid); return; @@ -708,7 +708,7 @@ void TaskController::DeadlinePerfMode() { if (ddlPowerModeEnable_) { StartTrace(HITRACE_TAG_ACE, "Deadline perf mode"); - SetAppAndRenderServicRate(uniAppRate_, systemRate_); + SetAppAndRenderServiceRate(uniAppRate_, systemRate_); ddlPowerModeEnable_ = false; CONCUR_LOGI("Deadline switch to perf mode"); FinishTrace(HITRACE_TAG_ACE); @@ -725,7 +725,7 @@ void TaskController::DeadlinePowerMode() appRate = configReader_->GetDegratationFps(appRate); rsRate = configReader_->GetDegratationFps(rsRate); } - SetAppAndRenderServicRate(appRate, rsRate); + SetAppAndRenderServiceRate(appRate, rsRate); ddlPowerModeEnable_ = true; CONCUR_LOGI("Deadline switch to power mode"); FinishTrace(HITRACE_TAG_ACE); @@ -912,7 +912,7 @@ void TaskController::SetRenderServiceRate(const Json::Value& payload) } } -void TaskController::SetAppAndRenderServicRate(int appRate, int rsRate) +void TaskController::SetAppAndRenderServiceRate(int appRate, int rsRate) { bool ret = OHOS::system::SetParameter(INTERVAL_APP_RATE, std::to_string(appRate)); if (ret == false) { -- Gitee