From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, PDS_RDNS_DYNAMIC_FP,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,RDNS_DYNAMIC, SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 691661F8C6 for ; Thu, 5 Aug 2021 19:08:27 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7D9723999010 for ; Thu, 5 Aug 2021 19:08:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D9723999010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628190506; bh=/9YPWjmIT3oBB+YvmbT6TmLA8ZvNLkmfYxl+d8YOg4s=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=nBcJKJE4KHQtpUUFXsl1vyy3/fGYeOVrfGg6wYGG+zclvJ1SqcRqCHuwR0hQBTeMY hiECxfSK6s0z87m+s38605X3FQwb1aekY/4Hl+hF/6mE8u6DAW17cLQ6FiXhQRv+TT yytM2GUUbamcXFOxq8qGxO+SEYGz9T9TgOEn96Vw= Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id 03924383F404 for ; Thu, 5 Aug 2021 19:04:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 03924383F404 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id BE8741F44321 To: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , linux-kernel@vger.kernel.org, Steven Rostedt , Sebastian Andrzej Siewior Subject: [PATCH 4/4] futex2: Documentation: Document futex_waitv() uAPI Date: Thu, 5 Aug 2021 16:04:05 -0300 Message-Id: <20210805190405.59110-5-andrealmeid@collabora.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210805190405.59110-1-andrealmeid@collabora.com> References: <20210805190405.59110-1-andrealmeid@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: =?utf-8?q?Andr=C3=A9_Almeida_via_Libc-alpha?= Reply-To: =?UTF-8?q?Andr=C3=A9=20Almeida?= Cc: Davidlohr Bueso , libc-alpha@sourceware.org, linux-api@vger.kernel.org, mtk.manpages@gmail.com, =?UTF-8?q?Andr=C3=A9=20Almeida?= , kernel@collabora.com, krisman@collabora.com Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" Create userspace documentation for futex_waitv() syscall, detailing how the arguments are used. Signed-off-by: André Almeida --- Documentation/userspace-api/futex2.rst | 79 ++++++++++++++++++++++++++ Documentation/userspace-api/index.rst | 1 + 2 files changed, 80 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..829805c24a51 --- /dev/null +++ b/Documentation/userspace-api/futex2.rst @@ -0,0 +1,79 @@ +.. SPDX-License-Identifier: GPL-2.0 + +====== +futex2 +====== + +:Author: André Almeida + + +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 *timo) + + struct futex_waitv { + uint64_t val; + void *uaddr; + unsigned int flags; + }; + +Userspace set 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 (shared, private) and size of futex. The +pointer for the first item of the array is passed as ``waiters``. An invalid +address for ``waiters`` or for any ``uaddr`` returns ``-EFAULT``. + +``nr_futexes`` specifies the size of the array. Numbers out of [1, 128] +interval will make the syscall return ``-EINVAL``. + +``flags`` can be used to set the timeout clock. + +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/futenctional/futex2_waitv.c``. + +Timeout +------- + +For every operation that has a ``struct timespec timo`` argument, it is an +optional argument that points to an absolute timeout. By default, it's measured +against ``CLOCK_MONOTONIC``, but the flag ``FUTEX_CLOCK_REALTIME`` can be used +to measure it against ``CLOCK_REALTIME``. 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 and is the +default type of a futex. 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 in the kernel and need to set the flag +``FUTEX_SHARED_FLAG``. + +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 0b5eefed027e..dac7189d9752 100644 --- a/Documentation/userspace-api/index.rst +++ b/Documentation/userspace-api/index.rst @@ -27,6 +27,7 @@ place where this information is gathered. iommu media/index sysfs-platform_profile + futex2 .. only:: subproject and html -- 2.32.0