gecko-dev/xpcom/threads
kriswright e326c6a800 Bug 1748378 - Create a way to deprioritize threadpools. r=nika
This will be used to deprioritize whole thread pools. The concept works as such:

- Set a thread pool's priority at any time
- Each thread will ensure their priority mirrors the parent pool's priority when it is finished processing events.

I chose to have threads only set themselves to the background when they finish processing events because an event dispatched at an expected priority should be completed at said priority. This ensures that any event dispatch that may expect normal priority (i.e. not operating in the background) has a chance to run at the established priority.

This patch enrolls the background IO to low priority on its creation. It also includes the MacOS implementation of the thread priorities, which utilizes mac's QoS service. According to MacOS's QoS structure, main threads operate at `user-interactive` and offthread work is done at a `default` state, meaning that the OS decides how to set the thread's priority somewhere between `utility` and `user-interactive`. When a thread is put in the background, it must be manually raised back to the expected priority, which means most threads must set themselves to `default` again and the main thread must set itself to `user-interactive`. I demonstrated this in the `nsThread` implementation by checking for the main thread and if this task is running on the main thread somehow, then we use the correct setting.

Rather than having the thread pools dispatch their own deprioritization tasks, I've decided to make this the job of the nsThread. In following bugs we will put entire processes' nsThreads in the background, which will require more use of the new nsThread codepaths.

This behavior is currently restricted to nightly only. On platforms with no implementation, nothing will change.

Differential Revision: https://phabricator.services.mozilla.com/D146534
2023-02-03 16:36:47 +00:00
..
AbstractThread.cpp Bug 1738106 - Part 4: Support ThreadSafeWeakPtr in TaskQueue, r=xpcom-reviewers,mccr8 2022-05-02 20:37:35 +00:00
AbstractThread.h Bug 1738106 - Part 4: Support ThreadSafeWeakPtr in TaskQueue, r=xpcom-reviewers,mccr8 2022-05-02 20:37:35 +00:00
BlockingResourceBase.cpp Bug 1761536 - Part 2: Replace nsTArray::elem_type with value_type, r=mccr8 2022-04-01 17:00:25 +00:00
BlockingResourceBase.h Bug 1207753 - Add MOZ_UNANNOTATED to all Mutexes/Monitors r=nika,kershaw 2022-03-16 18:47:08 +00:00
CPUUsageWatcher.cpp
CPUUsageWatcher.h
CondVar.h Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato 2022-08-03 16:39:41 +00:00
DataMutex.h Bug 1783299 - Add support for threadsafe mirrored StaticPref strings. r=KrisWright 2022-08-16 01:00:21 +00:00
DeadlockDetector.h
DelayedRunnable.cpp Bug 1738103 - Part 4: Add XPCOM support for shutdown tasks, r=necko-reviewers,KrisWright 2022-03-23 22:22:04 +00:00
DelayedRunnable.h Bug 1738103 - Part 4: Add XPCOM support for shutdown tasks, r=necko-reviewers,KrisWright 2022-03-23 22:22:04 +00:00
EventQueue.cpp
EventQueue.h Bug 1778575, add support for low priority tasks and use such to trigger pending RefreshDriverTimer, r=bas 2022-10-18 17:29:44 +00:00
EventTargetCapability.h Bug 1797354 - Allow specifying capability type in thread-safety macros, r=jesup,media-playback-reviewers,alwu 2022-10-28 19:55:30 +00:00
IdlePeriodState.cpp Bug 1797688 - Part 8: Substitute gXPCOMThreadsShutDown with InOrBeyond(XPCOMShutdownThreads) in IdlePeriodState::GetLocalIdleDeadline. r=xpcom-reviewers,mccr8 2022-11-01 14:08:45 +00:00
IdlePeriodState.h
IdleTaskRunner.cpp Bug 1774864 - Cleanup xpcom/ includes r=sylvestre 2022-06-24 07:13:59 +00:00
IdleTaskRunner.h Bug 1774864 - Cleanup xpcom/ includes r=sylvestre 2022-06-24 07:13:59 +00:00
InputTaskManager.cpp Bug 1795624 - remove dom.input_events.strict_input_vsync_alignment, r=sefeng 2022-10-17 17:02:24 +00:00
InputTaskManager.h Bug 1795624 - remove dom.input_events.strict_input_vsync_alignment, r=sefeng 2022-10-17 17:02:24 +00:00
LazyIdleThread.cpp Bug 1748378 - Create a way to deprioritize threadpools. r=nika 2023-02-03 16:36:47 +00:00
LazyIdleThread.h Backed out changeset eafcabbf729b (bug 1542802) for causing Gtest crashes. CLOSED TREE 2023-02-03 00:03:53 +02:00
LeakRefPtr.h
MainThreadIdlePeriod.cpp Bug 1771718, let idle period be shorter when frame rate is very high, r=farre 2022-06-02 10:40:54 +00:00
MainThreadIdlePeriod.h
MainThreadUtils.h Bug 1797354 - Allow specifying capability type in thread-safety macros, r=jesup,media-playback-reviewers,alwu 2022-10-28 19:55:30 +00:00
Monitor.h Bug 1797354 - Allow specifying capability type in thread-safety macros, r=jesup,media-playback-reviewers,alwu 2022-10-28 19:55:30 +00:00
MozPromise.h Bug 1800347, make it possible to set the priority of the Runnables used by MozPromise, r=emilio 2022-11-16 09:23:28 +00:00
MozPromiseInlines.h
Mutex.h Bug 1797354 - Allow specifying capability type in thread-safety macros, r=jesup,media-playback-reviewers,alwu 2022-10-28 19:55:30 +00:00
PerformanceCounter.cpp
PerformanceCounter.h
Queue.h
RWLock.cpp Bug 1757100 - Move minimal platform-dependent part of RWLock to mozglue/misc/PlatformRWLock.h&cpp - r=glandium,xpcom-reviewers 2022-02-27 23:32:55 +00:00
RWLock.h Bug 1797354 - Allow specifying capability type in thread-safety macros, r=jesup,media-playback-reviewers,alwu 2022-10-28 19:55:30 +00:00
RecursiveMutex.cpp
RecursiveMutex.h Bug 1797354 - Allow specifying capability type in thread-safety macros, r=jesup,media-playback-reviewers,alwu 2022-10-28 19:55:30 +00:00
ReentrantMonitor.h Bug 1797354 - Allow specifying capability type in thread-safety macros, r=jesup,media-playback-reviewers,alwu 2022-10-28 19:55:30 +00:00
SchedulerGroup.cpp Bug 1810981 - Remove unused SchedulerGroup member variables, r=farre 2023-01-18 14:33:00 +00:00
SchedulerGroup.h Bug 1810981 - Remove unused SchedulerGroup member variables, r=farre 2023-01-18 14:33:00 +00:00
SharedThreadPool.cpp Bug 1738103 - Part 4: Add XPCOM support for shutdown tasks, r=necko-reviewers,KrisWright 2022-03-23 22:22:04 +00:00
SharedThreadPool.h Bug 1738103 - Part 4: Add XPCOM support for shutdown tasks, r=necko-reviewers,KrisWright 2022-03-23 22:22:04 +00:00
SpinEventLoopUntil.h Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato 2022-08-03 16:39:41 +00:00
StateMirroring.h
StateWatching.h
SyncRunnable.h Bug 1772908 - [1/6] Drive-by cleanup: simplify use of SyncRunnable r=xpcom-reviewers,necko-reviewers,nika,valentin 2022-11-04 21:04:18 +00:00
SynchronizedEventQueue.cpp
SynchronizedEventQueue.h Bug 1738103 - Part 4: Add XPCOM support for shutdown tasks, r=necko-reviewers,KrisWright 2022-03-23 22:22:04 +00:00
TaskCategory.h
TaskController.cpp Bug 1803751 - Make some marker fields searchable and bump the profile version r=julienw 2022-12-13 14:19:07 +00:00
TaskController.h Bug 1762090, don't block refreshdrivers for too long time on linux, r=mstange 2022-04-06 00:40:25 +00:00
TaskDispatcher.h Bug 1746361 - Gecko Profiler: Track wrapped runnables throughout the tree. r=gerald 2022-01-05 15:26:24 +00:00
TaskQueue.cpp Bug 1738106 - Part 5: Track TaskQueue lifetimes to avoid leaking TaskQueues, r=xpcom-reviewers,mccr8 2022-05-02 20:37:35 +00:00
TaskQueue.h Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato 2022-08-03 16:39:41 +00:00
ThreadBound.h
ThreadDelay.cpp
ThreadDelay.h
ThreadEventQueue.cpp Bug 1799222 - Part 1: Prevent accidental dispatches to threadpool and timer threads, r=xpcom-reviewers,necko-reviewers,geckoview-reviewers,media-playback-reviewers,jesup,m_kato,padenot,kmag 2022-12-16 17:09:16 +00:00
ThreadEventQueue.h Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato 2022-08-03 16:39:41 +00:00
ThreadEventTarget.cpp Bug 1809753 - Part 2: Switch some calls to GetCurrentEventTarget() to NS_GetCurrentThread, r=mccr8 2023-01-16 23:14:11 +00:00
ThreadEventTarget.h Bug 1799222 - Part 1: Prevent accidental dispatches to threadpool and timer threads, r=xpcom-reviewers,necko-reviewers,geckoview-reviewers,media-playback-reviewers,jesup,m_kato,padenot,kmag 2022-12-16 17:09:16 +00:00
ThreadLocalVariables.cpp
ThrottledEventQueue.cpp Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato 2022-08-03 16:39:41 +00:00
ThrottledEventQueue.h
TimerThread.cpp Bug 1812080 - Fixed Timer Thread wake-up logic when adding timers r=smaug,florian 2023-02-02 16:06:33 +00:00
TimerThread.h Bug 1787974 - Fixed small logic change in FindNextFireTimeForCurrentThread(). r=smaug 2023-01-20 17:11:12 +00:00
VsyncTaskManager.cpp Bug 1795624 - remove dom.input_events.strict_input_vsync_alignment, r=sefeng 2022-10-17 17:02:24 +00:00
VsyncTaskManager.h
WinHandleWatcher.cpp Bug 1772908 - [5/6] Implement WinHandleWatcher r=xpcom-reviewers,nika 2022-12-13 16:38:06 +00:00
WinHandleWatcher.h Bug 1772908 - [5/6] Implement WinHandleWatcher r=xpcom-reviewers,nika 2022-12-13 16:38:06 +00:00
components.conf Bug 1541508 - Expose nsIEnvironment as Services.env r=xpcom-reviewers,kmag 2022-11-25 19:09:05 +00:00
moz.build Bug 1772908 - [5/6] Implement WinHandleWatcher r=xpcom-reviewers,nika 2022-12-13 16:38:06 +00:00
nsEnvironment.cpp Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato 2022-08-03 16:39:41 +00:00
nsEnvironment.h Bug 1514936, part 2 - Drop the outer arguments from static components. r=xpcom-reviewers,nika 2022-05-17 20:24:19 +00:00
nsICancelableRunnable.h
nsIDirectTaskDispatcher.idl Bug 1792357, part 2 - Non-scriptable classes don't need to be marked [builtinclass]. r=xpcom-reviewers,necko-reviewers,valentin,nika 2022-09-27 18:31:50 +00:00
nsIDiscardableRunnable.h
nsIEnvironment.idl Bug 1802288 - remove trailing whitespaces in idl/webidl files r=credential-management-reviewers,webidl,smaug,sgalich 2022-12-28 09:52:44 +00:00
nsIEventTarget.idl Bug 1799222 - Part 1: Prevent accidental dispatches to threadpool and timer threads, r=xpcom-reviewers,necko-reviewers,geckoview-reviewers,media-playback-reviewers,jesup,m_kato,padenot,kmag 2022-12-16 17:09:16 +00:00
nsIIdlePeriod.idl Bug 1792357, part 2 - Non-scriptable classes don't need to be marked [builtinclass]. r=xpcom-reviewers,necko-reviewers,valentin,nika 2022-09-27 18:31:50 +00:00
nsIIdleRunnable.h
nsINamed.idl
nsIProcess.idl Bug 1797840: Replace stray tab characters with spaces in IDL files throughout the tree. r=mccr8,necko-reviewers,credential-management-reviewers,smaug,sgalich,valentin 2022-10-28 18:08:17 +00:00
nsIRunnable.idl Bug 1778575, add support for low priority tasks and use such to trigger pending RefreshDriverTimer, r=bas 2022-10-18 17:29:44 +00:00
nsISerialEventTarget.idl
nsISupportsPriority.idl
nsITargetShutdownTask.h Bug 1738103 - Part 4: Add XPCOM support for shutdown tasks, r=necko-reviewers,KrisWright 2022-03-23 22:22:04 +00:00
nsIThread.idl Bug 1748378 - Create a way to deprioritize threadpools. r=nika 2023-02-03 16:36:47 +00:00
nsIThreadInternal.idl
nsIThreadManager.idl Bug 1807838, try to translate elements before load event fires, r=emilio 2023-01-10 22:47:20 +00:00
nsIThreadPool.idl Bug 1748378 - Create a way to deprioritize threadpools. r=nika 2023-02-03 16:36:47 +00:00
nsIThreadShutdown.idl Bug 1747526 - Return a handle from asyncShutdown to observe and cancel thread shutdown progress, r=xpcom-reviewers,KrisWright 2022-02-08 23:58:03 +00:00
nsITimer.idl Bug 1778211 - Reject xpidl CDATA containing 'virtual', r=xpcom-reviewers,necko-reviewers,mccr8,dragana 2022-07-06 14:53:06 +00:00
nsMemoryPressure.cpp
nsMemoryPressure.h
nsProcess.h Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato 2022-08-03 16:39:41 +00:00
nsProcessCommon.cpp Bug 1792574, part 3 - Don't include nsMemory where it isn't needed. r=xpcom-reviewers,necko-reviewers,valentin,nika 2022-09-28 15:17:46 +00:00
nsProxyRelease.cpp
nsProxyRelease.h Bug 1804755 - Log name for failed ProxyReleaseEvent dispatch warning, r=xpcom-reviewers,jstutte 2022-12-08 23:26:52 +00:00
nsThread.cpp Bug 1748378 - Create a way to deprioritize threadpools. r=nika 2023-02-03 16:36:47 +00:00
nsThread.h Bug 1805963 - Part 2: remove support for local execution, r=xpcom-reviewers,jstutte 2022-12-21 22:01:25 +00:00
nsThreadManager.cpp Bug 1748378 - Create a way to deprioritize threadpools. r=nika 2023-02-03 16:36:47 +00:00
nsThreadManager.h Bug 1768581 - Part 4: Postpone main nsThread destruction after full XPCOM shutdown. r=xpcom-reviewers,nika 2022-12-12 15:21:28 +00:00
nsThreadPool.cpp Bug 1748378 - Create a way to deprioritize threadpools. r=nika 2023-02-03 16:36:47 +00:00
nsThreadPool.h Bug 1748378 - Create a way to deprioritize threadpools. r=nika 2023-02-03 16:36:47 +00:00
nsThreadSyncDispatch.h Bug 1799222 - Part 1: Prevent accidental dispatches to threadpool and timer threads, r=xpcom-reviewers,necko-reviewers,geckoview-reviewers,media-playback-reviewers,jesup,m_kato,padenot,kmag 2022-12-16 17:09:16 +00:00
nsThreadUtils.cpp Bug 1809753 - Part 4: Remove unnecessary GetMainThreadEventTarget, r=mccr8 2023-01-16 23:14:12 +00:00
nsThreadUtils.h Bug 1809753 - Part 4: Remove unnecessary GetMainThreadEventTarget, r=mccr8 2023-01-16 23:14:12 +00:00
nsTimerImpl.cpp Bug 1787974 - nsTimerImpl directly keeps track of whether it's in a TimerThread::Entry r=smaug 2023-01-20 17:11:08 +00:00
nsTimerImpl.h Bug 1787974 - nsTimerImpl directly keeps track of whether it's in a TimerThread::Entry r=smaug 2023-01-20 17:11:08 +00:00