From patchwork Thu Aug 5 19:04:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 44589 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA674384C003 for ; Thu, 5 Aug 2021 19:04:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA674384C003 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628190290; bh=ySyOuj2XwDE3u7waooYHKRuiOJHkvPajXENX18vucJY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=lLLdQIvENCL7c2hU8/hlXmNu/D2dgGpuw1ytWPKAejGAN2X+EGLK5waavzNX3+Smv zzQlj8v3wwPerATLCvnosORL3mPFPVbBPIqZSfzO69R6p/AzyW1WqH9YcqssBSfGxY U8O2PKhS4zXO+nvwShI2osjcEvxjgBCbXNfUmmCY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id CCAF4385842B for ; Thu, 5 Aug 2021 19:04:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CCAF4385842B Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 30C5C1F4431A To: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , linux-kernel@vger.kernel.org, Steven Rostedt , Sebastian Andrzej Siewior Subject: [PATCH 0/4] futex2: Add wait on multiple futexes syscall Date: Thu, 5 Aug 2021 16:04:01 -0300 Message-Id: <20210805190405.59110-1-andrealmeid@collabora.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_MANYTO, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-Patchwork-Original-From: =?utf-8?q?Andr=C3=A9_Almeida_via_Libc-alpha?= From: =?utf-8?q?Andr=C3=A9_Almeida?= Reply-To: =?utf-8?q?Andr=C3=A9_Almeida?= Cc: Davidlohr Bueso , libc-alpha@sourceware.org, linux-api@vger.kernel.org, mtk.manpages@gmail.com, =?utf-8?q?Andr=C3=A9_Alm?= =?utf-8?q?eida?= , kernel@collabora.com, krisman@collabora.com Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Hi, As opposed to previous futex2 patchsets, this one adds only one syscall: futex_waitv(). This way we can focus on this operation that already have a well defined use case and has been tested for months now. The patchset reuses as much as possible of original futex code for the new operation, so the first commit move some stuff to futex header to make accessible for futex2. Ideally, I would completely replace futex_wait_setup() with futex_wait_multiple(): it is basic the same logic, but for n futexes, so for existing operations it was a matter of calling it with nr_futexes=1. This worked pretty well for futex_wait(): I tested with glibc tests, tested with a complete distro running on top of it and perf benchs presented no performance difference. However, it didn't work for futex_wait_requeue_pi(), since the wait path for it is slightly different of the normal wait, that would require some refactor to get it in a way to be easily replaced. So I decided to not replace it at all. Use case The use case of this syscall is to allow low level locking libraries to wait for multiple locks at the same time. This is specially useful for emulating Windows' WaitForMultipleObjects. A futex_waitv()-based solution has been used for some time at Proton's Wine (a compatibility layer to run Windows games on Linux). Compared to a solution that uses eventfd(), futex was able to reduce CPU utilization for games, and even increase frames per second for some games. This happens because eventfd doesn't scale very well for a huge number of read, write and poll calls compared to futex. Native game engines will benefit of this as well, given that this wait pattern is common for games. Testing Selftest is provided as part of this patchset. As stated above, I used the futex_wait_multiple() in FUTEX_WAIT path and it worked fine in a full distro. Throught Proton, I've tested futex_waitv() with modern games that issue more than 40k futex calls per second. André Almeida (4): futex: Prepare for futex_wait_multiple() futex2: Implement vectorized wait selftests: futex2: Add waitv test futex2: Documentation: Document futex_waitv() uAPI Documentation/userspace-api/futex2.rst | 79 ++++++ Documentation/userspace-api/index.rst | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + include/linux/compat.h | 9 + include/linux/futex.h | 75 ++++++ include/uapi/asm-generic/unistd.h | 5 +- include/uapi/linux/futex.h | 17 ++ init/Kconfig | 7 + kernel/Makefile | 1 + kernel/futex.c | 224 ++++++++++++++---- kernel/futex2.c | 198 ++++++++++++++++ kernel/sys_ni.c | 4 + .../selftests/futex/functional/.gitignore | 1 + .../selftests/futex/functional/Makefile | 3 +- .../selftests/futex/functional/futex2_waitv.c | 154 ++++++++++++ .../testing/selftests/futex/functional/run.sh | 3 + .../selftests/futex/include/futex2test.h | 72 ++++++ 18 files changed, 812 insertions(+), 43 deletions(-) create mode 100644 Documentation/userspace-api/futex2.rst create mode 100644 kernel/futex2.c create mode 100644 tools/testing/selftests/futex/functional/futex2_waitv.c create mode 100644 tools/testing/selftests/futex/include/futex2test.h