mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 07:10:19 +00:00
迁移服务优先调度
Signed-off-by: donglin <donglin9@huawei.com> Change-Id: If802489ed03d68a325376405df57b9d6fdf3951a
This commit is contained in:
parent
5741f41b1e
commit
c7bae761a1
@ -23,6 +23,7 @@
|
||||
#include "appfreeze_manager.h"
|
||||
#include "app_exit_reason_data_manager.h"
|
||||
#include "assert_fault_callback_death_mgr.h"
|
||||
#include "global_constant.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "int_wrapper.h"
|
||||
#include "multi_instance_utils.h"
|
||||
|
@ -283,16 +283,14 @@ void AbilityRecord::LoadUIAbility()
|
||||
int loadTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * LOAD_TIMEOUT_MULTIPLE;
|
||||
if (abilityInfo_.applicationInfo.asanEnabled || abilityInfo_.applicationInfo.tsanEnabled) {
|
||||
loadTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * LOAD_TIMEOUT_ASANENABLED;
|
||||
SendEvent(AbilityManagerService::LOAD_HALF_TIMEOUT_MSG, loadTimeout / HALF_TIMEOUT);
|
||||
SendEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, loadTimeout);
|
||||
} else {
|
||||
int coldStartTimeout =
|
||||
AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * COLDSTART_TIMEOUT_MULTIPLE;
|
||||
std::lock_guard guard(wantLock_);
|
||||
auto delayTime = want_.GetBoolParam("coldStart", false) ? coldStartTimeout : loadTimeout;
|
||||
SendEvent(AbilityManagerService::LOAD_HALF_TIMEOUT_MSG, delayTime / HALF_TIMEOUT);
|
||||
SendEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, delayTime);
|
||||
loadTimeout = want_.GetBoolParam("coldStart", false) ? coldStartTimeout : loadTimeout;
|
||||
}
|
||||
SendEvent(AbilityManagerService::LOAD_HALF_TIMEOUT_MSG, loadTimeout / HALF_TIMEOUT);
|
||||
SendEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, loadTimeout);
|
||||
std::string methodName = "LoadAbility";
|
||||
g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::LOAD, methodName);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "accesstoken_kit.h"
|
||||
#include "app_death_recipient.h"
|
||||
#include "app_mgr_constants.h"
|
||||
#include "app_utils.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "perf_profile.h"
|
||||
#include "permission_constants.h"
|
||||
@ -50,6 +51,7 @@ constexpr const char* TASK_SCENE_BOARD_ATTACH_TIMEOUT = "sceneBoardAttachTimeout
|
||||
constexpr const char* TASK_ATTACHED_TO_STATUS_BAR = "AttachedToStatusBar";
|
||||
constexpr const char* TASK_BLOCK_PROCESS_CACHE_BY_PIDS = "BlockProcessCacheByPids";
|
||||
constexpr int32_t SCENE_BOARD_ATTACH_TIMEOUT_TASK_TIME = 1000;
|
||||
constexpr const char* TASK_LOAD_ABILITY = "LoadAbilityTask";
|
||||
}; // namespace
|
||||
|
||||
AmsMgrScheduler::AmsMgrScheduler(
|
||||
@ -106,6 +108,15 @@ void AmsMgrScheduler::LoadAbility(const std::shared_ptr<AbilityInfo> &abilityInf
|
||||
amsHandler_->SubmitTask(timeoutTask, TASK_SCENE_BOARD_ATTACH_TIMEOUT, SCENE_BOARD_ATTACH_TIMEOUT_TASK_TIME);
|
||||
}
|
||||
|
||||
if (abilityInfo->bundleName == AAFwk::AppUtils::GetInstance().GetMigrateClientBundleName()) {
|
||||
amsHandler_->SubmitTask(loadAbilityFunc, AAFwk::TaskAttribute{
|
||||
.taskName_ = TASK_LOAD_ABILITY,
|
||||
.taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE,
|
||||
.taskPriority_ = AAFwk::TaskQueuePriority::IMMEDIATE
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
amsHandler_->SubmitTask(loadAbilityFunc);
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ constexpr const size_t VALID_DUMP_FFRT_ARG_SIZE = 2;
|
||||
constexpr const int MAX_DUMP_FFRT_PID_NUMBER = 3;
|
||||
constexpr const int BASE_TEN = 10;
|
||||
constexpr const char SIGN_TERMINAL = '\0';
|
||||
constexpr int32_t DEFAULT_CONCURRENT_NUMBER = 1;
|
||||
namespace {
|
||||
using namespace std::chrono_literals;
|
||||
constexpr const char* TASK_INIT_APPMGRSERVICEINNER = "InitAppMgrServiceInnerTask";
|
||||
@ -145,7 +146,8 @@ ErrCode AppMgrService::Init()
|
||||
return ERR_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("app_mgr_task_queue");
|
||||
taskHandler_ = AAFwk::TaskHandlerWrap::CreateConcurrentQueueHandler("app_mgr_task_queue",
|
||||
DEFAULT_CONCURRENT_NUMBER);
|
||||
eventHandler_ = std::make_shared<AMSEventHandler>(taskHandler_, appMgrServiceInner_);
|
||||
appMgrServiceInner_->SetTaskHandler(taskHandler_);
|
||||
appMgrServiceInner_->SetEventHandler(eventHandler_);
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
int32_t GetCollaboratorBrokerUID();
|
||||
int32_t GetCollaboratorBrokerReserveUID();
|
||||
int32_t MaxChildProcess();
|
||||
std::string GetMigrateClientBundleName();
|
||||
|
||||
private:
|
||||
void LoadResidentProcessInExtremeMemory();
|
||||
@ -98,6 +99,7 @@ private:
|
||||
volatile DeviceConfiguration<int32_t> collaboratorBrokerUid_ = {false, DEFAULT_INVALID_VALUE};
|
||||
volatile DeviceConfiguration<int32_t> collaboratorBrokerReserveUid_ = {false, DEFAULT_INVALID_VALUE};
|
||||
volatile DeviceConfiguration<int32_t> maxChildProcess_ = {false, DEFAULT_MAX_CHILD_PROCESS};
|
||||
DeviceConfiguration<std::string> migrateClientBundleName_ = {true, "com.huwei.hmos.migratecilent"};
|
||||
DISALLOW_COPY_AND_MOVE(AppUtils);
|
||||
};
|
||||
} // namespace AAFwk
|
||||
|
@ -61,6 +61,10 @@ friend class TaskHandle;
|
||||
public:
|
||||
static std::shared_ptr<TaskHandlerWrap> CreateQueueHandler(const std::string &queueName,
|
||||
TaskQoS queueQos = TaskQoS::DEFAULT);
|
||||
|
||||
static std::shared_ptr<TaskHandlerWrap> CreateConcurrentQueueHandler(const std::string &queueName,
|
||||
int32_t concurrentNum, TaskQoS queueQos = TaskQoS::DEFAULT);
|
||||
|
||||
static std::shared_ptr<TaskHandlerWrap> GetFfrtHandler();
|
||||
|
||||
TaskHandlerWrap(TaskHandlerWrap &) = delete;
|
||||
|
@ -25,6 +25,7 @@ enum class TaskStatus {
|
||||
FINISHED,
|
||||
CANCELED
|
||||
};
|
||||
|
||||
enum class TaskQoS {
|
||||
INHERENT = 0,
|
||||
BACKGROUND,
|
||||
@ -34,10 +35,19 @@ enum class TaskQoS {
|
||||
DEADLINE_REQUEST,
|
||||
USER_INTERACTIVE
|
||||
};
|
||||
|
||||
enum class TaskQueuePriority {
|
||||
IMMEDIATE = 0,
|
||||
HIGH,
|
||||
LOW,
|
||||
IDLE
|
||||
};
|
||||
|
||||
struct TaskAttribute {
|
||||
std::string taskName_;
|
||||
int64_t delayMillis_ = 0;
|
||||
TaskQoS taskQos_ = TaskQoS::DEFAULT;
|
||||
TaskQueuePriority taskPriority_ = TaskQueuePriority::LOW;
|
||||
|
||||
bool IsDefault() const
|
||||
{
|
||||
|
@ -67,6 +67,7 @@ constexpr const char* COLLABORATOR_BROKER_UID = "const.sys.abilityms.collaborato
|
||||
constexpr const char* COLLABORATOR_BROKER_RESERVE_UID = "const.sys.abilityms.collaborator_broker_reserve_uid";
|
||||
constexpr const char* MAX_CHILD_PROCESS = "const.max_native_child_process";
|
||||
constexpr const char* SUPPORT_MULTI_INSTANCE = "const.abilityms.support_multi_instance";
|
||||
constexpr const char* MIGRATE_CLIENT_BUNDLE_NAME = "const.sys.abilityms.migrate_client_bundle_name";
|
||||
}
|
||||
|
||||
AppUtils::~AppUtils() {}
|
||||
@ -449,5 +450,15 @@ bool AppUtils::IsSupportMultiInstance()
|
||||
TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isSupportMultiInstance_.value);
|
||||
return isSupportMultiInstance_.value;
|
||||
}
|
||||
|
||||
std::string AppUtils::GetMigrateClientBundleName()
|
||||
{
|
||||
if (!migrateClientBundleName_.isLoaded) {
|
||||
migrateClientBundleName_.value = system::GetParameter(MIGRATE_CLIENT_BUNDLE_NAME, "");
|
||||
migrateClientBundleName_.isLoaded = true;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::DEFAULT, "migrateClientBundleName_ is %{public}s", migrateClientBundleName_.value.c_str());
|
||||
return migrateClientBundleName_.value;
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
@ -39,6 +39,7 @@ private:
|
||||
|
||||
void BuildFfrtTaskAttr(const TaskAttribute &taskAttr, ffrt::task_attr &result);
|
||||
ffrt::qos Convert2FfrtQos(TaskQoS taskqos);
|
||||
ffrt_queue_priority_t Convert2FfrtPriority(TaskQueuePriority taskPrio);
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_FFRT_TASK_UTILS_WRAP_H
|
@ -22,6 +22,14 @@ constexpr int32_t QUEUE_TIME_OUT = 500000; // us
|
||||
QueueTaskHandlerWrap::QueueTaskHandlerWrap(const std::string &queueName, TaskQoS queueQos)
|
||||
: taskQueue_(queueName.c_str(), ffrt::queue_attr().qos(Convert2FfrtQos(queueQos)).timeout(QUEUE_TIME_OUT))
|
||||
{}
|
||||
|
||||
QueueTaskHandlerWrap::QueueTaskHandlerWrap(const std::string &queueName, int32_t concurrentNum, TaskQoS queueQos)
|
||||
: taskQueue_(
|
||||
ffrt::queue_type::queue_concurrent,
|
||||
queueName.c_str(),
|
||||
ffrt::queue_attr().qos(Convert2FfrtQos(queueQos)).timeout(QUEUE_TIME_OUT).max_concurrency(concurrentNum))
|
||||
{}
|
||||
|
||||
std::shared_ptr<InnerTaskHandle> QueueTaskHandlerWrap::SubmitTaskInner(std::function<void()> &&task,
|
||||
const TaskAttribute &taskAttr)
|
||||
{
|
||||
|
@ -25,6 +25,7 @@ namespace AAFwk {
|
||||
class QueueTaskHandlerWrap : public TaskHandlerWrap {
|
||||
public:
|
||||
QueueTaskHandlerWrap(const std::string &queueName, TaskQoS queueQos);
|
||||
QueueTaskHandlerWrap(const std::string &queueName, int32_t concurrentNum, TaskQoS queueQos);
|
||||
virtual ~QueueTaskHandlerWrap() = default;
|
||||
protected:
|
||||
std::shared_ptr<InnerTaskHandle> SubmitTaskInner(std::function<void()> &&task,
|
||||
|
@ -63,6 +63,12 @@ std::shared_ptr<TaskHandlerWrap> TaskHandlerWrap::CreateQueueHandler(const std::
|
||||
return std::make_shared<QueueTaskHandlerWrap>(queueName, queueQos);
|
||||
}
|
||||
|
||||
std::shared_ptr<TaskHandlerWrap> TaskHandlerWrap::CreateConcurrentQueueHandler(const std::string &queueName,
|
||||
int32_t concurrentNum, TaskQoS queueQos)
|
||||
{
|
||||
return std::make_shared<QueueTaskHandlerWrap>(queueName, concurrentNum, queueQos);
|
||||
}
|
||||
|
||||
std::shared_ptr<TaskHandlerWrap> TaskHandlerWrap::GetFfrtHandler()
|
||||
{
|
||||
static auto ffrtHandler = std::make_shared<FfrtTaskHandlerWrap>();
|
||||
@ -188,6 +194,22 @@ ffrt::qos Convert2FfrtQos(TaskQoS taskqos)
|
||||
|
||||
return ffrt::qos_inherit;
|
||||
}
|
||||
|
||||
ffrt_queue_priority_t Convert2FfrtPriority(TaskQueuePriority taskPrio)
|
||||
{
|
||||
switch (taskPrio) {
|
||||
case TaskQueuePriority::IMMEDIATE:
|
||||
return ffrt_queue_priority_t::ffrt_queue_priority_immediate;
|
||||
case TaskQueuePriority::HIGH:
|
||||
return ffrt_queue_priority_t::ffrt_queue_priority_high;
|
||||
case TaskQueuePriority::LOW:
|
||||
return ffrt_queue_priority_t::ffrt_queue_priority_low;
|
||||
case TaskQueuePriority::IDLE:
|
||||
return ffrt_queue_priority_t::ffrt_queue_priority_idle;
|
||||
}
|
||||
return ffrt_queue_priority_t::ffrt_queue_priority_low;
|
||||
}
|
||||
|
||||
void BuildFfrtTaskAttr(const TaskAttribute &taskAttr, ffrt::task_attr &result)
|
||||
{
|
||||
if (taskAttr.delayMillis_ > 0) {
|
||||
@ -199,6 +221,9 @@ void BuildFfrtTaskAttr(const TaskAttribute &taskAttr, ffrt::task_attr &result)
|
||||
if (taskAttr.taskQos_ != TaskQoS::DEFAULT) {
|
||||
result.qos(Convert2FfrtQos(taskAttr.taskQos_));
|
||||
}
|
||||
if (taskAttr.taskPriority_ != TaskQueuePriority::LOW) {
|
||||
result.priority(Convert2FfrtPriority(taskAttr.taskPriority_));
|
||||
}
|
||||
}
|
||||
} // namespace AAFWK
|
||||
} // namespace OHOS
|
@ -61,6 +61,7 @@ ohos_unittest("ams_mgr_scheduler_second_test") {
|
||||
"${ability_runtime_native_path}/appkit:appkit_native",
|
||||
"${ability_runtime_path}/utils/server/startup:startup_util",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:app_util",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
"//third_party/googletest:gmock_main",
|
||||
|
@ -57,6 +57,7 @@ ohos_unittest("ams_mgr_scheduler_test") {
|
||||
"${ability_runtime_native_path}/appkit:appkit_native",
|
||||
"${ability_runtime_path}/utils/server/startup:startup_util",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:app_util",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
"//third_party/googletest:gmock_main",
|
||||
|
@ -45,6 +45,7 @@ ohos_unittest("app_state_observer_manager_test") {
|
||||
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
|
||||
"${ability_runtime_path}/services/abilitymgr:abilityms_target",
|
||||
"${ability_runtime_services_path}/appmgr:libappms",
|
||||
"${ability_runtime_services_path}/common:app_util",
|
||||
"${ability_runtime_services_path}/common:perm_verification",
|
||||
"${ability_runtime_services_path}/common:task_handler_wrap",
|
||||
"${ability_runtime_test_path}/unittest:appmgr_test_source",
|
||||
|
@ -48,6 +48,8 @@ constexpr int32_t TYPE_RESERVE = 1;
|
||||
constexpr int32_t TYPE_OTHERS = 2;
|
||||
#endif
|
||||
|
||||
constexpr int32_t MIGRATE_CLIENT_TIMEOUT_MULTIPLE = 3;
|
||||
|
||||
constexpr int32_t GetLoadTimeOutBase()
|
||||
{
|
||||
return TIMEOUT_UNIT_TIME * LOAD_TIMEOUT_MULTIPLE;
|
||||
|
Loading…
Reference in New Issue
Block a user