Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2325514rwd; Wed, 17 May 2023 08:33:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4SRs/aXahOokZ/UV7k7ab5sgjDaKbsRnab5zzyENqWFLFBqW+PcCiHTtGxum40j2HzPblb X-Received: by 2002:a17:90a:7ac7:b0:250:4a18:f575 with SMTP id b7-20020a17090a7ac700b002504a18f575mr109008pjl.9.1684337585095; Wed, 17 May 2023 08:33:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684337585; cv=none; d=google.com; s=arc-20160816; b=T0Q9Yub9LPeO9IWS6MG6IO9ulmIWpjT1II+r+jytH4n7f1SCnprfCR/97EjSAvU4eS aaMaR71SUeEkQcy36u8uX/krAIESAuwQPGxRiu8ajQiPXS6FKEtrNCazF3B0Upkbs6gF gRSSm119DKJ0X09yYYVLiSkdwwZNMgtisbBU4MGziobkPpT2Lx+FWYjhwAzVSqlvdILh stXEdWRF+Kubljxd7xBBRMfkkdqTGWpJcmDq1JhwHf83fLf+hLUJsEFbflfdw/k1xBj5 HOfB/OnynAzfqakreRABKLJADnISh4nLE9CQhvelM/kDeRgX/+42y/LJZofycjY/Z8EH JNsA== 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=nompxkvZUzuou45SdMeS8Sk3Hn8mVXDPCY85VmhN7P4=; b=olqU22vCxFb4fFhaxymtHnNKYDasWFiHP9XFUplb3MlNseGF2TWfBqy5/ZBQXhETls EG4DK9gjq2SNq926fyOH02cjz8Z/jQgUpX6cmGCVZ5d8dIKm/uTvUJpVwyVDlRjpyf5p Lq1i7wygGWaDlJrmofVljBqvUzibuEzV8YpDDrq0kFy+C5/fKpuHJvriGgazkOCHiavj Hj++uV/CQ0n+g87B9oG8guFM0/UsvInO7WMaK2mRL0n4b93J65SFFmOSpDNQseARLJAY Vo8J11eJ1qr5tnxrVv4Bzu4bZS6HEsYmE+Elb8cbO0kI9n/h7+EFzXHB++gZFD0JBBeX yaBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=Ma0LIvxE; 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 c9-20020a170902d48900b001a9f42553ddsi22758210plg.296.2023.05.17.08.32.27; Wed, 17 May 2023 08:33:05 -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=Ma0LIvxE; 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 S232071AbjEQP1w (ORCPT + 99 others); Wed, 17 May 2023 11:27:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232353AbjEQP1U (ORCPT ); Wed, 17 May 2023 11:27:20 -0400 Received: from smtpout.efficios.com (unknown [IPv6:2607:5300:203:b2ee::31e5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBC58A24A; Wed, 17 May 2023 08:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1684337223; bh=dIw3rhHMZ7Lp2h8DWiNDF2A2BTJ7aMsSgYnH7zjBLU8=; h=From:To:Cc:Subject:Date:From; b=Ma0LIvxE0jZ5ZvZwg6GwgWj+R1P3SB+GJKRMi9UulYmtLrksnVnQkJ9z/UK54Bzno kQjEoMfbNmFmXiz0lN0ihUTjEDPpiZUwRWbnB8aJDrk1U12zEil19+/Rdy6YSBQzoF TQ/O0+hPRr4KZZz3icQDL6t+VJHP7PKMKO+n/uvHHNe6xdVWNAbLco6aXWwuzpTaJh ciAkvV1+RT7sfGvMIEHxbEglHeziORNeGVcjS6pBMsdY/x39g96eoTXxE1uX3wFxH0 97O7NlHgZJ6S/F2I7GK60igTX+RcJsj5r5URFbyrVT4L8kvK9WOmB9U9QHIC2MlpSU uinfMzhVaNCvQ== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4QLxmR1RqKz131q; Wed, 17 May 2023 11:27:03 -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 , Mathieu Desnoyers Subject: [RFC PATCH 0/4] Extend rseq with sched_state field Date: Wed, 17 May 2023 11:26:50 -0400 Message-Id: <20230517152654.7193-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,URIBL_BLOCKED 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 field, which contains 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. 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 | 12 ++ include/uapi/linux/rseq.h | 17 +++ kernel/rseq.c | 14 ++ tools/testing/selftests/rseq/.gitignore | 2 + tools/testing/selftests/rseq/Makefile | 3 +- tools/testing/selftests/rseq/rseq-abi.h | 17 +++ tools/testing/selftests/rseq/rseq.h | 5 + tools/testing/selftests/rseq/rseq_mutex.c | 120 ++++++++++++++++++ .../testing/selftests/rseq/sched_state_test.c | 71 +++++++++++ 9 files changed, 260 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