Implement low-power core threads for nsThread/pools
Categories
(Core :: XPCOM, enhancement)
Tracking
()
Tracking | Status | |
---|---|---|
firefox111 | --- | fixed |
People
(Reporter: KrisWright, Assigned: KrisWright)
References
(Blocks 2 open bugs)
Details
Attachments
(1 file, 2 obsolete files)
We could get some energy use improvements by moving some high-traffic, low-priority threadpools to use low-power cores where available. Here's how I think this will most likely go:
- Identify threads that should be using low-power cores where available
- Implement low-power cores where available in nsThread (ideally, by sending information to the OS to create a low-power thread)
- Create nsThreadPools capable of only creating nsThreads of this type
- Create a prototype patch with these changes that we can use to test the effectiveness of low-power threads on the browser (if possible)
I've already identified the IO background pool as a good user of low-power cores that is active on the platform I have an idea of how to implement it on. If there is an existing way to implement this on Linux, our memory monitor would also be an excellent user as it fires every 5-10 seconds and does a brief IO read as long as the user is active.
The way to do this on Apple Silicon is found here. Specifically, it looks like we can use pthread_set_qos_class_self_np
during thread creation to tell the OS that these threads are low priority. It looks like I may need to make some changes to our core thread creation to make this work, but ideally we can find a way to do this solely on the nsThread
side of things.
I'm not sure how other platforms are currently handling low-power cores (if at all), is there any documentation out there on this?
Comment 1•2 years ago
|
||
(In reply to Kris Wright :KrisWright from comment #0)
Thanks for looking at this!
I'm not sure how other platforms are currently handling low-power cores (if at all), is there any documentation out there on this?
On Windows, set the thread quality-of-service to "Eco" (new value only available in Windows 11, "Low" could be used on Windows 10 to help with battery life). Some documentation at https://docs.microsoft.com/en-us/windows/win32/procthread/quality-of-service and see also bug 1730011.
Assignee | ||
Updated•2 years ago
|
Assignee | ||
Comment 2•2 years ago
|
||
This will be used to deprioritize individual threads. The concept works as such:
- Set a thread pool's priority, which advances the current epoch.
- If new threads are low priority, dispatch a runnable to the thread on creation to have the thread set its priority/QoS status
- Have threads monitor their own epoch only when they run out of new events to process, so that we aren't shutting down any threads that are actively processing events. If the epoch doesn't match the current epoch, it will shut itself down.
This patch enrolls the background IO to low priority on its creation. The rest of the stack further elaborates on this base structure, for instance:
- Introduce OS-specific QoS rules
- Enable background browsing context monitoring for impacted OSes.
Assignee | ||
Comment 3•2 years ago
|
||
We can simply use pthread_set_qos_class_self_np
on macs to utilize the low-power cores for these actions. This only works for the new arm64 macs. However, setting the QoS status is no guarantee that the OS will actually only put this work on the low-power cores, but we can instruct it to do so when available. That way we don't have to address hangs on this work caused by low power cores being busy with other work. Note that this can only be run on the thread that is being set; I decided to go with this version so that I didn't have to delve into prthread code and create a lower-level way to change task scheduling.
Depends on D146534
Assignee | ||
Comment 4•2 years ago
|
||
Depends on D149901
Comment 5•2 years ago
|
||
In bug 1774844 I'm adding support for profiling power with the Firefox Profiler on M1 Macs (and Windows 11 machines), so that will probably help to validate the impact of patches from this bug.
Updated•2 years ago
|
Updated•2 years ago
|
Updated•2 years ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Pushed by kwright@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/705ee67c7392 Create a way to deprioritize threadpools. r=nika
Comment 7•1 year ago
|
||
bugherder |
Description
•