Skip to content

ntsync: budgeted wakes after unlock, SIGUSR1 deferral through a lock flag (test build) - #138

Draft
utkarshdalal wants to merge 3 commits into
proton_11.0-2from
ntsync-limit-wakes
Draft

utkarshdalal wants to merge 3 commits into
proton_11.0-2from
ntsync-limit-wakes

Conversation

@utkarshdalal

@utkarshdalal utkarshdalal commented Nov 16, 2026 •

Copy link
Copy Markdown

Test build for GameNative/ntsync-android#1. It pins ntsync-android to 6342614 and adds a Wine patch for that library's SIGUSR1 cooperation.

What changes

  • ntsync-android pin. A semaphore release, auto-reset event set or mutex unlock wakes at most as many waiters as it can satisfy. Those futex wakes are now issued after the shared region lock is released. Details are in ntsync-android#1.
  • common/dlls_ntdll_unix_server_c_ntsync_lock_flag.patch. ntdll_thread_data gets ntsync_lock_flag. When userspace ntsync is in use, server_init_process registers it with ntsync_set_lock_flag_hook (aarch64 and x86_64 only).
  • arm64ec/dlls_ntdll_unix_signal_arm64_c_ntsync_lock_flag.patch and x86_64/dlls_ntdll_unix_signal_x86_64_c_ntsync_lock_flag.patch. While the flag is set, usr1_handler marks the suspend pending and returns. The library re-raises SIGUSR1 right after it releases the lock. Before this, the library blocked SIGUSR1 around every lock acquisition, which cost two sigprocmask syscalls each time.
  • Build scripts. All three patches are registered at the end of both build-step lists, and android/ntsync_android/ntsync_user.h is synced with the library header.

NTSYNC_WAKE_ALL=1 still selects wake-all from the same build.

Result on The Forest (Odin 3)

New Game, the same pad loop, measured about 3 minutes into gameplay. Each column is one run of this PR's build at a different library pin:

Main thread c904dd8 f465609 6342614 + flag patch
Syscalls per second 47,600 90,600 43,200
Syscalls per frame 792 1,779 ~785
rt_sigprocmask on the release path 2 per walk 2 per walk none
pthread_mutex_unlock share 4.75 % 11.6 % 0.23 %
NtReleaseSemaphore share 21.0 % 29.9 % 29.6 %
Wake walks per second 5,085 16,883 ~38,000

What did not change: the release share stays at about 30 %. The release path is now one futex wake per walk. However, the game took 2.3 times more walks per second than in the f465609 run, and it did more signal operations per frame in this scene. The futex wake itself is now the whole cost. The scenes differ between runs, so fps is not compared; this run measured 53–59 fps while moving.

SIGUSR1 deferral was exercised in game: 4 suspends landed inside the lock, were deferred and were delivered after it. No stuck waits and no blocked region lock were seen.

Before merge

Tag ntsync-android and pin the tag here instead of the commit.

Utkarsh Dalal added 3 commits November 16, 2026 11:13
…c-android to wakes after unlock

- ci: pin ntsync-android 6342614 (GameNative/ntsync-android#1): release wakes are issued after the
  region unlock, and the library takes a per-thread lock flag from the host instead of masking SIGUSR1.
- common/dlls_ntdll_unix_server_c_ntsync_lock_flag.patch: ntdll_thread_data gets ntsync_lock_flag;
  server_init_process registers it with ntsync_set_lock_flag_hook on aarch64 and x86_64.
- arm64ec/dlls_ntdll_unix_signal_arm64_c_ntsync_lock_flag.patch,
  x86_64/dlls_ntdll_unix_signal_x86_64_c_ntsync_lock_flag.patch: usr1_handler marks the signal pending
  and returns while the flag is set; the library re-raises it right after the unlock.
- android/ntsync_android/ntsync_user.h synced with the library header.
@utkarshdalal utkarshdalal changed the title ntsync: wake only as many waiters as a signal op can satisfy (test build) ntsync: budgeted wakes after unlock, SIGUSR1 deferral through a lock flag (test build) Nov 16, 2026
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.

1 participant