adjust qos priority for partial gc

issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I9V0YF

Signed-off-by: xiongluo <xiongluo@huawei.com>
Change-Id: I4285021ebc9ff8b38dfb8d5c07cd83fa2dc0e416
This commit is contained in:
xiongluo 2024-06-04 22:02:13 +08:00
parent e4156293ae
commit f88552ff52
8 changed files with 54 additions and 16 deletions

View File

@ -472,9 +472,9 @@ void Jit::ChangeTaskPoolState(bool inBackground)
{
if (fastJitEnable_ || baselineJitEnable_) {
if (inBackground) {
JitTaskpool::GetCurrentTaskpool()->SetThreadPriority(false);
JitTaskpool::GetCurrentTaskpool()->SetThreadPriority(PriorityMode::BACKGROUND);
} else {
JitTaskpool::GetCurrentTaskpool()->SetThreadPriority(true);
JitTaskpool::GetCurrentTaskpool()->SetThreadPriority(PriorityMode::FOREGROUND);
}
}
}

View File

@ -580,6 +580,16 @@ public:
return runtimeState_;
}
bool SetMainThread()
{
return isMainThread_ = true;
}
bool IsMainThreadFast() const
{
return isMainThread_;
}
void SetCpuProfileName(std::string &profileName)
{
profileName_ = profileName;
@ -1532,6 +1542,7 @@ private:
bool finalizationCheckState_ {false};
// Shared heap
bool isMainThread_ {false};
bool fullMarkRequest_ {false};
CMap<ElementsKind, ConstantIndex> arrayHClassIndexMap_;

View File

@ -1841,7 +1841,7 @@ void Heap::ChangeGCParams(bool inBackground)
sweeper_->EnableConcurrentSweep(EnableConcurrentSweepType::DISABLE);
maxMarkTaskCount_ = 1;
maxEvacuateTaskCount_ = 1;
Taskpool::GetCurrentTaskpool()->SetThreadPriority(false);
Taskpool::GetCurrentTaskpool()->SetThreadPriority(PriorityMode::BACKGROUND);
} else {
LOG_GC(INFO) << "app is not inBackground";
if (GetMemGrowingType() != MemGrowingType::PRESSURE) {
@ -1853,7 +1853,7 @@ void Heap::ChangeGCParams(bool inBackground)
maxMarkTaskCount_ = std::min<size_t>(ecmaVm_->GetJSOptions().GetGcThreadNum(),
Taskpool::GetCurrentTaskpool()->GetTotalThreadNum() - 1);
maxEvacuateTaskCount_ = Taskpool::GetCurrentTaskpool()->GetTotalThreadNum();
Taskpool::GetCurrentTaskpool()->SetThreadPriority(true);
Taskpool::GetCurrentTaskpool()->SetThreadPriority(PriorityMode::FOREGROUND);
}
}

View File

@ -48,7 +48,10 @@ void PartialGC::RunPhases()
+ ";TotalCommit" + std::to_string(heap_->GetCommittedSize()));
TRACE_GC(GCStats::Scope::ScopeId::TotalGC, gcStats);
MEM_ALLOCATE_AND_GC_TRACE(heap_->GetEcmaVM(), PartialGC_RunPhases);
bool mainThreadInForeground = heap_->GetJSThread()->IsMainThreadFast() && !heap_->IsInBackground();
if (mainThreadInForeground) {
Taskpool::GetCurrentTaskpool()->SetThreadPriority(PriorityMode::STW);
}
markingInProgress_ = heap_->CheckOngoingConcurrentMarking();
LOG_GC(DEBUG) << "markingInProgress_" << markingInProgress_;
@ -66,6 +69,9 @@ void PartialGC::RunPhases()
Verification::VerifyEvacuate(heap_);
}
Finish();
if (mainThreadInForeground) {
Taskpool::GetCurrentTaskpool()->SetThreadPriority(PriorityMode::FOREGROUND);
}
if (heap_->IsConcurrentFullMark()) {
heap_->NotifyHeapAliveSizeAfterGC(heap_->GetHeapObjectSize());
}

View File

@ -102,6 +102,7 @@ void Runtime::InitializeIfFirstVm(EcmaVM *vm)
void Runtime::PreInitialization(const EcmaVM *vm)
{
mainThread_ = vm->GetAssociatedJSThread();
mainThread_->SetMainThread();
nativeAreaAllocator_ = std::make_unique<NativeAreaAllocator>();
heapRegionAllocator_ = std::make_unique<HeapRegionAllocator>();
stringTable_ = std::make_unique<EcmaStringTable>();

View File

@ -80,17 +80,31 @@ void Runner::ForEachTask(const std::function<void(Task*)> &f)
}
}
void Runner::SetQosPriority([[maybe_unused]] bool isForeground)
void Runner::SetQosPriority([[maybe_unused]] PriorityMode mode)
{
#ifdef ENABLE_QOS
if (isForeground) {
switch (mode) {
case PriorityMode::STW: {
for (uint32_t threadId : gcThreadId_) {
OHOS::QOS::SetQosForOtherThread(OHOS::QOS::QosLevel::QOS_USER_INTERACTIVE, threadId);
}
return;
}
case PriorityMode::FOREGROUND: {
for (uint32_t threadId : gcThreadId_) {
OHOS::QOS::SetQosForOtherThread(OHOS::QOS::QosLevel::QOS_USER_INITIATED, threadId);
}
} else {
return;
}
case PriorityMode::BACKGROUND: {
for (uint32_t threadId : gcThreadId_) {
OHOS::QOS::ResetQosForOtherThread(threadId);
}
return;
}
default:
UNREACHABLE();
break;
}
#endif
}

View File

@ -29,9 +29,15 @@
namespace panda::ecmascript {
static constexpr uint32_t MIN_TASKPOOL_THREAD_NUM = 3;
static constexpr uint32_t MAX_TASKPOOL_THREAD_NUM = 7;
static constexpr uint32_t MAX_TASKPOOL_THREAD_NUM = 5;
static constexpr uint32_t DEFAULT_TASKPOOL_THREAD_NUM = 0;
enum class PriorityMode {
STW,
FOREGROUND,
BACKGROUND
};
class Runner {
public:
explicit Runner(uint32_t threadNum,
@ -49,7 +55,7 @@ public:
void PUBLIC_API TerminateThread();
void TerminateTask(int32_t id, TaskType type);
void SetQosPriority(bool isForeground);
void SetQosPriority(PriorityMode mode);
void RecordThreadId();
uint32_t GetTotalThreadNum() const

View File

@ -63,9 +63,9 @@ public:
return runner_->IsInThreadPool(id);
}
void SetThreadPriority(bool isForeground)
void SetThreadPriority(PriorityMode mode)
{
runner_->SetQosPriority(isForeground);
runner_->SetQosPriority(mode);
}
void ForEachTask(const std::function<void(Task*)> &f);