[<prev] [next>] [day] [month] [year] [list]
Message-ID: <414e292195d720c780fab2781c749df3be6566aa.camel@posk.io>
Date: Mon, 15 Jun 2020 10:29:36 -0700
From: Peter Oskolkov <posk@...k.io>
To: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Darren Hart <dvhart@...radead.org>,
Vincent Guittot <vincent.guittot@...aro.org>
Cc: Peter Oskolkov <posk@...gle.com>, avagin@...gle.com,
"pjt@...gle.com" <pjt@...gle.com>, Ben Segall <bsegall@...gle.com>
Subject: [RFC PATCH 0/3] futex/sched: introduce FUTEX_SWAP operation
>From 42709b7f82d38c573fc1ff5f5aa7d0065ee54b82 Mon Sep 17 00:00:00 2001
From: Peter Oskolkov <posk@...gle.com>
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
Powered by blists - more mailing lists