Repository navigation
GPU decoders 0.3.7: a session from before a sleep keeps decoding, rebuilt at its next key frame - #160
Merged
Merged
Conversation
…again A user reports that with the AV1 and VP9 decoders a wake from sleep hangs the Mac a while later, with glitches first, and that right after a wake a VP9 video was red and broken in Chrome while Safari played it fine. His log shows Chrome's decoder process keeping two VP9 sessions open across the sleep, an AV1 session it opened after the wake never decoding a frame, and the hang after the next wake. Read in IDA (AMDRadeonX6000, 26.7.3 KDK): the kernel keeps a decoder's video context across a sleep but stops the VCN rings before it (systemWillSleep -> setSuspendResumeState(false)) and starts the engine again at wake (powerUpHW, internalDidWake -> enableContext), restoring only clocks and the power client; saveVCNSession is empty. Nothing tells the program: AMDRadeonVADriver2, AppleGVA and VideoToolbox have no sleep handling. AMDRadeonVADriver2 sends the engine a create-session command when a decoder opens and a destroy-session command, waited for with no time limit, when it closes. So, in decode/common: - vcn_sleep_mark: the time spent asleep since boot (mach_continuous_time minus mach_absolute_time) and kern.waketime. No notification: the decoder service's sandbox does not allow the user client IORegisterForSystemPower opens. - vcn_session_lost: a session opened before a sleep writes nothing more into its bitstream pool and schedules nothing; its frames fail as a malfunction, so VideoToolbox makes a new session. - vcn_session_close of such a session skips DeleteContexts, FreeBitstreamBufferPool and DeleteDriver and only destroys the accelerator, on the background queue; the kernel's close of the video context sends the engine nothing. - vcn_session_open refuses while a session of the same process from before a sleep is still open, in any of the plug-ins (they ask each other through the local notification center): VideoToolbox decodes in software until those are closed. AV1, VP9 and the legacy decoders call it. vtvp9test gets -renew and a line per pass, vtav1test -loop and -renew, for a sleep test. New tests: sessiontest section 12 and staletest (two plug-ins in one process), with a made-up sleep. Not run on a GPU or across a real sleep.
A session that finds the system slept since it opened now drops its old driver objects without sending them anything, opens a new driver, context and buffer pool in the same plug-in session, and drops frames until a key frame. The sleep is also noticed when the wall clock runs ahead of mach_absolute_time, and kern.waketime is read at most every 100 ms. Sessions from before a sleep no longer stop new ones from opening; they are counted once per process for the log. The loss is checked before a frame takes a picture slot.
…uilt at its next key frame A real sleep test showed 0.3.6 failing every frame of the sessions open across the sleep, while 0.3.5 kept decoding them correctly. The AV1 and VP9 sessions now keep decoding after a sleep and replace their driver objects at the next key frame that refreshes every reference, with no frame dropped. Only when the old session fails after the wake is it rebuilt at once, dropping frames up to a key frame. A command on the old session may take 15 s before it is given up on. -12911 is left for a rebuild that fails.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
0.3.6 turned out worse in a real sleep test: the sessions that stayed open across the sleep failed every frame, while 0.3.5 kept decoding them fine.
So 0.3.7 goes the other way. An AV1 or VP9 session that was open before a sleep keeps decoding, and swaps its driver objects for new ones at the next key frame that refreshes every reference, so no frame is dropped. Only if the old session actually fails after the wake is it rebuilt right away, dropping frames until a key frame. New sessions are no longer refused because of old ones in the same process.
Host tests pass (made-up driver: sleep, rebuild at a key frame, hidden frames, stuck GPU). Not tested yet across a real sleep on the card.