Commit graph

1039 commits

Author SHA1 Message Date
Eladash
7ff4509858 sys_lwcond: Fix a loose notification in cond wait 2022-08-11 12:44:40 +03:00
Eladash
f2997e4c00 LV2: Fix the most annoying race ever
Timeline of the race:
1. The PPU is in SLEEP state. state = suspend.
2. lv2_obj::awake is called on the traced thread and is now in ONPROC state, state = signal.
3. lv2_obj::awake is called by another thread externally with a priority higher than our traced thread and appends it to g_pending. state = suspend + signal.
4. lv2_obj::sleep/set_priority (higering priority) is called on any thread which is in ONPROC. Causing it to enter SLEEP or RUNNING state, while the traced thread is back in queue in ONPROC. state = suspend + signal.
5. The traced thread finally calls lv2_obj::awake on itself, g_pending decrements to 0 and we a have a rescheduling event, after XOR state = 0!!! (no signal)
6. In check_state: cpu_sleep_called is now true and remains this way.
7. Another thread with a higher prioty kicks in and appends the traced thread into g_pending. state = suspend.
8. The traced thread is at cpu_thread::cpu_wait(), and that's where it's gonna spend the rest of its life.
2022-08-11 12:44:40 +03:00
Eladash
683c1a6512 LV2: Optimize sys_ppu_thread a bit 2022-08-11 11:42:16 +03:00
Eladash
9b0d33048c Savestates/LV2: Fix race on _sys_lwcond_queue_wait saving
cpu_flag::again modification requires exclusive access.
2022-08-11 11:42:16 +03:00
Eladash
bc8bf2c329 sys_cond/lwcond: Fix waiting time in the debugger for mutex lock 2022-08-11 11:42:16 +03:00
Elad Ashkenazi
f0002501f7 sys_mutex/lwmutex: Regression fixes after #12378 2022-08-11 11:42:16 +03:00
Elad Ashkenazi
c4cc0154be LV2: Optimizations and fixes
Fix and optimize sys_ppu_thread_yield

Fix LV2 syscalls with timeout bug. (use ppu_thread::cancel_sleep instead)

Move timeout notification out of mutex scope

Allow g_waiting timeouts to be awaked in scope
2022-08-11 11:42:16 +03:00
Eladash
26e731b487 LV2: Re-add dropped optimization by previous commit
Currently only for lock-free syscalls.
2022-08-07 20:23:54 +03:00
Eladash
34bae90820 LV2: Move nearly all notifications out of all mutex scopes including IDM 2022-08-07 20:23:54 +03:00
Eladash
011aabe9ed LV2: Make sys_mutex and sys_lwmutex lock-free, add some busy waiting in sys_mutex_lock 2022-08-07 20:23:54 +03:00
Eladash
a17a6527f6 LV2: Move memory unlocking outside of mutex ownership and make it conditional 2022-08-07 20:23:54 +03:00
Eladash
73aaff1b29 LV2: allocation-free synchronization syscalls
* Show waiters' ID in kernel explorer.
* Remove deque dependency from sys_sync.h
2022-08-07 20:23:54 +03:00
Eladash
c7fbc16357 SPU: Postpone notifications to afterward group mutex ownership 2022-08-07 20:23:54 +03:00
Eladash
bc728db15b LV2: Add busy waiting before entering atomic wait 2022-08-07 20:23:54 +03:00
Eladash
2eebbd307d LV2: Minor optimization regarding signal flag 2022-08-07 20:23:54 +03:00
Eladash
dc851a729e LV2: Postpone thread notifications to afterward mutex ownership(s) 2022-08-07 20:23:54 +03:00
Eladash
6007fd630f Do not use lv2_obj::g_waiting when not needed in sys_timer_usleep 2022-08-07 20:23:54 +03:00
Elad Ashkenazi
88b80ebdf5
sys_net: Fix missing locks in some syscalls (#12459) 2022-08-04 21:31:34 +03:00
Elad Ashkenazi
0e1931f178
sys_lwcond: Fix rare race on mode 3 signal (#12413) 2022-08-04 14:13:51 +03:00
Eladash
bb9ae18c71 Savestates: Fix sys_rwlock_wunlock saving 2022-07-20 18:11:52 +03:00
Eladash
ce01457510 Fix futile wait regression in sys_lwcond_signal 2022-07-20 18:11:52 +03:00
Eladash
d106934336 Savestates: Fix saving sys_mutex_unlock 2022-07-19 10:43:51 +03:00
Eladash
c887865d54 Perform cleanup after Emulator::Load failures 2022-07-19 10:43:51 +03:00
Eladash
dc48944979 Prefer BDVD over HDD0 in vfs::retrieve 2022-07-19 10:43:51 +03:00
Eladash
12ebf77e22 Savestates: save sys_spu_initialize settings 2022-07-19 10:43:51 +03:00
Eladash
c0369b2e10 sys_net: Implement sys_net_abort 2022-07-17 14:53:03 +03:00
Eladash
e548743cbf Fixup rsx cpatures 2022-07-14 18:50:31 +03:00
Eladash
cdd6840826 Savestates/SPU: Complete fix for saving sys_spu_thread_receive_event 2022-07-12 15:15:42 +03:00
Eladash
befd7ceb89 Savestates/sys_spu: Minor fix in saving sys_spu_thread_receive_event 2022-07-10 14:19:59 +03:00
Vestrel
98b730c806
Audio: device switching and channel count detection (#12246) 2022-07-08 17:13:38 +02:00
Nekotekina
4b787b22c8 Implement FN (lambda shortener)
Useful for some higher order functions.
Allows to make short lambdas even shorter.
2022-07-08 14:47:41 +03:00
Eladash
3a9928de65 Savestates: Log file descriptor information 2022-07-08 12:57:43 +03:00
Eladash
1fd5fb2f7e Savestates: Fix minor race with LV2 timers 2022-07-08 12:57:43 +03:00
Eladash
5f8f9e33f1 RSX/Savestates: Replace GCM hack with a proper fix 2022-07-08 12:57:43 +03:00
Eladash
f0c71ae2ae Savestates: Fix saving sys_event_queue_destroy 2022-07-08 12:57:43 +03:00
Eladash
d8f3029952 Log LV2 periodic timers 2022-07-06 19:43:25 +03:00
Eladash
09c28f75b3 Savestates: Fix LV2 timers (fixes audio in some games) 2022-07-06 19:43:25 +03:00
Eladash
b692108f1e Savestates: HLE state saving POC in sys_lwmutex 2022-07-06 19:43:25 +03:00
Eladash
bd9ba7ef1f Remove incorrect Emu.IsStopped() checks 2022-07-05 08:25:36 +02:00
Eladash
a015bd1ebd Savestates: Add missing position placement 2022-07-05 08:25:36 +02:00
Eladash
3fc2194fd5 Savestates: Fix zombie PPU threads saving 2022-07-05 08:25:36 +02:00
Elad Ashkenazi
fcd297ffb2
Savestates Support For PS3 Emulation (#10478) 2022-07-04 16:02:17 +03:00
Eladash
f66256cc13 rsx: PS3 Native frame limiter improvements, add Infinite frame limiter
* Do not wait on DEVICE 0x30 semaphore, it seems like it is something to do with queue command synchronization.
 - This also fixes cellGcmSetFlipWithWaitLabel which is built specifically to enable accurate RSX flipping time, its waiting command is confirmed to be placed **AFTER** DEVICE 0x30 waiting.
* Fix default vsync state to be enabled. (and set it to enabled in cellGcmSetVBlankFrequency as well)
* Add experimental "Infinite" frame limiter mode.
* Fix spurious enabling of second vblank.
2022-06-25 15:30:41 +02:00
Nekotekina
ea23525f66 sys_fs: Add mountpoint for /dev_ps2disc 2022-06-24 19:55:44 +03:00
Eladash
64399d45c1 vm: Make falloc return value bool
Allow to check properly for the success of 0 address allocation.
2022-06-22 21:01:37 +03:00
Eladash
71e07dc6c7 IdManager.h: Improvements
* Ensure ::PtrSame<T, Derived> is true.
* Allow id_base, id_step and id_count to be of enumeration type.
* Fix potential deadlock in kernel explorer.

idm::select:
* Allow to select multiple inherited object types for idm::select.
* Allow function reference types. (they don't allow access to operator() directly, use deducing std::function constructor instead)
* Ensure ::is_same_ptr<T, object_type> is true.
2022-06-22 17:24:47 +03:00
Jeff Guo
cefc37a553
PPU LLVM arm64+macOS port (#12115)
* BufferUtils: use naive function pointer on Apple arm64

Use naive function pointer on Apple arm64 because ASLR breaks asmjit.
See BufferUtils.cpp comment for explanation on why this happens and how
to fix if you want to use asmjit.

* build-macos: fix source maps for Mac

Tell Qt not to strip debug symbols when we're in debug or relwithdebinfo
modes.

* LLVM PPU: fix aarch64 on macOS

Force MachO on macOS to fix LLVM being unable to patch relocations
during codegen. Adds Aarch64 NEON intrinsics for x86 intrinsics used by
PPUTranslator/Recompiler.

* virtual memory: use 16k pages on aarch64 macOS

Temporary hack to get things working by using 16k pages instead of 4k
pages in VM emulation.

* PPU/SPU: fix NEON intrinsics and compilation for arm64 macOS

Fixes some intrinsics usage and patches usages of asmjit to properly
emit absolute jmps so ASLR doesn't cause out of bounds rel jumps. Also
patches the SPU recompiler to properly work on arm64 by telling LLVM to
target arm64.

* virtual memory: fix W^X toggles on macOS aarch64

Fixes W^X on macOS aarch64 by setting all JIT mmap'd regions to default
to RW mode. For both SPU and PPU execution threads, when initialization
finishes we toggle to RX mode. This exploits Apple's per-thread setting
for RW/RX to let us be technically compliant with the OS's W^X
    enforcement while not needing to actually separate the memory
    allocated for code/data.

* PPU: implement aarch64 specific functions

Implements ppu_gateway for arm64 and patches LLVM initialization to use
the correct triple. Adds some fixes for macOS W^X JIT restrictions when
entering/exiting JITed code.

* PPU: Mark rpcs3 calls as non-tail

Strictly speaking, rpcs3 JIT -> C++ calls are not tail calls. If you
call a function inside e.g. an L2 syscall, it will clobber LR on arm64
and subtly break returns in emulated code. Only JIT -> JIT "calls"
should be tail.

* macOS/arm64: compatibility fixes

* vm: patch virtual memory for arm64 macOS

Tag mmap calls with MAP_JIT to allow W^X on macOS. Fix mmap calls to
existing mmap'd addresses that were tagged with MAP_JIT on macOS. Fix
memory unmapping on 16K page machines with a hack to mark "unmapped"
pages as RW.

* PPU: remove wrong comment

* PPU: fix a merge regression

* vm: remove 16k page hacks

* PPU: formatting fixes

* PPU: fix arm64 null function assembly

* ppu: clean up arch-specific instructions
2022-06-14 15:28:38 +03:00
RipleyTom
da6434a65a
Implements sys_fs_fcntl 0xC0000008 & 0xC000001A (#11957) 2022-06-11 13:12:42 +01:00
Megamouse
2a1e3b2b77 sys_rsxaudio: use max channel count from configured sound_modes 2022-06-09 18:59:13 +02:00
Megamouse
61823a5d62 sys_rsxaudio: only update config if the fxo is initialized 2022-06-09 18:59:13 +02:00