High/Low level emulation: Difference between revisions

Ahayri (talk | contribs)
No edit summary
Ahayri (talk | contribs)
Line 101: Line 101:
* '''Platform-Specific Memory and I/O Optimization''': Techniques like Fastmem, implemented in [[PCSX2]], Yuzu, and [[Dolphin]], optimize memory operations for significant performance gains by minimizing overhead and improving cache efficiency.<ref>{{cite web|url=https://github.com/PCSX2/pcsx2/pull/5821|title=PCSX2 Pull Request #5821|publisher=GitHub}}</ref><ref>{{cite web|url=https://github.com/PCSX2/pcsx2/pull/7295|title=PCSX2 Pull Request #7295|publisher=GitHub}}</ref><ref>{{cite web|url=https://web.archive.org/web/20240229141516/https://yuzu-emu.org/entry/yuzu-fastmem/#what-is-fastmem|title=What is Fastmem?|publisher=Yuzu}}</ref><ref>{{cite web|url=https://dolphin-emu.org/blog/2016/09/06/booting-the-final-gc-game/|title=Booting the Final GC Game|publisher=Dolphin Emulator}}</ref> Modern emulators leverage platform-specific APIs for these, allocate memory and optimize I/O performance. On Windows; functions like <code>VirtualAlloc2</code> and <code>MapViewOfFile3</code> provide fine-grained control over virtual memory regions.<ref>{{cite web|url=https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc2|title=VirtualAlloc2|publisher=Microsoft}}</ref><ref>{{cite web|url=https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffile3|title=MapViewOfFile3|publisher=Microsoft}}</ref> On Unix-like systems; emulators utilize POSIX functions such as <code>mmap()</code> for memory mapping and <code>madvise()</code> with flags like <code>MADV_DONTNEED</code> and <code>MADV_REMOVE</code> to provide hints to the kernel for more efficient memory handling.<ref>{{cite web|url=https://web.archive.org/web/20240110213529/https://yuzu-emu.org/entry/yuzu-progress-report-dec-2023#android-adventures-and-kernels-with-benefits|title=Yuzu Progress Report Dec 2023|publisher=Yuzu (via Wayback Machine)}}</ref> This is further enhanced by flexible context switching via the SysV ABI, allowing developers to tune low-level process behavior for emulation performance.<ref>{{cite web|url=https://old.reddit.com/r/emulation/comments/zwq9fu/ares_crossplatform_open_source_multisystem/j1ys10k/|title=Ares Cross-Platform Open-Source Multi-System Emulator - Reddit comment|publisher=Reddit}}</ref> For disk access; advanced I/O strategies like <code>io_uring</code>, <code>epoll</code>, and <code>O_DIRECT</code> reduce file I/O latency—particularly beneficial for systems with complex disc or disk streaming.
* '''Platform-Specific Memory and I/O Optimization''': Techniques like Fastmem, implemented in [[PCSX2]], Yuzu, and [[Dolphin]], optimize memory operations for significant performance gains by minimizing overhead and improving cache efficiency.<ref>{{cite web|url=https://github.com/PCSX2/pcsx2/pull/5821|title=PCSX2 Pull Request #5821|publisher=GitHub}}</ref><ref>{{cite web|url=https://github.com/PCSX2/pcsx2/pull/7295|title=PCSX2 Pull Request #7295|publisher=GitHub}}</ref><ref>{{cite web|url=https://web.archive.org/web/20240229141516/https://yuzu-emu.org/entry/yuzu-fastmem/#what-is-fastmem|title=What is Fastmem?|publisher=Yuzu}}</ref><ref>{{cite web|url=https://dolphin-emu.org/blog/2016/09/06/booting-the-final-gc-game/|title=Booting the Final GC Game|publisher=Dolphin Emulator}}</ref> Modern emulators leverage platform-specific APIs for these, allocate memory and optimize I/O performance. On Windows; functions like <code>VirtualAlloc2</code> and <code>MapViewOfFile3</code> provide fine-grained control over virtual memory regions.<ref>{{cite web|url=https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc2|title=VirtualAlloc2|publisher=Microsoft}}</ref><ref>{{cite web|url=https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffile3|title=MapViewOfFile3|publisher=Microsoft}}</ref> On Unix-like systems; emulators utilize POSIX functions such as <code>mmap()</code> for memory mapping and <code>madvise()</code> with flags like <code>MADV_DONTNEED</code> and <code>MADV_REMOVE</code> to provide hints to the kernel for more efficient memory handling.<ref>{{cite web|url=https://web.archive.org/web/20240110213529/https://yuzu-emu.org/entry/yuzu-progress-report-dec-2023#android-adventures-and-kernels-with-benefits|title=Yuzu Progress Report Dec 2023|publisher=Yuzu (via Wayback Machine)}}</ref> This is further enhanced by flexible context switching via the SysV ABI, allowing developers to tune low-level process behavior for emulation performance.<ref>{{cite web|url=https://old.reddit.com/r/emulation/comments/zwq9fu/ares_crossplatform_open_source_multisystem/j1ys10k/|title=Ares Cross-Platform Open-Source Multi-System Emulator - Reddit comment|publisher=Reddit}}</ref> For disk access; advanced I/O strategies like <code>io_uring</code>, <code>epoll</code>, and <code>O_DIRECT</code> reduce file I/O latency—particularly beneficial for systems with complex disc or disk streaming.


* '''Timing and Synchronization''': Emulators must accurately replicate the timing behavior of the original hardware to maintain proper game speed, audio-video synchronization, and prevent glitches or input lag. This requires minimizing host OS scheduling overhead and achieving precise timing: On Windows; high-resolution timers like <code>QueryPerformanceCounter()</code> and <code>timeBeginPeriod()</code> are used to achieve consistent polling intervals and input capture. On Unix-like systems; functions like <code>nanosleep()</code> and scheduling policies such as <code>SCHED_FIFO</code> or <code>SCHED_RR</code> prioritize time-sensitive emulator threads. For RTC emulation; platform-specific time zone APIs like <code>GetDynamicTimeZoneInformation</code> (Windows) and <code>localtime()</code> (POSIX) are used.
* '''Timing and Synchronization''': Emulators must accurately replicate the timing behavior of the original hardware to maintain proper game speed, audio-video synchronization, and prevent glitches or input lag. This requires minimizing host OS scheduling overhead and achieving precise timing: On Windows; high-resolution timers like <code>QueryPerformanceCounter()</code> and <code>timeBeginPeriod()</code> are used to achieve consistent polling intervals and input capture. On Unix-like systems; functions like <code>nanosleep()</code> and scheduling policies such as <code>SCHED_FIFO</code> or <code>SCHED_RR</code> prioritize time-sensitive emulator threads. Linux provides more precise control over timing for applications (like frame pacing in emulators) compared to Windows, where the default system timer resolution of approximately 15.6ms can be adjusted to finer granularity using high-resolution APIs, though this may impact power efficiency.[https://dolphin-emu.org/blog/2025/06/04/dolphin-progress-report-release-2506/#frame-pacing-improvements-2503-54-2503-56-and-2503-186-by-billiard]{{YouTubeVideo|3dkN-6TJNHs}} For RTC emulation; platform-specific time zone APIs like <code>GetDynamicTimeZoneInformation</code> (Windows) and <code>localtime()</code> (POSIX) are used.


====Third-Party Libraries and Ecosystem Integration====
====Third-Party Libraries and Ecosystem Integration====