Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1834990ybt; Mon, 15 Jun 2020 10:34:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJym6XgToRHQbOxWFVNI8emTPmqr8xilI52PunmMhA7m64+HjiHAAoTC+M4Yss5S1bzwIxUk X-Received: by 2002:aa7:cb52:: with SMTP id w18mr25303300edt.1.1592242457287; Mon, 15 Jun 2020 10:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592242457; cv=none; d=google.com; s=arc-20160816; b=pfSKD/oESg+7Zmr6oO3pPIQOVJJ6ZbAn6xtxvhQLHNky7o/stfzUlxY85mSucB0US4 R4blIGAs1l14guLUNYm1LhA8B/N/L9TSOdOVpMay8anR7rg0+hILbz1cVm876t56Vpac jB9UDOfgSNM6fyW0hHYqpu+yTD69euQXFAfIFcpKHl3nDQiznYoR4BeHxcZFNIV234KA Ai9nJPAt20NvDqm6vEMiH34woRAUvPwUM3i2hUHP53XuWaAmrzqoUDXsrC7arGx6Jzi6 m+rU9lOSIKKYl/3GSp1aA1Gk/+uEKoBtJ35XQIsBmff3ICetLmZdIQMqGOurs/kmxC7c 3/6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:date:cc:to:from:subject:message-id:dkim-signature; bh=oHS/ZWDmFWNspiTGg9ZwIPVjqiFxBzS/s0peQrsQBeU=; b=A8XGISnTfe+S+4XJTTPpV1Ifx/kKgjcUx8VkQnROU3HlZOCdvkJpGwEMzhXpw/GrI+ h/CYOys1uf3Kanp+QoydfIPjY/zkrKUz5eRvzbB1kyDO6EqCJjCDKnqCs7f3Ou0TcQYb aGxUG3LtIpPxhmo1cK/ekBeWXeVYwEg99zP1noBVh9Xn1vGHNy6qUsr0tEpDVpnGERYq TIscUR3HUSjON5YUrdNc2cqx73BLOD1E5/vJaMgpcJDoDS7gMfBAyNIoNwkdv1y8cE0l KjRLk7Or9NLzP0Txy16fWdG77DGahHJQHJ0XbV/xtZngmROAYLSTeZkb7eN63sV6Apdy VKQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=JRnP8V8d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n27si8988001eja.232.2020.06.15.10.33.53; Mon, 15 Jun 2020 10:34:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=JRnP8V8d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731111AbgFOR3j (ORCPT + 99 others); Mon, 15 Jun 2020 13:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729124AbgFOR3i (ORCPT ); Mon, 15 Jun 2020 13:29:38 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B727C061A0E for ; Mon, 15 Jun 2020 10:29:38 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id h185so8111341pfg.2 for ; Mon, 15 Jun 2020 10:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posk.io; s=google; h=message-id:subject:from:to:cc:date:user-agent:mime-version :content-transfer-encoding; bh=oHS/ZWDmFWNspiTGg9ZwIPVjqiFxBzS/s0peQrsQBeU=; b=JRnP8V8dgG9MpfUlXhsVakjVsVLk59lkgN9gQ0VuOBGYpCn9p6oRGc890J0HHkh5wb D8R+eZpCpVzfrXh6VyWQb36thUxbPAICaII9/dy4sJDiyOi2AU8UJyfpcFPlgdoP+j8U UUe/xEkqNNPTBc5SFtveeDa7/ZMIqFPz583i8pFt3RGnBk+nzCGlop6Dwnb3Vv+fIhrF E2U4+kGMw3q7GP1xVh4V+nkBv7vC6B27qlcQEf8Li2wmANRubTxmxDeh2JATPMccjKzZ 9Gm/p7Lke41jB4lb/4eDKUYWFDrHBcQ6RUQuZ2MnA/dyyRUARqowDaHwZavfQXZKQp8N xAJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:user-agent :mime-version:content-transfer-encoding; bh=oHS/ZWDmFWNspiTGg9ZwIPVjqiFxBzS/s0peQrsQBeU=; b=dHAHeICrpnbDwuo8yeWN3qoUi68Fh/w75QPWtsNUCOv0hNpG4t80wpA+TChOKNfWzK IohJXLIURiA43U/STA47qHBXq18RrfNCsSllK7M5AlhYUI4VASv3ynI+UUfns1Mo97w3 oFl3120+CBecHIi98P5MtzVWXZpHcnot8c2Kvoac0uXICuau9ixdJ2/6xdTknC54qWXi sUUZEOci7TyQuxhdWkZ4u/DrIJhBEUF5K86dr2FpwYMQu5aUmIdhqRIUoeUKecq4bNpu U6ZNSPzuaPeIxVyqfrnLGjlWGLk8F96+vR1/+pltY+IEfhK0Pk8sPJ4fE5gutAmxr8xz 1Pkw== X-Gm-Message-State: AOAM533yxYDhDfBxq0ZiPcHbXDuFHQSCc9EKVIdRGb9PIHG8+zV+1Bnn CGzhMn6pnmCowngUShFCtAb+D92EFV+9KSb4 X-Received: by 2002:a05:6a00:2b0:: with SMTP id q16mr24084381pfs.104.1592242177682; Mon, 15 Jun 2020 10:29:37 -0700 (PDT) Received: from posk-x1c (c-73-202-129-89.hsd1.ca.comcast.net. [73.202.129.89]) by smtp.gmail.com with ESMTPSA id q11sm116437pjq.52.2020.06.15.10.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 10:29:37 -0700 (PDT) Message-ID: <414e292195d720c780fab2781c749df3be6566aa.camel@posk.io> Subject: [RFC PATCH 0/3] futex/sched: introduce FUTEX_SWAP operation From: Peter Oskolkov To: Linux Kernel Mailing List , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Vincent Guittot Cc: Peter Oskolkov , avagin@google.com, "pjt@google.com" , Ben Segall Date: Mon, 15 Jun 2020 10:29:36 -0700 Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.2-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From 42709b7f82d38c573fc1ff5f5aa7d0065ee54b82 Mon Sep 17 00:00:00 2001 From: Peter Oskolkov Date: Mon, 15 Jun 2020 10:17:36 -0700 Subject: [RFC PATCH 0/3] futex/sched: introduce FUTEX_SWAP operation As Paul Turner presented at LPC in 2013 ... - pdf: http://pdxplumbers.osuosl.org/2013/ocw//system/presentations/1653/original/LPC%20-%20User%20Threading.pdf - video: https://www.youtube.com/watch?v=KXuZi9aeGTw ... Google has developed an M:N userspace threading subsystem backed by Google-private SwitchTo Linux Kernel API (page 17 in the pdf referenced above). This subsystem provides latency-sensitive services at Google with fine-grained user-space control/scheduling over what is running when, and this subsystem is used widely internally (called schedulers or fibers). This RFC patchset is the first step to open-source this work. As explained in the linked pdf and video, SwitchTo API has three core operations: wait, resume, and swap (=switch). So this patchset adds a FUTEX_SWAP operation that, in addition to FUTEX_WAIT and FUTEX_WAKE, will provide a foundation on top of which user-space threading libraries can be built. Another common use case for FUTEX_SWAP is message passing a-la RPC between tasks: task/thread T1 prepares a message, wakes T2 to work on it, and waits for the results; when T2 is done, it wakes T1 and waits for more work to arrive. Currently the simplest way to implement this is a. T1: futex-wake T2, futex-wait b. T2: wakes, does what it has been woken to do c. T2: futex-wake T1, futex-wait With FUTEX_SWAP, steps a and c above can be reduced to one futex operation that runs 5-10 times faster. Patches in this patchset: Patch 1: introduce FUTEX_SWAP futex operation that, internally, does wake + wait. The purpose of this patch is to work out the API. Patch 2: a first rough attempt to make FUTEX_SWAP faster than what wake + wait can do. Patch 3: a selftest that can also be used to benchmark FUTEX_SWAP vs FUTEX_WAKE + FUTEX_WAIT. Tested: see patch 3 in this patchset. Note: patches in this patchset have been built on top of tip/locking/core. Peter Oskolkov (3): futex: introduce FUTEX_SWAP operation futex, sched: add wake_up_swap, use in FUTEX_SWAP selftests/futex: add futex_swap selftest include/linux/sched.h | 1 + include/uapi/linux/futex.h | 2 + kernel/futex.c | 92 ++++++-- kernel/sched/core.c | 5 + kernel/sched/fair.c | 3 + kernel/sched/sched.h | 3 +- .../selftests/futex/functional/.gitignore | 1 + .../selftests/futex/functional/Makefile | 1 + .../selftests/futex/functional/futex_swap.c | 209 ++++++++++++++++++ .../selftests/futex/include/futextest.h | 19 ++ 10 files changed, 319 insertions(+), 17 deletions(-) create mode 100644 tools/testing/selftests/futex/functional/futex_swap.c -- 2.25.1