Commit Graph
340 Commits
Author SHA1 Message Date
Jens Stutte 31a063c7e3 Bug 1961386 - part 2: Add MOZ_GUARDED_BY to mTimeout in nsTimerImpl. r=xpcom-reviewers,nika,jlink
Given TimerThread::Entry contains a copy of the timeout, we can use that everywhere we have no lock on nsTimerImpl::mMutex, relying on the invariant that the timeout must not change while the timer is in the TimerThread.
Doing so enables us to annotate it and have stricter checks.
Note that one unsafe, DEBUG-only check remains but it is explicitly annotated as such. TSAN will tell if we are safe enough.

Differential Revision: https://phabricator.services.mozilla.com/D249898
2025-07-02 15:08:00 +00:00
Jens Stutte c53ea72851 Bug 1961386 - part 1: Remove VerifyTimerListConsistency. r=xpcom-reviewers,nika,jlink
The original intent of this DEBUG only function was to verify our book-keeping.
However, it prevents us from applying strict thread-safety checks on nsTimerImpl::mTimeout.
Given we are going to change our book-keeping up the stack, we can just remove it but:

- add an assertion directly before PostTimerEvent if the timeout remained unchanged
- add placeholder comments where to check for the correct sort order.

Differential Revision: https://phabricator.services.mozilla.com/D249897
2025-07-02 15:07:57 +00:00
Justin Link 9d11ed35e1 Bug 1946130: Made ComputeWakeupTimeFromTimers() handle the empty timer list case so that the caller doesn't have to r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251949
2025-06-25 15:43:46 +00:00
Justin Link 266243c053 Bug 1946130: Moved Wait() out of the if-statement so that we only call it in one location r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251948
2025-06-25 15:43:42 +00:00
Justin Link cb77d6f01b Bug 1946130: Moved Windows timer frequency management into its own class r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251947
2025-06-25 15:43:38 +00:00
Justin Link 71d9adc6e5 Bug 1946130: Moved TimerThread telemetry into its own class r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251946
2025-06-25 15:43:35 +00:00
Justin Link 2f274f3bdf Bug 1946130: Simplified structure of TimerThread::Run() to be clearer where the loop is and what it does r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246708
2025-06-25 15:43:31 +00:00
Justin Link 1965933130 Bug 1946130: Switched the order in TimerThread::Run() to put the common case first r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246707
2025-06-25 15:43:27 +00:00
Justin Link 9952f6d5ac Bug 1946130: Moved TimerThread::Run() waiting into its own function r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246706
2025-06-25 15:43:23 +00:00
Justin Link b5819f7b9f Bug 1946130: Moved some of the TimerThread::Run() statistics code into its own functions r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246705
2025-06-25 15:43:20 +00:00
Justin Link d42603de02 Bug 1946130: Moved telemetry of TimerThread::Run() into its own function r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246704
2025-06-25 15:43:16 +00:00
Serban Stanca bc5b8b89d1 Revert "Bug 1946130: Made ComputeWakeupTimeFromTimers() handle the empty timer list case so that the caller doesn't have to r=smaug" for causing build bustages in TimerThread.cpp.
This reverts commit b9517df139.

This reverts commit 94f1605943.

This reverts commit e7c8089ae5.

This reverts commit 3a5257cf5a.

This reverts commit a3aa7a9eb9.

This reverts commit f2796df814.

This reverts commit 615c0b00a9.

This reverts commit d385fb87cf.

This reverts commit 2de73f03c7.
2025-06-25 05:11:08 +00:00
Justin Link b9517df139 Bug 1946130: Made ComputeWakeupTimeFromTimers() handle the empty timer list case so that the caller doesn't have to r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251949
2025-06-25 04:37:33 +00:00
Justin Link 94f1605943 Bug 1946130: Moved Wait() out of the if-statement so that we only call it in one location r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251948
2025-06-25 04:37:29 +00:00
Justin Link e7c8089ae5 Bug 1946130: Moved Windows timer frequency management into its own class r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251947
2025-06-25 04:37:25 +00:00
Justin Link 3a5257cf5a Bug 1946130: Moved TimerThread telemetry into its own class r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251946
2025-06-25 04:37:22 +00:00
Justin Link a3aa7a9eb9 Bug 1946130: Simplified structure of TimerThread::Run() to be clearer where the loop is and what it does r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246708
2025-06-25 04:37:18 +00:00
Justin Link f2796df814 Bug 1946130: Switched the order in TimerThread::Run() to put the common case first r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246707
2025-06-25 04:37:14 +00:00
Justin Link 615c0b00a9 Bug 1946130: Moved TimerThread::Run() waiting into its own function r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246706
2025-06-25 04:37:10 +00:00
Justin Link d385fb87cf Bug 1946130: Moved some of the TimerThread::Run() statistics code into its own functions r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246705
2025-06-25 04:37:06 +00:00
Justin Link 2de73f03c7 Bug 1946130: Moved telemetry of TimerThread::Run() into its own function r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246704
2025-06-25 04:37:03 +00:00
Justin Link 57afb7f6e6 Bug 1959561: Implemented new TimerThread chaos mode wait time adjustment r=smaug
Previously we would scale the wait time by a randomly selected factor,
which meant that small waits would only ever get small (probably
ineffective) adjustments. Now we randomly pick an adjustment in a known
range and build our adjustment from that. This is simple, and doesn't
require the costly, and otherwise unnecessary, conversion of a TimeStamp
to microseconds.

Differential Revision: https://phabricator.services.mozilla.com/D245678
2025-04-22 15:59:06 +00:00
Justin Link 669ebd6797 Bug 1959561: Changed how TimerThread chaos mode affects early timer firing r=smaug
Ultimately what the previous logic did was to affect what timers qualify
for "early firing" by sliding their firing time earlier or later (and
then using this new time to see if they fall inside or outside of the
allowed early firing window).
We can do this more simply by instead adjusting the early firing
tolerance and we also don't need to change it for every timer.

Differential Revision: https://phabricator.services.mozilla.com/D245677
2025-04-22 15:59:05 +00:00
Justin Link 4ed2d80ebd Bug 1959561: Got rid of forceRunXXXTimer r=smaug
The forceRunXXXTimer variables were used only when chaos mode was
enabled to implement some strange behavior that I don't want to preserve
in the upcoming refactor.

Differential Revision: https://phabricator.services.mozilla.com/D245676
2025-04-22 15:59:05 +00:00
Justin Link c25142b2b8 Bug 1959561: Only check chaos mode once each loop iteration r=xpcom-reviewers,beth
Differential Revision: https://phabricator.services.mozilla.com/D245675
2025-04-22 15:59:05 +00:00
Jens Stutte 281c7d7622 Bug 1960536 - Remove obsolete MOZ_RUNINIT from static ThreadSafeAutoRefCnt instances. r=xpcom-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D245710
2025-04-16 12:55:10 +00:00
Jens Stutte dac7a7fb41 Bug 1958570 - Refactor nsTimerEvent::Shutdown to be based on a ThreadSafeAutoRefCnt of TimerEventAllocator refs. r=xpcom-reviewers,nika
The ThreadSafeAutoRefCnt takes care of the atomic fetch_sub that allows the calling thread to safely check for 0 without races.

Differential Revision: https://phabricator.services.mozilla.com/D244626
2025-04-15 06:58:10 +00:00
Florian Quèze 9609e47f62 Bug 1879329 - script generated replacement of the GleanMetrics.h includes, r=chutten,valentin,media-playback-reviewers,cookie-reviewers,anti-tracking-reviewers,profiler-reviewers,win-reviewers,rkraesig,emz,aabh,padenot.
Differential Revision: https://phabricator.services.mozilla.com/D234744
2025-01-21 11:21:45 +00:00
serge-sans-paille ead19d74bf Bug 1929260 - Use std::clamp instead of min/max chain in xpcom/threads r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D227972
2024-11-06 10:19:59 +00:00
serge-sans-paille 262f78c07f Bug 1922838 - Replace ArrayLength, ArrayEnd and MOZ_ARRAY_LENGTH by standard alternative r=glandium,necko-reviewers,jgilbert,application-update-reviewers,media-playback-reviewers,credential-management-reviewers,anti-tracking-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,bytesized,janv,dimi,daisuke,karlt,gstoll,canaltinova,timhuang
Namely std::size, std::end and std::size. This drops C support for
MOZ_ARRAY_LENGTH but it wasn't used anyway.

Differential Revision: https://phabricator.services.mozilla.com/D224611
2024-10-28 08:21:19 +00:00
Alexandru Marc a5eb905bf4 Backed out changeset d92f391b3b0c (bug 1922838) for backing out bug 1915351 2024-10-25 16:42:33 +03:00
serge-sans-paille 07101ac24d Bug 1922838 - Replace ArrayLength, ArrayEnd and MOZ_ARRAY_LENGTH by standard alternative r=glandium,necko-reviewers,jgilbert,application-update-reviewers,media-playback-reviewers,credential-management-reviewers,anti-tracking-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,bytesized,janv,dimi,daisuke,karlt,gstoll,canaltinova,timhuang
Namely std::size, std::end and std::size. This drops C support for
MOZ_ARRAY_LENGTH but it wasn't used anyway.

Differential Revision: https://phabricator.services.mozilla.com/D224611
2024-10-24 09:06:01 +00:00
Alexandru Marc 004e704b22 Backed out changeset 448597bce69d (bug 1922838) for causing build bustages. CLOSED TREE 2024-10-24 11:37:49 +03:00
serge-sans-paille 2c916d4973 Bug 1922838 - Replace ArrayLength, ArrayEnd and MOZ_ARRAY_LENGTH by standard alternative r=glandium,necko-reviewers,jgilbert,application-update-reviewers,media-playback-reviewers,credential-management-reviewers,anti-tracking-reviewers,places-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,bytesized,janv,dimi,daisuke,karlt,gstoll,canaltinova,timhuang
Namely std::size, std::end and std::size. This drops C support for
MOZ_ARRAY_LENGTH but it wasn't used anyway.

Differential Revision: https://phabricator.services.mozilla.com/D224611
2024-10-24 07:38:30 +00:00
Justin Link 9fb0d64095 Bug 1826224: Enable high-precision timers on Windows for foreground processes when not on battery power r=smaug
Initially controlled by a pref and only enabled by default in Nightly.

Differential Revision: https://phabricator.services.mozilla.com/D189555
2023-10-31 14:34:39 +00:00
Natalia Csoregi 1be331f04c Backed out changeset 88295a805fb9 (bug 1826224) for causing bustage on TimerThread.cpp. CLOSED TREE 2023-10-31 06:52:41 +02:00
Justin Link b505dbd7f8 Bug 1826224: Enable high-precision timers on Windows for foreground processes when not on battery power r=smaug
Initially controlled by a pref and only enabled by default in Nightly.

Differential Revision: https://phabricator.services.mozilla.com/D189555
2023-10-31 03:24:34 +00:00
Sylvestre Ledru b0fe72dee5 Bug 1856795 - Remove redundant member init r=emilio
Done with:
./mach static-analysis check --checks="-*, readability-redundant-member-init" --fix .

https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-member-init.html

Differential Revision: https://phabricator.services.mozilla.com/D190002
2023-10-15 15:29:02 +00:00
Cristina Horotan 7388749830 Backed out 2 changesets (bug 1856795) for causing build bustage at BasicEvents.h CLOSED TREE
Backed out changeset 1d98b028923a (bug 1856795)
Backed out changeset eae2ac93e17c (bug 1856795)
2023-10-14 21:42:14 +03:00
Sylvestre Ledru 4a97019e39 Bug 1856795 - Remove redundant member init r=emilio
Done with:
./mach static-analysis check --checks="-*, readability-redundant-member-init" --fix .

https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-member-init.html

Differential Revision: https://phabricator.services.mozilla.com/D190002
2023-10-14 17:34:26 +00:00
Olli Pettay 59bac9f5f4 Bug 1856545 - Try to utilize idle time more, r=farre
We can go through quite a few more timers these days, since timers are stored now in an array and iterating through that is fast.
Also, relying on timer value for another thread or low priority timers does prevent idle tasks to run in some cases, and now that more timers
are iterated through, that behavior can be tweaked.

For RefreshDriver this is taking the simple approach and just let idle tasks to run if RefreshDriver isn't ticking. We do start RefreshDriverTimer pretty
much always when something in DOM or layout is changing.

Differential Revision: https://phabricator.services.mozilla.com/D189909
2023-10-06 11:04:04 +00:00
Cristina Horotan 9e5159a3b2 Backed out changeset 5873383c36e2 (bug 1856545) for causing talos max run time exceeded failures. CLOSED TREE 2023-10-06 04:07:39 +03:00
Olli Pettay c46d698d22 Bug 1856545 - Try to utilize idle time more, r=farre
We can go through quite a few more timers these days, since timers are stored now in an array and iterating through that is fast.
Also, relying on timer value for another thread or low priority timers does prevent idle tasks to run in some cases, and now that more timers
are iterated through, that behavior can be tweaked.

For RefreshDriver this is taking the simple approach and just let idle tasks to run if RefreshDriver isn't ticking. We do start RefreshDriverTimer pretty
much always when something in DOM or layout is changing.

Differential Revision: https://phabricator.services.mozilla.com/D189909
2023-10-05 18:10:30 +00:00
Justin Link dbd41cc54d Bug 1831014: Allowed the first timer in a wake-up to fire slightly early as well. r=smaug
- Prior to this change, we allowed any timer *except* the first to fire early. Being woken up
slightly before our first timer is due was resulting in a lot of "wasted" wake-ups (where we wake
up and do nothing other than go back to sleep).
- This change results in waking up TimerThread 10% less frequently in my test case of watching a
YouTube video.
- Made the allowed early firing tolerance be a constant value rather than calculated at run-time.
- Also cleaned up some includes.

Differential Revision: https://phabricator.services.mozilla.com/D184017
2023-08-04 20:00:10 +00:00
Cristian Tuns b4da885613 Backed out changeset 61d2e733a10c (bug 1831014) for causing build bustages TimerThread.h CLOSED TREE 2023-08-03 14:29:40 -04:00
Justin Link a00c413d29 Bug 1831014: Allowed the first timer in a wake-up to fire slightly early as well. r=smaug
- Prior to this change, we allowed any timer *except* the first to fire early. Being woken up
slightly before our first timer is due was resulting in a lot of "wasted" wake-ups (where we wake
up and do nothing other than go back to sleep).
- This change results in waking up TimerThread 10% less frequently in my test case of watching a
YouTube video.
- Made the allowed early firing tolerance be a constant value rather than calculated at run-time.
- Also cleaned up some includes.

Differential Revision: https://phabricator.services.mozilla.com/D184017
2023-08-03 17:44:18 +00:00
Justin Link 074be5cb26 Bug 1829983 - Disabled assert that's invalid on Windows r=dthayer
Differential Revision: https://phabricator.services.mozilla.com/D180882
2023-06-15 14:59:10 +00:00
Justin Link 4508908bdf Bug 1829983 - Added some debug output in case this assert fails again r=dthayer
Differential Revision: https://phabricator.services.mozilla.com/D177800
2023-05-12 23:37:27 +00:00
Justin Link 0ce9126a89 Bug 1828427 - Removed incorrect assertion r=gerard-majax
Differential Revision: https://phabricator.services.mozilla.com/D175663
2023-04-20 21:05:18 +00:00
Florian Quèze dc510c9008 Bug 1828013 - Add a scriptable API to list all current nsITimer instances, r=smaug.
Differential Revision: https://phabricator.services.mozilla.com/D175430
2023-04-20 09:43:41 +00:00