From 689ae401baf3d9ff0ad8cdbd95cddefa703c03e2 Mon Sep 17 00:00:00 2001 From: Axi_Beft Date: Mon, 28 Apr 2025 19:38:53 +0800 Subject: [PATCH] data_share add qos Signed-off-by: Axi_Beft --- bundle.json | 1 + .../app/src/kvstore_data_service.cpp | 1 + .../service/data_share/BUILD.gn | 2 ++ .../data_share/data_share_service_impl.cpp | 29 +++++++++++++++---- .../data_share/data_share_service_impl.h | 1 + .../data_share/data_share_service_stub.cpp | 24 ++++++++++++++- .../data_share/data_share_service_stub.h | 1 + .../service/test/BUILD.gn | 2 ++ .../datashareservicestub_fuzzer/BUILD.gn | 2 ++ 9 files changed, 57 insertions(+), 6 deletions(-) diff --git a/bundle.json b/bundle.json index a8a25194b..55196f9c9 100644 --- a/bundle.json +++ b/bundle.json @@ -75,6 +75,7 @@ "napi", "netmanager_base", "os_account", + "qos_manager", "relational_store", "resource_management", "safwk", diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index e3a753dd8..efe511394 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -296,6 +296,7 @@ void KvStoreDataService::OnStart() } AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID); AddSystemAbilityListener(MEMORY_MANAGER_SA_ID); + AddSystemAbilityListener(CONCURRENT_TASK_SERVICE_ID); RegisterStoreInfo(); Handler handlerStoreInfo = std::bind(&KvStoreDataService::DumpStoreInfo, this, std::placeholders::_1, std::placeholders::_2); diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 17b71aaba..2aadc92be 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -127,6 +127,8 @@ ohos_shared_library("data_share_service") { "ipc:ipc_core", "json:nlohmann_json_static", "kv_store:distributeddb", + "qos_manager:concurrent_task_client", + "qos_manager:qos", "relational_store:native_rdb", "relational_store:rdb_data_share_adapter", "resource_management:global_resmgr", diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 54c7504ac..4bc9f24cc 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -25,6 +25,7 @@ #include "app_connect_manager.h" #include "common_event_manager.h" #include "common_event_support.h" +#include "concurrent_task_client.h" #include "data_ability_observer_interface.h" #include "data_share_profile_config.h" #include "dataobs_mgr_client.h" @@ -80,11 +81,17 @@ public: void DataShareServiceImpl::SystemAbilityStatusChangeListener::OnAddSystemAbility( int32_t systemAbilityId, const std::string &deviceId) { - if (systemAbilityId != COMMON_EVENT_SERVICE_ID) { - return; - } - ZLOGI("Common event service start. saId:%{public}d", systemAbilityId); - InitSubEvent(); + ZLOGI("saId:%{public}d", systemAbilityId); + if (systemAbilityId == COMMON_EVENT_SERVICE_ID) { + InitSubEvent(); + } else if (systemAbilityId == CONCURRENT_TASK_SERVICE_ID) { + std::unordered_map payload; + // get current thread pid + payload["pid"] = std::to_string(getpid()); + // request qos auth for current pid + OHOS::ConcurrentTask::ConcurrentTaskClient::GetInstance().RequestAuth(payload); + } + return; } DataShareServiceImpl::Factory::Factory() @@ -625,6 +632,7 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) DBDelegate::SetExecutorPool(binderInfo.executors); HiViewAdapter::GetInstance().SetThreadPool(binderInfo.executors); SubscribeCommonEvent(); + SubscribeConcurrentTask(); SubscribeTimeChanged(); SubscribeChange(); ZLOGI("end"); @@ -642,6 +650,17 @@ void DataShareServiceImpl::SubscribeCommonEvent() systemManager->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, callback); } +void DataShareServiceImpl::SubscribeConcurrentTask() +{ + sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemManager == nullptr) { + ZLOGE("System mgr is nullptr"); + return; + } + sptr callback(new SystemAbilityStatusChangeListener()); + systemManager->SubscribeSystemAbility(CONCURRENT_TASK_SERVICE_ID, callback); +} + void DataShareServiceImpl::SubscribeChange() { EventCenter::GetInstance().Subscribe(RemoteChangeEvent::RDB_META_SAVE, [this](const Event &event) { diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 0282591b3..8bba804e1 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -130,6 +130,7 @@ private: bool isRead, ExecuteCallbackEx callback); int32_t GetBMSAndMetaDataStatus(const std::string &uri, const int32_t tokenId); void SubscribeCommonEvent(); + void SubscribeConcurrentTask(); static void InitSubEvent(); void AutoLaunch(const DistributedData::Event &event); void SubscribeChange(); diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index cf353dcde..f9e30e806 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -25,10 +25,25 @@ #include "ishared_result_set.h" #include "itypes_util.h" #include "log_print.h" +#include "qos.h" #include "utils/anonymous.h" namespace OHOS { namespace DataShare { + +class DataShareServiceStub::QosManager { +public: + QosManager() + { + // set thread qos QOS_USER_INTERACTIVE + QOS::SetThreadQos(QOS::QosLevel::QOS_USER_INTERACTIVE); + } + ~QosManager() + { + QOS::ResetThreadQos(); + } +}; + bool DataShareServiceStub::CheckInterfaceToken(MessageParcel &data) { auto localDescriptor = IDataShareService::GetDescriptor(); @@ -378,6 +393,12 @@ int32_t DataShareServiceStub::OnNotifyConnectDone(MessageParcel &data, MessagePa int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) { + // set thread qos + DataShareServiceStub::QosManager qos; + // check thread qos + QOS::QosLevel curLevel; + int qosRet = QOS::GetThreadQos(curLevel); + int tryTimes = TRY_TIMES; while (!isReady_.load() && tryTimes > 0) { tryTimes--; @@ -385,7 +406,8 @@ int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me } auto callingPid = IPCSkeleton::GetCallingPid(); if (code != DATA_SHARE_SERVICE_CMD_QUERY && code != DATA_SHARE_SERVICE_CMD_GET_SILENT_PROXY_STATUS) { - ZLOGI("code:%{public}u, callingPid:%{public}d", code, callingPid); + ZLOGI("code:%{public}u, callingPid:%{public}d, qosRet:%{public}d, curLevel:%{public}d", + code, callingPid, qosRet, curLevel); } if (!CheckInterfaceToken(data)) { return DATA_SHARE_ERROR; diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.h b/services/distributeddataservice/service/data_share/data_share_service_stub.h index 3a92d14b1..71499d1fa 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.h +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.h @@ -27,6 +27,7 @@ public: void SetServiceReady(); private: + class QosManager; static constexpr std::chrono::milliseconds TIME_THRESHOLD = std::chrono::milliseconds(500); static bool CheckInterfaceToken(MessageParcel& data); int32_t OnInsert(MessageParcel& data, MessageParcel& reply); diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 1168f3153..d2f289a0f 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -930,6 +930,8 @@ ohos_unittest("DataShareServiceImplTest") { "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddb", + "qos_manager:concurrent_task_client", + "qos_manager:qos", "relational_store:native_rdb", "relational_store:rdb_data_share_adapter", "resource_management:global_resmgr", diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn index 32424a728..8858be69c 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn @@ -127,6 +127,8 @@ ohos_fuzztest("DataShareServiceStubFuzzTest") { "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddb", + "qos_manager:concurrent_task_client", + "qos_manager:qos", "relational_store:native_rdb", "relational_store:rdb_data_share_adapter", "resource_management:global_resmgr", -- Gitee