Skip to content

NT synchronization primitive driver

Elizabeth Figura linux-api linux-doc linux-kselftest lkml 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest30 patches 3 repliesIn review
  2. v628 patches 4 repliesSuperseded
  3. v528 patches 2 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v427 patches6 repliesSuperseded

Changes in v7 from the cover letter

* rename NTSYNC_IOC_SEM_POST to NTSYNC_IOC_SEM_RELEASE (matching the NT terminology instead of POSIX),

* change object creation ioctls to return the fds directly in the return value instead of through the args struct, which simplifies the API a bit.

* Link to v6: https://lore.kernel.org/lkml/[email protected]/
* Link to v5: https://lore.kernel.org/lkml/[email protected]/
* Link to v4: https://lore.kernel.org/lkml/[email protected]/
* Link to v3: https://lore.kernel.org/lkml/[email protected]/
* Link to v2: https://lore.kernel.org/lkml/[email protected]/
* Link to v1: https://lore.kernel.org/lkml/[email protected]/
* Link to RFC v2: https://lore.kernel.org/lkml/[email protected]/
* Link to RFC v1: https://lore.kernel.org/lkml/[email protected]/

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/30ntsync: Return the fd from NTSYNC_IOC_CREATE_SEM.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+3 -70 replies
2/30ntsync: Rename NTSYNC_IOC_SEM_POST to NTSYNC_IOC_SEM_RELEASE.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+6 -60 replies
3/30ntsync: Introduce NTSYNC_IOC_WAIT_ANY.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+260 -10 replies
4/30ntsync: Introduce NTSYNC_IOC_WAIT_ALL.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+323 -140 replies
5/30ntsync: Introduce NTSYNC_IOC_CREATE_MUTEX.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+79 -40 replies
6/30ntsync: Introduce NTSYNC_IOC_MUTEX_UNLOCK.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+54 -00 replies
7/30ntsync: Introduce NTSYNC_IOC_MUTEX_KILL.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+60 -20 replies
8/30ntsync: Introduce NTSYNC_IOC_CREATE_EVENT.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+65 -00 replies
9/30ntsync: Introduce NTSYNC_IOC_EVENT_SET.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+28 -00 replies
10/30ntsync: Introduce NTSYNC_IOC_EVENT_RESET.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+25 -00 replies
11/30ntsync: Introduce NTSYNC_IOC_EVENT_PULSE.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+7 -20 replies
12/30ntsync: Introduce NTSYNC_IOC_SEM_READ.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+25 -00 replies
13/30ntsync: Introduce NTSYNC_IOC_MUTEX_READ.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+27 -00 replies
14/30ntsync: Introduce NTSYNC_IOC_EVENT_READ.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+25 -00 replies
15/30ntsync: Introduce alertable waits.drivers/misc/ntsync.c include/uapi/linux/ntsync.h+63 -100 replies
16/30selftests: ntsync: Add some tests for semaphore state.tools/testing/selftests/Makefile tools/testing/selftests/drivers/ntsync/.gitignore tools/testing/selftests/drivers/ntsync/Makefile +2 more+155 -00 replies
17/30selftests: ntsync: Add some tests for mutex state.tools/testing/selftests/drivers/ntsync/ntsync.c+187 -00 replies
18/30selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ANY.tools/testing/selftests/drivers/ntsync/ntsync.c+114 -00 replies
19/30selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ALL.tools/testing/selftests/drivers/ntsync/ntsync.c+91 -20 replies
20/30selftests: ntsync: Add some tests for wakeup signaling with WINESYNC_IOC_WAIT_ANY.tools/testing/selftests/drivers/ntsync/ntsync.c+143 -00 replies
21/30selftests: ntsync: Add some tests for wakeup signaling with WINESYNC_IOC_WAIT_ALL.tools/testing/selftests/drivers/ntsync/ntsync.c+91 -00 replies
22/30selftests: ntsync: Add some tests for manual-reset event state.tools/testing/selftests/drivers/ntsync/ntsync.c+86 -00 replies
23/30selftests: ntsync: Add some tests for auto-reset event state.tools/testing/selftests/drivers/ntsync/ntsync.c+56 -00 replies
24/30selftests: ntsync: Add some tests for wakeup signaling with events.tools/testing/selftests/drivers/ntsync/ntsync.c+141 -40 replies
25/30selftests: ntsync: Add tests for alertable waits.tools/testing/selftests/drivers/ntsync/ntsync.c+164 -30 replies
26/30selftests: ntsync: Add some tests for wakeup signaling via alerts.tools/testing/selftests/drivers/ntsync/ntsync.c+62 -00 replies
27/30selftests: ntsync: Add a stress test for contended waits.tools/testing/selftests/drivers/ntsync/ntsync.c+72 -00 replies
28/30maintainers: Add an entry for ntsync.MAINTAINERS+9 -00 replies
29/30docs: ntsync: Add documentation for the ntsync uAPI.Documentation/userspace-api/index.rst Documentation/userspace-api/ntsync.rst+386 -00 replies
30/30ntsync: No longer depend on BROKEN.drivers/misc/Kconfig+0 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v7 yet.

Read the v7 thread

Cover letter [PATCH v7 00/30] NT synchronization primitive driver

This patch series implements a new char misc driver, /dev/ntsync, which is used to implement Windows NT synchronization primitives.

NT synchronization primitives are unique in that the wait functions both are vectored, operate on multiple types of object with different behaviour (mutex, semaphore, event), and affect the state of the objects they wait on. This model is not compatible with existing kernel synchronization objects or interfaces, and therefore the ntsync driver implements its own wait queues and locking.

This patch series is rebased against the "char-misc-next" branch of gregkh/char-misc.git.

== Background ==

The Wine project emulates the Windows API in user space. One particular part of that API, namely the NT synchronization primitives, have historically been implemented via RPC to a dedicated "kernel" process. However, more recent applications use these APIs more strenuously, and the overhead of RPC has become a bottleneck.

The NT synchronization APIs are too complex to implement on top of existing primitives without sacrificing correctness. Certain operations, such as NtPulseEvent() or the "wait-for-all" mode of NtWaitForMultipleObjects(), require direct control over the underlying wait queue, and implementing a wait queue sufficiently robust for Wine in user space is not possible. This proposed driver, therefore, implements the problematic interfaces directly in the Linux kernel.

This driver was presented at Linux Plumbers Conference 2023. For those further interested in the history of synchronization in Wine and past attempts to solve this problem in user space, a recording of the presentation can be viewed here:

https://www.youtube.com/watch?v=NjU4nyWyhU8

== Performance ==

The performance measurements described below are copied from earlier versions of the patch set. While some of the code has changed, I do not currently anticipate that it has changed drastically enough to affect those measurements.

The gain in performance varies wildly depending on the application in question and the user's hardware. For some games NT synchronization is not a bottleneck and no change can be observed, but for others frame rate improvements of 50 to 150 percent are not atypical. The following table lists frame rate measurements from a variety of games on a variety of hardware, taken by users Dmitry Skvortsov, FuzzyQuils, OnMars, and myself:

Game Upstream ntsync improvement
===========================================================================
Anger Foot 69 99 43%

Call of Juarez                   99.8           224.1           125%
Dirt 3                          110.6           860.7           678%
Forza Horizon 5                 108             160              48%
Lara Croft: Temple of Osiris    141             326             131%
Metro 2033                      164.4           199.2            21%
Resident Evil 2                  26              77             196%
The Crew                         26              51              96%
Tiny Tina's Wonderlands         130             360             177%
Total War Saga: Troy            109             146              34%

===========================================================================

== Patches ==

The intended semantics of the patches are broadly intended to match those of the corresponding Windows functions. For those not already familiar with the Windows functions (or their undocumented behaviour), patch 27/28 provides a detailed specification, and individual patches also include a brief description of the API they are implementing.

The patches making use of this driver in Wine can be retrieved or browsed here:

https://repo.or.cz/wine/zf.git/shortlog/refs/heads/ntsync7

== Previous versions ==

Changes from v6:

* rename NTSYNC_IOC_SEM_POST to NTSYNC_IOC_SEM_RELEASE (matching the NT terminology instead of POSIX),

* change object creation ioctls to return the fds directly in the return value instead of through the args struct, which simplifies the API a bit.

* Link to v6: https://lore.kernel.org/lkml/[email protected]/
* Link to v5: https://lore.kernel.org/lkml/[email protected]/
* Link to v4: https://lore.kernel.org/lkml/[email protected]/
* Link to v3: https://lore.kernel.org/lkml/[email protected]/
* Link to v2: https://lore.kernel.org/lkml/[email protected]/
* Link to v1: https://lore.kernel.org/lkml/[email protected]/
* Link to RFC v2: https://lore.kernel.org/lkml/[email protected]/
* Link to RFC v1: https://lore.kernel.org/lkml/[email protected]/

Elizabeth Figura (30):
ntsync: Return the fd from NTSYNC_IOC_CREATE_SEM.
ntsync: Rename NTSYNC_IOC_SEM_POST to NTSYNC_IOC_SEM_RELEASE.
ntsync: Introduce NTSYNC_IOC_WAIT_ANY.
ntsync: Introduce NTSYNC_IOC_WAIT_ALL.
ntsync: Introduce NTSYNC_IOC_CREATE_MUTEX.
ntsync: Introduce NTSYNC_IOC_MUTEX_UNLOCK.
ntsync: Introduce NTSYNC_IOC_MUTEX_KILL.
ntsync: Introduce NTSYNC_IOC_CREATE_EVENT.
ntsync: Introduce NTSYNC_IOC_EVENT_SET.
ntsync: Introduce NTSYNC_IOC_EVENT_RESET.
ntsync: Introduce NTSYNC_IOC_EVENT_PULSE.
ntsync: Introduce NTSYNC_IOC_SEM_READ.
ntsync: Introduce NTSYNC_IOC_MUTEX_READ.
ntsync: Introduce NTSYNC_IOC_EVENT_READ.
ntsync: Introduce alertable waits.
selftests: ntsync: Add some tests for semaphore state.
selftests: ntsync: Add some tests for mutex state.
selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ANY.
selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ALL.
selftests: ntsync: Add some tests for wakeup signaling with
WINESYNC_IOC_WAIT_ANY.
selftests: ntsync: Add some tests for wakeup signaling with
WINESYNC_IOC_WAIT_ALL.
selftests: ntsync: Add some tests for manual-reset event state.
selftests: ntsync: Add some tests for auto-reset event state.
selftests: ntsync: Add some tests for wakeup signaling with events.
selftests: ntsync: Add tests for alertable waits.
selftests: ntsync: Add some tests for wakeup signaling via alerts.
selftests: ntsync: Add a stress test for contended waits.
maintainers: Add an entry for ntsync.
docs: ntsync: Add documentation for the ntsync uAPI.
ntsync: No longer depend on BROKEN.

 Documentation/userspace-api/index.rst         |    1 +
 Documentation/userspace-api/ntsync.rst        |  385 +++++
 MAINTAINERS                                   |    9 +
 drivers/misc/Kconfig                          |    1 -
 drivers/misc/ntsync.c                         |  992 +++++++++++-
 include/uapi/linux/ntsync.h                   |   42 +-
 tools/testing/selftests/Makefile              |    1 +
 .../selftests/drivers/ntsync/.gitignore       |    1 +
 .../testing/selftests/drivers/ntsync/Makefile |    7 +
 tools/testing/selftests/drivers/ntsync/config |    1 +
 .../testing/selftests/drivers/ntsync/ntsync.c | 1343 +++++++++++++++++
 11 files changed, 2767 insertions(+), 16 deletions(-)
 create mode 100644 Documentation/userspace-api/ntsync.rst
 create mode 100644 tools/testing/selftests/drivers/ntsync/.gitignore
 create mode 100644 tools/testing/selftests/drivers/ntsync/Makefile
 create mode 100644 tools/testing/selftests/drivers/ntsync/config
 create mode 100644 tools/testing/selftests/drivers/ntsync/ntsync.c

base-commit: cdd30ebb1b9f36159d66f088b61aee264e649d7a

Signature · 1 line
2.45.2