From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE603C77B7A for ; Mon, 29 May 2023 19:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbjE2TOh (ORCPT ); Mon, 29 May 2023 15:14:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229695AbjE2TO1 (ORCPT ); Mon, 29 May 2023 15:14:27 -0400 Received: from smtpout.efficios.com (unknown [IPv6:2607:5300:203:b2ee::31e5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5567AAD; Mon, 29 May 2023 12:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1685387662; bh=BuBFuJov4/08X+aS9ZPKMQM67VPLxpAoQ7NIMWm8KVA=; h=From:To:Cc:Subject:Date:From; b=F/U4EMf3L4KQEw4uC86Y2qkSiRYS7EegfItvbqZ3mgR+CV3EHp/2aGZmEn+ZAJcQ8 NNlrnk66WzIwMhyqM7kr3nvCdEO1Sf5q0WY9B/Wt/hXY3cQGelIIbd4aigq+DeXhDk vXCKtNbgKIJAVt77ji+jQ9SZjBAWxzCltQPDVn8TjoaxTzO+/cznrrloXjzX98o50v c0Koe/YMLrRzMIJMd0CjeLpFRAA39P5yd8bHn/rLuW3tx3+ueoaAYaW4VGps8MUi+Y qJ2TYxTNBZ1ppbdCq4XB5y/HNaNx82HjOkpxwBWzUJtSfe7vsnLX1073+9TgzwYTd0 mkCQ4lO6o3Kdw== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4QVQF94MPDz16DG; Mon, 29 May 2023 15:14:21 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , "Paul E . McKenney" , Boqun Feng , "H . Peter Anvin" , Paul Turner , linux-api@vger.kernel.org, Christian Brauner , Florian Weimer , David.Laight@ACULAB.COM, carlos@redhat.com, Peter Oskolkov , Alexander Mikhalitsyn , Chris Kennelly , Ingo Molnar , Darren Hart , Davidlohr Bueso , =?UTF-8?q?Andr=C3=A9=20Almeida?= , libc-alpha@sourceware.org, Steven Rostedt , Jonathan Corbet , Noah Goldstein , Daniel Colascione , longman@redhat.com, Mathieu Desnoyers Subject: [RFC PATCH v2 0/4] Extend rseq with sched_state_ptr field Date: Mon, 29 May 2023 15:14:12 -0400 Message-Id: <20230529191416.53955-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This prototype extends struct rseq with a new sched_state_ptr field, which points to a structure containing a "on-cpu" flag kept up-to-date by the scheduler. It is meant to be used by userspace adaptative mutexes to decide between busy-wait and futex wait system call (releasing the CPU) behaviors based on the current state of the mutex owner. The goal is to improve use-cases where the duration of the critical sections for a given lock follows a multi-modal distribution, preventing statistical guesses from doing a good job at choosing between busy-wait and futex wait behavior. This is in response to the LWN coverage of 2023 Open Source Summit North America (https://lwn.net/Articles/931789/) unscheduled slot "Adaptive spinning in user space" presented by André Almeida. New in this v2: - Introduce a "struct rseq_sched_state", which contains the on-cpu scheduler flag and a thread ID field. This eliminates false sharing on the struct rseq cache lines caused by busy-waiting. I have favored adding a "thread ID" field to struct rseq_sched_state rather than adding stores of owner pointer in addition to a compare-and-swap and store on a uint32_t for lock state to minimize the number of stores to perform on the fast-path. Feedback is welcome! Mathieu Mathieu Desnoyers (4): rseq: Add sched_state field to struct rseq selftests/rseq: Add sched_state rseq field and getter selftests/rseq: Implement sched state test program selftests/rseq: Implement rseq_mutex test program include/linux/sched.h | 16 +++ include/uapi/linux/rseq.h | 41 ++++++ kernel/rseq.c | 43 +++++++ tools/testing/selftests/rseq/.gitignore | 2 + tools/testing/selftests/rseq/Makefile | 3 +- tools/testing/selftests/rseq/rseq-abi.h | 42 ++++++ tools/testing/selftests/rseq/rseq.c | 13 ++ tools/testing/selftests/rseq/rseq.h | 5 + tools/testing/selftests/rseq/rseq_mutex.c | 120 ++++++++++++++++++ .../testing/selftests/rseq/sched_state_test.c | 72 +++++++++++ 10 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/rseq/rseq_mutex.c create mode 100644 tools/testing/selftests/rseq/sched_state_test.c -- 2.25.1