dolphin icon indicating copy to clipboard operation
dolphin copied to clipboard

BlockingLoop: cleanup Run() logic using compare_exchange_strong

Open ligfx opened this issue 8 years ago • 13 comments

Rather than trying to manually handle state changes that might have occurred between a load and a store, use std::atomic's compare_exchange_strong. Also changes the state machine from Need Execution -> Last Execution -> Done -> Sleeping to Need Execution -> Executing -> Done -> Sleeping.

BlockingLoopTest takes the same amount of time to run before and after this change (~260ms on my computer).

ligfx avatar Aug 30 '17 19:08 ligfx

LGTM, but I'm bad at atomics, so maybe someone else should review it as well.

degasus avatar Sep 05 '17 07:09 degasus

If you were testing on x86, it makes sense that you saw no perf difference, because the generated code should be literally identical; x86 has no concept of weak atomic updates (which accurately indicate success/failure). Changes that deal with atomic semantics should be tested, but they only really need to be tested on arm.

shuffle2 avatar Sep 06 '17 16:09 shuffle2

@shuffle2 Can you explain that a bit more? As written, this PR only uses strong atomic updates.

ligfx avatar Oct 19 '17 00:10 ligfx

@ligfx in a previous comment you say you tested weak/strong and didn't see a perf difference. That's because there is literally no difference on x86. If you want to tweak the semantics for perf and maintain proper behavior, you'd need to test on an architecture where it will actually make a difference in the first place.

shuffle2 avatar Oct 19 '17 22:10 shuffle2

Ah, I see what you mean. Does the current state of the PR need to be tested on ARM, though, or is just x86 okay? I'm not planning on introducing weak atomic semantics at this point.

ligfx avatar Oct 19 '17 22:10 ligfx

Yea, shouldn't need special care on ARM then.

shuffle2 avatar Oct 19 '17 23:10 shuffle2

Please merge.

This allows Rogue Squadron 3 to get in game again!

nbohr1more avatar Apr 12 '18 01:04 nbohr1more

This wasn't intended to change any logic, merely to clean up the code. If it is changing something that's most likely a bug (unless it inadvertently fixed a bug, which seems less likely). @nbohr1more do you have a bug report you can link to?

ligfx avatar Apr 12 '18 19:04 ligfx

I couldn't find an existing bug report but I can create one.

This patch makes the loading behavior more correct.

Currently, if you try to load the Speeder Bike level in master you will be greeted by an infinite buzz sound and black screen after the cut scene.

With this change, you can get in-game and play if you let the cut scene play and if you cancel the cut-scene you have a black screen but in-game audio plays.

So it seems to be more correct than master.

nbohr1more avatar Apr 13 '18 18:04 nbohr1more

@nbohr1more are you comparing master + these commits to master, or the auto-created build for this pull request against master?

shuffle2 avatar Apr 14 '18 05:04 shuffle2

Manual rebuild:

  1. In this PR, I expand "Show all checks"
  2. Scroll down to pr_win-x64 and click details
  3. Click the Rebuild button in the upper right
  4. Download the build from step 8 (upload)

nbohr1more avatar Apr 15 '18 03:04 nbohr1more

It seems like the "details" link next to pr-win-x64 doesn't go to the related page (check the Build Properties tab on the buildbot page).
In any case, I don't think triggering a rebuild would rebase the PR commits onto master, anyways (you're just seeing a change in behavior between this PR's base revision and current master).

cc @delroth for the buildbot links...

shuffle2 avatar Apr 15 '18 04:04 shuffle2

Rebase?

Zopolis4 avatar Feb 17 '23 05:02 Zopolis4