Bug 1708042, add control priority to the main thread, r=bas

Differential Revision: https://phabricator.services.mozilla.com/D115404
This commit is contained in:
Olli Pettay 2021-05-21 15:46:45 +00:00
Родитель 33d6bda86d
Коммит 19f47e75ab
5 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -10651,6 +10651,12 @@
value: true
mirror: always
# If control tasks aren't enabled, they get medium high priority.
- name: threads.control_event_queue.enabled
type: RelaxedAtomicBool
value: true
mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "timer."
#---------------------------------------------------------------------------

Просмотреть файл

@ -33,6 +33,8 @@ void EventQueueInternal<ItemsPerPage>::PutEvent(
static_cast<uint32_t>(EventQueuePriority::InputHigh));
static_assert(static_cast<uint32_t>(nsIRunnablePriority::PRIORITY_VSYNC) ==
static_cast<uint32_t>(EventQueuePriority::Vsync));
static_assert(static_cast<uint32_t>(nsIRunnablePriority::PRIORITY_CONTROL) ==
static_cast<uint32_t>(EventQueuePriority::Control));
if (mForwardToTC) {
TaskController* tc = TaskController::Get();

Просмотреть файл

@ -25,6 +25,7 @@ enum class EventQueuePriority {
InputHigh,
Vsync,
InputHighest,
Control,
Count
};

Просмотреть файл

@ -15,6 +15,7 @@
#include "ThreadEventTarget.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/TaskController.h"
#include "mozilla/StaticPrefs_threads.h"
using namespace mozilla;
@ -81,7 +82,9 @@ bool ThreadEventQueue::PutEventInternal(already_AddRefed<nsIRunnable>&& aEvent,
if (nsCOMPtr<nsIRunnablePriority> runnablePrio = do_QueryInterface(e)) {
uint32_t prio = nsIRunnablePriority::PRIORITY_NORMAL;
runnablePrio->GetPriority(&prio);
if (prio == nsIRunnablePriority::PRIORITY_VSYNC) {
if (prio == nsIRunnablePriority::PRIORITY_CONTROL) {
aPriority = EventQueuePriority::Control;
} else if (prio == nsIRunnablePriority::PRIORITY_VSYNC) {
aPriority = EventQueuePriority::Vsync;
} else if (prio == nsIRunnablePriority::PRIORITY_INPUT_HIGH) {
aPriority = EventQueuePriority::InputHigh;
@ -93,6 +96,11 @@ bool ThreadEventQueue::PutEventInternal(already_AddRefed<nsIRunnable>&& aEvent,
aPriority = EventQueuePriority::Idle;
}
}
if (aPriority == EventQueuePriority::Control &&
!StaticPrefs::threads_control_event_queue_enabled()) {
aPriority = EventQueuePriority::MediumHigh;
}
}
MutexAutoLock lock(mLock);

Просмотреть файл

@ -29,6 +29,10 @@ interface nsIRunnablePriority : nsISupports
const unsigned short PRIORITY_MEDIUMHIGH = 4;
const unsigned short PRIORITY_INPUT_HIGH = 5;
const unsigned short PRIORITY_VSYNC = 6;
// INPUT_HIGHEST is InputTaskManager's internal priority
//const unsigned short PRIORITY_INPUT_HIGHEST = 7;
const unsigned short PRIORITY_CONTROL = 8;
readonly attribute unsigned long priority;
};