Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2767362ybt; Mon, 22 Jun 2020 06:35:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1hi/gLbCTsSMjqjnYbbPhhVObTdY7vX4AXS/Sf7hohOVWE3mOP7kD2xDdw5RA9kJO1WaI X-Received: by 2002:a17:906:3951:: with SMTP id g17mr16191749eje.414.1592832925385; Mon, 22 Jun 2020 06:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592832925; cv=none; d=google.com; s=arc-20160816; b=nOdzYxiPkvTBov6Mmx4rMT0XSp6HUnlH+T+o0893SCvrqq96FWaz8FGetI7GOAc3Ys eoPFAnidDc/mGjjSPWO50MLQNzcbZbHJAyEhuupv4d/lvwW5Qz8V0rJNMcfCesAX+flM FC3rZLi4EHwCEfLck7dD5UikjjQ6JsI+aCsZjeMH3WsBNowlrvxvCpE6tax/IQyhBlde 7+je0GiRvUwID9afe3RbCjgLU4e3qOuVXHzLSohF0pUeTb/XrJwDQOfWgQFxrkWBTT6l gjvtCD+ZuNnnQo/lVQwLaXL4xz0b+mAxOfdlBcR0Vf6g7JZFYjdalIywX/Q0IzK5qNk8 4V4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=sTd7LicY185JjmYkASNJZqode2H0qZcuUtoLofxdYco=; b=x3cRtIKlcr4mdedUHHP603nsQgO4Q9gHfi/cqWcpEF4UWocYCRiFd3TnMubzWRNh0p jXU5dBzSGs7iVTpCso/d448Zx1d4emQ8a055KZOLNI8Ke4+hePbvgYRmsW52357HPZTb yQ3RF8A893pXXzx2Gl0Y7qx7mDozIGQEq1ylCLAQN84AHhCJcTfLrH6332mcGEHq1smo OTIZ1B/P2eKxX3dqAgKEjCXTK/4TL6bpEVOPZkqlx1OA5uKgcr1aKXxpGTqPdxJk5TcS Jpv1HIQ2VNalldhu8zg0Q+ZYuiE4uvyc6XEG/vFWMuDACrh8WtnIUeTaNuEWEs1guTRK e0UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cpLmTQUZ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt7si8221216ejb.395.2020.06.22.06.35.01; Mon, 22 Jun 2020 06:35:25 -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=@gmail.com header.s=20161025 header.b=cpLmTQUZ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728998AbgFVNbN (ORCPT + 99 others); Mon, 22 Jun 2020 09:31:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728254AbgFVNbM (ORCPT ); Mon, 22 Jun 2020 09:31:12 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95B2DC061573 for ; Mon, 22 Jun 2020 06:31:12 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id e18so8154086pgn.7 for ; Mon, 22 Jun 2020 06:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=sTd7LicY185JjmYkASNJZqode2H0qZcuUtoLofxdYco=; b=cpLmTQUZkR6m0WNqPIFfJoZ9+rqMJH+zXIs3tcsWiRgb1S3gyTbh5MPEEtQhzoabKK lYXIjIQQAMRcnNDPaECfgEHxRbEEUR/nNXLFlGwaNlOD/8Z8bEMPWAAUdh1PFX4UyR0+ Avjxcwcz8p+VR8S/7S1jWaEDhgPJkhIfLAXeU5SqVCcyqoI0Nu8eeL/gbhBnXMSIAiHb //Fd/L630VCJOHi2hOH+zHctgv7m4TTbM19Dk4vFHzCUIrUQfZGApdbLgCutZPTUb4eb Oyiqq9EOOtu3LJhucWjCczpAMA/szf7k6M3BdXvHx3I1CaS1tCTP1qIbfZdQT0WCuF6Z AyfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=sTd7LicY185JjmYkASNJZqode2H0qZcuUtoLofxdYco=; b=pV2hblnFZipiFSD0wiv8p0NuT7jQuCh56ctkOMQe0m/UVblvmfO7sKaXW/yQ+zeugB PnwJeL/+Qd2GwIkL7VVC+6NdS7e8B0X6TyekNUDSFhI0itZevtK5XSYc8biZRroeyhm2 5abmReNG2X+P46G4rr2TIvcSaKgriSkUZXWrFYgg0rX6L08ExKOXhX9kALe4PSagoDAW gIBXp5gdAdYQz5QgUA00KDlaD3XVWXcQvlQcyhKxQxzR8eOKHOD+O302bMojRjPcoqYD Gl1CbVedZNX5LlgwHYxZ1pyZibkb0jluEj/YWUOGboMM7fROX0YwgATEzeaYn+Mu1/bF dSxA== X-Gm-Message-State: AOAM533IPmPEnCNvmr9MX4kN5t11tpOHyWqvNxA787FupABGX6Hrlz7g 18wT22Txjo76DjKdaP1OpEM= X-Received: by 2002:a63:a55e:: with SMTP id r30mr12828963pgu.329.1592832672125; Mon, 22 Jun 2020 06:31:12 -0700 (PDT) Received: from aaronlu-desktop ([47.89.83.71]) by smtp.gmail.com with ESMTPSA id z140sm14479088pfc.135.2020.06.22.06.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 06:31:11 -0700 (PDT) Date: Mon, 22 Jun 2020 21:31:04 +0800 From: Aaron Lu To: Peter Oskolkov Cc: Linux Kernel Mailing List , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Vincent Guittot , Peter Oskolkov , avagin@google.com, "pjt@google.com" , Ben Segall Subject: Re: [RFC PATCH 0/3 v2] futex: introduce FUTEX_SWAP operation Message-ID: <20200622133104.GA1525@aaronlu-desktop> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 16, 2020 at 10:22:11AM -0700, Peter Oskolkov wrote: > From 7b091e46de4f9227b5a943e6d78283564e8c1c72 Mon Sep 17 00:00:00 2001 > From: Peter Oskolkov > Date: Tue, 16 Jun 2020 10:13:58 -0700 > Subject: [RFC PATCH 0/3 v2] futex: introduce FUTEX_SWAP operation > > 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. schbench used futex wait/wake to do sleep/wakeup between message thread and worker thread and when worker thread is 1 per message thread, the message thread and worker thread is also flipcall style. So I modified schbench to make use of futex_swap and did a comparison. In the not overloaded case, both runs roughly the same with futex_swap performing slightly better. In the overloaded case, futex_swap performs better than futex wait/wake in all metrics, with 90th seeing the largest difference: 2556us vs 6us. I guess when the scheduler change is in place, more latency gain is expected. Here is the log of the schbench run(on a 16core/32cpu x86_64 machine): overloaded case original schbench(aka futex wait/wake) $./schbench -m 64 -t 1 -r 30 Latency percentiles (usec) 50.0000th: 7 75.0000th: 9 90.0000th: 2556 95.0000th: 7112 *99.0000th: 14160 99.5000th: 17504 99.9000th: 22688 min=0, max=30351 with futex swap $./schbench -m 64 -t 1 -r 30 Latency percentiles (usec) 50.0th: 4 75.0th: 5 90.0th: 6 95.0th: 4568 *99.0th: 12912 99.5th: 15152 99.9th: 20384 min=0, max=30723 not overloaded case original schbench(aka futex wait/wake) $./schbench -m 32 -t 1 -r 30 Latency percentiles (usec) 50.0000th: 6 75.0000th: 7 90.0000th: 8 95.0000th: 9 *99.0000th: 10 99.5000th: 12 99.9000th: 18 min=0, max=398 with futex swap $./schbench -m 32 -t 1 -r 30 Latency percentiles (usec) 50.0th: 4 75.0th: 5 90.0th: 5 95.0th: 6 *99.0th: 8 99.5th: 9 99.9th: 12 min=0, max=245