From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754746AbbDNK1S (ORCPT ); Tue, 14 Apr 2015 06:27:18 -0400 Received: from mail-wi0-f171.google.com ([209.85.212.171]:36255 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753793AbbDNK06 (ORCPT ); Tue, 14 Apr 2015 06:26:58 -0400 Date: Tue, 14 Apr 2015 12:26:52 +0200 From: Ingo Molnar To: Peter Zijlstra Cc: rusty@rustcorp.com.au, mathieu.desnoyers@efficios.com, oleg@redhat.com, paulmck@linux.vnet.ibm.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, andi@firstfloor.org, rostedt@goodmis.org, tglx@linutronix.de, laijs@cn.fujitsu.com, linux@horizon.com, Andrea Arcangeli , David Woodhouse , Rik van Riel , Michel Lespinasse Subject: Re: [PATCH v5 05/10] seqlock: Better document raw_write_seqcount_latch() Message-ID: <20150414102652.GB13015@gmail.com> References: <20150413141126.756350256@infradead.org> <20150413141213.492831596@infradead.org> <20150413163201.GC6040@gmail.com> <20150413191750.GK23123@twins.programming.kicks-ass.net> <20150413194725.GY24151@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150413194725.GY24151@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Peter Zijlstra wrote: > On Mon, Apr 13, 2015 at 09:17:50PM +0200, Peter Zijlstra wrote: > > On Mon, Apr 13, 2015 at 06:32:02PM +0200, Ingo Molnar wrote: > > > > > > Btw., I realize this is just a sample, but couldn't this be written > > > more optimally as: > > > > > > do { > > > seq = READ_ONCE(latch->seq); > > > smp_read_barrier_depends(); > > > > > > idx = seq & 0x01; > > > entry = data_query(latch->data[idx], ...); > > > > > > smp_rmb(); > > > } while (seq != latch->seq); > > > > > > Should we look at introducing yet another seq primitive? > > Like so? > > --- > --- a/include/linux/seqlock.h > +++ b/include/linux/seqlock.h > @@ -233,6 +233,11 @@ static inline void raw_write_seqcount_en > s->sequence++; > } > > +static inline int raw_read_seqcount_latch(seqcount_t *s) > +{ > + return lockless_dereference(s->sequence); > +} > + > /** > * raw_write_seqcount_latch - redirect readers to even/odd copy > * @s: pointer to seqcount_t > @@ -284,8 +289,7 @@ static inline void raw_write_seqcount_en > * unsigned seq, idx; > * > * do { > - * seq = latch->seq; > - * smp_rmb(); > + * seq = lockless_dereference(latch->seq); > * > * idx = seq & 0x01; > * entry = data_query(latch->data[idx], ...); > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -393,7 +393,7 @@ static __always_inline u64 __ktime_get_f > u64 now; > > do { > - seq = raw_read_seqcount(&tkf->seq); > + seq = raw_read_seqcount_latch(&tkf->seq); > tkr = tkf->base + (seq & 0x01); > now = ktime_to_ns(tkr->base) + timekeeping_get_ns(tkr); > } while (read_seqcount_retry(&tkf->seq, seq)); Sounds good to me! Thanks, Ingo