Message ID | 20210625081104.1134598-1-kurt@linutronix.de |
---|---|
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> 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 459DF385AC22 for <patchwork@sourceware.org>; Fri, 25 Jun 2021 08:11:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 459DF385AC22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624608710; bh=KgO3ZkGQGjp275Naj0EK/ncAuq/lwiaM+tO6iPj5igo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=DF5QUZFgYkUuem/xlrQVjbICM/1m9nntG0mAqTGzLQKo+5z/OTJoyVt4GZvzdVtMj 34U8U+eYJY6awf9cFzoaqDygrijFPSaYe2UHZKCxFMoHkYtYSaEvAYDhJX59xxChR4 MMlBrIiHDOHJ0n5EqtB92nP3SDThBA0iDZLMAjJA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by sourceware.org (Postfix) with ESMTPS id 5AA643858001 for <libc-alpha@sourceware.org>; Fri, 25 Jun 2021 08:11:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5AA643858001 To: libc-alpha@sourceware.org Subject: [PATCH v1 0/6] nptl: Introduce and use FUTEX_LOCK_PI2 Date: Fri, 25 Jun 2021 10:10:58 +0200 Message-Id: <20210625081104.1134598-1-kurt@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Kurt Kanzenbach via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Kurt Kanzenbach <kurt@linutronix.de> Cc: Florian Weimer <fweimer@redhat.com>, Sebastian Andrzej Siewior <bigeasy@linutronix.de>, Kurt Kanzenbach <kurt@linutronix.de>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Joseph Myers <joseph@codesourcery.com> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
nptl: Introduce and use FUTEX_LOCK_PI2
|
|
Message
Kurt Kanzenbach
June 25, 2021, 8:10 a.m. UTC
Linux real time applications often make use of mutexes with priority inheritance enabled due to problems such as unbounded priority inversion. In addition, some applications make use of timeouts e.g., by utilizing pthread_mutex_clocklock(). However, the combination of priority inheritance enabled mutexes with timeouts based on CLOCK_MONOTONIC doesn't work. That is because the underlying Linux kernel futex interface didn't support it, yet. Using CLOCK_REALTIME is possible, but it is subject to adjustments (NTP, PTP, ...). Therefore, Thomas proposed and introduced a new futex operation called FUTEX_LOCK_PI2 with support for selectable clocks [1]. Here is a proof of concept patch set adding FUTEX_LOCK_PI2 in order to support pthread_mutex_clocklock(MONOTONIC)/PI. The idea is to use futex_lock_pi2() by default, and fallback to futex_lock_pi() in case the kernel is too old. There's also a bugreport for glibc with a test case: https://sourceware.org/bugzilla/show_bug.cgi?id=26801 Changes since RFC: * FUTEX_LOCK_PI2 merged in upstream Linux kernel (Thomas Gleixner, Peter Zijlstra) * Make of __ASSUME_FUTEX_LOCK_PI2 in the implementation (Adhemerval Zanella) * Get rid of probing for FUTEX_LOCK_PI2 in timedlock (Adhemerval Zanella) * Adjust the test cases (Adhemerval Zanella) * Use correct Linux kernel version (Joseph Myers) Previous versions: * https://sourceware.org/pipermail/libc-alpha/2021-June/127798.html Thanks, Kurt [1] - https://lkml.kernel.org/lkml/20210422194417.866740847@linutronix.de/ Kurt Kanzenbach (6): Linux: Add FUTEX_LOCK_PI2 nptl: Introduce futex_lock_pi2() nptl: Use futex_lock_pi2() nptl: Remove mutex test 10 nptl: mutex-test5: Include CLOCK_MONOTONIC for PI nptl: mutex-test9: Include CLOCK_MONOTONIC for PI nptl/Makefile | 2 +- nptl/pthread_mutex_timedlock.c | 10 +- nptl/tst-mutexpi10.c | 68 ----------- sysdeps/nptl/futex-internal.h | 131 ++++++++++++++++++++++ sysdeps/nptl/lowlevellock-futex.h | 1 + sysdeps/pthread/tst-mutex5.c | 20 +++- sysdeps/pthread/tst-mutex9.c | 9 +- sysdeps/unix/sysv/linux/kernel-features.h | 8 ++ 8 files changed, 163 insertions(+), 86 deletions(-) delete mode 100644 nptl/tst-mutexpi10.c
Comments
On Fri Jun 25 2021, Kurt Kanzenbach wrote: > Linux real time applications often make use of mutexes with priority inheritance > enabled due to problems such as unbounded priority inversion. In addition, some > applications make use of timeouts e.g., by utilizing pthread_mutex_clocklock(). > > However, the combination of priority inheritance enabled mutexes with timeouts > based on CLOCK_MONOTONIC doesn't work. That is because the underlying Linux > kernel futex interface didn't support it, yet. Using CLOCK_REALTIME is possible, > but it is subject to adjustments (NTP, PTP, ...). Therefore, Thomas proposed and > introduced a new futex operation called FUTEX_LOCK_PI2 with support for > selectable clocks [1]. > > Here is a proof of concept patch set adding FUTEX_LOCK_PI2 in order to support > pthread_mutex_clocklock(MONOTONIC)/PI. The idea is to use futex_lock_pi2() by > default, and fallback to futex_lock_pi() in case the kernel is too old. > > There's also a bugreport for glibc with a test case: > > https://sourceware.org/bugzilla/show_bug.cgi?id=26801 > > Changes since RFC: > > * FUTEX_LOCK_PI2 merged in upstream Linux kernel (Thomas Gleixner, Peter Zijlstra) > * Make of __ASSUME_FUTEX_LOCK_PI2 in the implementation (Adhemerval Zanella) > * Get rid of probing for FUTEX_LOCK_PI2 in timedlock (Adhemerval Zanella) > * Adjust the test cases (Adhemerval Zanella) > * Use correct Linux kernel version (Joseph Myers) > > Previous versions: > > * https://sourceware.org/pipermail/libc-alpha/2021-June/127798.html Ping. Any comments on this version? Thanks, Kurt
On 25/06/2021 05:10, Kurt Kanzenbach wrote: > Linux real time applications often make use of mutexes with priority inheritance > enabled due to problems such as unbounded priority inversion. In addition, some > applications make use of timeouts e.g., by utilizing pthread_mutex_clocklock(). > > However, the combination of priority inheritance enabled mutexes with timeouts > based on CLOCK_MONOTONIC doesn't work. That is because the underlying Linux > kernel futex interface didn't support it, yet. Using CLOCK_REALTIME is possible, > but it is subject to adjustments (NTP, PTP, ...). Therefore, Thomas proposed and > introduced a new futex operation called FUTEX_LOCK_PI2 with support for > selectable clocks [1]. > > Here is a proof of concept patch set adding FUTEX_LOCK_PI2 in order to support > pthread_mutex_clocklock(MONOTONIC)/PI. The idea is to use futex_lock_pi2() by > default, and fallback to futex_lock_pi() in case the kernel is too old. > > There's also a bugreport for glibc with a test case: > > https://sourceware.org/bugzilla/show_bug.cgi?id=26801 > > Changes since RFC: > > * FUTEX_LOCK_PI2 merged in upstream Linux kernel (Thomas Gleixner, Peter Zijlstra) > * Make of __ASSUME_FUTEX_LOCK_PI2 in the implementation (Adhemerval Zanella) > * Get rid of probing for FUTEX_LOCK_PI2 in timedlock (Adhemerval Zanella) > * Adjust the test cases (Adhemerval Zanella) > * Use correct Linux kernel version (Joseph Myers) > > Previous versions: > > * https://sourceware.org/pipermail/libc-alpha/2021-June/127798.html > > Thanks, > Kurt > > [1] - https://lkml.kernel.org/lkml/20210422194417.866740847@linutronix.de/ Patch looks ok in general, I think I have only minor comments. I see that FUTEX_LOCK_PI2 is already on Linus tree, should it should be safe to assume it will on v5.14 (although is not yet released). We are in the slush freeze for the 2.34 release, so you would like to check with Carlos O'Donell if this set is suitable to inclusion. It does not change any ABI, but I will need to some time to boot a kernel to actually test it.
On Fri Jul 09 2021, Adhemerval Zanella wrote: > Patch looks ok in general, I think I have only minor comments. I see that > FUTEX_LOCK_PI2 is already on Linus tree, should it should be safe to assume > it will on v5.14 (although is not yet released). > > We are in the slush freeze for the 2.34 release, so you would like to check > with Carlos O'Donell if this set is suitable to inclusion. It does not > change any ABI, but I will need to some time to boot a kernel to actually > test it. There is no hurry. I just wanted to make sure that the implementation is moving into the right direction. I'll integrate your review comments and post v2 when Linux v5.14.0 is actually released. That should make it easier for testing. Thanks, Kurt