Commit Graph
529 Commits
Author SHA1 Message Date
Florian Quèze b3ed96f65d Bug 1913624 - Remove expired telemetry histogram THREAD_WAKEUP, r=TravisLong.
Depends on D219460

Differential Revision: https://phabricator.services.mozilla.com/D219461
2024-08-20 20:56:45 +00:00
Nika Layzell e246cec06d Bug 1895081 - Add extra assertions to nsThread initialization, r=xpcom-reviewers,jstutte
Differential Revision: https://phabricator.services.mozilla.com/D212313
2024-06-04 18:36:18 +00:00
Randell Jesup 9b645a5d9a Bug 1862556: Allow LongTask markers to be generated for any nsThread r=nika
Differential Revision: https://phabricator.services.mozilla.com/D192532
2023-12-07 04:15:44 +00:00
Cristian Tuns f38b72b3b6 Backed out 2 changesets (bug 1862556, bug 1862557) for causing build bustages in nsThreadManager.cpp CLOSED TREE
Backed out changeset 4ef47a21279a (bug 1862557)
Backed out changeset 2573ea9f377b (bug 1862556)
2023-12-06 17:33:12 -05:00
Randell Jesup 65482e6ab8 Bug 1862556: Allow LongTask markers to be generated for any nsThread r=nika
Differential Revision: https://phabricator.services.mozilla.com/D192532
2023-12-06 18:38:49 +00:00
Nika Layzell f56b27a28d Bug 1851045 - Part 3: Fix potential issue with late shutdown nsThread creation, r=xpcom-reviewers,KrisWright
This fixes the issue described in comment 7 by doing a few changes to how threads are created, and members on nsThreadManager are managed.

 * The thread list is moved to be a member of `nsThreadManager`, which is
   already a statically allocated singleton.

 * The flag for whether new thread creation is allowed is moved from being an
   atomic to being guarded by the same mutex as the thread list, meaning that
   it could be checked and a new thread could be added to the list atomically.

 * Threads which require shutdown are initialized atomically from the point of
   view of the thread manager, meaning that the check in ShutdownNonMainThreads
   is guaranteed to catch all successfully started nsThread instances.

Differential Revision: https://phabricator.services.mozilla.com/D188623
2023-09-27 19:14:16 +00:00
Nika Layzell 8baa1c9176 Bug 1851045 - Part 2: Clean up manual reference counting for self in nsThread, r=xpcom-reviewers,KrisWright
This patch instead replaces this manual reference counting by replacing the raw
pointer in the `ThreadInitData` type with a `RefPtr`.

Differential Revision: https://phabricator.services.mozilla.com/D188622
2023-09-27 19:14:15 +00:00
Iulian Moraru 4a4a6a9477 Backed out 3 changesets (bug 1851045) for causing multiple crashes related to LinkedList.
Backed out changeset c813616ed664 (bug 1851045)
Backed out changeset c53ebef234df (bug 1851045)
Backed out changeset 3350d1b78562 (bug 1851045)
2023-09-21 03:07:37 +03:00
Nika Layzell 4cd32e8655 Bug 1851045 - Part 3: Fix potential issue with late shutdown nsThread creation, r=xpcom-reviewers,KrisWright
This fixes the issue described in comment 7 by doing a few changes to how threads are created, and members on nsThreadManager are managed.

 * The thread list is moved to be a member of `nsThreadManager`, which is
   already a statically allocated singleton.

 * The flag for whether new thread creation is allowed is moved from being an
   atomic to being guarded by the same mutex as the thread list, meaning that
   it could be checked and a new thread could be added to the list atomically.

 * Threads which require shutdown are initialized atomically from the point of
   view of the thread manager, meaning that the check in ShutdownNonMainThreads
   is guaranteed to catch all successfully started nsThread instances.

Differential Revision: https://phabricator.services.mozilla.com/D188623
2023-09-20 21:46:05 +00:00
Nika Layzell c4031a0421 Bug 1851045 - Part 2: Clean up manual reference counting for self in nsThread, r=xpcom-reviewers,KrisWright
This patch instead replaces this manual reference counting by replacing the raw
pointer in the `ThreadInitData` type with a `RefPtr`.

Differential Revision: https://phabricator.services.mozilla.com/D188622
2023-09-20 21:46:05 +00:00
Florian Quèze de6cef3975 Bug 1836191 - remove PerformanceCounter that was only used by ChromeUtils.requestPerformanceMetrics, r=smaug.
Differential Revision: https://phabricator.services.mozilla.com/D179697
2023-06-08 21:53:18 +00:00
Andreas Pehrson 043896f9b5 Bug 1826530 - Implement MessagePumpForNonMainUIThreads for mac. r=xpcom-reviewers,ipc-reviewers,mstange,nika
The MessagePump implemented here is a MessagePumpCFRunLoopBase that also handles
xpcom events.

Differential Revision: https://phabricator.services.mozilla.com/D175101
2023-05-23 09:05:07 +00:00
Noemi Erli 5ec1e1bb6c Backed out 4 changesets (bug 1826530) for causing build bustages in MessagePump_android.cpp CLOSED TREE
Backed out changeset 027080336f71 (bug 1826530)
Backed out changeset 2174d8d45249 (bug 1826530)
Backed out changeset fe9e6fccc2e6 (bug 1826530)
Backed out changeset 2534ba3f140f (bug 1826530)
2023-05-23 10:13:17 +03:00
Andreas Pehrson 65a0804c0f Bug 1826530 - Implement MessagePumpForNonMainUIThreads for mac. r=xpcom-reviewers,ipc-reviewers,mstange,nika
The MessagePump implemented here is a MessagePumpCFRunLoopBase that also handles
xpcom events.

Differential Revision: https://phabricator.services.mozilla.com/D175101
2023-05-23 06:51:53 +00:00
Randell Jesup cc7d3c0765 Bug 1825117: Add Telemetry for Runnable execution times if they're long r=nika
Differential Revision: https://phabricator.services.mozilla.com/D173878
2023-04-13 19:22:45 +00:00
Andreas Pehrson 1df5ea5056 Bug 1800213 - Add a flag for creating nsThreads with a NONMAINUITHREAD MessageLoop. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D166062
2023-02-28 14:32:42 +00:00
kriswright e04f04014d 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
Nika Layzell 801c40814f Bug 1809753 - Part 1: Remove quantum-dom nsIThread::EventTarget methods, r=mccr8
We aren't likely to try to make these changes any time soon, so cleaning out
these unnecessary methods which just return `this` will simplify things.

I was unable to find any calls to the `.eventTarget` getter in JS, which makes
sense, as the nsIThread type is only really used in JS as a wrapper around the
main thread in older code. Because of that, it has been removed as well.

Differential Revision: https://phabricator.services.mozilla.com/D166605
2023-01-16 23:14:10 +00:00
Sandor Molnar f236c54e45 Backed out 6 changesets (bug 1809752, bug 1809753) for causing perma failures in browser/components/firefoxview/tests/browser/browser_feature_callout_position.js
Backed out changeset ea05784d74c4 (bug 1809753)
Backed out changeset 7c9b20eebcc8 (bug 1809753)
Backed out changeset d0267ac2256d (bug 1809753)
Backed out changeset aa9f2971bd6f (bug 1809753)
Backed out changeset f0d9fcfaa6f8 (bug 1809752)
Backed out changeset 6d58c799cffe (bug 1809752)
2023-01-17 03:19:24 +02:00
Nika Layzell 754d395675 Bug 1809753 - Part 1: Remove quantum-dom nsIThread::EventTarget methods, r=mccr8
We aren't likely to try to make these changes any time soon, so cleaning out
these unnecessary methods which just return `this` will simplify things.

I was unable to find any calls to the `.eventTarget` getter in JS, which makes
sense, as the nsIThread type is only really used in JS as a wrapper around the
main thread in older code. Because of that, it has been removed as well.

Differential Revision: https://phabricator.services.mozilla.com/D166605
2023-01-16 23:14:10 +00:00
Nika Layzell 01573bca62 Bug 1805963 - Part 2: remove support for local execution, r=xpcom-reviewers,jstutte
The only consumer of this feature has been removed, so we don't need it
anymore. It acts very differently than other runnables run on the main thread,
so removing it will simplify things.

Differential Revision: https://phabricator.services.mozilla.com/D164841
2022-12-21 22:01:25 +00:00
Marian-Vasile Laza ee66f965f7 Backed out 2 changesets (bug 1805963) for causing mochitest failures on LSObject.cpp. CLOSED TREE
Backed out changeset d70e48585724 (bug 1805963)
Backed out changeset f627a5289831 (bug 1805963)
2022-12-20 23:53:40 +02:00
Nika Layzell f20bef0e9b Bug 1805963 - Part 2: remove support for local execution, r=xpcom-reviewers,jstutte
The only consumer of this feature has been removed, so we don't need it
anymore. It acts very differently than other runnables run on the main thread,
so removing it will simplify things.

Differential Revision: https://phabricator.services.mozilla.com/D164841
2022-12-20 20:22:03 +00:00
Nika Layzell 119713a821 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
Differential Revision: https://phabricator.services.mozilla.com/D161349
2022-12-16 17:09:16 +00:00
Nika Layzell c332ec42e3 Bug 1805961 - DrainDirectTasks before and after OnProcessNextEvent, r=smaug
This will mean that we drain direct tasks immediately after executing
things like native OS messages through OnProcessNextEvent, and also that
we drain direct messages immediately when entering a nested event loop,
rather than after processing the first runnable in that nested event
loop. This should make the behaviour a bit more consistent.

Differential Revision: https://phabricator.services.mozilla.com/D164839
2022-12-16 16:23:16 +00:00
Nazım Can Altınova c91a8714b7 Bug 1803751 - Make some marker fields searchable and bump the profile version r=julienw
Differential Revision: https://phabricator.services.mozilla.com/D163714
2022-12-13 14:19:07 +00:00
Iulian Moraru 94985653c4 Backed out changeset 27f8690ebc50 (bug 1803751) for causing xpcshell failures on test_feature_mainthreadio.js. CLOSED TREE 2022-12-12 17:43:23 +02:00
Nazım Can Altınova 76eaba45b7 Bug 1803751 - Make some marker fields searchable and bump the profile version r=julienw
Differential Revision: https://phabricator.services.mozilla.com/D163714
2022-12-12 13:11:56 +00:00
Cristian Tuns de12c42c7f Backed out changeset 42315c023471 (bug 1799222) for causing multiple failures CLOSED TREE 2022-12-06 16:35:58 -05:00
Nika Layzell e8f474cee1 Bug 1799222 - Prevent accidental dispatches to threadpool and timer threads, r=xpcom-reviewers,necko-reviewers,geckoview-reviewers,media-playback-reviewers,jesup,m_kato,padenot,kmag
Differential Revision: https://phabricator.services.mozilla.com/D161349
2022-12-06 20:44:15 +00:00
Olli Pettay 9375e345e2 Bug 1795624 - remove dom.input_events.strict_input_vsync_alignment, r=sefeng
Had to rename input_event_queue.supported to dom.input_event_queue.supported so that
it could be used as a static pref.

Differential Revision: https://phabricator.services.mozilla.com/D159488
2022-10-17 17:02:24 +00:00
Jens Stutte 92c87bc660 Bug 1770451 - Trace important shutdown events in a thread's name if MOZ_DIAGNOSTIC_ASSERT_ENABLED. r=xpcom-reviewers,barret
Depends on D148761

Differential Revision: https://phabricator.services.mozilla.com/D148775
2022-06-15 18:15:02 +00:00
Jens Stutte 14ae335943 Bug 1770451 - Release assert if a thread shutdown is unexpectedly going to cause a hang on the joining thread. r=xpcom-reviewers,nika
There is a code path that can make us not dispatch the `nsThreadShutdownAckEvent` at the end of `nsThread::ThreadFunc`. The only known and legitimate way to arrive here should be via StopWaitingAndLeakThread. We want to ensure that if we take this code path someone else already marked the shutdown context as complete.

Differential Revision: https://phabricator.services.mozilla.com/D148761
2022-06-15 18:15:01 +00:00
Nika Layzell f909e52377 Bug 1713773 - Part 1: Simplify nsThreadManager shutdown, r=xpcom-reviewers,mccr8
Differential Revision: https://phabricator.services.mozilla.com/D142600
2022-04-12 20:22:24 +00:00
Iulian Moraru 9d22133f93 Backed out changeset 75811190935c (bug 1713773) for causing leaks on mutex/nsthread. 2022-04-11 19:01:16 +03:00
Nika Layzell 6bd0d10536 Bug 1713773 - Simplify nsThreadManager shutdown, r=xpcom-reviewers,mccr8
Differential Revision: https://phabricator.services.mozilla.com/D142600
2022-04-11 14:33:45 +00:00
Nika Layzell c320f56d5b Bug 1738103 - Part 4: Add XPCOM support for shutdown tasks, r=necko-reviewers,KrisWright
Tasks registered with shutdown tasks are called when the target
nsISerialEventTarget is about to be destroyed.

Differential Revision: https://phabricator.services.mozilla.com/D129840
2022-03-23 22:22:04 +00:00
Dave Townsend 7f95da49d8 Bug 1756148: Setting a thread's affinity is not supported on ARM64 chipset on macOS. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D139110
2022-02-18 20:20:35 +00:00
Nika Layzell 48c03cc7c2 Bug 1747526 - Return a handle from asyncShutdown to observe and cancel thread shutdown progress, r=xpcom-reviewers,KrisWright
This change introduces a new interface, nsIThreadShutdown, which is used
to handle the relevant state for communicating thread shutdown state
between the joining and terminating threads. This type is now returned
from `nsIThread::AsyncShutdown` and can be used to register callbacks
for when thread shutdown is complete, as well as cancel shutdown
entirely, leading to the underlying PRThread never being joined using
PR_JoinThread. This leaking limitation may be avoidable if support for
detaching PRThreads is added to NSPR, or nsThread switches to a more
feature-complete threading API.

This patch also uses the new interface to rework nsThreadPool's Shutdown
and ShutdownWithTimeout methods to avoid poking at nsThread internals
and instead use the publicly facing methods. This allows us to start
async shutdown for all threads and spin the event loop until they all
complete, or a timeout timer fires.

Differential Revision: https://phabricator.services.mozilla.com/D136045
2022-02-08 23:58:03 +00:00
Nika Layzell e9722a7b92 Bug 1747939 - Relax dispatch_ack assertion to handle ShutdownWithTimeout, r=jstutte
Differential Revision: https://phabricator.services.mozilla.com/D135084
2022-01-05 19:01:44 +00:00
Jens Stutte a80634544a Bug 1741377: Add a check to verify the successful dispatch of the nsThread shutdown ack event. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D131220
2021-11-17 19:25:28 +00:00
Gerald Squelart 8c94ff82ed Bug 1738627 - profiler_thread_is_being_profiled_for_markers - r=canaltinova
`profiler_thread_is_being_profiled` is used a lot for markers, so it makes sense to have a specialized version, which is a bit shorter, and lives in ProfilerMarkers.h.

Differential Revision: https://phabricator.services.mozilla.com/D130009
2021-11-08 23:59:35 +00:00
Cristian Tuns 839b72e1d3 Backed out 5 changesets (bug 1738627) for causing xpcshell failures on test_ext_geckoProfiler_schema.js CLOSED TREE
Backed out changeset 42d385d7da97 (bug 1738627)
Backed out changeset edeb3a338954 (bug 1738627)
Backed out changeset 98f02e35134d (bug 1738627)
Backed out changeset 711daa6dd24b (bug 1738627)
Backed out changeset 49e12753a40c (bug 1738627)
2021-11-05 05:12:28 -04:00
Gerald Squelart 019bfd575e Bug 1738627 - profiler_thread_is_being_profiled_for_markers - r=canaltinova
`profiler_thread_is_being_profiled` is used a lot for markers, so it makes sense to have a specialized version, which is a bit shorter, and lives in ProfilerMarkers.h.

Differential Revision: https://phabricator.services.mozilla.com/D130009
2021-11-05 05:52:28 +00:00
Florian Quèze 23e763f19d Bug 1738285 - move AUTO_PROFILE_FOLLOWING_RUNNABLE to its own header, r=gerald.
Differential Revision: https://phabricator.services.mozilla.com/D129825
2021-10-28 20:35:06 +00:00
Jens Stutte 981621bbe6 Bug 1735129: Add thread's name in nsThread::Shutdown's SpinEventLoopUntil annotation. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D128270
2021-10-21 12:46:06 +00:00
Jens Stutte beae6a3055 Bug 1735284: Add a check in nsThread::ShutdownInternal if the shutdown event could be dispatched. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D128167
2021-10-21 11:51:09 +00:00
Jens Stutte 26f8284daa Bug 1735129: Add thread-safe name getter to nsThread. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D128356
2021-10-21 11:51:08 +00:00
Jens Stutte 93c5dfd754 Bug 1731564: Introduce a motivated SpinEventLoopUntil for direct use from C++. r=xpcom-reviewers,nika,necko-reviewers
This patch:
- moves the AutoNestedEventLoopAnnotation into SpinEventLoopUntil.h
- introduces the motivated SpinEventLoopUntil
- maps remaining SpinEventLoopUntil instances to SpinEventLoopUntil with "Missing motivation."
- changes relevant uses in nsThread and nsThreadManager to the motivated SpinEventLoopUntil
- changes all uses with IgnoreAndContinue behavior to the motivated SpinEventLoopUntil

Differential Revision: https://phabricator.services.mozilla.com/D126714
2021-10-07 08:06:10 +00:00
Marian-Vasile Laza 7de6967c5a Backed out 18 changesets (bug 1731564) for causing build bustages on SpinEventLoopUntil. CLOSED TREE
Backed out changeset 0464dbdc8584 (bug 1731564)
Backed out changeset 0d996df13545 (bug 1731564)
Backed out changeset 5630a0e7a109 (bug 1731564)
Backed out changeset 37b41d187cdb (bug 1731564)
Backed out changeset d37700fa60b6 (bug 1731564)
Backed out changeset b0ce7db44b99 (bug 1731564)
Backed out changeset aa5ec3aa1535 (bug 1731564)
Backed out changeset 73b648f1fa70 (bug 1731564)
Backed out changeset bb8fb0f9833e (bug 1731564)
Backed out changeset 0d8905144f5d (bug 1731564)
Backed out changeset 2cfb094a1ec3 (bug 1731564)
Backed out changeset 78d3b0257a6a (bug 1731564)
Backed out changeset e9d32926e93c (bug 1731564)
Backed out changeset 874cab520ce5 (bug 1731564)
Backed out changeset d8071cc32bd9 (bug 1731564)
Backed out changeset 283c5393cbbc (bug 1731564)
Backed out changeset 317bc38e3de5 (bug 1731564)
Backed out changeset 53e3f4862439 (bug 1731564)
2021-10-07 00:09:19 +03:00