diff --git a/hal/Hal.cpp b/hal/Hal.cpp index 92d99cf43eb7..911f3e501217 100644 --- a/hal/Hal.cpp +++ b/hal/Hal.cpp @@ -417,12 +417,6 @@ const char* ProcessPriorityToString(ProcessPriority aPriority) { } } -UniquePtr CreatePerformanceHintSession( - const nsTArray& aThreads, - mozilla::TimeDuration aTargetWorkDuration) { - return hal_impl::CreatePerformanceHintSession(aThreads, aTargetWorkDuration); -} - void Init() { MOZ_ASSERT(!sInitialized); diff --git a/hal/Hal.h b/hal/Hal.h index adecfd905e44..712537005724 100644 --- a/hal/Hal.h +++ b/hal/Hal.h @@ -7,7 +7,6 @@ #ifndef mozilla_Hal_h #define mozilla_Hal_h -#include "base/platform_thread.h" #include "nsTArray.h" #include "mozilla/hal_sandbox/PHal.h" #include "mozilla/HalScreenConfiguration.h" @@ -237,20 +236,6 @@ void UnlockScreenOrientation(); */ void SetProcessPriority(int aPid, hal::ProcessPriority aPriority); -/** - * Creates a PerformanceHintSession. - * - * A PerformanceHintSession represents a workload shared by a group of threads - * that should be completed in a target duration each cycle. - * - * Each cycle, the actual work duration should be reported using - * PerformanceHintSession::ReportActualWorkDuration(). The system can then - * adjust the scheduling accordingly in order to achieve the target. - */ -UniquePtr CreatePerformanceHintSession( - const nsTArray& aThreads, - mozilla::TimeDuration aTargetWorkDuration); - } // namespace MOZ_HAL_NAMESPACE } // namespace mozilla diff --git a/hal/HalTypes.h b/hal/HalTypes.h index 47b2be0e263d..e89392f35526 100644 --- a/hal/HalTypes.h +++ b/hal/HalTypes.h @@ -8,8 +8,6 @@ #include "ipc/EnumSerializer.h" #include "mozilla/Observer.h" -#include "mozilla/TimeStamp.h" -#include "mozilla/UniquePtr.h" namespace mozilla { namespace hal { @@ -60,26 +58,6 @@ enum WakeLockControl { NUM_WAKE_LOCK }; -/** - * Represents a workload shared by a group of threads that should be completed - * in a target duration each cycle. - * - * This is created using hal::CreatePerformanceHintSession(). Each cycle, the - * actual work duration should be reported using ReportActualWorkDuration(). The - * system can then adjust the scheduling accordingly in order to achieve the - * target. - */ -class PerformanceHintSession { - public: - virtual ~PerformanceHintSession() = default; - - // Updates the session's target work duration for each cycle. - virtual void UpdateTargetWorkDuration(TimeDuration aDuration) = 0; - - // Reports the session's actual work duration for a cycle. - virtual void ReportActualWorkDuration(TimeDuration aDuration) = 0; -}; - } // namespace hal } // namespace mozilla diff --git a/hal/android/AndroidPerformanceHintManager.cpp b/hal/android/AndroidPerformanceHintManager.cpp deleted file mode 100644 index 16ec53ac6920..000000000000 --- a/hal/android/AndroidPerformanceHintManager.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#include "Hal.h" -#include "HalLog.h" -#include "HalTypes.h" - -#include "AndroidBuild.h" - -#include -#include -#include -#include - -typedef struct APerformanceHintManager APerformanceHintManager; -typedef struct APerformanceHintSession APerformanceHintSession; - -namespace mozilla { -namespace hal_impl { - -#define LOAD_FN(api, lib, name) \ - do { \ - api->m##name = reinterpret_cast(dlsym(handle, #name)); \ - if (!api->m##name) { \ - HAL_ERR("Failed to load %s", #name); \ - return nullptr; \ - } \ - } while (false) - -class PerformanceHintManagerApi final { - public: - static PerformanceHintManagerApi* Get() { - // C++ guarantees local static variable initialization is thread safe - static UniquePtr api = Create(); - return api.get(); - } - - APerformanceHintManager* APerformanceHint_getManager() const { - return mAPerformanceHint_getManager(); - } - - APerformanceHintSession* APerformanceHint_createSession( - APerformanceHintManager* manager, const int32_t* threadIds, size_t size, - int64_t initialTargetWorkDurationNanos) const { - return mAPerformanceHint_createSession(manager, threadIds, size, - initialTargetWorkDurationNanos); - } - - int APerformanceHint_updateTargetWorkDuration( - APerformanceHintSession* session, int64_t targetDurationNanos) const { - return mAPerformanceHint_updateTargetWorkDuration(session, - targetDurationNanos); - } - - int APerformanceHint_reportActualWorkDuration( - APerformanceHintSession* session, int64_t actualDurationNanos) const { - return mAPerformanceHint_reportActualWorkDuration(session, - actualDurationNanos); - } - - void APerformanceHint_closeSession(APerformanceHintSession* session) const { - mAPerformanceHint_closeSession(session); - } - - private: - PerformanceHintManagerApi() = default; - - static UniquePtr Create() { - if (mozilla::jni::GetAPIVersion() < __ANDROID_API_T__) { - return nullptr; - } - - void* const handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL); - if (!handle) { - HAL_ERR("Failed to open libandroid.so"); - return nullptr; - } - - auto api = WrapUnique(new PerformanceHintManagerApi()); - LOAD_FN(api, handle, APerformanceHint_getManager); - LOAD_FN(api, handle, APerformanceHint_createSession); - LOAD_FN(api, handle, APerformanceHint_updateTargetWorkDuration); - LOAD_FN(api, handle, APerformanceHint_reportActualWorkDuration); - LOAD_FN(api, handle, APerformanceHint_closeSession); - - return api; - } - - using FnAPerformanceHint_getManager = APerformanceHintManager* (*)(); - using FnAPerformanceHint_createSession = - APerformanceHintSession* (*)(APerformanceHintManager* manager, - const int32_t* threadIds, size_t size, - int64_t initialTargetWorkDurationNanos); - using FnAPerformanceHint_updateTargetWorkDuration = - int (*)(APerformanceHintSession* session, int64_t targetDurationNanos); - using FnAPerformanceHint_reportActualWorkDuration = - int (*)(APerformanceHintSession* session, int64_t actualDurationNanos); - using FnAPerformanceHint_closeSession = - void (*)(APerformanceHintSession* session); - - FnAPerformanceHint_getManager mAPerformanceHint_getManager = nullptr; - FnAPerformanceHint_createSession mAPerformanceHint_createSession = nullptr; - FnAPerformanceHint_updateTargetWorkDuration - mAPerformanceHint_updateTargetWorkDuration = nullptr; - FnAPerformanceHint_reportActualWorkDuration - mAPerformanceHint_reportActualWorkDuration = nullptr; - FnAPerformanceHint_closeSession mAPerformanceHint_closeSession = nullptr; -}; - -class AndroidPerformanceHintSession final : public hal::PerformanceHintSession { - public: - // Creates a PerformanceHintSession wrapping the provided NDK - // APerformanceHintSession instance. This assumes ownership of aSession, - // therefore the caller must not close the session itself. - explicit AndroidPerformanceHintSession(APerformanceHintSession* aSession) - : mSession(aSession) {} - - AndroidPerformanceHintSession(AndroidPerformanceHintSession& aOther) = delete; - AndroidPerformanceHintSession(AndroidPerformanceHintSession&& aOther) { - mSession = aOther.mSession; - aOther.mSession = nullptr; - } - - ~AndroidPerformanceHintSession() { - if (mSession) { - PerformanceHintManagerApi::Get()->APerformanceHint_closeSession(mSession); - } - } - - void UpdateTargetWorkDuration(TimeDuration aDuration) override { - PerformanceHintManagerApi::Get()->APerformanceHint_updateTargetWorkDuration( - mSession, aDuration.ToMicroseconds() * 1000); - } - - void ReportActualWorkDuration(TimeDuration aDuration) override { - PerformanceHintManagerApi::Get()->APerformanceHint_reportActualWorkDuration( - mSession, aDuration.ToMicroseconds() * 1000); - } - - private: - APerformanceHintSession* mSession; -}; - -static APerformanceHintManager* InitManager() { - const auto* api = PerformanceHintManagerApi::Get(); - if (!api) { - return nullptr; - } - - // At the time of writing we are only aware of PerformanceHintManager being - // implemented on Tensor devices (Pixel 6 and 7 families). On most devices - // createSession() will simply return null. However, on some devices - // createSession() does return a session but scheduling does not appear to be - // affected in any way. Rather than pretending to the caller that - // PerformanceHintManager is available on such devices, return null allowing - // them to use another means of achieving the performance they require. - const auto socManufacturer = java::sdk::Build::SOC_MANUFACTURER()->ToString(); - if (!socManufacturer.EqualsASCII("Google")) { - return nullptr; - } - - return api->APerformanceHint_getManager(); -} - -UniquePtr CreatePerformanceHintSession( - const nsTArray& aThreads, - mozilla::TimeDuration aTargetWorkDuration) { -#if __ANDROID_API__ < __ANDROID_API_L__ - // pthread_gettid_np() (used below) didn't exist prior to lollipop. Currently - // 32-bit builds use an older NDK minimum version than this, meaning we cannot - // use this feature. But that's okay since only the very most recent devices - // support PerformanceHintManager, and users will likely be running 64 bit - // builds on them. This limitation will be removed when we next update the - // minimum version in bug 1820295. - return nullptr; -#else - - // C++ guarantees local static variable initialization is thread safe - static APerformanceHintManager* manager = InitManager(); - - if (!manager) { - return nullptr; - } - - const auto* api = PerformanceHintManagerApi::Get(); - - nsTArray tids(aThreads.Length()); - std::transform(aThreads.cbegin(), aThreads.cend(), MakeBackInserter(tids), - [](pthread_t handle) { return pthread_gettid_np(handle); }); - - APerformanceHintSession* session = api->APerformanceHint_createSession( - manager, tids.Elements(), tids.Length(), - aTargetWorkDuration.ToMicroseconds() * 1000); - if (!session) { - return nullptr; - } - - return MakeUnique(session); -#endif -} - -} // namespace hal_impl -} // namespace mozilla diff --git a/hal/fallback/FallbackPerformanceHintManager.cpp b/hal/fallback/FallbackPerformanceHintManager.cpp deleted file mode 100644 index 768665011366..000000000000 --- a/hal/fallback/FallbackPerformanceHintManager.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set sw=2 ts=8 et ft=cpp : */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "Hal.h" - -namespace mozilla { -namespace hal_impl { - -UniquePtr CreatePerformanceHintSession( - const nsTArray& aThreads, - mozilla::TimeDuration aTargetWorkDuration) { - return nullptr; -} - -} // namespace hal_impl -} // namespace mozilla diff --git a/hal/moz.build b/hal/moz.build index bc13c596c0d1..f5534acb1a4b 100644 --- a/hal/moz.build +++ b/hal/moz.build @@ -37,7 +37,6 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] == "android": "/widget/android", ] UNIFIED_SOURCES += [ - "android/AndroidPerformanceHintManager.cpp", "android/AndroidProcessPriority.cpp", "android/AndroidSensor.cpp", ] @@ -109,7 +108,6 @@ else: if CONFIG["MOZ_WIDGET_TOOLKIT"] != "android": UNIFIED_SOURCES += [ "fallback/FallbackNetwork.cpp", - "fallback/FallbackPerformanceHintManager.cpp", ] if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa": diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index d06ab2fca462..f9dd7f1e390d 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -38,7 +38,6 @@ #include "mozilla/CycleCollectedJSContext.h" #include "mozilla/DebugOnly.h" #include "mozilla/DisplayPortUtils.h" -#include "mozilla/Hal.h" #include "mozilla/InputTaskManager.h" #include "mozilla/IntegerRange.h" #include "mozilla/PresShell.h" @@ -630,10 +629,6 @@ class VsyncRefreshDriverTimer : public RefreshDriverTimer { // longer tick this timer. mVsyncObserver->Shutdown(); mVsyncObserver = nullptr; - - if (mClosePerfSessionTimer) { - mClosePerfSessionTimer->Cancel(); - } } bool ShouldGiveNonVsyncTasksMoreTime() { @@ -784,12 +779,6 @@ class VsyncRefreshDriverTimer : public RefreshDriverTimer { mProcessedVsync = true; } - TimeDuration GetPerformanceHintTarget() { - // Estimate that we want to the tick to complete in at most half of the - // vsync period. This is fairly arbitrary and can be tweaked later. - return GetTimerRate() / int64_t(2); - } - void TickRefreshDriver(VsyncId aId, TimeStamp aVsyncTimestamp) { MOZ_ASSERT(NS_IsMainThread()); @@ -797,14 +786,7 @@ class VsyncRefreshDriverTimer : public RefreshDriverTimer { TimeStamp tickStart = TimeStamp::Now(); - const TimeDuration previousRate = mVsyncRate; - const TimeDuration rate = GetTimerRate(); - - if (mPerformanceHintSession && rate != previousRate) { - mPerformanceHintSession->UpdateTargetWorkDuration( - GetPerformanceHintTarget()); - } - + TimeDuration rate = GetTimerRate(); if (TimeDuration::FromMilliseconds(nsRefreshDriver::DefaultInterval() / 2) > rate) { sMostRecentHighRateVsync = tickStart; @@ -828,10 +810,6 @@ class VsyncRefreshDriverTimer : public RefreshDriverTimer { TimeStamp tickEnd = TimeStamp::Now(); - if (mPerformanceHintSession) { - mPerformanceHintSession->ReportActualWorkDuration(tickEnd - tickStart); - } - // Re-read mLastTickStart in case there was a nested tick inside this // tick. TimeStamp mostRecentTickStart = mLastTickStart; @@ -891,35 +869,6 @@ class VsyncRefreshDriverTimer : public RefreshDriverTimer { OnTimerStart(); } mIsTicking = true; - - static bool canUsePerformanceHintSession = true; - if (canUsePerformanceHintSession) { - if (mClosePerfSessionTimer) { - mClosePerfSessionTimer->Cancel(); - } - - // While the timer is active create a PerformanceHintSession for the main - // thread and stylo threads in the content process. We can only do so - // when using a single vsync source for the process, otherwise these - // threads may be performing work for multiple VsyncRefreshDriverTimers - // and we will misreport the duration. - if (XRE_IsContentProcess() && !mPerformanceHintSession && mVsyncChild) { - nsTArray threads; - Servo_ThreadPool_GetThreadHandles(&threads); -#ifdef XP_WIN - threads.AppendElement(GetCurrentThread()); -#else - threads.AppendElement(pthread_self()); -#endif - - mPerformanceHintSession = hal::CreatePerformanceHintSession( - threads, GetPerformanceHintTarget()); - - // Avoid repeatedly attempting to create a session if it is not - // supported. - canUsePerformanceHintSession = mPerformanceHintSession != nullptr; - } - } } void StopTimer() override { @@ -931,25 +880,6 @@ class VsyncRefreshDriverTimer : public RefreshDriverTimer { mVsyncChild->RemoveChildRefreshTimer(mVsyncObserver); } mIsTicking = false; - - if (mPerformanceHintSession) { - if (!mClosePerfSessionTimer) { - mClosePerfSessionTimer = NS_NewTimer(); - } - // If the timer is not restarted within 5 seconds then close the - // PerformanceHintSession. This is a balance between wanting to close the - // session promptly when timer is inactive to save power, but equally not - // wanting to repeatedly create and destroy sessions nor cause frequent - // wakeups by the timer repeatedly firing. - mClosePerfSessionTimer->InitWithNamedFuncCallback( - [](nsITimer* aTimer, void* aClosure) { - VsyncRefreshDriverTimer* self = - static_cast(aClosure); - self->mPerformanceHintSession.reset(); - }, - this, 5000, nsITimer::TYPE_ONE_SHOT_LOW_PRIORITY, - "VsyncRefreshDriverTimer::mClosePerfSessionTimer"); - } } public: @@ -1007,12 +937,6 @@ class VsyncRefreshDriverTimer : public RefreshDriverTimer { // The timestamp is effectively mLastProcessedTick + some duration. TimeStamp mSuspendVsyncPriorityTicksUntil; bool mProcessedVsync; - - UniquePtr mPerformanceHintSession; - // Used to wait a certain amount of time after the refresh driver timer is - // stopped before closing the PerformanceHintSession if the timer has not - // been restarted. - RefPtr mClosePerfSessionTimer; }; // VsyncRefreshDriverTimer /** diff --git a/servo/components/style/global_style_data.rs b/servo/components/style/global_style_data.rs index 3fad81c2a98a..ba1b82fd6bd9 100644 --- a/servo/components/style/global_style_data.rs +++ b/servo/components/style/global_style_data.rs @@ -14,18 +14,6 @@ use gecko_profiler; use parking_lot::{Mutex, RwLock, RwLockReadGuard}; use rayon; use std::{io, thread}; -#[cfg(unix)] -use std::os::unix::thread::{JoinHandleExt, RawPthread}; -#[cfg(windows)] -use std::os::windows::{io::AsRawHandle, prelude::RawHandle}; -use thin_vec::ThinVec; - -/// Platform-specific handle to a thread. -#[cfg(unix)] -pub type PlatformThreadHandle = RawPthread; -/// Platform-specific handle to a thread. -#[cfg(windows)] -pub type PlatformThreadHandle = RawHandle; /// Global style data pub struct GlobalStyleData { @@ -121,22 +109,6 @@ impl StyleThreadPool { pub fn pool(&self) -> RwLockReadGuard> { self.style_thread_pool.read() } - - /// Returns a list of the pool's platform-specific thread handles. - pub fn get_thread_handles(handles: &mut ThinVec) { - // Force the lazy initialization of STYLE_THREAD_POOL so that the threads get spawned and - // their join handles are added to STYLE_THREAD_JOIN_HANDLES. - lazy_static::initialize(&STYLE_THREAD_POOL); - - for join_handle in STYLE_THREAD_JOIN_HANDLES.lock().iter() { - #[cfg(unix)] - let handle = join_handle.as_pthread_t(); - #[cfg(windows)] - let handle = join_handle.as_raw_handle(); - - handles.push(handle); - } - } } #[cfg(feature = "servo")] diff --git a/servo/ports/geckolib/cbindgen.toml b/servo/ports/geckolib/cbindgen.toml index 3818bb9760c0..3474af64e03a 100644 --- a/servo/ports/geckolib/cbindgen.toml +++ b/servo/ports/geckolib/cbindgen.toml @@ -57,8 +57,6 @@ derive_neq = true # These depend on the build. "target_pointer_width = 32" = "SERVO_32_BITS" "target_pointer_width = 64" = "HAVE_64BIT_BUILD" -"unix" = "XP_UNIX" -"windows" = "XP_WIN" [macro_expansion] bitflags = true @@ -337,8 +335,6 @@ renaming_overrides_prefixing = true "FontPaletteValueSet" = "gfx::FontPaletteValueSet" "PaletteValues" = "gfx::FontPaletteValueSet::PaletteValues" "ThinVec" = "nsTArray" -"RawPthread" = "pthread_t" -"RawHandle" = "void*" [export.body] "CSSPixelLength" = """ diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index fe110b501537..8ead1d47176e 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -92,7 +92,7 @@ use style::gecko_bindings::structs::{nsINode as RawGeckoNode, Element as RawGeck use style::gecko_bindings::sugar::ownership::Strong; use style::gecko_bindings::sugar::refptr::RefPtr; use style::global_style_data::{ - GlobalStyleData, PlatformThreadHandle, StyleThreadPool, GLOBAL_STYLE_DATA, STYLE_THREAD_POOL, + GlobalStyleData, StyleThreadPool, GLOBAL_STYLE_DATA, STYLE_THREAD_POOL, }; use style::invalidation::element::restyle_hints::RestyleHint; use style::invalidation::stylesheets::RuleChangeKind; @@ -1563,11 +1563,6 @@ pub unsafe extern "C" fn Servo_ShutdownThreadPool() { StyleThreadPool::shutdown(); } -#[no_mangle] -pub unsafe extern "C" fn Servo_ThreadPool_GetThreadHandles(handles: &mut ThinVec) { - StyleThreadPool::get_thread_handles(handles); -} - #[no_mangle] pub unsafe extern "C" fn Servo_StyleSheet_FromSharedData( extra_data: *mut URLExtraData,