diff --git a/common/src/config_reader.cpp b/common/src/config_reader.cpp index 26c46a662c24a4ecc834f07632fe413dc3391bc4..bdc3e8afa10139d6227f8e283a36edc86eee1b5f 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 4d6e2e6afdb510bc5f788c5a24686a0e40674110..5dadc7a3232e4c6a406eab9ba3b6afcdd2b55fa0 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); @@ -119,7 +119,7 @@ private: int executorNum_ = 0; std::map appBundleName; std::unique_ptr configReader_ = nullptr; - std::unordered_map appTypeCache_; + std::unordered_map appTypeCache_; const std::string RENDER_SERVICE_PROCESS_NAME = "render_service"; const std::string RESOURCE_SCHEDULE_PROCESS_NAME = "resource_schedule_service"; diff --git a/services/src/concurrent_task_controller.cpp b/services/src/concurrent_task_controller.cpp index 9d6f03089bc365847331df8b45e3105dbea28275..d1cb67a82a8151836fec4bab77bad931a150791c 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; @@ -607,7 +607,7 @@ void TaskController::NewAppStart(int uid, int pid, const std::string& bundleName authApps_.push_back(pid); appBundleName[pid] = bundleName; if (ddlSceneSchedSwitch_ && appType != APP_TYPE_INVALID) { - appTypeCache_[bundleName] = appType; + appTypeCache_[pid] = appType; } } @@ -635,6 +635,9 @@ void TaskController::AppKilled(int uid, int pid) } } appBundleName.erase(pid); + if (ddlSceneSchedSwitch_) { + appTypeCache_.erase(pid); + } } int TaskController::AuthSystemProcess(int pid) @@ -708,7 +711,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 +728,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 +915,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) { @@ -1004,13 +1007,12 @@ int TaskController::ParseAppType(const Json::Value& payload) bool TaskController::IsVideoApp(int pid) { - if (!ddlSceneSchedSwitch_ || appBundleName.find(pid) == appBundleName.end()) { + if (!ddlSceneSchedSwitch_) { return false; } - std::string bundleName = appBundleName[pid]; - if (appTypeCache_.find(bundleName) != appTypeCache_.end()) { - return appTypeCache_[bundleName] == APP_TYPE_VIDEO || - appTypeCache_[bundleName]== APP_TYPE_VIDEO_CLIP; + if (appTypeCache_.find(pid) != appTypeCache_.end()) { + return appTypeCache_[pid] == APP_TYPE_VIDEO || + appTypeCache_[pid]== APP_TYPE_VIDEO_CLIP; } return false; }