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

Rewrite waitable atomics #9117

Merged
merged 8 commits into from Oct 24, 2020
Merged

Rewrite waitable atomics #9117

merged 8 commits into from Oct 24, 2020

Conversation

Nekotekina
Copy link
Member

Relatively big change to waitable atomics.

  1. Don't return prematurely if condition is not met (does not affect ones with set timeout).
  2. Use one semaphore per thread. This seems to improve efficiency in some scenarious for little sacrifice.

@dio-gh
Copy link
Contributor

dio-gh commented Oct 23, 2020

I was reached out to by friends on Discord, that you wanted this PR tested in relation to #8363.

I tested the latest PR build against the latest master build, and the issue persists:

image

On the left half of the frametime graph the game window was focused, on the right half the game window was unfocused. This is the same as on master.

Please mention the issue through Github next time instead, if you want it tested by those affected.

@Nekotekina
Copy link
Member Author

Nekotekina commented Oct 23, 2020

Ahh that's unfortunate, but thank you for testing. I have other ideas in mind.

@Nekotekina
Copy link
Member Author

Added new Win8+ API path which may dramatically change performance for everyone.
@dio-gh can be worth retesting.

@dio-gh
Copy link
Contributor

dio-gh commented Oct 24, 2020

Checked with the latest commit, the game (Demon's Souls) hangs on loading now. I also didn't notice an improvement sadly, but I couldn't check properly due to said hang. Gonna go sleep now.

RPCS3.log.zip

Edit: uploaded a new log, cause I originally had logging off.

@Nekotekina
Copy link
Member Author

Last version seems working!

Use individual semaphore for each thread.
Unfortunately, limit max thread waiting for single address (60).
If limit is reached, use busy waiting.
Try non-blocking wake up function first.
Using raw_notify() everywhere was overkill.
Some of them are available only since Windows 8.
@dio-gh
Copy link
Contributor

dio-gh commented Oct 24, 2020

Color me impressed, the latest commit resolves most of #8363!

image

Demon's Souls is now working better than ever on my system.

A curious case to look at would be F1 Race Stars though. The game suffers massively from scheduling issues, it used to be that it'd run seamlessly unfocused, and lag then hang catastrophically when focused. That situation has improved with this, but I noticed that it's also having issues unfocused now. Whether this is due to the PR's changes, or the past months' master changes, I'm yet to test. Gonna go do that now.

Update: Seems like it's the latter, so this PR is a net improvement. 🎉 I can open a separate ticket for F1 Race Stars if preferred, since that's definitely an odd one out game.

Update 2: Tested another game called Dead Nation. There still seems to be a discrepancy between focused and unfocused unfortunately, but it's a lot milder now. I also asked for a retest in the original issue ticket, and a user already reported that they're still having issues; therefore, I'll keep the ticket open. Thanks for the fixes though, this is already a major step forward.

Win7 will remain using old API (keyed events).
@legend800
Copy link

This broke SW Force Unleashed 2:
#9199

elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 16, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 16, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 16, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 16, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 16, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 16, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 16, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 16, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 16, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 16, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 17, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Dec 17, 2020
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
elad335 added a commit to elad335/rpcs3 that referenced this pull request Feb 12, 2021
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
* Added some thread_ctrl::wait_on to fix emulation stopping.
elad335 added a commit to elad335/rpcs3 that referenced this pull request Feb 12, 2021
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
* Added some thread_ctrl::wait_on to fix emulation stopping.
elad335 added a commit to elad335/rpcs3 that referenced this pull request Feb 12, 2021
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by RPCS3#9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
* Remove cpu_flag::dbg_global_stop, use cpu_flag::exit instead. (essentially a duplicated flag)
* Added some thread_ctrl::wait_on to fix emulation stopping.
Nekotekina pushed a commit that referenced this pull request Feb 13, 2021
* Use atomic waitables instead instead of global thread wait as often as possible.
* Add ::is_stopped() and and ::is_paued() which can be used in atomic loops and with atomic wait. (constexpr cpu flags test functions)
* Fix notification bug of sys_spu_thread_group_exit/terminate. (old bug, enhanced by #9117)
* Function time statistics at Emu.Stop() restored. (instead of current "X syscall failed with 0x00000000 : 0")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants