Closed Bug 1848766 Opened 1 years ago Closed 1 years ago

Use PerformanceHintManager on Android for main thread and stylo thread pool threads

Categories

(Core :: Performance Engineering, task)

Unspecified
Android
task

Tracking

()

RESOLVED FIXED
118 Branch
Tracking Status
firefox118 --- fixed

People

(Reporter: jnicol, Assigned: jnicol)

References

(Blocks 1 open bug)

Details

(Keywords: perf-alert, Whiteboard: [sp3])

Attachments

(3 files)

We have been experimenting with PerformanceHintManager on Android. This is a fairly recent API that allows you to specify a target work duration for a set of threads. You continually report the actual work duration, and the system will schedule the threads appropriately in order to hit the target. This makes better use of the powerful cores on heterogenous CPUs, which we've seen to be an issue with the stylo thread pool on Android (see bug 1834977).

From testing this API only appears to make a difference on my Pixel 6 and Pixel 7 devices. On other devices createHintSession() API call either returns null, or it returns an object but the scheduling does not appear to be affected in any way. The Pixel implementation can be found here. It appears to make use of Linux's "Util Clamp" feature.

Despite unfortunately not having an effect on most devices, on the devices where it does work it appears to be an unequivocal win, increasing the speedometer score on my Pixel 7 from ~6.3 to ~6.8. We should therefore use it when available. For other devices we may want to find an alternative solution such as manually setting the CPU affinity of these threads, but the right approach there is a bit less obvious so let's do that in a follow up.

On Unix platforms this is a pthread_t, and on windows it is a HANDLE.

Assignee: nobody → jnicol
Status: NEW → ASSIGNED

PerformanceHintManager is an Android API that allows the caller to
create a PerformanceHintSession, representing a workload shared by a
group of threads that should be completed within a target duration
each cycle. The actual duration spent working is reported each cycle,
and the system can then adjust scheduling of the threads accordingly
in order to hit the target going forward.

This patch adds the API to HAL along with an Android
implementation (and a nop fallback implementation for other
platforms).

Depends on D186237

On Android devices with heterogeneous CPUs we often see the main
thread, and even more frequently the stylo threadpool threads, being
scheduled on devices' little cores even when there is plenty of work
to do. This patch uses the PerformanceHintManager API to help the
system schedule these threads more intelligently.

When VsyncRefreshDriverTimer is started, we create a
PerformanceHintSession for the main thread and stylo threadpool
threads, with a (fairly arbitrary) target duration of half the refresh
period. Each tick we report the actual duration spent. 500ms after the
timer is stopped we destroy the session, unless the timer has been
restarted again.

Depends on D186238

Whiteboard: [sp3]
Attachment #9349026 - Attachment description: Bug 1848766 - Add API to get stylo threadpool thread handles. r?smaug,emilio → Bug 1848766 - Add API to get stylo threadpool thread handles. r?emilio
Attachment #9349027 - Attachment description: Bug 1848766 - Add PerformanceHintManager implementation to HAL. r?smaug,emilio → Bug 1848766 - Add PerformanceHintManager implementation to HAL. r?emilio
Attachment #9349028 - Attachment description: Bug 1848766 - Use PerformanceHintManager for main thread and stylo threads in VsyncRefreshDriverTimer. r?smaug,emilio → Bug 1848766 - Use PerformanceHintManager for main thread and stylo threads in VsyncRefreshDriverTimer. r?emilio
Pushed by jnicol@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4e1c2cc65d1c Add API to get stylo threadpool thread handles. r=emilio https://hg.mozilla.org/integration/autoland/rev/065b16762c94 Add PerformanceHintManager implementation to HAL. r=smaug,emilio,geckoview-reviewers,owlish https://hg.mozilla.org/integration/autoland/rev/a645cf8f45e9 Use PerformanceHintManager for main thread and stylo threads in VsyncRefreshDriverTimer. r=smaug

Sorry, moved some code around which caused an unused function warning in 32 bit android builds. moved it back so should work now

Flags: needinfo?(jnicol)
Pushed by jnicol@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/9a102218c667 Add API to get stylo threadpool thread handles. r=emilio https://hg.mozilla.org/integration/autoland/rev/99fee20f2c11 Add PerformanceHintManager implementation to HAL. r=smaug,emilio,geckoview-reviewers,owlish https://hg.mozilla.org/integration/autoland/rev/b53328c9eece Use PerformanceHintManager for main thread and stylo threads in VsyncRefreshDriverTimer. r=smaug
Component: Performance → Performance Engineering
Status: ASSIGNED → RESOLVED
Closed: 1 years ago
Resolution: --- → FIXED
Target Milestone: --- → 118 Branch
See Also: → 1850231

(In reply to Pulsebot from comment #7)

Pushed by jnicol@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/9a102218c667
Add API to get stylo threadpool thread handles. r=emilio
https://hg.mozilla.org/integration/autoland/rev/99fee20f2c11
Add PerformanceHintManager implementation to HAL.
r=smaug,emilio,geckoview-reviewers,owlish
https://hg.mozilla.org/integration/autoland/rev/b53328c9eece
Use PerformanceHintManager for main thread and stylo threads in
VsyncRefreshDriverTimer. r=smaug

== Change summary for alert #39370 (as of Tue, 22 Aug 2023 15:37:55 GMT) ==

Improvements:

Ratio Test Platform Options Absolute values (old vs new)
4% cross_origin_pageload windows10-64-shippable-qr e10s fission stylo webrender 275.40 -> 265.65
3% cross_origin_pageload windows10-64-shippable-qr e10s fission stylo webrender-sw 276.34 -> 266.89

For up to date results, see: https://treeherder.mozilla.org/perfherder/alerts?id=39370

Blocks: 1850573

The perf alert is somewhat unexpected, could it be from another change instead? This patch mostly does nothing on non-Android (and in fact not even on the Android devices we have in CI!). I think the only change it should have made is that we may spawn the stylo threads sooner.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: