From 600465b8e377e9057a266a0412c739dfbf6bb7f9 Mon Sep 17 00:00:00 2001 From: aaabbb Date: Wed, 22 May 2024 18:03:23 +0800 Subject: [PATCH] delete rtg group in background Signed-off-by: aaabbb --- services/include/concurrent_task_controller.h | 4 ++ services/src/concurrent_task_controller.cpp | 72 ++++++++++++++----- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/services/include/concurrent_task_controller.h b/services/include/concurrent_task_controller.h index 7f4c321..11f94ec 100644 --- a/services/include/concurrent_task_controller.h +++ b/services/include/concurrent_task_controller.h @@ -46,6 +46,7 @@ public: private: void TypeMapInit(); void QosApplyInit(); + void SelfRenderAppInit(); int TryCreateSystemGroup(); void TryCreateHardwareGroup(); void TryCreateRsGroup(); @@ -103,6 +104,7 @@ private: std::atomic curGamePid_ = -1; int executorNum_ = 0; std::map appBundleName; + std::unordered_set selfRenderAppList; const std::string RENDER_SERVICE_PROCESS_NAME = "render_service"; const std::string RESOURCE_SCHEDULE_PROCESS_NAME = "resource_schedule_service"; @@ -127,6 +129,8 @@ public: void SetGrpId(int grpId); bool IsValid(); void PrintKeyThreads(); + void DeleteRtgGrp(); + void RecreateRtgGrp(); private: int pid_ = 0; diff --git a/services/src/concurrent_task_controller.cpp b/services/src/concurrent_task_controller.cpp index 3df8bb1..56b264c 100644 --- a/services/src/concurrent_task_controller.cpp +++ b/services/src/concurrent_task_controller.cpp @@ -320,6 +320,7 @@ void TaskController::Init() TypeMapInit(); qosPolicy_.Init(); TryCreateRsGroup(); + SelfRenderAppInit(); } void TaskController::Release() @@ -348,6 +349,15 @@ void TaskController::TypeMapInit() msgType_.insert(pair("loseFocus", MSG_LOSE_FOCUS)); } +void TaskController::SelfRenderAppInit() +{ + selfRenderAppList.clear(); + selfRenderAppList.insert("com.example.weexapp"); + selfRenderAppList.insert("com.taobao.taobao_hmos"); + selfRenderAppList.insert("com.taobao.taobao4hmos"); + selfRenderAppList.insert("com.amap.hmapp"); +} + void TaskController::TryCreateRSMainGrp() { if (renderServiceMainGrpId_ == -1) { @@ -492,9 +502,13 @@ void TaskController::NewForeground(int uid, int pid) if (iter->GetPid() == pid) { found = true; if (ddlEnabled && pid != curGamePid_) { + if (selfRenderAppList.count(appBundleName[pid]) == 0) { + iter->RecreateRtgGrp(); + } iter->AddKeyThread(uiTid, PRIO_RT); } iter->BeginScene(); + break; } } if (!found) { @@ -504,20 +518,16 @@ void TaskController::NewForeground(int uid, int pid) void TaskController::NewForegroundAppRecord(int pid, int uiTid, bool ddlEnabled) { - ForegroundAppRecord *tempRecord = nullptr; - if (pid == curGamePid_) { - tempRecord = new ForegroundAppRecord(pid, uiTid, false); - } else { - tempRecord = new ForegroundAppRecord(pid, uiTid, true); + ForegroundAppRecord tempRecord(pid, uiTid, false); + if (pid != curGamePid_) { + tempRecord = ForegroundAppRecord(pid, uiTid, true); } - if (tempRecord->IsValid()) { - foregroundApp_.push_back(*tempRecord); + if (tempRecord.IsValid()) { + foregroundApp_.push_back(tempRecord); if (ddlEnabled && pid != curGamePid_) { - tempRecord->AddKeyThread(uiTid, PRIO_RT); + tempRecord.AddKeyThread(uiTid, PRIO_RT); } - tempRecord->BeginScene(); - } else { - delete tempRecord; + tempRecord.BeginScene(); } } @@ -540,7 +550,11 @@ void TaskController::NewBackground(int uid, int pid) std::lock_guard lock(appInfoLock_); for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { if (iter->GetPid() == pid) { - iter->EndScene(); + if (selfRenderAppList.count(appBundleName[pid]) == 0) { + iter->DeleteRtgGrp(); + } else { + iter->EndScene(); + } return; } } @@ -577,6 +591,7 @@ void TaskController::AppKilled(int uid, int pid) std::lock_guard lock(appInfoLock_); for (auto iter = foregroundApp_.begin(); iter != foregroundApp_.end(); iter++) { if (iter->GetPid() == pid) { + iter->DeleteRtgGrp(); foregroundApp_.erase(iter++); break; } @@ -876,12 +891,7 @@ ForegroundAppRecord::ForegroundAppRecord(int pid, int uiTid, bool createGrp) } } -ForegroundAppRecord::~ForegroundAppRecord() -{ - if (grpId_ > 0) { - DestroyRtgGrp(grpId_); - } -} +ForegroundAppRecord::~ForegroundAppRecord() {} void ForegroundAppRecord::AddKeyThread(int tid, int prio) { @@ -986,5 +996,31 @@ void ForegroundAppRecord::PrintKeyThreads() } CONCUR_LOGD("%{public}s", strLog.c_str()); } + +void ForegroundAppRecord::DeleteRtgGrp() +{ + if (grpId_ > 0) { + int ret = DestroyRtgGrp(grpId_); + if (ret < 0) { + CONCUR_LOGE("delete rtg grp failed, errno = %{public}d (%{public}s)", errno, strerror(errno)); + } else { + CONCUR_LOGI("delete rtg grp success, rtg id %{public}d.", grpId_); + grpId_ = 0; + } + } +} + +void ForegroundAppRecord::RecreateRtgGrp() +{ + grpId_ = TaskController::GetInstance().CreateNewRtgGrp(PRIO_RT, MAX_KEY_THREADS); + for (auto tid : keyThreads_) { + int ret = AddThreadToRtg(tid, grpId_, PRIO_RT); + if (ret != 0) { + CONCUR_LOGI("Add key thread fail: Kernel err report. ret is %{public}d", ret); + } else { + CONCUR_LOGI("Add key thread %{public}d", tid); + } + } +} } // namespace ConcurrentTask } // namespace OHOS -- Gitee