Commit Graph
245 Commits
Author SHA1 Message Date
Jens Stutte 96f51ca7b2 Bug 1895438 - Do not add NS_DISPATCH_AT_END in BackgroundEventTarget::Dispatch. r=xpcom-reviewers,nika
The original intention of adding NS_DISPATCH_AT_END always when on the
same pool was to reduce the risk of spinning up unneeded threads.

Bug 1891664 introduced two changes that make this now unwanted:
- we always wait for the dispatching thread to pick up the event
- we give threads a grace timeout before shutting them down

So before bug 1891664 landed, this flag would just have influenced
if we create a new thread, but if there was an idle thread, the event
would just process immediately and in parallel without any latency.

Now the event will wait for the dispatching thread to become idle if
NS_DISPATCH_AT_END is set, which might increase the latency if we are
not at the end of the dispatching event as we are instead in the case of
TaskQueue dispatches.

What's more, the grace timeout reduces the risk of noise from frequent
thread creation and destruction, such that creating a new thread when
there is load we can immediately serve is actually best for latency.

Differential Revision: https://phabricator.services.mozilla.com/D212399
2024-06-04 07:20:11 +00:00
Jens Stutte c804b8a4e2 Bug 1891936 - Have explicit grace timeout settings for the BackgroundEventTarget thread pools. r=KrisWright
Differential Revision: https://phabricator.services.mozilla.com/D209197
2024-06-01 09:05:55 +00:00
Jens Stutte 53e1705e16 Bug 1891664 - Have a grace timeout before shutting down excess idle threads. r=xpcom-reviewers,necko-reviewers,dom-storage-reviewers,nika,janv,jesup#!xpcom-reviewers
Have idleThreadGraceTimeout and idleThreadMaximumTimeout instead of just idleThreadTimeout.
Clarify that idleThreadMaximumTimeout is only affecting allowed idle threads.
Make idle threads end only after at minimum idleThreadGraceTimeout even if they are in excess.
Remove the idleThreadTimeoutRegressive setting.

Introduce a "most recently used" priority for notifying idle threads to
avoid excessive round-robin through all available idle threads.
The management of the linked list has constant time, adding thus only
minimal overhead wrt to the previous wasIdle flags we had.

As a side effect (and coming from the investigations in bug 1891732) to
some extent this can help to improve the "logical thread affinity",
together with trying to keep events dispatched with NS_DISPATCH_AT_END
on the dispatching thread as much as possible, which should help
TaskQueue a lot with affinity.

Differential Revision: https://phabricator.services.mozilla.com/D209884
2024-06-01 09:05:53 +00:00
Denis Palmeiro 5c062218b6 Bug 1887068: Add perfetto event traces for taskcontroller tasks and dom performance measurement markers. r=smaug
Depends on D205662

Differential Revision: https://phabricator.services.mozilla.com/D205663
2024-04-15 15:34:04 +00:00
Cristina Horotan 886fe5f5a4 Backed out 4 changesets (bug 1887068, bug 1890934) on request by causing build bustages
Backed out changeset 68a7a8a3bb0f (bug 1890934)
Backed out changeset 658f4b57b8ec (bug 1887068)
Backed out changeset 61a9d3a1e592 (bug 1887068)
Backed out changeset efbf5c7065e3 (bug 1887068)
2024-04-12 02:14:44 +03:00
Denis Palmeiro a63122839e Bug 1887068: Add perfetto event traces for taskcontroller tasks and dom performance measurement markers. r=smaug
Depends on D205662

Differential Revision: https://phabricator.services.mozilla.com/D205663
2024-04-10 17:48:08 +00:00
Cristian Tuns d9503794a6 Backed out 3 changesets (bug 1887068) for causing build bustages in toolkit/* CLOSED TREE
Backed out changeset c6863f012b03 (bug 1887068)
Backed out changeset 3a4d2b74219e (bug 1887068)
Backed out changeset 90a702920d77 (bug 1887068)
2024-04-09 18:19:08 -04:00
Denis Palmeiro f61b8829df Bug 1887068: Add perfetto event traces for taskcontroller tasks and dom performance measurement markers. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D205663
2024-04-09 19:05:36 +00:00
Gabriele Svelto e1e9346196 Bug 1831092 - Use the new pull-based API for all crash annotations and remove the global annotations table r=jgilbert,necko-reviewers,media-playback-reviewers,profiler-reviewers,win-reviewers,padenot,handyman,afranchuk,valentin,alwu,sotaro
This changes comes with several different refactorings all rolled into one,
unfotunately I couldn't find a way to pull them apart:
- First of all annotations now can either recorded (that is, we copy the value
  and have the crash reporting code own the copy) or registered. Several
  annotations are changed to use this functionality so that we don't need to
  update them as their value change.
- The code in the exception handler is modified to read the annotations from
  the mozannotation_client crate. This has the unfortunate side-effect that
  we need three different bits of code to serialize them: one for annotations
  read from a child process, one for reading annotations from the main process
  outside of the exception handler and one for reading annotations from the
  main process within the exception handler. As we move to fully
  out-of-process crash reporting the last two methods will go away.
- The mozannotation_client crate now doesn't record annotation types anymore.
  I realized as I was working on this that storing types at runtime has two
  issues: the first one is that buggy code might change the type of an
  annotation (that is record it under two different types at two different
  moments), the second issue is that types might become corrupt during a
  crash, so better enforce them at annotation-writing time. The end result is
  that the mozannotation_* crates now only store byte buffers, track the
  format the data is stored in (null-terminated string, fixed size buffer,
  etc...) but not the type of data each annotation is supposed to contain.
- Which brings us to the next change: concrete types for annotations are now
  enforced when they're written out. If an annotation doesn't match the
  expected type it's skipped. Storing an annotation with the wrong type will
  also trigger an assertion in debug builds.

Differential Revision: https://phabricator.services.mozilla.com/D195248
2024-03-04 10:24:43 +00:00
Randell Jesup c23d7dbcaa Bug 1862557: Add LongTask profiler marker generation to SocketThread r=necko-reviewers,kershaw
Includes separate markers for OnSocketReady() calls after Poll()

Differential Revision: https://phabricator.services.mozilla.com/D192533
2023-12-07 04:15:44 +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 68136cf1b9 Bug 1851045 - Part 5: Eliminate nsThreadManager's static destructor, r=emilio
This both reduces the number of registered static destructors, and avoids the
assertion in the LinkedList destructor without depending on a StaticAutoPointer
(which requires an allocation & additional indirection) by using the new
NeverDestroyed type from part 4.

Differential Revision: https://phabricator.services.mozilla.com/D189249
2023-09-27 19:14:17 +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 b1a6e95662 Bug 1851045 - Part 1: Remove unused members from nsThreadManager, r=xpcom-reviewers,KrisWright
Differential Revision: https://phabricator.services.mozilla.com/D188621
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 a20b870dcd Bug 1851045 - Part 1: Remove unused members from nsThreadManager, r=xpcom-reviewers,KrisWright
Differential Revision: https://phabricator.services.mozilla.com/D188621
2023-09-20 21:46:04 +00:00
Paul Bone 3724c31670 Bug 1839596 - Explicitly tell jemalloc which is the main thread r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D181724
2023-06-30 00:57:20 +00:00
Karl Tomlinson ccc6e99c22 Bug 1840313 return full TaskQueue class from CreateBackgroundTaskQueue() r=xpcom-reviewers,nika
This makes TaskQueue methods such as BeginShutdown() and IsEmpty() available
to clients.

Only the interface class nsISerialEventTarget was previously returned over
concerns [1] that returning a TaskQueue might imply that clients would need to
explicitly shut down the TaskQueue, but this was not correct.  TaskQueues do
not require explicit shutdown [2].

Limited lifetime queues have been an option for clients since
BackgroundEventTarget's ownership of these queues until shutdown was
removed [3].

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1584568#c5
[2] https://searchfox.org/mozilla-central/rev/05d1afda588e54be73e31ef4e022dde91f1ed97a/xpcom/threads/TaskQueue.h#49
[3] https://hg.mozilla.org/integration/autoland/rev/77022ce2c24b#l3.37

Differential Revision: https://phabricator.services.mozilla.com/D181966
2023-06-26 21:52:50 +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 c4e5607998 Bug 1809752 - Part 1: Allow querying the current nsThreadPool, r=mccr8
This was always being tracked internlly to implement
nsThreadPool::IsOnCurrentThread, however this patch exposes the getter
publicly.

This will be used to assert if GetCurrentSerialEventTarget() is called from a
threadpool thread without a TaskQueue in the next part.

Differential Revision: https://phabricator.services.mozilla.com/D166603
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 e217d09ffb Bug 1809752 - Part 1: Allow querying the current nsThreadPool, r=mccr8
This was always being tracked internlly to implement
nsThreadPool::IsOnCurrentThread, however this patch exposes the getter
publicly.

This will be used to assert if GetCurrentSerialEventTarget() is called from a
threadpool thread without a TaskQueue in the next part.

Differential Revision: https://phabricator.services.mozilla.com/D166603
2023-01-16 23:14:10 +00:00
Olli Pettay 96675a9568 Bug 1807838, try to translate elements before load event fires, r=emilio
...but call sizeToContent* only after AppWindow::OnChromeLoaded().

Differential Revision: https://phabricator.services.mozilla.com/D166011
2023-01-10 22:47:20 +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
Jens Stutte 7cc3faec1d Bug 1768581 - Part 4: Postpone main nsThread destruction after full XPCOM shutdown. r=xpcom-reviewers,nika
Some debug infrastructure like MOZ_WEAKPTR_INIT_THREAD_SAFETY_CHECK  that can apparently be triggered by nsComponentManagerImpl::gComponentManager->FreeService() seem to rely on the existence of a serial event target even if they do not post any events. So it seems sound to keep a representation of the main thread as nsThread object until after final XPCOM shutdown.
But nsThreadManager::ShutdownMainThread() does more, it processes the last round of events, removes the thread's observer  and closes down the background event target. We do not want to move these operations to happen later than before, such that we split the nsThread release into a separate function and move that together with AbstractThread::ShutdownMainThread() behind FreeService().

Depends on D160628

Differential Revision: https://phabricator.services.mozilla.com/D162497
2022-12-12 15:21:28 +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
Butkovits Atila e775bd40e5 Backed out 4 changesets (bug 1768581, bug 1709184) for causing high frequency Xpcshell failures at test_bug1274685_unowned_list.js. CLOSED TREE
Backed out changeset 6bae0f16eae9 (bug 1768581)
Backed out changeset 1f111f5b8baf (bug 1768581)
Backed out changeset a3d89b2ef44a (bug 1709184)
Backed out changeset 98f1dc6f0123 (bug 1709184)
2022-11-23 22:09:33 +02:00
Jens Stutte 28fdba1f4f Bug 1768581 - Part 13: Postpone main nsThread destruction after full XPCOM shutdown. r=xpcom-reviewers,nika
Some debug infrastructure like MOZ_WEAKPTR_INIT_THREAD_SAFETY_CHECK  that can apparently be triggered by nsComponentManagerImpl::gComponentManager->FreeService() seem to rely on the existence of a serial event target even if they do not post any events. So it seems sound to keep a representation of the main thread as nsThread object until after final XPCOM shutdown.
But nsThreadManager::ShutdownMainThread() does more, it processes the last round of events, removes the thread's observer  and closes down the background event target. We do not want to move these operations to happen later than before, such that we split the nsThread release into a separate function and move that together with AbstractThread::ShutdownMainThread() behind FreeService().

Depends on D160628

Differential Revision: https://phabricator.services.mozilla.com/D162497
2022-11-23 16:03:18 +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
Nika Layzell fd842eb0ec Bug 1764119 - Part 1: Do final KillClearOnShutdown after XPCOM threads shutdown, r=xpcom-reviewers,kmag,jstutte
This patch moves where we perform the final KillClearOnShutdown to occur
after we've shut down non-main threads, but before the main thread stops
accepting events. This should help ensure that unsuspecting events,
including those triggered from nsIThreadShutdownTask tasks, don't run
after KillClearOnShutdown has been run on background or main threads.

This KillClearOnShutdown was moved to occur before
nsThreadManager::Shutdown() in bug 1637890, as there were examples of
KillClearOnShutdown callbacks which needed to be able to dispatch
main-thread runnables. This change should not regress that use-case, as
we are still accepting new events on the main thread after the callback.

Non-main threads were already unreliable after this call as we already
block normal dispatches by setting gXPCOMThreadsShutdown, and new
threads cannot be started for the background thread pool.

Differential Revision: https://phabricator.services.mozilla.com/D144591
2022-05-02 20:38:43 +00:00
Nika Layzell bcebb32f5d Bug 1738106 - Part 5: Track TaskQueue lifetimes to avoid leaking TaskQueues, r=xpcom-reviewers,mccr8
Differential Revision: https://phabricator.services.mozilla.com/D142606
2022-05-02 20:37:35 +00:00
Nika Layzell 260ebb1412 Bug 1738106 - Part 3: Switch to TaskQueue::Create, r=xpcom-reviewers,necko-reviewers,media-playback-reviewers,dragana,alwu,barret
In future parts, TaskQueue will require extra initialization to be performed
which cannot happen in a constructor, as it takes references to the TaskQueue
object itself, which will require the introduction of a helper method. This
patch switches all callers of the TaskQueue constructor to use the new method.

Differential Revision: https://phabricator.services.mozilla.com/D142604
2022-05-02 20:37:34 +00:00
criss 79d73b87ae Backed out 2 changesets (bug 1764119) for causing build bustages. CLOSED TREE
Backed out changeset 62743521627e (bug 1764119)
Backed out changeset f8ba6b0a8c6f (bug 1764119)
2022-05-02 19:35:23 +03:00
Nika Layzell 29df0559e6 Bug 1764119 - Part 1: Do final KillClearOnShutdown after XPCOM threads shutdown, r=xpcom-reviewers,kmag,jstutte
This patch moves where we perform the final KillClearOnShutdown to occur
after we've shut down non-main threads, but before the main thread stops
accepting events. This should help ensure that unsuspecting events,
including those triggered from nsIThreadShutdownTask tasks, don't run
after KillClearOnShutdown has been run on background or main threads.

This KillClearOnShutdown was moved to occur before
nsThreadManager::Shutdown() in bug 1637890, as there were examples of
KillClearOnShutdown callbacks which needed to be able to dispatch
main-thread runnables. This change should not regress that use-case, as
we are still accepting new events on the main thread after the callback.

Non-main threads were already unreliable after this call as we already
block normal dispatches by setting gXPCOMThreadsShutdown, and new
threads cannot be started for the background thread pool.

Differential Revision: https://phabricator.services.mozilla.com/D144591
2022-05-02 16:09:03 +00:00
Tooru Fujisawa 2f63d8765c Bug 1761590 - Enter microtask when evaluating console/debugger input. r=nchevobbe,smaug
Differential Revision: https://phabricator.services.mozilla.com/D143356
2022-04-14 01:42:59 +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
Randell Jesup 78128c6eba Bug 1207753 - nsThreadManager thread-safety annotations r=nika
Differential Revision: https://phabricator.services.mozilla.com/D142020
2022-03-31 20:06:35 +00:00
Randell Jesup 74d0b2c0eb Bug 1757477: nsThreadManager clean up r=nika
Differential Revision: https://phabricator.services.mozilla.com/D142019
2022-03-30 18:46:53 +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
Randell Jesup 855202c183 Bug 1207753 - Add MOZ_UNANNOTATED to all Mutexes/Monitors r=nika,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D140849
2022-03-16 18:47:08 +00:00
Noemi Erli 16f5f5f2b9 Backed out changeset 12a59e5a50bf (bug 1207753) for causing build bustage CLOSED TREE 2022-03-16 18:32:51 +02:00
Randell Jesup a98b1f8218 Bug 1207753 - Add MOZ_UNANNOTATED to all Mutexes/Monitors r=nika,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D140849
2022-03-16 16:16:14 +00:00
Butkovits Atila 01197944a0 Backed out changeset a68ee4b09f92 (bug 1207753) for causing Hazard bustages. CLOSED TREE 2022-03-16 14:38:14 +02:00
Randell Jesup fe15f2115d Bug 1207753 - Add MOZ_UNANNOTATED to all Mutexes/Monitors r=nika,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D140849
2022-03-16 12:01:14 +00:00