Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp903071ybh; Wed, 22 Jul 2020 16:46:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQmATdZvYTAFVBVe8MDqCPITWLe5E6duL1RWpMl+TOE6pZ++I3jnoGaoTwgB9qLnOLKLQV X-Received: by 2002:a17:906:4949:: with SMTP id f9mr1834995ejt.495.1595461578715; Wed, 22 Jul 2020 16:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595461578; cv=none; d=google.com; s=arc-20160816; b=st1gcKjrmEsAheuPFegou9/sxzSgRYIWeluP1Jqp+wNKedJXuOHVXlq+MbRFAPnbsB AAYfmdEc3KbmVBYPpJfNzHNqMen49bbG+VgtzpvC7CtpsEoDKTPe9TYITe9w3JY9l0jz tercJKve4iERjvMiPeOjOT7DYyMHU1bLAnAGcYGAD96ReuUEcTSNUTUTELGWaSkaK6h3 aqELJJRKnSequwA//BYPOIFkc6CP5URdv8HGDyNQ4WPyTSgivoMR9XgLnwHcnkbZ9dyt SCiagFzrbRApmegCz4WC6trVI0as7fhP2JaHMPqc5XN3iUJYg50HhYS2wqoqJUuNtT1J fyTA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=jUExGfM+953A+bS/pUbiCTiJmKxiMhSnl8wFBZoEMeE=; b=HUi9gtj+ktiNooKwI0EMbOiHFzjfRi/lKrSOfx48U86+9X3q6MBEkY2teEy4Y7yJgj ijGCgXsqSm7W0APzEhxd42UcG4HbcktFdzTSsWh04sOthXHWNXrAgM1RstPPB/iOBl6j FYVxDPo9EDblAqlnPjbg0x+38T2KJW5GbkdGOg8r+Re4nUJ7J+9J3lpQdC/LyVnA2cFA v3dZkb6bMktgcZsm6/QGvDX64ptbQksGJaOauf0AgdwTdftQjL61rHQDkGzpd0mCF6Vx HqDf8Liu0Q4/81Mo6x2B/6i1TFPvWZK0MSlt/B4F676sl7VOaDc4PtexdMMkI1nebdQV b7Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=ZLFrfAiM; 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 do14si1149227ejc.39.2020.07.22.16.45.56; Wed, 22 Jul 2020 16:46:18 -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=ZLFrfAiM; 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 S1733042AbgGVXpo (ORCPT + 99 others); Wed, 22 Jul 2020 19:45:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726685AbgGVXpo (ORCPT ); Wed, 22 Jul 2020 19:45:44 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22E0EC0619DC for ; Wed, 22 Jul 2020 16:45:44 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id k22so3461234oib.0 for ; Wed, 22 Jul 2020 16:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posk.io; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jUExGfM+953A+bS/pUbiCTiJmKxiMhSnl8wFBZoEMeE=; b=ZLFrfAiMWAgjGgB/LtApRIC8/J6QB5YZr9E2vnZP+7xCoJFgG8XLZ/+238YT5PL43g rO3KzjCVobRN6pXIoL5vfi/jJfwpLVjG9Z+aUTJiy4uT6r28rjjJVwCI58r653sXfTTG SWGiFElNO/D7OwwzvC+OQ/rfnMab76ddZsLhUxdv6G2G/tfcZ9X5KztENyOQX9H3vi8E syKNyviJ0gm8z8ykItCuyC0eLtH7kDESNW3++zjdb0ypvBHAFB4VpL/ubkS+mstEY1Xt gSXMd69T4Ie8pA9Ldyzc2cC8XVf7LnFaRIqal/CBeGuvtIJpJFK8Ps3chwPhL6noN9zC W2Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jUExGfM+953A+bS/pUbiCTiJmKxiMhSnl8wFBZoEMeE=; b=eEtU8LEuJB4/KWW4L0EyFo0pflqS5DcExH+2HseAxQtzq1YVD7jKVGQW7+vOYljoIg bBvyK13gdBpn5mbWwjzD/yY13Mgu9IVr7Vf9qrZYXVpxqUexOzxFDSx13AaV+1mqZmOQ 9vMceynAD/F6UrSDoWo2q47nqy53VpkPmcWL4/DdUnBeV05OLGz/bbFYNaMEIjETCe7F uIb6wnxw1EVdPy0zELLblzaQOYtBfPuovZeJLbyGRvgYe0l8PRTdeZJqyOdd7kJ+7/fP dE5weY4MQHXpmL2hgDZQZmgc/XjQQGf3+60P7wDKw50wC1/0ewzfEnQlbyOFORe+uW4l ep1Q== X-Gm-Message-State: AOAM532Ka9mO7OVH0lWGy5cbzPQEZ3xKN8yn438p8J1MEXIM6+eI0uQQ IGoWC14JxSKk8EYkHEmVSUF8JBvIdmI= X-Received: by 2002:aca:c392:: with SMTP id t140mr1660809oif.131.1595461543248; Wed, 22 Jul 2020 16:45:43 -0700 (PDT) Received: from posk-x1c.lan (23-118-52-46.lightspeed.sntcca.sbcglobal.net. [23.118.52.46]) by smtp.gmail.com with ESMTPSA id x9sm294804ota.9.2020.07.22.16.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 16:45:42 -0700 (PDT) From: Peter Oskolkov To: Linux Kernel Mailing List , Thomas Gleixner , Ingo Molnar , Ingo Molnar , Peter Zijlstra , Darren Hart , Vincent Guittot Cc: Peter Oskolkov , Andrei Vagin , Paul Turner , Ben Segall , Aaron Lu Subject: [PATCH for 5.9 0/3] FUTEX_SWAP (tip/locking/core) Date: Wed, 22 Jul 2020 16:45:35 -0700 Message-Id: <20200722234538.166697-1-posk@posk.io> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Oskolkov 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 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. Peter Oskolkov (3): futex: introduce FUTEX_SWAP operation futex/sched: add wake_up_process_prefer_current_cpu, use in FUTEX_SWAP selftests/futex: add futex_swap selftest include/linux/sched.h | 1 + include/uapi/linux/futex.h | 2 + kernel/futex.c | 89 ++++++-- kernel/sched/core.c | 5 + kernel/sched/fair.c | 3 + kernel/sched/sched.h | 1 + .../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, 315 insertions(+), 16 deletions(-) create mode 100644 tools/testing/selftests/futex/functional/futex_swap.c -- 2.25.1