Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Frame Advance (Reverts PR 2396, Fixes issue 8718) #3712

Closed

Conversation

RisingFog
Copy link
Member

This reverts PR #2396, which caused frame advance to unpause randomly instead of properly stepping through frames.

This fixes issue 8718: https://bugs.dolphin-emu.org/issues/8718

Review on Reviewable

@lioncash
Copy link
Member

lioncash commented Mar 5, 2016

So, uh, yeah, what about the part where that fixes a race condition?

I honestly couldn't care less about TASers abilities to frame advance if it means reintroducing a data race

@RisingFog
Copy link
Member Author

That PR fixed one race condition and introduced a much more obvious race condition.

If we're wanting to release stable any time soon, we need to get the current issues out of the way. As far as I know, reverting this PR reverts to behaviour from 4.0.2, and can be addressed once 5.0 is released.

@lioncash
Copy link
Member

lioncash commented Mar 5, 2016

I disagree with fixing a race condition by reverting to another one that's less significant. Consider actually fixing the underlying issue.

@RisingFog RisingFog closed this Mar 5, 2016
@RisingFog
Copy link
Member Author

Re-opening this PR while I look into a better solution.

@RisingFog
Copy link
Member Author

I'm still working on getting a Linux setup in place to do some further debugging on the issue.

After getting some more information on the original PR, it appears that it was to fix issues when debugging the JIT. I'm not sure if this issue would happen on normal operation.

@RisingFog
Copy link
Member Author

After finally setting up my linux environment, I did some testing with tsan enabled.

I didn't find any races relating to the original PR, but I did find a few race conditions which should be looked at in separate PRs.

@RisingFog RisingFog changed the title Revert Fix a race condition when pausing the CPU core. Fix Frame Advance (Reverts PR 2396, Fixes issue 8718) Mar 15, 2016
@RisingFog
Copy link
Member Author

@dolphin-emu-bot rebuild

@delroth delroth added this to the Dolphin Release 5.0 milestone Mar 26, 2016
@RisingFog
Copy link
Member Author

This is clearly not the correct method of fixing this, closing this PR.

@RisingFog RisingFog closed this Apr 5, 2016
@RisingFog
Copy link
Member Author

After some debate on IRC, re-opening yet again.

@RisingFog RisingFog reopened this Apr 11, 2016
@EmptyChaos
Copy link
Contributor

The problem appears to be a race condition in CPU::EnableStepping + Core::GetState. Core::GetState returns CORE_PAUSED when CPU::IsStepping returns true but PowerPC::Pause happens first in CPU::EnableStepping(false) before the FIFO is paused. This enables a race condition where Movie::DoFrameStep tries to set SetState(CORE_RUN) on the GUI Thread before the SetState(CORE_PAUSED) in Movie::FrameUpdate has finished on the GPU Thread and the FIFO then gets stuck in the Fifo::EmulatorState(false) state.

@phire
Copy link
Member

phire commented Apr 12, 2016

Of course, the solution to race conditions is always more locks.

@EmptyChaos
Copy link
Contributor

Another problem: In Single Thread mode, Movie::FrameUpdate's Core::SetState(CORE_PAUSE) will deadlock itself since PowerPC::Pause will wait on s_state_change to be set by FinishStateMove which is not going to happen in a combined CPU-GPU thread.

Currently it happens to work through a desynchronization bug — the FinishStateMove from the previous Movie::FrameUpdate will linger in s_state_change causing the WaitFor to succeed when it should not, but the first Frame Advance will always deadlock. The desynchronization bug causes the profiling bug from 2396 to resurface.

@RisingFog
Copy link
Member Author

http://hastebin.com/imixevowup.xml

This was the tsan trace I was able to get yesterday with the current master with frame advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants