Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756674AbcDGPpB (ORCPT ); Thu, 7 Apr 2016 11:45:01 -0400 Received: from mail-oi0-f51.google.com ([209.85.218.51]:33952 "EHLO mail-oi0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751345AbcDGPo7 (ORCPT ); Thu, 7 Apr 2016 11:44:59 -0400 MIME-Version: 1.0 In-Reply-To: <20160407152432.GZ3448@twins.programming.kicks-ass.net> References: <20151027235635.16059.11630.stgit@pjt-glaptop.roam.corp.google.com> <20160407120254.GY3448@twins.programming.kicks-ass.net> <20160407152432.GZ3448@twins.programming.kicks-ass.net> From: Andy Lutomirski Date: Thu, 7 Apr 2016 08:44:38 -0700 Message-ID: Subject: Re: [RFC PATCH 0/3] restartable sequences v2: fast user-space percpu critical sections To: Peter Zijlstra Cc: Mathieu Desnoyers , "Paul E. McKenney" , Ingo Molnar , Paul Turner , Andi Kleen , Chris Lameter , Dave Watson , Josh Triplett , Linux API , "linux-kernel@vger.kernel.org" , Andrew Hunter , Linus Torvalds Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2578 Lines: 70 On Thu, Apr 7, 2016 at 8:24 AM, Peter Zijlstra wrote: > On Thu, Apr 07, 2016 at 07:35:26AM -0700, Andy Lutomirski wrote: >> What I meant was: rather than shoving individual values into the TLABI >> thing, shove in a pointer: >> >> struct commit_info { >> u64 post_commit_rip; >> u32 cpu; >> u64 *event; >> // whatever else; >> }; >> >> and then put a commit_info* in TLABI. >> >> This would save some bytes in the TLABI structure. > > But would cost us extra indirections. The whole point was getting this > stuff at a constant offset from the TLS segment register. I don't think the extra indirections would matter much. The kernel would have to chase the pointer, but only in the very rare case where it resumes userspace during a commit or on the immediately following instruction. At the very least, post_commit_rip and the abort address (which I forgot about) could both live in a static structure, and shoving a pointer to *that* into TLABI space is one store instead of two. Admittedly, this is just a minor tweak either way. I'm just wondering an extra indirect variant ends up being slightly faster. > >> > So letting the user manage the event is doable, but it would still be >> > advisable to have the event in the same shared word. >> > >> >> Why is a single load needed? The event and CPU in the TLABI structure >> are only ever accessed from the thread in question. > > Its not required, but being able to do a single load saves on cycles, > less cycles is more good. > >> That way we could take an async signal, handle it, and resume, even in >> the middle of a commit, without aborting. Of course, if the signal >> hander tried to access the same rseq-protected resource, it would bump >> the event counter and cause an abort. > > Ah, so what happens if the signal happens before the commit but after > the load of the seqcount? > > Then, even if the signal motifies the count, we'll not observe. > Where exactly? In my scheme, nothing except the kernel ever loads the seqcount. The user code generates a fresh value, writes it to memory, and then, just before commit, writes that same value to the TLABI area and then double-checks that the value it wrote at the beginning is still there. If the signal modifies the count, then the user code won't directly notice, but prepare_exit_to_usermode on the way out of the signal will notice that the (restored) TLABI state doesn't match the counter that the signal handler changed and will just to the abort address. --Andy -- Andy Lutomirski AMA Capital Management, LLC