Closed Bug 1748378 Opened 2 years ago Closed 1 year ago

Implement low-power core threads for nsThread/pools

Categories

(Core :: XPCOM, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
111 Branch
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?

(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.

Depends on: 1757474
Blocks: 1757474
No longer depends on: 1757474

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.

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

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.

Attachment #9282235 - Attachment is obsolete: true
Attachment #9282236 - Attachment is obsolete: true
Attachment #9276844 - Attachment description: WIP: Bug 1748378 - Create a way to deprioritize threadpools. → Bug 1748378 - Create a way to deprioritize threadpools.
Blocks: 1805932
Attachment #9276844 - Attachment description: Bug 1748378 - Create a way to deprioritize threadpools. → WIP: Bug 1748378 - Create a way to deprioritize threadpools.
Attachment #9276844 - Attachment description: WIP: Bug 1748378 - Create a way to deprioritize threadpools. → Bug 1748378 - Create a way to deprioritize threadpools.
Pushed by kwright@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/705ee67c7392
Create a way to deprioritize threadpools. r=nika
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 111 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: