Skip to content

Commit

Permalink
Cherry-pick bd0c3f3. rdar://113230434
Browse files Browse the repository at this point in the history
    [visionOS] Under thermal throttling Safari webpage went blank when navigating
    https://bugs.webkit.org/show_bug.cgi?id=261374
    <radar://113230434>

    Reviewed by Dean Jackson.

    When the system is throttled due to thermal pressure, we can easily hit process
    timeouts and then web pages will fail to load.

    * Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:
    (WebKit::adjustedTimeoutForThermalState):
    (WebKit::AuxiliaryProcessProxy::AuxiliaryProcessProxy):
    Query if thermal mitigation is enabled and increase process timeout if so.

    * Source/WebCore/platform/ThermalMitigationNotifier.cpp:
    (WebCore::ThermalMitigationNotifier::isThermalMitigationEnabled):
    Default implementation.

    * Source/WebCore/platform/ThermalMitigationNotifier.h:
    * Source/WebCore/platform/cocoa/ThermalMitigationNotifier.mm:
    (WebCore::isThermalMitigationEnabled):
    (-[WebThermalMitigationObserver thermalMitigationEnabled]):
    (WebCore::ThermalMitigationNotifier::isThermalMitigationEnabled):
    Add static member function to query if thermal mitigation is enabled
    as we don't need an instance function in AuxiliaryProcessProxy

    * Source/WebCore/WebCore.xcodeproj/project.pbxproj:
    Make ThermalMitigationNotifier.h a private header.

    Canonical link: https://commits.webkit.org/268149@main
Identifier: 265423.1038@safari-7616-branch
  • Loading branch information
mwyrzykowski authored and MyahCobbs committed Sep 25, 2023
1 parent 51f1661 commit 5ec82cd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
0BE030A20F3112FB003C1A46 /* RenderLineBoxList.h in Headers */ = {isa = PBXBuildFile; fileRef = 0BE030A10F3112FB003C1A46 /* RenderLineBoxList.h */; settings = {ATTRIBUTES = (Private, ); }; };
0C3F1F5B10C8871200D72CE1 /* WebGLUniformLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C3F1F5810C8871200D72CE1 /* WebGLUniformLocation.h */; };
0C45342810CDBBFA00869157 /* JSWebGLUniformLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C45342610CDBBFA00869157 /* JSWebGLUniformLocation.h */; };
0D44C33E2ABA1B9F0017FB5D /* ThermalMitigationNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D8EF8122A9D511F000118F8 /* ThermalMitigationNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
0E7058F41BC5CEDA0045A507 /* SearchPopupMenuCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E7058F31BC5CCD70045A507 /* SearchPopupMenuCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
0E9C1157291C18A400A2C2F2 /* ScreenDataOverrides.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E9C1155291BF3CC00A2C2F2 /* ScreenDataOverrides.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F03C0741884695E00A5F8CA /* SystemMemory.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F03C0731884695E00A5F8CA /* SystemMemory.h */; };
Expand Down Expand Up @@ -41252,6 +41253,7 @@
44C9919F0F3D210E00586670 /* ThemeIOS.h in Headers */,
BCE659E60EA92FB2007E4533 /* ThemeMac.h in Headers */,
BCE659A90EA927B9007E4533 /* ThemeTypes.h in Headers */,
0D44C33E2ABA1B9F0017FB5D /* ThermalMitigationNotifier.h in Headers */,
976D6C95122B8A3D001FD1F7 /* ThreadableBlobRegistry.h in Headers */,
0B90561B0F2578BF0095FF6A /* ThreadableLoader.h in Headers */,
0B90561C0F2578BF0095FF6A /* ThreadableLoaderClient.h in Headers */,
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/platform/ThermalMitigationNotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ bool ThermalMitigationNotifier::thermalMitigationEnabled() const
return false;
}

bool ThermalMitigationNotifier::isThermalMitigationEnabled()
{
return false;
}

#endif

} // namespace WebCore
1 change: 1 addition & 0 deletions Source/WebCore/platform/ThermalMitigationNotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ThermalMitigationNotifier : public CanMakeWeakPtr<ThermalMitigationNotifie
WEBCORE_EXPORT ~ThermalMitigationNotifier();

WEBCORE_EXPORT bool thermalMitigationEnabled() const;
WEBCORE_EXPORT static bool isThermalMitigationEnabled();

private:
#if HAVE(APPLE_THERMAL_MITIGATION_SUPPORT)
Expand Down
14 changes: 13 additions & 1 deletion Source/WebCore/platform/cocoa/ThermalMitigationNotifier.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
#import <Foundation/NSProcessInfo.h>
#import <wtf/MainThread.h>

namespace WebCore {
static bool isThermalMitigationEnabled()
{
return NSProcessInfo.processInfo.thermalState >= NSProcessInfoThermalStateSerious;
}
}

@interface WebThermalMitigationObserver : NSObject
@property (nonatomic) WeakPtr<WebCore::ThermalMitigationNotifier> notifier;
@property (nonatomic, readonly) BOOL thermalMitigationEnabled;
Expand Down Expand Up @@ -66,7 +73,7 @@ - (void)thermalStateDidChange

- (BOOL)thermalMitigationEnabled
{
return NSProcessInfo.processInfo.thermalState >= NSProcessInfoThermalStateSerious;
return WebCore::isThermalMitigationEnabled();
}

@end
Expand All @@ -89,6 +96,11 @@ - (BOOL)thermalMitigationEnabled
return [m_observer thermalMitigationEnabled];
}

bool ThermalMitigationNotifier::isThermalMitigationEnabled()
{
return WebCore::isThermalMitigationEnabled();
}

void ThermalMitigationNotifier::notifyThermalMitigationChanged(bool enabled)
{
m_callback(enabled);
Expand Down
15 changes: 14 additions & 1 deletion Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,23 @@
#import <pal/spi/ios/MobileGestaltSPI.h>
#endif

#if PLATFORM(VISION)
#import <WebCore/ThermalMitigationNotifier.h>
#endif

namespace WebKit {

static Seconds adjustedTimeoutForThermalState(Seconds timeout)
{
#if PLATFORM(VISION)
return WebCore::ThermalMitigationNotifier::isThermalMitigationEnabled() ? (timeout * 20) : timeout;
#else
return timeout;
#endif
}

AuxiliaryProcessProxy::AuxiliaryProcessProxy(bool alwaysRunsAtBackgroundPriority, Seconds responsivenessTimeout)
: m_responsivenessTimer(*this, responsivenessTimeout)
: m_responsivenessTimer(*this, adjustedTimeoutForThermalState(responsivenessTimeout))
, m_alwaysRunsAtBackgroundPriority(alwaysRunsAtBackgroundPriority)
#if USE(RUNNINGBOARD)
, m_timedActivityForIPC(3_s)
Expand Down

0 comments on commit 5ec82cd

Please sign in to comment.