Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3549552rwd; Mon, 29 May 2023 12:27:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VUrmV3wMs4aXFNLVkdHOAfnre3sRj1s75o7LiW8hl2Vx3k88cr+BPMZ3iu2dC+/F9Qn8a X-Received: by 2002:a17:90b:1e4a:b0:253:38bf:9757 with SMTP id pi10-20020a17090b1e4a00b0025338bf9757mr52051pjb.43.1685388455877; Mon, 29 May 2023 12:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685388455; cv=none; d=google.com; s=arc-20160816; b=j79dCbKApemawQx8tHN+5mSGoWH1eSf0FwWZBaWsMEL9DjeeFmBqV/2Jqtwl28oBsf d/pQFmbT4hwlY35q9o3MaGyv20KaKlqgvwcK59NVHDMXU2u00GntWar6PsKMXX5fGxcq MYq9ib3Ig1AGF+Hg9v3Fr68o5ooqaCI7VxxXixIL9PFIByKjCe0ZmFTK8L08TR5vsxAp IYK8i2uE9/pOyP8ra9VtjXdnlV9EoR+8OhLUyvtA/KOxZE9wTIwifZMA4AuXMyYPK9Al Z6cirSZWGPzwMcI6TutfjDPH/8SaXJd0K4Psi2BQU4auNbZkJVslO9nrD4iYRYNlNrE8 UlDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=sPINeHvJX5lYryNeMvChlUTHeLgySd6hV/PHqz10wv0=; b=NhEILxAPU+A5Dcs3iUgIbpctwAA3sfJVtckX0YiTsl9VNDRMAT+/EOpjnEfKbvlvP+ ncZQvUUTNP9fHv4KGQPaYHBExaXFMUZHBYADSp9mVhGGtrl8g0vfdOvhmDi3kkrpSGsU lTNFP0ZwAV18uFW3bMMoIFMgUCWyo8lNot/CvFv3+NROm/cdABerPzQka3htW+3S3qp1 1u77xrehtbFAw1qmljZGtRDiAygLuNObp8gfijtGdObqK6wkfmecKSc91yoop3qyRvbX 3RGJJ9t/0kxiYu+eqAMYo5xT+Q7HgYIrqQbneVb1kdVqiKn3H5SR26HEdEZ4EIKcTB1T m9lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b="F/U4EMf3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ca1-20020a17090af30100b002565045f145si4677877pjb.122.2023.05.29.12.27.21; Mon, 29 May 2023 12:27:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b="F/U4EMf3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbjE2TOg (ORCPT + 99 others); Mon, 29 May 2023 15:14:36 -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 X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RDNS_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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