diff --git a/frameworks/concurrent_task_client/include/concurrent_task_type.h b/frameworks/concurrent_task_client/include/concurrent_task_type.h index 019e6d51d68a038cd3478ca3a7c326faec8abaef..ada4b13c2b709c0e369c0abd4f85de0226bd08e0 100644 --- a/frameworks/concurrent_task_client/include/concurrent_task_type.h +++ b/frameworks/concurrent_task_client/include/concurrent_task_type.h @@ -24,6 +24,8 @@ enum MsgType { MSG_BACKGROUND, MSG_APP_START, MSG_APP_KILLED, + MSG_CONTINUOUS_TASK_START, + MSG_CONTINUOUS_TASK_END, MSG_FOCUS, MSG_SYSTEM_MAX, MSG_APP_START_TYPE = 100, diff --git a/interfaces/inner_api/qos.h b/interfaces/inner_api/qos.h index 70cda2235e8b2e96b5f7aaec1c891392002dcfbe..76398502a7ff06a03824ab7ecf87f3aa7099136c 100644 --- a/interfaces/inner_api/qos.h +++ b/interfaces/inner_api/qos.h @@ -23,6 +23,9 @@ enum class QosLevel { QOS_UTILITY, QOS_DEFAULT, QOS_USER_INITIATED, + QOS_DEADLINE_REQUEST, + QOS_USER_INTERACTIVE, + QOS_KEY_BACKGROUND, QOS_MAX, }; diff --git a/qos/BUILD.gn b/qos/BUILD.gn index f1ba6657dcf1443e352437e6b0a3af4a726f6e55..0bb66046f005b46d23a4ab731d74b30e99c63dcd 100644 --- a/qos/BUILD.gn +++ b/qos/BUILD.gn @@ -29,6 +29,11 @@ ohos_shared_library("qos") { "qos.cpp", ] + if (defined( + global_parts_info.hmosresourceschedule_frame_aware_sched_override)) { + defines = [ "QOS_EXT_ENABLE" ] + } + external_deps = [ "hilog:libhilog" ] subsystem_name = "resourceschedule" diff --git a/services/include/concurrent_task_controller.h b/services/include/concurrent_task_controller.h index 837a0d3a7fd8670e6729de24a854a4731f0ad9ed..a18c72eb7b916ee718b9efcdab3aca35f992ba5a 100644 --- a/services/include/concurrent_task_controller.h +++ b/services/include/concurrent_task_controller.h @@ -57,6 +57,7 @@ private: void NewBackground(int uid, int pid); void NewAppStart(int uid, int pid); void AppKilled(int uid, int pid); + void ContinuousTaskProcess(int uid, int pid, int status); bool ModifySystemRate(const Json::Value& payload); void SetAppRate(const Json::Value& payload); int FindRateFromInfo(int uiTid, const Json::Value& payload); diff --git a/services/include/qos_interface.h b/services/include/qos_interface.h index cd98940bc3c426edea438a31b5bc676d5f51b90e..ece62ebd2d68f49fcfda4d73389783ed87e615ac 100644 --- a/services/include/qos_interface.h +++ b/services/include/qos_interface.h @@ -25,7 +25,7 @@ extern "C" { */ constexpr int SYSTEM_UID = 1000; constexpr int ROOT_UID = 0; -constexpr int NR_QOS = 6; +constexpr int NR_QOS = 7; constexpr unsigned int SET_RTG_ENABLE = 1; constexpr unsigned int QOS_CTRL_IPC_MAGIC = 0xCC; constexpr unsigned int AUTH_CTRL_IPC_MAGIC = 0xCD; @@ -40,6 +40,9 @@ struct AuthCtrlData { unsigned int rtgUaFlag; unsigned int qosUaFlag; unsigned int status; +#ifdef QOS_EXT_ENABLE + bool enhance_status; +#endif }; enum class AuthManipulateType { @@ -63,12 +66,20 @@ enum class AuthStatus { enum AuthCtrlCmdid { BASIC_AUTH_CTRL = 1, +#ifdef QOS_EXT_ENABLE + ENHANCE_AUTH_CTRL = 2, +#endif AUTH_CTRL_MAX_NR }; #define BASIC_AUTH_CTRL_OPERATION \ _IOWR(AUTH_CTRL_IPC_MAGIC, BASIC_AUTH_CTRL, struct AuthCtrlData) +#ifdef QOS_EXT_ENABLE +#define ENHANCE_AUTH_CTRL_OPERATION \ + _IOWR(AUTH_CTRL_IPC_MAGIC, ENHANCE_AUTH_CTRL, struct AuthCtrlData) +#endif + /* * qos ctrl */ @@ -163,6 +174,7 @@ int AuthPause(unsigned int uid); int AuthDelete(unsigned int uid); int AuthGet(unsigned int uid, unsigned int *uaFlag, unsigned int *status); int AuthSwitch(unsigned int uid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status); +int AuthEnhance(unsigned int uid, bool enhance_status); int QosApply(unsigned int level); int QosApplyForOther(unsigned int level, int tid); int QosLeave(void); diff --git a/services/src/concurrent_task_controller.cpp b/services/src/concurrent_task_controller.cpp index 5d56ab4b2bc0cdee4a3b8ba17fc9597e47648d44..43960a800f6804317e1f83a4761db8ac397c9fef 100644 --- a/services/src/concurrent_task_controller.cpp +++ b/services/src/concurrent_task_controller.cpp @@ -213,6 +213,8 @@ void TaskController::TypeMapInit() msgType_.insert(pair("background", MSG_BACKGROUND)); msgType_.insert(pair("appStart", MSG_APP_START)); msgType_.insert(pair("appKilled", MSG_APP_KILLED)); + msgType_.insert(pair("continuousStart", MSG_CONTINUOUS_TASK_START)); + msgType_.insert(pair("continuousEnd", MSG_CONTINUOUS_TASK_END)); } void TaskController::TryCreateRsGroup() @@ -289,6 +291,10 @@ void TaskController::DealSystemRequest(int requestType, const Json::Value& paylo case MSG_APP_KILLED: AppKilled(uid, pid); break; + case MSG_CONTINUOUS_TASK_START: + case MSG_CONTINUOUS_TASK_END: + ContinuousTaskProcess(uid, pid, requestType); + break; default: CONCUR_LOGE("Unknown system request"); break; @@ -454,6 +460,20 @@ void TaskController::AppKilled(int uid, int pid) } } +void TaskController::ContinuousTaskProcess(int uid, int pid, int status) +{ + int ret = -1; + if (status == static_cast(MSG_CONTINUOUS_TASK_START)) { + ret = AuthEnhance(uid, true); + CONCUR_LOGI("auth_enhance uid %{public}d start, ret %{public}d", uid, ret); + } else if (status == static_cast(MSG_CONTINUOUS_TASK_END)) { + ret = AuthEnhance(uid, false); + CONCUR_LOGI("auth_enhance uid %{public}d end, ret %{public}d", uid, ret); + } else { + CONCUR_LOGE("Invalid auth_enhance status %{public}d", status); + } +} + void TaskController::QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload) { pid_t uid = IPCSkeleton::GetInstance().GetCallingUid(); diff --git a/services/src/qos_interface.cpp b/services/src/qos_interface.cpp index 0e46ca6c6084b064154a0280c91999dea13c4cab..2d6f775c5909f0bb0c1b70064fa7f9c4bfee75e2 100644 --- a/services/src/qos_interface.cpp +++ b/services/src/qos_interface.cpp @@ -220,6 +220,24 @@ int AuthGet(unsigned int uid, unsigned int *uaFlag, unsigned int *status) return ret; } +int AuthEnhance(unsigned int uid, bool enhance_status) +{ + int ret = 0; +#ifdef QOS_EXT_ENABLE + struct AuthCtrlData data; + int fd = TrivalOpenAuthCtrlNode(); + if (fd < 0) { + return fd; + } + + data.uid = uid; + data.enhance_status = enhance_status; + ret = ioctl(fd, ENHANCE_AUTH_CTRL_OPERATION, &data); + close(fd); +#endif + return ret; +} + int QosApply(unsigned int level) { int tid = gettid(); diff --git a/services/src/qos_policy.cpp b/services/src/qos_policy.cpp index f068fb785c815baa7c1fec47784785328d25c1fa..e3ec9851ca602e5a71c38cfc3026a4e2fd0ef921 100644 --- a/services/src/qos_policy.cpp +++ b/services/src/qos_policy.cpp @@ -28,6 +28,7 @@ static struct QosPolicyDatas g_defaultQosPolicy = { {0, 0, 0, 1024, 0}, {0, 0, 0, 1024, 0}, {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, } }; @@ -48,6 +49,7 @@ static struct QosPolicyDatas g_foregroundQosPolicy = { {0, 0, 0, 1024, 0}, {0, 0, 0, 1024, 0}, #endif + {0, 0, 0, 1024, 0}, } }; @@ -67,6 +69,7 @@ static struct QosPolicyDatas g_backgroundQosPolicy = { {0, 0, 0, 1024, 0}, {0, 0, 0, 1024, 0}, #endif + {0, 0, 0, 1024, 0}, } }; @@ -87,6 +90,7 @@ static struct QosPolicyDatas g_systemServerQosPolicy = { {0, 0, 0, 1024, 0}, {0, 0, 0, 1024, 0}, #endif + {0, 0, 0, 1024, 0}, } }; diff --git a/test/unittest/phone/concurrent_task_controller_test.cpp b/test/unittest/phone/concurrent_task_controller_test.cpp index e8afd668ff95a000da1362ffe99537386f684f4e..e695d513f49d319ed64fb619880af1ea482371de 100644 --- a/test/unittest/phone/concurrent_task_controller_test.cpp +++ b/test/unittest/phone/concurrent_task_controller_test.cpp @@ -207,6 +207,7 @@ HWTEST_F(ConcurrentTaskControllerTest, NewForegroundTest, TestSize.Level1) fore.NewAppStart(uid, tid); fore.NewForeground(uid, tid); fore.NewBackground(uid, tid); + fore.ContinuousTaskProcess(uid, tid, static_cast(MSG_CONTINUOUS_TASK_START)); fore.AppKilled(uid, tid); uid = 574; fore.foregroundApp_.push_back(ForegroundAppRecord(574, 0)); @@ -219,6 +220,7 @@ HWTEST_F(ConcurrentTaskControllerTest, NewForegroundTest, TestSize.Level1) fore.NewAppStart(uid, tid); fore.NewForeground(uid, tid); fore.NewBackground(uid, tid); + fore.ContinuousTaskProcess(uid, tid, static_cast(MSG_CONTINUOUS_TASK_END)); fore.AppKilled(uid, tid); } diff --git a/test/unittest/phone/qos_interface_test.cpp b/test/unittest/phone/qos_interface_test.cpp index 42a3b22b554e24010da51b420875dd689aba27c5..b154419c4a3d55ac72b7608be417a2b630799d4b 100644 --- a/test/unittest/phone/qos_interface_test.cpp +++ b/test/unittest/phone/qos_interface_test.cpp @@ -152,6 +152,22 @@ HWTEST_F(QosInterfaceTest, AuthGetTest, TestSize.Level1) EXPECT_EQ(ret, -1); } +/** + * @tc.name: AuthEnhanceTest + * @tc.desc: Test whether the AuthEnhance interface are normal. + * @tc.type: FUNC + */ +HWTEST_F(QosInterfaceTest, AuthEnhanceTest, TestSize.Level1) +{ + unsigned int uid = 1000; + bool enhance_status = false; + int ret = AuthEnhance(uid, enhance_status); + EXPECT_EQ(ret, 0); + enhance_status = false; + ret = AuthEnhance(uid, enhance_status); + EXPECT_EQ(ret, 0); +} + /** * @tc.name: QosApplyForOtherTest * @tc.desc: Test whether the QosApplyForOther interface are normal. @@ -222,6 +238,7 @@ static struct QosPolicyDatas g_defaultQosPolicy = { {0, 0, 0, 1024, 0}, {0, 0, 0, 1024, 0}, {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, } }; diff --git a/test/unittest/phone/qos_test.cpp b/test/unittest/phone/qos_test.cpp index 451128c5590b75ffeb81198761b850dc01983fd3..9ad18425ba20092af40d88ab6629bf4b1398471d 100644 --- a/test/unittest/phone/qos_test.cpp +++ b/test/unittest/phone/qos_test.cpp @@ -63,6 +63,14 @@ HWTEST_F(QosTest, SetThreadQosTest1, TestSize.Level1) EXPECT_EQ(ret, 0); ret = SetThreadQos(QosLevel::QOS_BACKGROUND); EXPECT_EQ(ret, 0); + ret = SetThreadQos(QosLevel::QOS_DEADLINE_REQUEST); + EXPECT_EQ(ret, 0); + ret = SetThreadQos(QosLevel::QOS_USER_INTERACTIVE); + EXPECT_EQ(ret, 0); + ret = SetThreadQos(QosLevel::QOS_KEY_BACKGROUND); + EXPECT_EQ(ret, 0); + ret = SetThreadQos(QosLevel::QOS_MAX); + EXPECT_EQ(ret, -1); } HWTEST_F(QosTest, SetThreadQosTest2, TestSize.Level1)