Commit Graph
222 Commits
Author SHA1 Message Date
Justin Link 9a82dfd19a Bug 1787974 - Fixed problem where AddTimerInternal() could add a new timer in the wrong spot. r=smaug
The previous version used IndexOfFirstElementGt which is implemented
with a binary search. That doesn't work correctly because the mTimers
array that is being searched is maintained in sorted order
*only if the "cancelled" timers are skipped*. This revision replaces the
binary search with a linear search which can handle this without
problem. Given that the number of timers present at any one time is
fairly modest, a linear search is probably a more appropriate choice
anyway.

Also added a new function, VerifyTimerListConsistency, which is called
once per wake-up in the main loop and enabled only in DEBUG builds, that
checks mTimers for ordering and consistency.

Differential Revision: https://phabricator.services.mozilla.com/D164294
2023-01-20 17:11:12 +00:00
Gerald Squelart 2e3fbffdda Bug 1787974 - AddTimerInternal efficiently inserts by shifting entries until next gap r=smaug
This makes the code more complex, but it is needed to keep this most-used
function efficient related to its old implementation using `std::push_heap`.

Differential Revision: https://phabricator.services.mozilla.com/D164292
2023-01-20 17:11:11 +00:00
Gerald Squelart 8c00fb4d09 Bug 1787974 - Changing mTimers from heap to timestamp-sorted array r=smaug
Inserting elements in the sorted array is more costly than pushing to a binary
heap, but this is balanced by the removal of indirections and de/allocations,
and the upcoming re-use of empty entries.

In the end, this change is necessary to allow future improvements like timer-
coalescing, where we'll need to see multiple timers in order.

Bonus: FindNextFireTimeForCurrentThread changes a lot, because it used to have
to `pop_heap` elements and then `push_heap` them back! (Sometimes resulting in
subtle changes for timers with the same timeout.) So this one benefits the
most.

Differential Revision: https://phabricator.services.mozilla.com/D164291
2023-01-20 17:11:11 +00:00
Gerald Squelart 94eed5ea1a Bug 1787974 - In TimerThread::Shutdown, only Take non-null entries r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D164290
2023-01-20 17:11:11 +00:00
Gerald Squelart af0ac64ae3 Bug 1787974 - Entry::Forget doesn't need a parameter r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D164289
2023-01-20 17:11:10 +00:00
Gerald Squelart 62b5f945dd Bug 1787974 - Entry constructor only takes an nsTimerImpl* r=smaug
So entries now store the given timeout value (instead of clamping it to after "now").
And we store this timeout first, as it's accessed more frequently.

Differential Revision: https://phabricator.services.mozilla.com/D164288
2023-01-20 17:11:09 +00:00
Gerald Squelart 9e24f70602 Bug 1787974 - TimerThread stores Entry's instead of UniquePtrs to Entry's r=smaug
This removes memory heap allocations and deallocations, and indirections to access entries.

Differential Revision: https://phabricator.services.mozilla.com/D164287
2023-01-20 17:11:09 +00:00
Gerald Squelart 132204b11f Bug 1787974 - nsTimerImpl directly keeps track of whether it's in a TimerThread::Entry r=smaug
nsTimerImplHolder can now be removed.

Differential Revision: https://phabricator.services.mozilla.com/D164286
2023-01-20 17:11:08 +00:00
Gerald Squelart 397d620e2d Bug 1787974 - Do a linear search in RemoveTimerInternal to stop going through the holder r=smaug
Note that it's about 4 times slower in practice! But this will be balanced in later patches.

Differential Revision: https://phabricator.services.mozilla.com/D164285
2023-01-20 17:11:08 +00:00
Otto Länd c1900835a6 Bug 1799222, 1799222: apply code formatting via Lando
# ignore-this-changeset
2022-12-16 19:09: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
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
Fabrice Desré e29be44cb7 Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152575
2022-08-03 16:39:41 +00:00
Andreea Pavel fc724b92fc Backed out changeset b9d2965591b9 (bug 1761040) for landing with wrong author CLOSED TREE DONTBUILD 2022-08-03 18:55:00 +03:00
Andreea Pavel eda47f3911 Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152575
2022-08-03 15:27:43 +00:00
Andreea Pavel c2e97d2e06 Backed out changeset a907159a482f (bug 1761040) for causing build bustages on a CLOSED TREE 2022-08-02 04:59:08 +03:00
Fabrice Desré d2d02e8493 Bug 1761040 - Prefix thread safety macros with MOZ_ r=geckoview-reviewers,media-playback-reviewers,alwu,jesup,m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152575
2022-08-02 00:49:41 +00:00
Gerald Squelart 91e7cef5bf Bug 1767396 - Don't wake up the timer thread when removing timers - r=florian,smaug
Differential Revision: https://phabricator.services.mozilla.com/D146031
2022-06-20 11:33:09 +00:00
Gerald Squelart 95dacf976a Bug 1767396 - AddTimer also awakens the timer thread if the new timer has a zero delay - r=smaug
This ensures that 0-delay timers are executed very quickly; without this, they
would rely on the timer thread waking up "naturally" as scheduled, but on some
platforms there could be significant delays (many milliseconds) before the
thread would actually wake up, compared to notifications that are handled
almost immediately.

Even though by specs, timers may be subject to being late, some users of
0-delay timers, in particular through JS' `setTimeout(code, 0)`, rely on the
code being executed as soon as possible (i.e., queued pretty much immediately
on the event loop).
Until now, this was almost guaranteed by the very frequent calls to
RemoveTimer, which always notified the timer thread and made it wake up very
quickly.
However the following patch is going to remove notifications from RemoveTimer,
so before that one lands we now need to ensure that 0-delay timer will still
be invoked at least as quickly as before.

Depends on D146030

Differential Revision: https://phabricator.services.mozilla.com/D149706
2022-06-20 11:33:09 +00:00
Gerald Squelart 6229a37bc7 Bug 1767396 - AUTO_TIMERS_STATS - r=florian
This will help during development, to measure before/after times in TimerThread functions.

Differential Revision: https://phabricator.services.mozilla.com/D146030
2022-06-20 11:33:08 +00:00
Narcis Beleuzu 0f0ea03aa3 Backed out 2 changesets (bug 1767396) for wpt failures on iframe-focus-event-after-iframe-gets-focus.html CLOSED TREE
Backed out changeset 39b9ecc2224a (bug 1767396)
Backed out changeset 77aa60771db2 (bug 1767396)
2022-05-20 02:54:56 +03:00
Gerald Squelart dfd3e8a775 Bug 1767396 - Don't wake up the timer thread when removing timers - r=florian,smaug
Differential Revision: https://phabricator.services.mozilla.com/D146031
2022-05-19 20:31:25 +00:00
Gerald Squelart 88643a5ee7 Bug 1767396 - AUTO_TIMERS_STATS - r=florian
This will help during development, to measure before/after times in TimerThread functions.

Differential Revision: https://phabricator.services.mozilla.com/D146030
2022-05-19 20:31:24 +00:00
Gerald Squelart cc9f3020d5 Bug 1766357 - Remove unused and empty TimerThread::InitLocks - r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D144660
2022-04-27 01:14:37 +00:00
Razvan Cojocaru d1849133f4 Bug 1757668 - Use TimeDuration::ToMicroseconds() in TimerThread::Run(). r=sefeng,nika
Modify the code so that instead of getting microseconds by first
getting milliseconds, then multiplying by 1000, it retrieves the
microseconds value directly.

Differential Revision: https://phabricator.services.mozilla.com/D143472
2022-04-12 19:39:48 +00:00
Randell Jesup 687bab8ee0 Bug 1207753 - xpcom Timer thread-safety annotations r=nika
Differential Revision: https://phabricator.services.mozilla.com/D130572
2022-03-19 03:43:57 +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
Randell Jesup 30620287d0 Bug 1746523: xpcom Timer cleanup, assertions and comments r=bwc,xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D134089
2022-02-01 20:25:16 +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
Gerald Squelart 53da93c1f8 Bug 1735697 - Only record markers from actually-profiled threads - r=florian
`profiler_add_marker()` now checks if the marker's target thread is actively being profiled. This is to prevent adding markers that would be discarded anyway, from taking CPU time to process, and from using space in the profile buffer.

This means that `profiler_thread_is_being_profiled(ProfilerThreadId)` must be used when a marker is intended for another thread, i.e., when it uses the MarkerThreadId option.

(Note: since baseprofiler::profiler_thread_is_being_profiled(ProfilerThreadId) is not available, baseprofiler::AddMarker cannot prevent markers targetted at non-profiled thread; There are none yet anyway.)

Differential Revision: https://phabricator.services.mozilla.com/D128576
2021-10-18 23:11:30 +00:00
Andreas Pehrson 0e1197fb9b Bug 1729964 - Move timer-release threading assert from TimerThread to nsTimerImpl. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D127622
2021-10-06 14:33:41 +00:00
Daniel Holbert 8715febbdf Bug 1733729: Fix non-unified build bustage in xpcom directory. r=mccr8
These changes were necessary for me to build successfully with this in my
mozconfig:
 ac_add_options --enable-debug
 ac_add_options --disable-unified-build
 ac_add_options --enable-profiling

While I'm here, I removed a duplicate include in InputTaskManager.h, and made
nsThreadPool.cpp include its own header first, to match Gecko common practice.

Differential Revision: https://phabricator.services.mozilla.com/D127503
2021-10-05 00:29:56 +00:00
Nazım Can Altınova 4c17a9df40 Bug 1728544 - Make the MarkerSchema::Searchable enum class values CamelCased r=gerald
Differential Revision: https://phabricator.services.mozilla.com/D124242
2021-09-03 14:30:10 +00:00
Nazım Can Altınova 78dc6f6c66 Bug 1728544 - Make the MarkerSchema::Format enum class values CamelCased r=gerald
Differential Revision: https://phabricator.services.mozilla.com/D124241
2021-09-03 14:30:10 +00:00
Nazım Can Altınova 9bc6c810fc Bug 1728544 - Make the MarkerSchema::Location enum class values CamelCased r=gerald
Differential Revision: https://phabricator.services.mozilla.com/D124240
2021-09-03 14:30:09 +00:00
Florian Quèze 50f6b1fd86 Bug 1728228 - Add profiler markers in the Timer thread to understand its activity, r=gerald,smaug,KrisWright.
Differential Revision: https://phabricator.services.mozilla.com/D123989
2021-08-31 13:41:46 +00:00
Olli Pettay 216c9e6d9c Bug 1724107, be more precise when counting the number of allocator users, r=KrisWright
The patch is based on code inspection.

One could move sAllocatorUsers also to Free(), but shouldn't matter in practise.

Differential Revision: https://phabricator.services.mozilla.com/D121868
2021-08-05 19:36:32 +00:00
Florian Quèze 76d92a054e Bug 1715257 - Remove Task Tracer code from the profiler, r=gerald,necko-reviewers.
Differential Revision: https://phabricator.services.mozilla.com/D117996
2021-06-17 09:33:00 +00:00
Iulian Moraru 4b5e996bef Backed out changeset 617a466d0cce (bug 1715257) for causing build bustages. CLOSED TREE 2021-06-17 10:58:16 +03:00
Florian Quèze 2b195470a1 Bug 1715257 - Remove Task Tracer code from the profiler, r=gerald,necko-reviewers.
Differential Revision: https://phabricator.services.mozilla.com/D117996
2021-06-17 06:12:10 +00:00
Kershaw Chang 34c73fb959 Bug 1415923 - Ignore sleep and wake notifications on OSX r=xpcom-reviewers,KrisWright
Differential Revision: https://phabricator.services.mozilla.com/D103228
2021-02-04 21:40:47 +00:00
Honza Bambas d04898063e Bug 1648781 - MOZ_LOG of timer events dispatch and run, MOZ_LOG of idle-dispatch timeout, r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D81467
2020-06-30 10:57:28 +00:00
Dana Keeler 716470558f Bug 1644224 - make nsTimerEvent::sCanDeleteAllocator atomic/sequentially consistent r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D78771
2020-06-08 19:59:40 +00:00