Received: by 10.192.165.148 with SMTP id m20csp2126879imm; Thu, 3 May 2018 10:48:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpefV1zFqDE4p/MPa7MAqC7O9dA61p8kiD7Ml14VEhTVLncAHC1SWxBz5OiTyy/ZJ/7ncJU X-Received: by 10.98.159.202 with SMTP id v71mr23868590pfk.233.1525369727669; Thu, 03 May 2018 10:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525369727; cv=none; d=google.com; s=arc-20160816; b=VCbemVxvUAwGYFatAkUiDziVS1vOo8t+zzZOzS5Kvngb4e413zDIckUWsNoEfyrOR3 R3kyGCBN/ARUuor2c8SlIMjEQ6Av3UKLR1XYbW8mdAOK//9vjWJrTtPCm+fPa2DFT7H7 7VekMVOfpgcNEYl/i2LcVa0kHRtUZLtnTqJn0LZboWeBs4WtNxx6dYrjVPmBt0xflIe5 +7a+VnlBD0j0Ehu3bBDCqOs8SyqA6tlUL+iDx8o0RnuJdUxaXfwFd2BrYSQ7H1ColMMo 3vvk+W+q0hmnK0ElA/azXGeDcFLoJcXQGBroFECulDIalXEgIKmjk2UDSyeZmXYkp9jq Qmcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=PdhmCmglKqzzpw+7cjpJPPAe33NjGtxgJojAGmH4pIw=; b=vJMMEdWva/uBNPckUnW/G9mxaLrM03u3WuIGFBYSwNYWudINAn9aznmieW64CawibF Jn/kYldp0qM4xEFOPDrMVM9d+Eoz1E6fzZC7woZsset+06AJWh9fclFxPaaWuYmWVUrD rM48iTLe4oc9hnYgdlaCCW8IcKo10gwEU2lY2oyO+a38yXIyOQoLdTvbzW0MSJCbIYF3 JcbFWRRFsbW2rt/Dck2kUaNAvTgVIjEQd7N74c++v9z6xXBNpUfqMA9XneqGJ15eE/vY IAB4wVxUfnfjP9YwTlBo7tNo3bpJD+7jNuKXoFHXhqJ+8FiJZhqJtpQ9JTa25KomFTy9 kCxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HQcD4lpT; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b16si14351211pfd.240.2018.05.03.10.48.33; Thu, 03 May 2018 10:48:47 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=HQcD4lpT; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751324AbeECRrM (ORCPT + 99 others); Thu, 3 May 2018 13:47:12 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:43215 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751269AbeECRrI (ORCPT ); Thu, 3 May 2018 13:47:08 -0400 Received: by mail-io0-f194.google.com with SMTP id t23-v6so22606328ioc.10 for ; Thu, 03 May 2018 10:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PdhmCmglKqzzpw+7cjpJPPAe33NjGtxgJojAGmH4pIw=; b=HQcD4lpT3+oljQSd3lRLVTm8VazgexiTOIQlatDxAdIl7++IiAtKzVczt0k3TSU/Y+ GDYMYs5WKMgnSq7twLC+gGHaZ3wThlTqocCJwJ087hTce7Nq9zJtChUxonbnyfwdewMN LRYuksLx5PC8Ppdc8KmGw/Go0eOx2SsHOGGemoqw/MoCC7Yl1X5cQxUNxcreEt2ajTL2 8yFb9oZn9IFKZPRCzCcJvMS2wW1waw+/Tw75gSIczVcPDRebRwnqE+nm5qlw5fQpd/ud I52/ADHgMKfeAviSzCZ93It/IQJn+flyAG2KE0wU+zEzmGYKF8olOjYxGwmpXWIkxwa+ GC8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PdhmCmglKqzzpw+7cjpJPPAe33NjGtxgJojAGmH4pIw=; b=VKdPOUwk2cYE/XAXXC8/IO1H4qiw5DB3C03a+3SCeMVO0G1dcAttX8Nwdguh1Vezfq JT17Sf/f/X6EVhquODfxDFRRg9G2f6fK0NZsJYc28aS2yQvYTAfvvW7X6rMNba1TeKlG wMKWMVVeE7nyxmJJwSonLAhP8z/F4kHmdf/W1oLn5c8+XejrIYcVkAAPqZRgt5eXJjov p8HBwt0dlxCuiSk7zfbrq/s7g8G2zKOj/W5LgHJZSeeyKqku+okSUNwbczI/1uDKaTr5 KpNJDwe1a4BroM9cp1DcEOZmZfxEMj9N3uku0Vi0mT5DpEx5zEOaKzScZxUIIAtUHQ5Y QmfA== X-Gm-Message-State: ALQs6tDqtnSxwudHMp/JN8XrFKIUfrY0C6EnIboWr6h0llzaHa/YM16P bz43RdtI6ltfe6IGub8FUlDlSy5TcMqI1uHB26mgzw== X-Received: by 2002:a6b:be01:: with SMTP id o1-v6mr25174981iof.299.1525369626448; Thu, 03 May 2018 10:47:06 -0700 (PDT) MIME-Version: 1.0 References: <20180430224433.17407-1-mathieu.desnoyers@efficios.com> <660904075.9201.1525276988842.JavaMail.zimbra@efficios.com> <1718748931.10084.1525363941807.JavaMail.zimbra@efficios.com> In-Reply-To: From: Joel Fernandes Date: Thu, 03 May 2018 17:46:55 +0000 Message-ID: Subject: Re: [RFC PATCH for 4.18 00/14] Restartable Sequences To: Daniel Colascione Cc: Mathieu Desnoyers , Peter Zijlstra , Paul McKenney , Boqun Feng , Andy Lutomirski , davejwatson@fb.com, LKML , linux-api@vger.kernel.org, Paul Turner , Andrew Morton , linux@arm.linux.org.uk, Thomas Gleixner , Ingo Molnar , hpa@zytor.com, Andrew Hunter , andi@firstfloor.org, cl@linux.com, bmaurer@fb.com, Steven Rostedt , Josh Triplett , torvalds@linux-foundation.org, Catalin Marinas , Will Deacon , mtk.manpages@gmail.com, longman@redhat.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel, Nice to have this healthy discussion about pros/cons. Adding Waiman to the discussion as well. Curious to hear what Waiman and Peter think about all this. Some more comments inline. On Thu, May 3, 2018 at 10:19 AM Daniel Colascione wrote: > On Thu, May 3, 2018 at 9:48 AM Joel Fernandes wrote: > > > > can skip the manual schedule we were going to perform. > > > By the way, if we eventually find a way to enhance user-space mutexes in > > the > > > fashion you describe here, it would belong to another TLS area, and > would > > > be registered by another system call than rseq. I proposed a more > generic > > Right. Also I still don't see any good reason why optimistic spinning in > > the kernel with FUTEX_LOCK, as Peter described, can't be used instead of > > using the rseq implementation and spinning in userspace, for such a case. > I > > don't really fully buy that we need to design this interface assuming any > > privilege transition level time. > > If privilege level transitions are slow, > > we're going to have bad performance anyway. > That's not the case. There's a large class of program that does useful work > while seldom entering the kernel: just ask the user-space network stack > people. Yes, I am aware of that. I was just saying in general, a system such as an Android embedded system, not an HPC based system does make a lot of system calls. I am not arguing that doing more things in userspace is good or bad here. I am just talking about why do something else for no good reasons (see below) when work has already been done on this area. > It's not wise to design interfaces around system calls being cheap. Even if > system calls are currently cheap enough on some architectures some of the > time, there's no guarantee that they'll stay that way, especially relative > to straight-line user-mode execution. A pure user-space approach, on the > other hand, involves no work in the kernel, and doing nothing is always the > optimal strategy. Besides, there are environments where system calls end up > being more expensive than you might think: consider strace or rr. If the > kernel needs to get involved on some path, it's best that its involvement > be as light as possible. Ofcourse, but I think we shouldn't do a premature optimization here without real data on typical Android devices about the cost of system calls entry/exit, vs spin time. I am not against userspace lock based on rseq if there is data and good reason, before investing significant time on reinventing the wheel. > > we should really stick to using FUTEX_LOCK and > > reuse all the work that went into that area for Android and otherwise (and > > work with Waiman and others on improving that if there are any problems > > with it). > FUTEX_LOCK is a return to the bad old days when systems gave you a fixed > list of synchronization primitives and if you wanted something else, tough. I am not saying we should fix sync. primitives made available to userspace, or anything. I am talking about yours/our usecase and whether another sync primitive interface is needed. For example, have another syscall to register TLS area is a new interface, vs using the existing futex interface. Linus is also against adding new sycalls unnecessarily. > That the latest version of the FUTEX_LOCK patch includes a separate > FUTEX_LOCK_SHARED mode is concerning. The functionality the kernel provides Why? That's just for reader-locks. What's the concern there? I know you had something in mind about efficient userspace rw locks but I am curious either way what you have in mind. > to userspace should be more general-purpose and allow more experimentation > without changes in the kernel. I see no reason to force userspace into 1) > reserving 30 bits of its lockword for a TID and 2) adopting the kernel's Based on our offline chat, this is for only 32-bit only systems though right? Also based on Peter's idea of putting the recursion counter outside, there shouldn't be a space issue? > idea of spin time heuristics and lock stealing when the same basic > functionality can be provided in a generic way while reserving only one > bit. That this mechanism happens to be more efficient as well is a bonus. And also probably easy to get wrong. Heuristics are hard and it would be good to work with community on getting best approach for that and improving existing code. Also about "generic way", that's even more reason in my view to do it in the kernel. > "Mechanism not policy" is still a good design principle. Again, I am not advocating forcing of interfaces anything, but I'm against reinventing the wheel and am all for spending time on improving existing things. thanks! - Joel