Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp815945ybt; Wed, 24 Jun 2020 11:55:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZ1VV+zXG4FwQFWSOklbktLHat/Di1A2nQQBU24HmF63eibi3q/fxky96p+eOc5gP9so9F X-Received: by 2002:a17:906:4350:: with SMTP id z16mr25991866ejm.139.1593024900129; Wed, 24 Jun 2020 11:55:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593024900; cv=none; d=google.com; s=arc-20160816; b=Km0Iwtqr4lG0+DyUoddOiDIEFKefxbMemD/ikDYU3PGz4DB/hfh05He1A+tV0wChm5 aZlm6W4vqCfQLXimKIRg/UdUI1JjMPeAp2UtGLU6J8hsduFcxL5rCM/ACcmI8MLWFcsZ Wm3tKYTK8jkUweeaAv0lLjfcsLm+86W9KmN4u67ZeB+QWv8JHLBoxGJU819wAde1pCuq tNQGhssPW7gvRZPbjK16XBuYH7pFMqe3tU0ZxunehGnM3S6phzqt4aQgc1Uybb6USlgP nuEf7y7FoV7OuE3yTzcggH7SqmkC6EHCNWfd/X0w81zaO8WELeOSPdoONa1prM0Nx36z k5fQ== 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=BCiaaWmbk0Di+X9fHfl+8hsyQQjpSBo2pUzuO1oJ7No=; b=SujVIjZXGIjCVnHqrmnpIkmgedxFwz5+3ovDBPLg3P3XUqukGA1+3Wts260AnCiBOm S66HlIZhPoY4dtH7g3oVEQDcy++2X97Iuwu3BeAt3idJ1a42fK9qdia3lxVubsZgNKzR PU9nyeu9TfTylfZ0s6lMxKdxSP5iNRx7aT7/flGw9CzlWRw5GPf0RXnMyU6xrM3XUsaK PbK2zE6eBXU07nTaa8HwFUEbHgrv3dtKIo7Nwz4FB0dUWPLwnNZAGobM8ce+kAgP1EXF +xrqPbi+6b8cUuehp5Lb2Uh9ZG02XnHHXoV6hlrDEW3xLG3v8NTb6ATIdu6mnSjf+sMn 92qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=C3QK6nZK; 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 v20si8710231ejx.754.2020.06.24.11.54.35; Wed, 24 Jun 2020 11:55:00 -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=C3QK6nZK; 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 S2406123AbgFXSxQ (ORCPT + 99 others); Wed, 24 Jun 2020 14:53:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405119AbgFXSxN (ORCPT ); Wed, 24 Jun 2020 14:53:13 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AA84C061573 for ; Wed, 24 Jun 2020 11:53:13 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id t6so1849209pgq.1 for ; Wed, 24 Jun 2020 11:53:13 -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=BCiaaWmbk0Di+X9fHfl+8hsyQQjpSBo2pUzuO1oJ7No=; b=C3QK6nZKBLTG/bnyb3NAzjC/gCmktk9N5OR9gZftUZ3RRiLe+PGS/TpxWSEzWrvZyO 3QDc9rbWp7GXDdyY2i5JyPN7UKVlztdcXv1eqWcgdY8xwB9V0x7DNJGpWRMPjSsrwT86 KSH+p52yKY1Hwh7ynviW6TziZa+WrM/cGNPknXZixodfa1Sgk2HDUH3K923pPUCkQ2N9 rLnTOaVWjHBhzMqxjHCrNmmRLWliyS0FexmMd1pA/NZOigACCRQSpwqYkvbpx59ZLfXm 33lBYA0hlF9Q7i94G2GxH0A4Hev06hIC2WSmC6WlPRFehmKnH8HRrQFNnsAqrAQaeqcY QqLg== 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=BCiaaWmbk0Di+X9fHfl+8hsyQQjpSBo2pUzuO1oJ7No=; b=tUO/+5cqW3bGFSwzE04Vm5op3njv57HUgnw/CweEW3aY/T74/txgfarzG8ar+tS4rs CbownGaJGb9WuqgyUyVivBo+PkNbuj0qXgfdSOOQsZmJ2NScMC0uoCKet60LvJW3jm7w IVfXznphl4C/0a8RAbpIw6C230e1McOZoKn3LINI5J2gocDxpXFoeRdPcFTTWyORClGz z5uuUWWM4dYXO1qtjRElP3JSXiOcZhcEM1ndrc2Hj9kVi7aTVb3/d5ZU5gXyeudpPisZ n5lpnC69xr96RKpblyqZUla/TK1iXZs3Lym4m9xRpFaLjW8IW8cWxZ8MlvRluMmZ8Xos eHyA== X-Gm-Message-State: AOAM532zAqp/dPPIPcYxrazAXc59aDGHI6LJaSWw3fTCYBxQEintlg24 Z4SCmujb9hxOF2j7TSMiOo2LsotwvTRWEr53 X-Received: by 2002:a63:f903:: with SMTP id h3mr23700047pgi.437.1593024792283; Wed, 24 Jun 2020 11:53:12 -0700 (PDT) Received: from posk-x1c.lan (c-73-202-129-89.hsd1.ca.comcast.net. [73.202.129.89]) by smtp.gmail.com with ESMTPSA id q10sm22295815pfk.86.2020.06.24.11.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 11:53:11 -0700 (PDT) From: Peter Oskolkov To: Linux Kernel Mailing List , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Vincent Guittot Cc: Peter Oskolkov , Andrei Vagin , Paul Turner , Ben Segall , Aaron Lu Subject: [RFC PATCH 0/3 v3] futex/sched: introduce FUTEX_SWAP operation Date: Wed, 24 Jun 2020 11:52:44 -0700 Message-Id: <20200624185247.13269-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 This is an RFC! 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. v2: fix undefined symbol error ifndef CONFIG_SMP. v3: rebased onto the latest tip/locking/core. 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 | 96 ++++++-- 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, 322 insertions(+), 16 deletions(-) create mode 100644 tools/testing/selftests/futex/functional/futex_swap.c -- 2.25.1