linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "André Almeida" <andrealmeid@collabora.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Darren Hart <dvhart@infradead.org>,
	linux-kernel@vger.kernel.org,
	Steven Rostedt <rostedt@goodmis.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: kernel@collabora.com, krisman@collabora.com,
	linux-api@vger.kernel.org, libc-alpha@sourceware.org,
	mtk.manpages@gmail.com, "Davidlohr Bueso" <dave@stgolabs.net>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"André Almeida" <andrealmeid@collabora.com>
Subject: [PATCH v2 22/22] futex2: Documentation: Document sys_futex_waitv() uAPI
Date: Thu, 23 Sep 2021 14:11:11 -0300	[thread overview]
Message-ID: <20210923171111.300673-23-andrealmeid@collabora.com> (raw)
In-Reply-To: <20210923171111.300673-1-andrealmeid@collabora.com>

Create userspace documentation for futex_waitv() syscall, detailing how
the arguments are used.

Signed-off-by: André Almeida <andrealmeid@collabora.com>
---
 Documentation/userspace-api/futex2.rst | 86 ++++++++++++++++++++++++++
 Documentation/userspace-api/index.rst  |  1 +
 2 files changed, 87 insertions(+)
 create mode 100644 Documentation/userspace-api/futex2.rst

diff --git a/Documentation/userspace-api/futex2.rst b/Documentation/userspace-api/futex2.rst
new file mode 100644
index 000000000000..7d37409df355
--- /dev/null
+++ b/Documentation/userspace-api/futex2.rst
@@ -0,0 +1,86 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+======
+futex2
+======
+
+:Author: André Almeida <andrealmeid@collabora.com>
+
+futex, or fast user mutex, is a set of syscalls to allow userspace to create
+performant synchronization mechanisms, such as mutexes, semaphores and
+conditional variables in userspace. C standard libraries, like glibc, uses it
+as a means to implement more high level interfaces like pthreads.
+
+futex2 is a followup version of the initial futex syscall, designed to overcome
+limitations of the original interface.
+
+User API
+========
+
+``futex_waitv()``
+-----------------
+
+Wait on an array of futexes, wake on any::
+
+  futex_waitv(struct futex_waitv *waiters, unsigned int nr_futexes,
+              unsigned int flags, struct timespec *timeout, clockid_t clockid)
+
+  struct futex_waitv {
+        __u64 val;
+        __u64 uaddr;
+        __u32 flags;
+        __u32 __reserved;
+  };
+
+Userspace sets an array of struct futex_waitv (up to a max of 128 entries),
+using ``uaddr`` for the address to wait for, ``val`` for the expected value
+and ``flags`` to specify the type (e.g. private) and size of futex.
+``__reserved`` needs to be 0, but it can be used for future extension. The
+pointer for the first item of the array is passed as ``waiters``. An invalid
+address for ``waiters`` or for any ``uaddr`` returns ``-EFAULT``.
+
+If userspace has 32-bit pointers, it should do a explicit cast to make sure
+the upper bits are zeroed. ``uintptr_t`` does the tricky and it works for
+both 32/64-bit pointers.
+
+``nr_futexes`` specifies the size of the array. Numbers out of [1, 128]
+interval will make the syscall return ``-EINVAL``.
+
+The ``flags`` argument of the syscall needs to be 0, but it can be used for
+future extension.
+
+For each entry in ``waiters`` array, the current value at ``uaddr`` is compared
+to ``val``. If it's different, the syscall undo all the work done so far and
+return ``-EAGAIN``. If all tests and verifications succeeds, syscall waits until
+one of the following happens:
+
+- The timeout expires, returning ``-ETIMEOUT``.
+- A signal was sent to the sleeping task, returning ``-ERESTARTSYS``.
+- Some futex at the list was awaken, returning the index of some waked futex.
+
+An example of how to use the interface can be found at ``tools/testing/selftests/futex/functional/futex_waitv.c``.
+
+Timeout
+-------
+
+``struct timespec *timeout`` argument is an optional argument that points to an
+absolute timeout. You need to specify the type of clock being used at
+``clockid`` argument. ``CLOCK_MONOTONIC`` and ``CLOCK_REALTIME`` are supported.
+This syscall accepts only 64bit timespec structs.
+
+Types of futex
+--------------
+
+A futex can be either private or shared. Private is used for processes that
+shares the same memory space and the virtual address of the futex will be the
+same for all processes. This allows for optimizations in the kernel. To use
+private futexes, it's necessary to specify ``FUTEX_PRIVATE_FLAG`` in the futex
+flag. For processes that doesn't share the same memory space and therefore can
+have different virtual addresses for the same futex (using, for instance, a
+file-backed shared memory) requires different internal mechanisms to be get
+properly enqueued. This is the default behavior, and it works with both private
+and shared futexes.
+
+Futexes can be of different sizes: 8, 16, 32 or 64 bits. Currently, the only
+supported one is 32 bit sized futex, and it need to be specified using
+``FUTEX_32`` flag.
diff --git a/Documentation/userspace-api/index.rst b/Documentation/userspace-api/index.rst
index c432be070f67..a61eac0c73f8 100644
--- a/Documentation/userspace-api/index.rst
+++ b/Documentation/userspace-api/index.rst
@@ -28,6 +28,7 @@ place where this information is gathered.
    media/index
    sysfs-platform_profile
    vduse
+   futex2
 
 .. only::  subproject and html
 
-- 
2.33.0


  parent reply	other threads:[~2021-09-23 17:13 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23 17:10 [PATCH v2 00/22] futex: splitup and waitv syscall André Almeida
2021-09-23 17:10 ` [PATCH v2 01/22] futex: Move to kernel/futex/ André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-10-09 14:23     ` André Almeida
2021-10-09 15:56       ` Peter Zijlstra
2021-09-23 17:10 ` [PATCH v2 02/22] futex: Split out syscalls André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:10 ` [PATCH v2 03/22] futex: Rename {,__}{,un}queue_me() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:10 ` [PATCH v2 04/22] futex: Rename futex_wait_queue_me() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:10 ` [PATCH v2 05/22] futex: Rename: queue_{,un}lock() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:10 ` [PATCH v2 06/22] futex: Rename __unqueue_futex() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:10 ` [PATCH v2 07/22] futex: Rename hash_futex() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:10 ` [PATCH v2 08/22] futex: Rename: {get,cmpxchg}_futex_value_locked() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:10 ` [PATCH v2 09/22] futex: Split out PI futex André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:10 ` [PATCH v2 10/22] futex: Rename: hb_waiter_{inc,dec,pending}() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:11 ` [PATCH v2 11/22] futex: Rename: match_futex() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:11 ` [PATCH v2 12/22] futex: Rename mark_wake_futex() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:11 ` [PATCH v2 13/22] futex: Split out requeue André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-10-13 16:57     ` Mike Galbraith
2021-10-15 10:01       ` Peter Zijlstra
2021-09-23 17:11 ` [PATCH v2 14/22] futex: Split out wait/wake André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:11 ` [PATCH v2 15/22] futex: Simplify double_lock_hb() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for Peter Zijlstra
2021-09-23 17:11 ` [PATCH v2 16/22] futex: Implement sys_futex_waitv() André Almeida
2021-10-06 11:50   ` Peter Zijlstra
     [not found]     ` <47b13460-27a4-474c-879b-ed1c668e5923@www.fastmail.com>
2021-10-07  9:08       ` Peter Zijlstra
2021-10-07 13:27         ` Steven Rostedt
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for André Almeida
2021-09-23 17:11 ` [PATCH v2 17/22] futex,x86: Wire up sys_futex_waitv() André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for André Almeida
2021-09-23 17:11 ` [PATCH v2 18/22] futex,arm: " André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for André Almeida
2021-09-23 17:11 ` [PATCH v2 19/22] selftests: futex: Add sys_futex_waitv() test André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for André Almeida
2021-09-23 17:11 ` [PATCH v2 20/22] selftests: futex: Test sys_futex_waitv() timeout André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for André Almeida
2021-11-09 11:18   ` [PATCH v2 20/22] " Vasily Gorbik
2021-11-09 12:52     ` André Almeida
2021-11-09 13:00       ` Adhemerval Zanella
2021-11-09 13:05       ` Arnd Bergmann
2021-09-23 17:11 ` [PATCH v2 21/22] selftests: futex: Test sys_futex_waitv() wouldblock André Almeida
2021-10-09 10:07   ` [tip: locking/core] " tip-bot2 for André Almeida
2021-09-23 17:11 ` André Almeida [this message]
2021-10-09 10:06   ` [tip: locking/core] futex2: Documentation: Document sys_futex_waitv() uAPI tip-bot2 for André Almeida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210923171111.300673-23-andrealmeid@collabora.com \
    --to=andrealmeid@collabora.com \
    --cc=arnd@arndb.de \
    --cc=bigeasy@linutronix.de \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=kernel@collabora.com \
    --cc=krisman@collabora.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mtk.manpages@gmail.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).