From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932565AbbDMRIW (ORCPT ); Mon, 13 Apr 2015 13:08:22 -0400 Received: from mail.efficios.com ([78.47.125.74]:55716 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751996AbbDMRIT (ORCPT ); Mon, 13 Apr 2015 13:08:19 -0400 Date: Mon, 13 Apr 2015 17:08:19 +0000 (UTC) From: Mathieu Desnoyers To: Ingo Molnar Cc: Peter Zijlstra , rusty@rustcorp.com.au, 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 Message-ID: <1979415164.29724.1428944899771.JavaMail.zimbra@efficios.com> In-Reply-To: <20150413163201.GC6040@gmail.com> References: <20150413141126.756350256@infradead.org> <20150413141213.492831596@infradead.org> <20150413163201.GC6040@gmail.com> Subject: Re: [PATCH v5 05/10] seqlock: Better document raw_write_seqcount_latch() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [192.222.194.238] X-Mailer: Zimbra 8.0.7_GA_6021 (ZimbraWebClient - FF37 (Linux)/8.0.7_GA_6021) Thread-Topic: seqlock: Better document raw_write_seqcount_latch() Thread-Index: Sw5bwcO7P/70ZaYwDrqRQANqGOBzfA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- Original Message ----- > > * Peter Zijlstra wrote: > [...] > > + * The query will have a form like: > > + * > > + * struct entry *latch_query(struct latch_struct *latch, ...) > > + * { > > + * struct entry *entry; > > + * unsigned seq, idx; > > + * > > + * do { > > + * seq = latch->seq; > > + * smp_rmb(); > > + * > > + * idx = seq & 0x01; > > + * entry = data_query(latch->data[idx], ...); > > + * > > + * smp_rmb(); > > + * } while (seq != latch->seq); > > 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); > > Note that there's just a single smp_rmb() barrier: the READ_ONCE() is > there to make sure GCC doesn't calculate 'idx' from two separate > reads, but otherwise there's a direct data dependency on latch->seq so > no smp_rmb() is needed, only a data dependency barrier when doing the > first lookup AFAICS? > > (This doesn't matter on x86 where smp_rmb() is barrier().) The latch evolved from seqlock.h, where there was no data dependency between the sequence counter and the data read, hence the smp_rmb(). Indeed, there is a data dependency in the case of the latch, so I think your approach of READ_ONCE + smp_read_barrier_depends() is appropriate. Thanks! Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com