Received: by 10.213.65.68 with SMTP id h4csp2497068imn; Mon, 2 Apr 2018 08:36:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx48F9+D4K9/IgNGYjYJxCOp7cwIkoFkEK33n/WBGQvhNCIQ3eLBEjeKZqn2hpbSPzD7mGrMe X-Received: by 2002:a17:902:9a88:: with SMTP id w8-v6mr10279989plp.29.1522683378528; Mon, 02 Apr 2018 08:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522683378; cv=none; d=google.com; s=arc-20160816; b=x1Uha02nj4IJp8OlZkZqonXZKTlW/o93n+Y64TJNdQTQUFgH2JSIBNzFqjfKWr853N FMWdPOC83/NL2RaaWlMYqIp2MHPsP4UAkK3vShg0mIcOrzOm/XsVZW5LubCGb3Txz4se qSf03QJkY1gNxKTOXQ2u3/1MWvTdlkKrps7tgixL7mduSr5yz1EAm/pDIeuCh1NIQ2Lp I/XVwlKJO12TAzOS3c+uNVx7MgyTwiIRuzYpYgd2mrpgZvw7Y5bhqtz8Iaz6M/EDdy8o HWa5/FsOm+kQ1kahbnAMWR4oX8TENAccKXdwkpyELTe8FJFtzuGM8Me850TpX7suZQTY S14A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:arc-authentication-results; bh=wDY1UiicHsKGWdrBdGAbJZAN+Ta0z3TZglGpEwisqkY=; b=zFfLtLR98T7ceO2i3x+qFjEVUj4Qa4M6/T+rRx27QqrkxmazM1HXPFeAN+O5smB6ou KQpwJPmc4uSzAApGc0gVubhVust7sGjOJ+dzqN0Rsk9BCEbBQpogohOQIbPCG/l8DAJf vPkA5j6JsjWDZMPq8k4zGglNmZ+HOVdkM1zvKoulRN7VaVZgPTrrtSIDh3ITfuJkUB9z W/awpeIC2kRsB1slIFSCMtas1GkULJ8BFn8gEQD73/1h5Q4/PQxJzjR/0ZHu6mj0x0EI R2u0Uf16BJ0HqTbhK3B5Xg25Wf1wpeMmbb0I/iZpnvgJQUzu8Pqhbp7OLQrsksTX15ON XFcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31-v6si519560plj.703.2018.04.02.08.36.04; Mon, 02 Apr 2018 08:36:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752464AbeDBPdP (ORCPT + 99 others); Mon, 2 Apr 2018 11:33:15 -0400 Received: from mail.efficios.com ([167.114.142.138]:51794 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751443AbeDBPdK (ORCPT ); Mon, 2 Apr 2018 11:33:10 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 03FB71A711C; Mon, 2 Apr 2018 11:33:10 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id puDFjLMfnoeZ; Mon, 2 Apr 2018 11:33:09 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 201241A7119; Mon, 2 Apr 2018 11:33:09 -0400 (EDT) X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id b1ImASGf5ybS; Mon, 2 Apr 2018 11:33:09 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 0261E1A710E; Mon, 2 Apr 2018 11:33:09 -0400 (EDT) Date: Mon, 2 Apr 2018 11:33:08 -0400 (EDT) From: Mathieu Desnoyers To: One Thousand Gnomes Cc: Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Andy Lutomirski , Dave Watson , linux-kernel , linux-api , Paul Turner , Andrew Morton , Russell King , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Andrew Hunter , Andi Kleen , Chris Lameter , Ben Maurer , rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon , Michael Kerrisk , Alexander Viro Message-ID: <1890356924.1736.1522683188833.JavaMail.zimbra@efficios.com> In-Reply-To: <20180401171356.085a2a33@alans-desktop> References: <20180327160542.28457-1-mathieu.desnoyers@efficios.com> <20180327160542.28457-3-mathieu.desnoyers@efficios.com> <20180401171356.085a2a33@alans-desktop> Subject: Re: [RFC PATCH for 4.17 02/21] rseq: Introduce restartable sequences system call (v12) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.7_GA_1964 (ZimbraWebClient - FF52 (Linux)/8.8.7_GA_1964) Thread-Topic: rseq: Introduce restartable sequences system call (v12) Thread-Index: ZlI8yYRhtR4Zm8XQBnk6z8Kg2ePiGg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Apr 1, 2018, at 12:13 PM, One Thousand Gnomes gnomes@lxorguk.ukuu.org.uk wrote: > On Tue, 27 Mar 2018 12:05:23 -0400 > Mathieu Desnoyers wrote: > >> Expose a new system call allowing each thread to register one userspace >> memory area to be used as an ABI between kernel and user-space for two >> purposes: user-space restartable sequences and quick access to read the >> current CPU number value from user-space. > > What is the *worst* case timing achievable by using the atomics ? What > does it do to real time performance requirements ? Given that there are two system calls introduced in this series (rseq and cpu_opv), can you clarify which system call you refer to in the two questions above ? For rseq, given that its userspace works pretty much like a read seqlock (it retries on failure), it has no impact whatsoever on scheduler behavior. So characterizing its worst case timing does not appear to be relevant. > For cpu_opv you now > give an answer but your answer is assuming there isn't another thread > actively thrashing the cache or store buffers, and that the user didn't > sneakily pass in a page of uncacheable memory (eg framebuffer, or GPU > space). Are those considered as device pages ? > > I don't see anything that restricts it to cached pages. With that check > in place for x86 at least it would probably be ok and I think the sneaky > attacks to make it uncacheable would fail becuase you've got the pages > locked so trying to give them to an accelerator will block until you are > done. > > I still like the idea it's just the latencies concern me. Indeed, cpu_opv touches pages that are shared with user-space with preemption off, so this one affects the scheduler latency. The worse-case timings I measured for cpu_opv were with cache-cold memory. So I expect that another thread actively trashing the cache would be in the same ballpark figure. It does not account for a concurrent thread thrashing the store buffers though. The checks enforcing which pages can be touched by cpu_opv operations are done within cpu_op_check_page(). is_zone_device_page() is used to ensure no device page is touched with preempt disabled. I understand that you would prefer to disallow pages of uncacheable memory as well, which I'm fine with. Is there an API similar to is_zone_device_page() to check whether a page is uncacheable ? > >> Restartable sequences are atomic with respect to preemption >> (making it atomic with respect to other threads running on the >> same CPU), as well as signal delivery (user-space execution >> contexts nested over the same thread). > > CPU generally means 'big lump with legs on it'. You are not atomic to the > same CPU, because that CPU may have 30+ cores with 8 threads per core. > > It could do with some better terminology (hardware thread, CPU context ?) Would you be OK with Christoph's terminology of "Hardware Execution Context" ? > >> In a typical usage scenario, the thread registering the rseq >> structure will be performing loads and stores from/to that >> structure. It is however also allowed to read that structure >> from other threads. The rseq field updates performed by the >> kernel provide relaxed atomicity semantics, which guarantee >> that other threads performing relaxed atomic reads of the cpu >> number cache will always observe a consistent value. > > So what happens to your API if the kernel atomics get improved ? You are > effectively exporting rseq behaviour from private to public. Relaxed atomics is pretty much the loosest kind of consistency we can provide before we start allowing the compiler to do load/store tearing (it's basically a volatile store of a word-aligned word). It does not involve any kind of memory barrier whatsoever. I expect that the atomics that may evolve in the future will be those with release/acquire and implicit barriers semantics. The relaxed atomicity does not cover any of these. Thanks, Mathieu > > Alan -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com