From: Peter Zijlstra <peterz@infradead.org>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Ingo Molnar <mingo@redhat.com>, Paul Turner <commonly@gmail.com>,
Andi Kleen <andi@firstfloor.org>, Chris Lameter <cl@linux.com>,
Dave Watson <davejwatson@fb.com>,
Josh Triplett <josh@joshtriplett.org>,
Linux API <linux-api@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Andrew Hunter <ahh@google.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [RFC PATCH 0/3] restartable sequences v2: fast user-space percpu critical sections
Date: Thu, 7 Apr 2016 22:11:56 +0200 [thread overview]
Message-ID: <20160407201156.GC3448@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CALCETrVGo1Di3qamxx1NAFUSN_o=-HnYRDpeVp7zrQEBwe5u-g@mail.gmail.com>
On Thu, Apr 07, 2016 at 09:43:33AM -0700, Andy Lutomirski wrote:
> More concretely, this looks like (using totally arbitrary register
> assingments -- probably far from ideal, especially given how GCC's
> constraints work):
>
> enter the critical section:
> 1:
> movq %[cpu], %%r12
> movq {address of counter for our cpu}, %%r13
> movq {some fresh value}, (%%r13)
> cmpq %[cpu], %%r12
> jne 1b
>
> ... do whatever setup or computation is needed...
>
> movq $%l[failed], %%rcx
> movq $1f, %[commit_instr]
> cmpq {whatever counter we chose}, (%%r13)
> jne %l[failed]
> cmpq %[cpu], %%r12
> jne %l[failed]
>
> <-- a signal in here that conflicts with us would clobber (%%r13), and
> the kernel would notice and send us to the failed label
>
> movq %[to_write], (%[target])
> 1: movq $0, %[commit_instr]
And the kernel, for every thread that has had the syscall called and a
thingy registered, needs to (at preempt/signal-setup):
if (get_user(post_commit_ip, current->post_commit_ip))
return -EFAULT;
if (likely(!post_commit_ip))
return 0;
if (regs->ip >= post_commit_ip)
return 0;
if (get_user(seq, (u32 __user *)regs->r13))
return -EFAULT;
if (regs->$(which one holds our chosen seq?) == seq) {
/* nothing changed, do not cancel, proceed to commit. */
return 0;
}
if (put_user(0UL, current->post_commit_ip))
return -EFAULT;
regs->ip = regs->rcx;
> In contrast to Paul's scheme, this has two additional (highly
> predictable) branches and requires generation of a seqcount in
> userspace. In its favor, though, it doesnt need preemption hooks,
Without preemption hooks, how would one thread preempting another at the
above <-- clobber anything and cause the commit to fail?
> it's inherently debuggable,
It is more debuggable, agreed.
> and it allows multiple independent
> rseq-protected things to coexist without forcing each other to abort.
And the kernel only needs to load the second cacheline if it lands in
the middle of a finish block, which should be manageable overhead I
suppose.
But the userspace chunk is lots slower as it needs to always touch
multiple lines, since the @cpu, @seq and @post_commit_ip all live in
separate lines (although I suppose @cpu and @post_commit_ip could live
in the same).
The finish thing needs 3 registers for:
- fail ip
- seq pointer
- seq value
Which I suppose is possible even on register constrained architectures
like i386.
next prev parent reply other threads:[~2016-04-07 20:12 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-27 23:56 [RFC PATCH 0/3] restartable sequences v2: fast user-space percpu critical sections Paul Turner
2015-10-27 23:56 ` [RFC PATCH v2 1/3] restartable sequences: user-space per-cpu " Paul Turner
2015-11-19 16:38 ` Johannes Berg
2015-12-11 12:56 ` Mathieu Desnoyers
2015-10-27 23:57 ` [RFC PATCH v2 2/3] restartable sequences: x86 ABI Paul Turner
2015-10-28 5:03 ` Peter Zijlstra
2015-10-28 5:19 ` Paul Turner
2015-12-11 13:30 ` Mathieu Desnoyers
2015-10-27 23:57 ` [RFC PATCH v2 3/3] restartable sequences: basic self-tests Paul Turner
2016-04-05 20:33 ` Mathieu Desnoyers
2016-04-06 7:43 ` Peter Zijlstra
2016-04-06 13:39 ` Mathieu Desnoyers
2016-04-06 19:25 ` Peter Zijlstra
2015-10-28 14:44 ` [RFC PATCH 0/3] restartable sequences v2: fast user-space percpu critical sections Dave Watson
2015-12-11 12:05 ` Mathieu Desnoyers
2015-12-11 13:39 ` Mathieu Desnoyers
2016-04-06 15:56 ` Andy Lutomirski
2016-04-07 12:02 ` Peter Zijlstra
2016-04-07 14:35 ` Andy Lutomirski
2016-04-07 15:24 ` Peter Zijlstra
2016-04-07 15:39 ` Peter Zijlstra
2016-04-07 15:44 ` Andy Lutomirski
2016-04-07 15:53 ` Peter Zijlstra
2016-04-07 16:43 ` Andy Lutomirski
2016-04-07 20:11 ` Peter Zijlstra [this message]
2016-04-07 22:05 ` Andy Lutomirski
2016-04-08 1:11 ` Mathieu Desnoyers
2016-04-08 1:21 ` Andy Lutomirski
2016-04-08 2:05 ` Mathieu Desnoyers
2016-04-08 17:46 ` Mathieu Desnoyers
2016-04-08 21:16 ` Andy Lutomirski
2016-04-08 21:25 ` Linus Torvalds
2016-04-10 14:07 ` Mathieu Desnoyers
2016-04-08 11:02 ` Peter Zijlstra
2016-04-08 15:57 ` Andy Lutomirski
2016-04-08 6:41 ` Peter Zijlstra
2016-04-08 15:58 ` Andy Lutomirski
2016-04-11 21:55 ` Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160407201156.GC3448@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=ahh@google.com \
--cc=andi@firstfloor.org \
--cc=cl@linux.com \
--cc=commonly@gmail.com \
--cc=davejwatson@fb.com \
--cc=josh@joshtriplett.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox