Skip to content
  • Gabriel Krisman Bertazi's avatar
    futex: Implement FUTEX_WAIT_MULTIPLE · 49d20023
    Gabriel Krisman Bertazi authored
    
    
    This is a new futex operation to allow a thread to wait on several
    futexes at the same time, and wake up on any of them.  In a sense, it
    implements one of the features that was supported by pooling on the old
    FUTEX_FD interface.
    
    My use case for this feature lies in Wine, where we want to implement a
    similar function available in Windows, mainly for event handling.  The
    wine folks have an implementation of the userspace side using eventfd,
    but it suffers from bad performance, as shown in the measurements below.
    
    Technically, the old FUTEX_WAIT implementation can be easily
    reimplemented using do_futex_wait_multiple, with a count one, and I have
    a patch demonstrating how it works.  I'm not proposing it, since futex
    is such a tricky code, that I'd be more confortable to have
    FUTEX_WAIT_MULTIPLE running upstream for a couple development cycles,
    before considering modifying FUTEX_WAIT.
    
    This was tested using three mechanisms:
    
    1) By reimplementing FUTEX_WAIT in terms of FUTEX_WAIT_MULTIPLE and
    running tools/testing/selftests/futex and a full linux distro on top of
    this kernel.
    
    2) By an example code that exercises the FUTEX_WAIT_MULTIPLE path on a
    multi thread, event handling setup.
    
    3) By running the Wine fsync implementation and executing multi-threaded
    applications, in particular modern games on top of the implementation.
    
    Signed-off-by: default avatarZebediah Figura <z.figura12@gmail.com>
    Signed-off-by: default avatarSteven Noonan <steven@valvesoftware.com>
    Signed-off-by: default avatarPierre-Loup A. Griffais <pgriffais@valvesoftware.com>
    Signed-off-by: default avatarGabriel Krisman Bertazi <krisman@collabora.com>
    49d20023