From 19f4e18c49e110bb3514aebeb7862a433d22f2ba Mon Sep 17 00:00:00 2001 From: sodanotgreen Date: Thu, 25 Apr 2024 21:22:51 +0800 Subject: [PATCH] =?UTF-8?q?aa=E6=90=BA=E5=B8=A6=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sodanotgreen --- frameworks/native/appkit/app/main_thread.cpp | 4 ++++ frameworks/native/runtime/js_runtime.cpp | 5 +++++ .../app_manager/include/appmgr/app_launch_data.h | 11 +++++++++++ .../app_manager/src/appmgr/app_launch_data.cpp | 7 +++++++ interfaces/inner_api/runtime/include/runtime.h | 1 + services/abilitymgr/src/ability_record.cpp | 4 ++++ services/appmgr/include/app_running_record.h | 4 +++- services/appmgr/src/app_mgr_service_inner.cpp | 3 +++ services/appmgr/src/app_running_record.cpp | 6 ++++++ .../ability_record_test/ability_record_test.cpp | 2 ++ .../app_mgr_service_inner_test.cpp | 6 ++++++ tools/aa/include/ability_command.h | 2 +- tools/aa/src/ability_command.cpp | 11 ++++++++++- 13 files changed, 63 insertions(+), 3 deletions(-) diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 794f3004af..298adac24b 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1374,6 +1374,10 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con options.uid = bundleInfo.applicationInfo.uid; options.apiTargetVersion = appInfo.apiTargetVersion; options.pkgContextInfoJsonStringMap = pkgContextInfoJsonStringMap; + if (applicationInfo_->appProvisionType == Constants::APP_PROVISION_TYPE_DEBUG ) { + TAG_LOGD(AAFwkTag::JSRUNTIME, "Start Mutile Thread Mode: %{public}d.", appLaunchData.GetMutileThread()); + options.isMultiThread = appLaunchData.GetMutileThread(); + } options.jitEnabled = appLaunchData.IsJITEnabled(); AbilityRuntime::ChildProcessManager::GetInstance().SetForkProcessJITEnabled(appLaunchData.IsJITEnabled()); if (!bundleInfo.hapModuleInfos.empty()) { diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 741771e5e3..d6c9ffed90 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -628,6 +628,8 @@ void JsRuntime::PostPreload(const Options& options) std::string sandBoxAnFilePath = SANDBOX_ARK_CACHE_PATH + options.arkNativeFilePath; postOption.SetAnDir(sandBoxAnFilePath); } + TAG_LOGD(AAFwkTag::JSRUNTIME, "Start Mutile Thread Mode: %{public}d.", options.isMultiThread); + postOption.SetMutileThreadCheck(options.isMultiThread); bool profileEnabled = OHOS::system::GetBoolParameter("ark.profile", false); postOption.SetEnableProfile(profileEnabled); TAG_LOGD(AAFwkTag::JSRUNTIME, "ASMM JIT Verify PostFork, jitEnabled: %{public}d", options.jitEnabled); @@ -803,6 +805,9 @@ bool JsRuntime::CreateJsEnv(const Options& options) TAG_LOGD(AAFwkTag::JSRUNTIME, "ASMM JIT Verify CreateJsEnv, jitEnabled: %{public}d", options.jitEnabled); pandaOption.SetEnableJIT(options.jitEnabled); + TAG_LOGD(AAFwkTag::JSRUNTIME, "Start Mutile Thread Mode: %{public}d.", options.isMultiThread); + pandaOption.SetMutileThreadCheck(options.isMultiThread); + if (IsUseAbilityRuntime(options)) { // aot related bool aotEnabled = OHOS::system::GetBoolParameter("persist.ark.aot", true); diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h b/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h index 525c5b0ded..cabe14e474 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h @@ -172,6 +172,16 @@ public: return perfCmd_; } + inline void SetMutileThread(const bool multiThread) + { + isMultiThread_ = multiThread; + } + + inline bool GetMutileThread() const + { + return isMultiThread_; + } + inline void SetJITEnabled(const bool jitEnabled) { jitEnabled_ = jitEnabled; @@ -238,6 +248,7 @@ private: std::string perfCmd_; bool jitEnabled_ = false; bool isNativeStart_ = false; + bool isMultiThread_ = false; std::string appRunningUniqueId_; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp index 42f6ecbd99..7f6c872d4b 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp @@ -96,6 +96,12 @@ bool AppLaunchData::Marshalling(Parcel &parcel) const TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write app running unique id."); return false; } + + if (!parcel.WriteBool(isMultiThread_)) { + TAG_LOGE(AAFwkTag::APPMGR, "Failed to write is multi thread flag."); + return false; + } + return true; } @@ -140,6 +146,7 @@ bool AppLaunchData::ReadFromParcel(Parcel &parcel) jitEnabled_ = parcel.ReadBool(); isNativeStart_ = parcel.ReadBool(); appRunningUniqueId_ = parcel.ReadString(); + isMultiThread_ = parcel.ReadBool(); return true; } diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index 2783c47c81..8154bae53a 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -60,6 +60,7 @@ public: bool isStageModel = true; bool isTestFramework = false; bool jitEnabled = false; + bool isMultiThread = false; int32_t uid = -1; // ArkTsCard start bool isUnique = false; diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 2f809b4e40..8b8ae683cb 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -69,6 +69,7 @@ using namespace OHOS::AAFwk::PermissionConstants; const std::string DEBUG_APP = "debugApp"; const std::string NATIVE_DEBUG = "nativeDebug"; const std::string PERF_CMD = "perfCmd"; +const std::string MULTI_THREAD = "multiThread"; const std::string DMS_PROCESS_NAME = "distributedsched"; const std::string DMS_MISSION_ID = "dmsMissionId"; const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId"; @@ -2497,6 +2498,9 @@ void AbilityRecord::SetWant(const Want &want) if (!perfCmd.empty()) { want_.SetParam(PERF_CMD, perfCmd); } + if (multiThread) { + want_.SetParam(MULTI_THREAD, true); + } } Want AbilityRecord::GetWant() const diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index bfbc80d133..81146f0a62 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -593,6 +593,7 @@ public: bool IsDebugging() const; void SetNativeDebug(bool isNativeDebug); void SetPerfCmd(const std::string &perfCmd); + void SetMultiThread(const bool multiThread); void AddRenderRecord(const std::shared_ptr &record); void RemoveRenderRecord(const std::shared_ptr &record); std::shared_ptr GetRenderRecordByPid(const pid_t pid); @@ -743,7 +744,7 @@ public: void SetAssertionPauseFlag(bool flag); bool IsAssertionPause() const; - + void SetJITEnabled(const bool jitEnabled); bool IsJITEnabled() const; @@ -896,6 +897,7 @@ private: bool isRestartApp_ = false; // Only app calling RestartApp can be set to true bool isAssertPause_ = false; bool isNativeStart_ = false; + bool isMultiThread_ = false; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 66b33bacba..da7abc062d 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -116,6 +116,7 @@ const std::string FUNC_NAME = "main"; const std::string RENDER_PARAM = "invalidparam"; const std::string COLD_START = "coldStart"; const std::string PERF_CMD = "perfCmd"; +const std::string MULTI_THREAD = "multiThread"; const std::string DEBUG_CMD = "debugCmd"; const std::string ENTER_SANDBOX = "sandboxApp"; const std::string DLP_PARAMS_INDEX = "ohos.dlp.params.index"; @@ -1569,6 +1570,7 @@ std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord(spt appRecord->SetDebugApp(true); } appRecord->SetPerfCmd(want->GetStringParam(PERF_CMD)); + appRecord->SetMultiThread(want->GetBoolParam(MULTI_THREAD, false)); appRecord->SetAppIndex(want->GetIntParam(DLP_PARAMS_INDEX, 0)); appRecord->SetSecurityFlag(want->GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false)); appRecord->SetRequestProcCode(want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0)); @@ -3372,6 +3374,7 @@ void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const Ap appRecord->SetDebugApp(true); } appRecord->SetPerfCmd(wantPtr->GetStringParam(PERF_CMD)); + appRecord->SetMultiThread(wantPtr->GetBoolParam(MULTI_THREAD, false)); } appRecord->SetProcessAndExtensionType(abilityInfoPtr); appRecord->SetTaskHandler(taskHandler_); diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 00423413cd..9bbf999844 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -433,6 +433,7 @@ void AppRunningRecord::LaunchApplication(const Configuration &config) launchData.SetAppIndex(appIndex_); launchData.SetDebugApp(isDebugApp_); launchData.SetPerfCmd(perfCmd_); + launchData.SetMutileThread(isMultiThread_); launchData.SetJITEnabled(jitEnabled_); launchData.SetNativeStart(isNativeStart_); launchData.SetAppRunningUniqueId(std::to_string(startTimeMillis_)); @@ -1630,6 +1631,11 @@ void AppRunningRecord::SetPerfCmd(const std::string &perfCmd) perfCmd_ = perfCmd; } +void AppRunningRecord::SetMultiThread(const bool multiThread) +{ + isMultiThread_ = multiThread; +} + void AppRunningRecord::SetAppIndex(const int32_t appIndex) { appIndex_ = appIndex; diff --git a/test/unittest/ability_record_test/ability_record_test.cpp b/test/unittest/ability_record_test/ability_record_test.cpp index fc7ced6d9f..d4353e2b65 100644 --- a/test/unittest/ability_record_test/ability_record_test.cpp +++ b/test/unittest/ability_record_test/ability_record_test.cpp @@ -568,8 +568,10 @@ HWTEST_F(AbilityRecordTest, AaFwk_AbilityMS_Want, TestSize.Level1) { Want want; want.SetFlags(100); + want.SetParam("multiThread", true); abilityRecord_->SetWant(want); EXPECT_EQ(want.GetFlags(), abilityRecord_->GetWant().GetFlags()); + EXPECT_EQ(want.GetBoolParam("multiThread",false), abilityRecord_->GetWant().GetBoolParam("multiThread",false)); } /* diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index e61a77818b..e6613207eb 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -1198,6 +1198,12 @@ HWTEST_F(AppMgrServiceInnerTest, CreateAppRunningRecord_001, TestSize.Level0) applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); EXPECT_EQ(appRecord5, nullptr); + appMgrServiceInner->appRunningManager_ = nullptr; + want->SetParam("multiThread", false); + std::shared_ptr appRecord6 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + EXPECT_EQ(appRecord6, nullptr); + TAG_LOGI(AAFwkTag::TEST, "CreateAppRunningRecord_001 end"); } diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index 8724545aac..c5b6a0026e 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -70,7 +70,7 @@ const std::string HELP_MSG_START = "usage: aa start \n" "options list:\n" " -h, --help list available commands\n" - " [-d ] [-a -b ] [-m ] [-D] [-S] " + " [-d ] [-a -b ] [-m ] [-p ] [-D] [-S] [-N] [-R]" " [--ps ] " " [--pi ] " " [--pb ] " diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 47e1e8c818..b37cfcb4b2 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -47,7 +47,7 @@ constexpr int OPTION_PARAMETER_NULL_STRING = 260; const std::string DEVELOPERMODE_STATE = "const.security.developermode.state"; -const std::string SHORT_OPTIONS = "ch:d:a:b:e:t:p:s:m:A:U:CDSN"; +const std::string SHORT_OPTIONS = "ch:d:a:b:e:t:p:s:m:A:U:CDSNR"; constexpr struct option LONG_OPTIONS[] = { {"help", no_argument, nullptr, 'h'}, {"device", required_argument, nullptr, 'd'}, @@ -59,6 +59,7 @@ constexpr struct option LONG_OPTIONS[] = { {"cold-start", no_argument, nullptr, 'C'}, {"debug", no_argument, nullptr, 'D'}, {"native-debug", no_argument, nullptr, 'N'}, + {"mutil-thread", no_argument, nullptr,'R'}, {"action", required_argument, nullptr, 'A'}, {"URI", required_argument, nullptr, 'U'}, {"entity", required_argument, nullptr, 'e'}, @@ -1398,6 +1399,7 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win bool isContinuation = false; bool isSandboxApp = false; bool isNativeDebug = false; + bool isMultiThread = false; while (true) { counter++; @@ -1796,6 +1798,10 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win isNativeDebug = true; break; } + case 'R': { + isMultiThread = true; + TAG_LOGD(AAFwkTag::AA_TOOL, "isMultiThread"); + } case 0: { break; } @@ -1858,6 +1864,9 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want& want, std::string& win if (!typeVal.empty()) { want.SetType(typeVal); } + if (isMultiThread) { + want.SetParam("multiThread", isMultiThread); + } } }