From b987686c6f228745d4410c6e9887bff35cc35a1c Mon Sep 17 00:00:00 2001 From: Xujiafei Date: Sun, 24 Mar 2024 22:01:08 +0800 Subject: [PATCH 1/2] add taskload Signed-off-by: Xujiafei --- services/include/concurrent_task_controller.h | 4 +++- services/src/concurrent_task_controller.cpp | 20 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/services/include/concurrent_task_controller.h b/services/include/concurrent_task_controller.h index 9b5f5e8..2f6b60d 100644 --- a/services/include/concurrent_task_controller.h +++ b/services/include/concurrent_task_controller.h @@ -28,6 +28,8 @@ namespace OHOS { namespace ConcurrentTask { +const int LOAD_MARGIN = -1; + class ForegroundAppRecord; class TaskController { @@ -41,7 +43,7 @@ public: void RequestAuth(const Json::Value& payload); void Init(); void Release(); - int CreateNewRtgGrp(int prioType, int rtNum); + int CreateNewRtgGrp(int prioType, int rtNum, int taskload=LOAD_MARGIN, bool useTaskloadFlag=false); private: void TypeMapInit(); diff --git a/services/src/concurrent_task_controller.cpp b/services/src/concurrent_task_controller.cpp index 8eb4245..247548d 100644 --- a/services/src/concurrent_task_controller.cpp +++ b/services/src/concurrent_task_controller.cpp @@ -43,6 +43,7 @@ namespace { constexpr int RTG_TYPE_MAX = 3; constexpr int RS_UID = 1003; constexpr int EXECUTOR_LIMIT_NUM = 3; + constexpr int HARDWARE_LOAD_MARGIN = 3000; } #define CMD_ID_SET_RTG \ @@ -196,19 +197,23 @@ void TaskController::QueryRenderService(int uid, int pid, IntervalReply& queryRs void TaskController::QueryHardware(int uid, int pid, IntervalReply& queryRs) { - if (uid != RS_UID) { + if (uid != RS_UID || queryRs.tid <= 0) { return; } - if (hardwareGrpId_ < 0) { - return; + if (hardwareGrpId_ <= 0) { + hardwareGrpId_ = CreateNewRtgGrp(PRIO_NORMAL, MAX_KEY_THREADS, HARDWARE_LOAD_MARGIN, true); + if (hardwareGrpId_ <= 0) + { + CONCUR_LOGI("CreateRsRtgGroup for Hardware failed"); + return; + } } + queryRs.rtgId = hardwareGrpId_; hardwareTid_ = queryRs.tid; int ret = AddThreadToRtg(hardwareTid_, renderServiceGrpId_, PRIO_RT); if (ret < 0) { - CONCUR_LOGE("uid %{public}d tid %{public}d join hardware group failed.", uid, rsTid_); - return; + CONCUR_LOGE("uid %{public}d tid %{public}d join hardware group failed.", uid, hardwareTid_); } - queryRs.tid = hardwareGrpId_; } void TaskController::QueryExecutorStart(int uid, int pid, IntervalReply& queryRs) @@ -285,7 +290,6 @@ void TaskController::TypeMapInit() void TaskController::TryCreateRsGroup() { renderServiceGrpId_ = TryCreateSystemGroup(); - hardwareGrpId_ = renderServiceGrpId_; } int TaskController::TryCreateSystemGroup() @@ -746,7 +750,7 @@ void TaskController::PrintInfo() } } -int TaskController::CreateNewRtgGrp(int prioType, int rtNum) +int TaskController::CreateNewRtgGrp(int prioType, int rtNum, int taskload, bool userTaskloadFlag) { struct rtg_grp_data grp_data; int ret; -- Gitee From e1e5e3156e0f9bec819b0825a7ef6de1c1bb347b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8A=A0=E9=A3=9E?= Date: Fri, 12 Apr 2024 03:56:21 +0000 Subject: [PATCH 2/2] =?UTF-8?q?RS=20=E6=8B=86=E6=B5=81=E6=B0=B4=E5=B9=B6?= =?UTF-8?q?=E8=A1=8C=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 徐加飞 --- .../include/concurrent_task_type.h | 5 +- services/include/concurrent_task_controller.h | 12 +- services/src/concurrent_task_controller.cpp | 137 ++++++++++++------ .../phone/concurrent_svc_intf_test.cpp | 2 +- .../phone/concurrent_task_controller_test.cpp | 22 +-- 5 files changed, 116 insertions(+), 62 deletions(-) diff --git a/frameworks/concurrent_task_client/include/concurrent_task_type.h b/frameworks/concurrent_task_client/include/concurrent_task_type.h index 10c0c18..55a9b42 100644 --- a/frameworks/concurrent_task_client/include/concurrent_task_type.h +++ b/frameworks/concurrent_task_client/include/concurrent_task_type.h @@ -45,11 +45,12 @@ enum PrioType { enum QueryIntervalItem { QUERY_UI = 0, QUERY_RENDER = 1, - QUERY_RENDER_SERVICE = 2, + QUERY_RENDER_SERVICE_MAIN = 2, QUERY_COMPOSER = 3, QUERY_HARDWARE = 4, QUERY_EXECUTOR_START = 5, - QURRY_TYPE_MAX + QUERY_RENDER_SERVICE_RENDER = 6, + QURRY_TYPE_MAX, }; enum DeadlineType { diff --git a/services/include/concurrent_task_controller.h b/services/include/concurrent_task_controller.h index 2f6b60d..a70fafb 100644 --- a/services/include/concurrent_task_controller.h +++ b/services/include/concurrent_task_controller.h @@ -50,10 +50,12 @@ private: void QosApplyInit(); int TryCreateSystemGroup(); void TryCreateHardwareGroup(); - void TryCreateRsGroup(); + void TryCreateRSMainGrp(); + void TryCreateRSRenderGrp(); void QueryUi(pid_t uid, IntervalReply& queryRs); void QueryRender(pid_t uid, IntervalReply& queryRs); - void QueryRenderService(pid_t uid, pid_t pid, IntervalReply& queryRs); + void QueryRenderServiceMain(pid_t uid, pid_t pid, IntervalReply& queryRs); + void QueryRenderServiceRender(pid_t uid, pid_t pid, IntervalReply& queryRs); void QueryHardware(pid_t uid, pid_t pid, IntervalReply& queryRs); void QueryExecutorStart(pid_t uid, pid_t pid, IntervalReply& queryRs); void QueryHwc(pid_t uid, IntervalReply& queryRs); @@ -88,9 +90,11 @@ private: std::unordered_map msgType_ = {}; QosPolicy qosPolicy_; std::vector authApps_; - int renderServiceGrpId_ = -1; + int renderServiceMainGrpId_ = -1; + int renderServiceRenderGrpId_ = -1; + int renderServiceMainTid_ = -1; + int renderServiceRenderTid_ = -1; int hardwareGrpId_ = -1; - int rsTid_ = -1; int hardwareTid_ = -1; int systemRate_ = 0; bool rtgEnabled_ = false; diff --git a/services/src/concurrent_task_controller.cpp b/services/src/concurrent_task_controller.cpp index 247548d..2c097d0 100644 --- a/services/src/concurrent_task_controller.cpp +++ b/services/src/concurrent_task_controller.cpp @@ -16,14 +16,16 @@ #include #include #include -#include #include +#include +#include +#include #include #include #include "accesstoken_kit.h" -#include "concurrent_task_log.h" #include "rtg_interface.h" #include "ipc_skeleton.h" +#include "concurrent_task_log.h" #include "parameters.h" #include "concurrent_task_controller.h" @@ -33,7 +35,7 @@ using namespace OHOS::Security::AccessToken; namespace OHOS { namespace ConcurrentTask { namespace { - const std::string INTERVAL_DDL = "persist.ffrt.interval.renderthread"; + const std::string INTERVAL_DDL = "ffrt.interval.renderthread"; const std::string INTERVAL_APP_RATE = "persist.ffrt.interval.appRate"; const std::string INTERVAL_RS_RATE = "persist.ffrt.interval.rsRate"; constexpr int CURRENT_RATE = 120; @@ -43,7 +45,6 @@ namespace { constexpr int RTG_TYPE_MAX = 3; constexpr int RS_UID = 1003; constexpr int EXECUTOR_LIMIT_NUM = 3; - constexpr int HARDWARE_LOAD_MARGIN = 3000; } #define CMD_ID_SET_RTG \ @@ -103,8 +104,11 @@ void TaskController::QueryInterval(int queryItem, IntervalReply& queryRs) case QUERY_RENDER: QueryRender(uid, queryRs); break; - case QUERY_RENDER_SERVICE: - QueryRenderService(uid, pid, queryRs); + case QUERY_RENDER_SERVICE_MAIN: + QueryRenderServiceMain(uid, pid, queryRs); + break; + case QUERY_RENDER_SERVICE_RENDER: + QueryRenderServiceRender(uid, pid, queryRs); break; case QUERY_COMPOSER: QueryHwc(uid, queryRs); @@ -164,56 +168,80 @@ void TaskController::QueryRender(int uid, IntervalReply& queryRs) } } -void TaskController::QueryRenderService(int uid, int pid, IntervalReply& queryRs) +void TaskController::QueryRenderServiceMain(int uid, int pid, IntervalReply& queryRs) { if (GetProcessNameByToken() != RENDER_SERVICE_PROCESS_NAME) { return; } + if (authedRSPid_ != pid) { + if (AuthSystemProcess(pid) != 0) { + return; + } + authedRSPid_ = pid; + } + if (renderServiceMainGrpId_ <= 0) { + TryCreateRSMainGrp(); + if (renderServiceMainGrpId_ <= 0) { + CONCUR_LOGE("uid %{public}d create rs group failed", uid); + return; + } + } + queryRs.rtgId = renderServiceMainGrpId_; + if (renderServiceMainTid_ <= 0 || renderServiceMainTid_ != queryRs.tid) { + renderServiceMainTid_ = queryRs.tid; + int ret = AddThreadToRtg(renderServiceMainTid_, renderServiceMainGrpId_, PRIO_RT); + if (ret < 0) { + CONCUR_LOGE("uid %{public}d tid %{public}d join rs group failed.", uid, renderServiceMainTid_); + } + } + SetFrameRateAndPrioType(renderServiceMainGrpId_, CURRENT_RATE, PARAM_TYPE); +} - if (!rsAuthed_) { +void TaskController::QueryRenderServiceRender(int uid, int pid, IntervalReply& queryRs) +{ + if (GetProcessNameByToken() != RENDER_SERVICE_PROCESS_NAME) { + return; + } + if (authedRSPid_ != pid) { if (AuthSystemProcess(pid) != 0) { return; } - rsAuthed_ = true; + authedRSPid_ = pid; } - if (renderServiceGrpId_ <= 0) { - TryCreateRsGroup(); - CONCUR_LOGI("uid %{public}d query rs group failed and create %{public}d.", uid, renderServiceGrpId_); - if (renderServiceGrpId_ <= 0) { + if (renderServiceRenderGrpId_ <= 0) { + TryCreateRSRenderGrp(); + if (renderServiceRenderGrpId_ <= 0) { CONCUR_LOGE("uid %{public}d create rs group failed", uid); return; } } - queryRs.rtgId = renderServiceGrpId_; - if (rsTid_ <= 0) { - rsTid_ = queryRs.tid; - int ret = AddThreadToRtg(rsTid_, renderServiceGrpId_, PRIO_RT); + queryRs.rtgId = renderServiceRenderGrpId_; + if (renderServiceRenderTid_ <= 0 || renderServiceRenderTid_ != queryRs.tid) { + renderServiceRenderTid_ = queryRs.tid; + int ret = AddThreadToRtg(renderServiceRenderTid_, renderServiceRenderGrpId_, PRIO_RT); if (ret < 0) { - CONCUR_LOGE("uid %{public}d tid %{public}d join rs group failed.", uid, rsTid_); + CONCUR_LOGE("uid %{public}d tid %{public}d join rs group failed.", uid, renderServiceMainTid_); } } - SetFrameRateAndPrioType(renderServiceGrpId_, CURRENT_RATE, PARAM_TYPE); + SetFrameRateAndPrioType(renderServiceRenderGrpId_, CURRENT_RATE, PARAM_TYPE); } void TaskController::QueryHardware(int uid, int pid, IntervalReply& queryRs) { - if (uid != RS_UID || queryRs.tid <= 0) { + if (uid != RS_UID) { return; } - if (hardwareGrpId_ <= 0) { - hardwareGrpId_ = CreateNewRtgGrp(PRIO_NORMAL, MAX_KEY_THREADS, HARDWARE_LOAD_MARGIN, true); - if (hardwareGrpId_ <= 0) - { - CONCUR_LOGI("CreateRsRtgGroup for Hardware failed"); - return; - } + if (hardwareGrpId_ < 0) { + return; } - queryRs.rtgId = hardwareGrpId_; hardwareTid_ = queryRs.tid; - int ret = AddThreadToRtg(hardwareTid_, renderServiceGrpId_, PRIO_RT); + TryCreateRSMainGrp(); + int ret = AddThreadToRtg(hardwareTid_, renderServiceMainGrpId_, PRIO_RT); if (ret < 0) { - CONCUR_LOGE("uid %{public}d tid %{public}d join hardware group failed.", uid, hardwareTid_); + CONCUR_LOGE("uid %{public}d tid %{public}d join hardware group failed.", uid, renderServiceMainTid_); + return; } + queryRs.rtgId = hardwareGrpId_; } void TaskController::QueryExecutorStart(int uid, int pid, IntervalReply& queryRs) @@ -221,7 +249,7 @@ void TaskController::QueryExecutorStart(int uid, int pid, IntervalReply& queryRs if (uid != RS_UID) { return; } - if (renderServiceGrpId_ < 0) { + if (renderServiceMainGrpId_ < 0) { return; } std::lock_guard lock(executorStartLock_); @@ -231,13 +259,13 @@ void TaskController::QueryExecutorStart(int uid, int pid, IntervalReply& queryRs if (queryRs.tid <= 0) { return; } - int ret = AddThreadToRtg(queryRs.tid, renderServiceGrpId_, PRIO_RT); + int ret = AddThreadToRtg(queryRs.tid, renderServiceMainGrpId_, PRIO_RT); if (ret < 0) { - CONCUR_LOGE("uid %{public}d tid %{public}d join executor group failed.", uid, rsTid_); + CONCUR_LOGE("uid %{public}d tid %{public}d join executor group failed.", uid, renderServiceMainTid_); return; } executorNum_++; - queryRs.rtgId = renderServiceGrpId_; + queryRs.rtgId = renderServiceMainGrpId_; } void TaskController::QueryHwc(int uid, IntervalReply& queryRs) @@ -267,11 +295,16 @@ void TaskController::Init() void TaskController::Release() { msgType_.clear(); - if (renderServiceGrpId_ <= 0) { + if (renderServiceMainGrpId_ <= 0) { + return; + } + DestroyRtgGrp(renderServiceMainGrpId_); + renderServiceMainGrpId_ = -1; + if (renderServiceRenderGrpId_ <= 0) { return; } - DestroyRtgGrp(renderServiceGrpId_); - renderServiceGrpId_ = -1; + DestroyRtgGrp(renderServiceRenderGrpId_); + renderServiceRenderGrpId_ = -1; } void TaskController::TypeMapInit() @@ -287,9 +320,25 @@ void TaskController::TypeMapInit() msgType_.insert(pair("loseFocus", MSG_LOSE_FOCUS)); } +void TaskController::TryCreateRSMainGrp() +{ + if (renderServiceMainGrpId_ == -1) { + renderServiceMainGrpId_ = TryCreateSystemGroup(); + hardwareGrpId_ = renderServiceMainGrpId_; + } +} + +void TaskController::TryCreateRSRenderGrp() +{ + if (renderServiceRenderGrpId_ == -1) { + renderServiceRenderGrpId_ = TryCreateSystemGroup(); + } +} + void TaskController::TryCreateRsGroup() { - renderServiceGrpId_ = TryCreateSystemGroup(); + TryCreateRSMainGrp(); + TryCreateRSRenderGrp(); } int TaskController::TryCreateSystemGroup() @@ -553,7 +602,7 @@ void TaskController::QueryDeadline(int queryItem, DeadlineReply& ddlReply, const { pid_t uid = IPCSkeleton::GetInstance().GetCallingUid(); std::string processName = GetProcessNameByToken(); - if (processName != RENDER_SERVICE_PROCESS_NAME && processName != RESOURCE_SCHEDULE_PROCESS_NAME) { + if (processName != RENDER_SERVICE_PROCESS_NAME && processName != GAME_SERVICE_PROCESS_NAME) { CONCUR_LOGE("Invalid uid %{public}d, only RS or RSS can call QueryDeadline", uid); return; } @@ -706,11 +755,11 @@ int TaskController::FindRateFromInfo(int uiTid, const Json::Value& payload) void TaskController::SetRenderServiceRate(const Json::Value& payload) { - int rsRate = FindRateFromInfo(rsTid_, payload); - if (renderServiceGrpId_ > 0 && rsRate > 0 && rsRate != systemRate_) { + int rsRate = FindRateFromInfo(renderServiceMainTid_, payload); + if (renderServiceMainGrpId_ > 0 && rsRate > 0 && rsRate != systemRate_) { CONCUR_LOGI("set rs rate %{public}d rtgId is %{public}d, old rate is %{public}d", - rsRate, renderServiceGrpId_, systemRate_); - SetFrameRate(renderServiceGrpId_, rsRate); + rsRate, renderServiceMainGrpId_, systemRate_); + SetFrameRate(renderServiceMainGrpId_, rsRate); systemRate_ = rsRate; bool ret = OHOS::system::SetParameter(INTERVAL_RS_RATE, std::to_string(rsRate)); if (ret == false) { @@ -750,7 +799,7 @@ void TaskController::PrintInfo() } } -int TaskController::CreateNewRtgGrp(int prioType, int rtNum, int taskload, bool userTaskloadFlag) +int TaskController::CreateNewRtgGrp(int prioType, int rtNum) { struct rtg_grp_data grp_data; int ret; diff --git a/test/unittest/phone/concurrent_svc_intf_test.cpp b/test/unittest/phone/concurrent_svc_intf_test.cpp index d63e605..8c8042a 100644 --- a/test/unittest/phone/concurrent_svc_intf_test.cpp +++ b/test/unittest/phone/concurrent_svc_intf_test.cpp @@ -104,7 +104,7 @@ HWTEST_F(ConcurrentSvcIntfTest, QueryNagativeItem, TestSize.Level1) */ HWTEST_F(ConcurrentSvcIntfTest, QueryRenderServiceTest, TestSize.Level1) { - int grpId = QueryInterval(QUERY_RENDER_SERVICE); + int grpId = QueryInterval(QUERY_RENDER_SERVICE_MAIN); #if TDD_MUSL EXPECT_GT(grpId, 0); #else diff --git a/test/unittest/phone/concurrent_task_controller_test.cpp b/test/unittest/phone/concurrent_task_controller_test.cpp index 416e9ce..c7af0af 100644 --- a/test/unittest/phone/concurrent_task_controller_test.cpp +++ b/test/unittest/phone/concurrent_task_controller_test.cpp @@ -85,7 +85,7 @@ HWTEST_F(ConcurrentTaskControllerTest, QueryIntervalTest, TestSize.Level1) queInt.QueryInterval(queryItem, queryRs); queryItem = QUERY_RENDER; queInt.QueryInterval(queryItem, queryRs); - queryItem = QUERY_RENDER_SERVICE; + queryItem = QUERY_RENDER_SERVICE_MAIN; queInt.QueryInterval(queryItem, queryRs); queryItem = QUERY_COMPOSER; queInt.QueryInterval(queryItem, queryRs); @@ -136,14 +136,14 @@ HWTEST_F(ConcurrentTaskControllerTest, QueryRenderServiceTest, TestSize.Level1) int uid = SYSTEM_UID; int pid = getpid(); IntervalReply queryRs = {87, 657, 357, 214}; - TaskController::GetInstance().QueryRenderService(uid, pid, queryRs); - int flag = TaskController::GetInstance().renderServiceGrpId_; - TaskController::GetInstance().renderServiceGrpId_ = 1; - TaskController::GetInstance().QueryRenderService(uid, pid, queryRs); - TaskController::GetInstance().renderServiceGrpId_ = -1; - TaskController::GetInstance().QueryRenderService(uid, pid, queryRs); - TaskController::GetInstance().renderServiceGrpId_ = flag; - TaskController::GetInstance().QueryRenderService(uid, pid, queryRs); + TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs); + int flag = TaskController::GetInstance().renderServiceMainTid_; + TaskController::GetInstance().renderServiceMainTid_ = 1; + TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs); + TaskController::GetInstance().renderServiceMainTid_ = -1; + TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs); + TaskController::GetInstance().renderServiceMainTid_ = flag; + TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs); } /** @@ -387,9 +387,9 @@ HWTEST_F(ConcurrentTaskControllerTest, SetRenderServiceRateTest, TestSize.Level1 { Json::Value payload; payload["758"] = "120"; - TaskController::GetInstance().rsTid_ = 758; + TaskController::GetInstance().renderServiceMainTid_ = 758; TaskController::GetInstance().systemRate_ = 0; - TaskController::GetInstance().renderServiceGrpId_ = 1; + TaskController::GetInstance().renderServiceMainTid_ = 1; TaskController::GetInstance().SetRenderServiceRate(payload); EXPECT_EQ(TaskController::GetInstance().systemRate_, 120); EXPECT_EQ(OHOS::system::GetIntParameter("persist.ffrt.interval.rsRate", 0), 120); -- Gitee