tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit d89acdce02035974ba540c785e797a6996e99b51
parent 209546251a628937764e84bdef7da588298ff8f2
Author: agoloman <agoloman@mozilla.com>
Date:   Fri, 14 Nov 2025 13:12:36 +0200

Revert "Bug 1995934 - Remove BaseTimeDuration::Resolution. r=glandium" for causing build bustages @TestTimeStamp.cpp.

This reverts commit db5606dc9f6c06ff908aafdf3055c781667af375.

Diffstat:
Mmozglue/misc/TimeStamp.h | 9+++++++++
Mmozglue/misc/TimeStamp_darwin.cpp | 12+++++++++++-
Mmozglue/misc/TimeStamp_posix.cpp | 4++++
Mmozglue/misc/TimeStamp_windows.cpp | 17++++++++++++-----
4 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/mozglue/misc/TimeStamp.h b/mozglue/misc/TimeStamp.h @@ -36,6 +36,7 @@ class BaseTimeDurationPlatformUtils { static MFBT_API double ToSeconds(int64_t aTicks); static MFBT_API double ToSecondsSigDigits(int64_t aTicks); static MFBT_API int64_t TicksFromMilliseconds(double aMilliseconds); + static MFBT_API int64_t ResolutionInTicks(); }; /** @@ -236,6 +237,14 @@ class BaseTimeDuration { return aStream << aDuration.ToMilliseconds() << " ms"; } + // Return a best guess at the system's current timing resolution, + // which might be variable. BaseTimeDurations below this order of + // magnitude are meaningless, and those at the same order of + // magnitude or just above are suspect. + static BaseTimeDuration Resolution() { + return FromTicks(BaseTimeDurationPlatformUtils::ResolutionInTicks()); + } + // We could define additional operators here: // -- convert to/from other time units // -- scale duration by a float diff --git a/mozglue/misc/TimeStamp_darwin.cpp b/mozglue/misc/TimeStamp_darwin.cpp @@ -26,6 +26,9 @@ #include "mozilla/TimeStamp.h" #include "mozilla/Uptime.h" +// Each tick is significant, so we have a resolution of 1. +static constexpr uint64_t kResolution = 1; + static const uint64_t kUsPerSec = 1000000; static const double kNsPerMsd = 1000000.0; static const double kNsPerSecd = 1000000000.0; @@ -53,7 +56,9 @@ double BaseTimeDurationPlatformUtils::ToSeconds(int64_t aTicks) { double BaseTimeDurationPlatformUtils::ToSecondsSigDigits(int64_t aTicks) { MOZ_ASSERT(gInitialized, "calling TimeDuration too early"); - // We trust mach_timebase_info that all digits are significant. + // As we fix the resolution to 1, all digits are significant and there are + // no extra calculations needed. Ensure we do not change this inadvertedly. + static_assert(kResolution == 1); return ToSeconds(aTicks); } @@ -72,6 +77,11 @@ int64_t BaseTimeDurationPlatformUtils::TicksFromMilliseconds( return result; } +int64_t BaseTimeDurationPlatformUtils::ResolutionInTicks() { + MOZ_ASSERT(gInitialized, "calling TimeDuration too early"); + return static_cast<int64_t>(kResolution); +} + void TimeStamp::Startup() { if (gInitialized) { return; diff --git a/mozglue/misc/TimeStamp_posix.cpp b/mozglue/misc/TimeStamp_posix.cpp @@ -171,6 +171,10 @@ int64_t BaseTimeDurationPlatformUtils::TicksFromMilliseconds( return result; } +int64_t BaseTimeDurationPlatformUtils::ResolutionInTicks() { + return static_cast<int64_t>(sResolution); +} + static bool gInitialized = false; void TimeStamp::Startup() { diff --git a/mozglue/misc/TimeStamp_windows.cpp b/mozglue/misc/TimeStamp_windows.cpp @@ -33,6 +33,11 @@ static double sTicksPerMsd; // ---------------------------------------------------------------------------- static constexpr double kMsPerSecd = 1000.0; +// Note: Resolution used to be sampled based on a loop of QPC calls. +// While it is true that on most systems we cannot expect to subsequently +// sample QPC values as fast as the QPC frequency, we still will get that +// as resolution of the sampled values, that is we have 1 tick resolution. +static constexpr LONGLONG kResolution = 1; namespace mozilla { @@ -45,10 +50,6 @@ static inline ULONGLONG PerformanceCounter() { static void InitConstants() { // Query the frequency from QPC and rely on it for all values. - // Note: The resolution used to be sampled based on a loop of QPC calls. - // While it is true that on most systems we cannot expect to subsequently - // sample QPC values as fast as the QPC frequency, we still will get that - // as resolution of the sampled values, that is we have 1 tick resolution. LARGE_INTEGER freq; bool hasQPC = ::QueryPerformanceFrequency(&freq); MOZ_RELEASE_ASSERT(hasQPC); @@ -66,7 +67,9 @@ MFBT_API double BaseTimeDurationPlatformUtils::ToSeconds(int64_t aTicks) { MFBT_API double BaseTimeDurationPlatformUtils::ToSecondsSigDigits( int64_t aTicks) { - // We trust QueryPerformanceFrequency that all digits are significant. + // As we fix the resolution to 1, all digits are significant and there are + // no extra calculations needed. Ensure we do not change this inadvertedly. + static_assert(kResolution == 1); return ToSeconds(aTicks); } @@ -85,6 +88,10 @@ BaseTimeDurationPlatformUtils::TicksFromMilliseconds(double aMilliseconds) { return (int64_t)result; } +MFBT_API int64_t BaseTimeDurationPlatformUtils::ResolutionInTicks() { + return static_cast<int64_t>(kResolution); +} + // Note that we init early enough during startup such that we are supposed to // not yet have started other threads which could try to use us. static bool gInitialized = false;