Open Bug 2090731 Opened 11 days ago Updated 10 days ago

Timers in child processes fire late after waking from sleep on Windows

Categories

(Core :: XPCOM, defect)

defect

Tracking

()

ASSIGNED

People

(Reporter: jstutte, Assigned: jstutte)

References

(Blocks 1 open bug)

Details

Attachments

(7 external files)

On Windows, TimeStamp (QPC) counts system sleep, but the timer thread waits on a relative waitable timer, which since Windows 8 does not count down while the computer is asleep (SetWaitableTimerEx). After a wake, timers that became due during sleep are overdue, but the timer thread keeps waiting for the rest of its pre-sleep wait.

The parent process handles this: wake_notification makes TimerThread::DoAfterSleep recompute the wait. Child processes never get wake_notification, so their overdue timers fire only once the old wait runs out or something else re-arms the timer thread (a new timer, for instance). This comes from reading the code and has not been measured.

The same applies to macOS, Linux and Android once TimeStamp counts sleep there (bug 1204823), so this bug also prepares for that change.

The patches:

  • forward wake_notification (wake only, not sleep) from the parent to content, GPU, RDD and utility processes
  • handle it only in the parent's nsIOService, which already forwards the resulting link change
  • stop ignoring wake notifications in the macOS timer thread (the pref becomes timer.ignore_sleep_notifications and only covers sleep)
  • treat application-foreground as a wake on Android, which has no wake notification

Once TimeStamp counts sleep on macOS (bug 1204823), the timer thread, which
waits on a clock that does not, needs the wake notification to recompute its
wait. Only sleep notifications stay ignored on macOS, as they may come without
a matching wake notification. The pref is renamed to match its narrower
meaning.

The following patches forward wake_notification to child processes. The
network change and captive portal recheck it triggers in nsIOService are
parent-only work, and the parent already forwards the link change to content
processes.

Assignee: nobody → jstutte
Status: NEW → ASSIGNED

Timers that became due during sleep only fire promptly after wake when the
timer thread gets wake_notification, which so far only the parent process
receives. On Windows, child process timers can already fire late after wake
today, as TimeStamp counts sleep but the timer thread's relative waitable timer
does not.

Content processes now also skip input event telemetry for events from before
the wake, as the parent already does.

Its timer thread waits on a clock that does not advance during sleep, so like
content processes it needs the wake notification to fire timers that became
due while the system was asleep.

Its timer thread waits on a clock that does not advance during sleep, so like
content processes it needs the wake notification to fire timers that became
due while the system was asleep.

Their timer threads wait on a clock that does not advance during sleep, so
like content processes they need the wake notification to fire timers that
became due while the system was asleep.

Android has no system wake notification, and the device usually sleeps while
Firefox is in the background. So the timer thread handles
application-foreground like wake_notification, and the parent forwards it to
the GPU, RDD and utility processes as a wake. Content processes already get
application-foreground.

This only matters once TimeStamp counts sleep on Android (bug 1204823).

Attachment #9677406 - Attachment description: WIP: Bug 2090731 Part 1 - Handle wake notifications in TimerThread on macOS. r?#xpcom-reviewers → Bug 2090731 Part 1 - Handle wake notifications in TimerThread on macOS. r?#xpcom-reviewers
Attachment #9677407 - Attachment description: WIP: Bug 2090731 Part 2 - Only handle wake_notification in the parent's nsIOService. r?#necko-reviewers → Bug 2090731 Part 2 - Only handle wake_notification in the parent's nsIOService. r?#necko-reviewers
Attachment #9677408 - Attachment description: WIP: Bug 2090731 Part 3 - Forward wake_notification to content processes. r?#dom-reviewers → Bug 2090731 Part 3 - Forward wake_notification to content processes. r?#dom-reviewers
Attachment #9677409 - Attachment description: WIP: Bug 2090731 Part 4 - Forward wake_notification to the GPU process. r?#gfx-reviewers → Bug 2090731 Part 4 - Forward wake_notification to the GPU process. r?#gfx-reviewers
Attachment #9677410 - Attachment description: WIP: Bug 2090731 Part 5 - Forward wake_notification to the RDD process. r?#media-playback-reviewers → Bug 2090731 Part 5 - Forward wake_notification to the RDD process. r?#media-playback-reviewers
Attachment #9677411 - Attachment description: WIP: Bug 2090731 Part 6 - Forward wake_notification to utility processes. r?#ipc-reviewers → Bug 2090731 Part 6 - Forward wake_notification to utility processes. r?#ipc-reviewers
Attachment #9677412 - Attachment description: WIP: Bug 2090731 Part 7 - Treat returning to the foreground as a wake on Android. r?#xpcom-reviewers,#geckoview-reviewers → Bug 2090731 Part 7 - Treat returning to the foreground as a wake on Android. r?#xpcom-reviewers,#geckoview-reviewers
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: