-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Core: Add synchronization to state changes (Fix Frame Step and FIFO Player - Issue 8718) #3794
Conversation
37aac62
to
cfd87ce
Compare
This looks like a great alternative to saying "HACK IT." |
Review status: 0 of 28 files reviewed at latest revision, 9 unresolved discussions. Source/Core/Core/Core.cpp, line 737 [r1] (raw file): Source/Core/Core/Core.h, line 55 [r1] (raw file): Source/Core/Core/Movie.cpp, line 1436 [r1] (raw file): Source/Core/Core/Movie.cpp, line 1458 [r1] (raw file): Source/Core/Core/HW/CPU.cpp, line 25 [r1] (raw file): Source/Core/Core/HW/DVDInterface.cpp, line 481 [r1] (raw file): Source/Core/Core/PowerPC/PowerPC.cpp, line 259 [r1] (raw file): Source/Core/Core/PowerPC/PowerPC.cpp, line 275 [r1] (raw file): Source/Core/Core/PowerPC/PowerPC.cpp, line 287 [r1] (raw file): Comments from Reviewable |
cfd87ce
to
b98bb95
Compare
Review status: 0 of 28 files reviewed at latest revision, 9 unresolved discussions. Source/Core/Core/Core.cpp, line 737 [r1] (raw file): Source/Core/Core/Core.h, line 55 [r1] (raw file): Source/Core/Core/Movie.cpp, line 1436 [r1] (raw file): Source/Core/Core/Movie.cpp, line 1458 [r1] (raw file): Source/Core/Core/HW/CPU.cpp, line 25 [r1] (raw file): Source/Core/Core/HW/DVDInterface.cpp, line 481 [r1] (raw file): Source/Core/Core/PowerPC/PowerPC.cpp, line 259 [r1] (raw file): Source/Core/Core/PowerPC/PowerPC.cpp, line 275 [r1] (raw file): Source/Core/Core/PowerPC/PowerPC.cpp, line 287 [r1] (raw file): Comments from Reviewable |
b98bb95
to
81bf1ff
Compare
Hint, putting Reviewed 20 of 28 files at r1, 6 of 6 files at r2. Source/Core/Core/Core.cpp, line 529 [r2] (raw file): Source/Core/Core/Core.h, line 85 [r2] (raw file): Source/Core/Core/HW/CPU.cpp, line 20 [r2] (raw file): Source/Core/Core/PowerPC/PowerPC.cpp, line 36 [r2] (raw file): Source/Core/Core/PowerPC/PowerPC.cpp, line 307 [r2] (raw file): Source/Core/DolphinWX/MainNoGUI.cpp, line 42 [r2] (raw file): Comments from Reviewable |
@dolphin-emu-bot rebuild |
81bf1ff
to
1e44ab2
Compare
Review status: 7 of 27 files reviewed at latest revision, 2 unresolved discussions. Source/Core/Core/Core.cpp, line 529 [r2] (raw file): The problem is no longer relevant as it's been resolved through other changes. Source/Core/Core/Core.h, line 85 [r2] (raw file): Source/Core/Core/HW/CPU.cpp, line 20 [r2] (raw file): Source/Core/Core/PowerPC/PowerPC.cpp, line 36 [r2] (raw file): Source/Core/Core/PowerPC/PowerPC.cpp, line 307 [r2] (raw file): Source/Core/DolphinWX/MainNoGUI.cpp, line 42 [r2] (raw file): Comments from Reviewable |
1e44ab2
to
05ff4da
Compare
Review status: 7 of 27 files reviewed at latest revision, 1 unresolved discussion. Source/Core/Core/FifoPlayer/FifoPlayer.h, line 55 [r6] (raw file): Comments from Reviewable |
366562a
to
5838481
Compare
Review status: 7 of 27 files reviewed at latest revision, 1 unresolved discussion. Source/Core/Core/FifoPlayer/FifoPlayer.h, line 55 [r6] (raw file): Comments from Reviewable |
5838481
to
0e14272
Compare
This will need a rebase |
da51314
to
bc368e8
Compare
Just to confirm, i can't reproduce the framestop unpause issue anymore with this. Tested with a fifo log and the intro of twilight princess(wii), where i can reproduce the issue reliably on Dolphin 4.0-9251, but not on the buiild from the buildbot based on Dolphin 4.0-9251 and this pr. |
d9c402e
to
dfc3c8f
Compare
I've adjusted the architecture since the original version. I elided Has anyone tested the Android build? I don't have a testing setup for it and the change is mildly complex. I haven't removed |
This seems to need another rebase |
dfc3c8f
to
8db0f40
Compare
Review status: 2 of 28 files reviewed at latest revision, 6 unresolved discussions. Source/Core/Core/FifoPlayer/FifoPlayer.cpp, line 66 [r12] (raw file):
explicit CPUCore(FifoPlayer* parent) Source/Core/Core/HW/CPU.cpp, line 63 [r12] (raw file):
Inline isn't necessary here, since it's static. Source/Core/Core/HW/CPU.cpp, line 151 [r12] (raw file):
Ditto Source/Core/Core/HW/CPU.cpp, line 211 [r12] (raw file):
Ditto Source/Core/Core/PowerPC/PowerPC.h, line 167 [r12] (raw file):
Is there any reason why these are here in the header instead of being called/accessed 'long-form'? (or being put in the .cpp file) PowerPC.h is used in a lot of places, and some of them don't actually need these within the namespace (especially if it's pulling things in from another namespace). Source/Core/DolphinQt2/Main.cpp, line 26 [r12] (raw file):
Unnecessary space Comments from Reviewable |
@mimimi085181 I'm not opposed to it being merged, provided adequate testing by others for potential subtle regressions is done (it would be nice to include in 5.0, to be honest, since it'd make for a better stable release for TASers). Some external testing from a few different people might be nice (for example, via other TASers, just to make sure it quashes all of their problems with frame stepping, etc).
|
I don't see much of an issue source wise, other than the ones @lioncash already pointed out. But tbh, I only skimmed thru them and don't have as much time to spend as I'd like...
|
@EmptyChaos: Can you address the latest comments and rebase on top of lastest master, after pr 3810 was merged? I'd like somebody to post a build of this in the TAS community, so both TAS related changes can be tested with one build. |
If someone needs testing, I'll do it. I'm a TASer from TASVideos and ready to test your Work-in-Progress builds. (Sorry if my english is bad) |
Fix Frame Advance and FifoPlayer pause/unpause/stop. CPU::EnableStepping is not atomic but is called from multiple threads which races and leaves the system in a random state; also instruction stepping was unstable, m_StepEvent had an almost random value because of the dual purpose it served which could cause races where CPU::Run would SingleStep when it was supposed to be sleeping. FifoPlayer never FinishStateMove()d which was causing it to deadlock. Rather than partially reimplementing CPU::Run, just use CPUCoreBase and then call CPU::Run(). More DRY and less likely to have weird bugs specific to the player (i.e the previous freezing on pause/stop). Refactor PowerPC::state into CPU since it manages the state of the CPU Thread which is controlled by CPU, not PowerPC. This simplifies the architecture somewhat and eliminates races that can be caused by calling PowerPC state functions directly instead of using CPU's (because they bypassed the EnableStepping lock).
Fix TASInputDlg which was trying to access the GUI without the GUI lock from the CPU Thread.
EndPlayInput runs on the CPU thread so it can't directly call UpdateWantDeterminism. PlayController also tries to ChangeDisc from the CPU Thread which is also invalid. It now just pauses execution and posts a request to the Host to fix it instead. The Core itself also did dodgy things like PauseAndLock-ing from the CPU Thread and SetState from EmuThread which have been removed.
8db0f40
to
c1944f6
Compare
@EmptyChaos: Thank you very much. @Dimon12321: Now it's ready for testing. You can download the windows version of the test build from here: Please test if frame advance works properly, if you set frame advance to a hotkey, and use that hotkey instead of the menu option. Also, if you have the Wii U Gamecube Controller adapter, please test with that as well. |
This problem is the 'gift' that keeps on giving. I found a potential race I missed earlier in
|
A very small group of people from TASVideos (and me too) have tested your build already. We don't know what else are you going to change in the build, but now Frame Advance works just fine! We got NO random unpauses. Probably RisingFog will add his word there if needed. |
What's left to be done before this is ready to merge? |
@Dimon12321 Thanks for testing. @RisingFog I think (hope) this is done now, I've resolved all the races I could find. There could be more of course, but I haven't identified any other issues currently. The |
Everyone has been testing and reviewing this for a while and I don't know of any big flaws. TASers have tested it, I've verified it to fix the issues I've run into, and we do know that it fixes some serious bugs and race conditions. The question that remains is: can this affect things that we're not anticipating to cause regressions? Considering that we're trying to gear up for 5.0 and this fixes a blocker, a decision has to be made. If we do decide to merge it, the sooner we merge it the more likely we are to catch any of those potential unanticipated bugs. |
Review status: 2 of 36 files reviewed at latest revision, 1 unresolved discussion. Source/Core/Core/HW/CPU.cpp, line 166 [r13] (raw file):
Now that I look over this again, it's slightly worrying to potentially include this in 5.0 with the small possibility of deadlocks (if this was pre-existing with the old code to begin with, then I don't particularly have a problem here). Comments from Reviewable |
I could deadlock the GUI thread right now through that. I run into the bug all the time. It's not a regression in this Pull Request. |
Review status: 2 of 36 files reviewed at latest revision, 1 unresolved discussion. Source/Core/Core/HW/CPU.cpp, line 166 [r13] (raw file):
|
Alright, given this fixes quite a few races and underlying issues, as well as making stable a much better experience for TASers (and if any regressions related to TASing happens in later dev versions, at least they have a more modern stable release to fall back to as a last resort), I'd like to include this in 5.0. Particularly because it handles a deadlock case more gracefully than what master currently does. I'll give everyone 24 hours to leave concerns or arguments against doing this.
|
Triggered the gui"crash" in this build; it recovered after a while and I didn't lost all my progress in "Bratz: Rock Angelz" I'm now heavily, heavily favoring merging this. It works around a crash I see 3 - 5 times a week in Dolphin! |
Grace period is over with no objections. |
[Needs PR #3769 as well]Alternative to #3712 that fixes the underlying race. The basic problem is that
CPU::EnableStepping
is a non-atomic function that was only designed to be called from the Host thread so it races when called from the CPU/GPU or any other system thread. One thread will go through and stop the CPU, mute the audio and pause the FIFO while the other unpauses the CPU, unmutes the audio and unpauses the FIFO resulting in a random final state (e.g. CPU running with no video, CPU and video running with no audio). Other functions which depend onEnableStepping
likeCore::SetState
andCPU::Break
inherit those bugs.This PR makes the implicit design choices explicit:
CPU::EnableStepping
,Core::SetState
andCore::PauseAndLock
are now Host thread only.CPU::Break
has been rewritten as a threadsafe way for system threads to doEnableStepping(true)
only.I've removed the anti-deadlock hack (lock timeout) for testing purposes but that needs to go back in before this can be merged.A known source of deadlocks iswxMsgAlert
(CPUPanicAlert
s, GUI tries to CORE_PAUSE/PauseAndLock/EnableStepping and deadlocks waiting for the CPU waiting for the GUI waiting for the CPU...), this is somewhat intractable to fix since it requires one of 1) removing wxMsgAlert entirely, 2) shifting Core::SetState/CPU::EnableStepping/Core::PauseAndLock calls onto a dedicated background thread so that the GUI never calls a blocking Core function directly, or 3) spawning an external helper process to display the messages.This change is