From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753390AbaGPVGH (ORCPT ); Wed, 16 Jul 2014 17:06:07 -0400 Received: from www.linutronix.de ([62.245.132.108]:59928 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753280AbaGPVFX (ORCPT ); Wed, 16 Jul 2014 17:05:23 -0400 Message-Id: <20140716205057.481379409@linutronix.de> User-Agent: quilt/0.63-1 Date: Wed, 16 Jul 2014 21:05:21 -0000 From: Thomas Gleixner To: LKML Cc: John Stultz , Peter Zijlstra , Mathieu Desnoyers , Ingo Molnar , Steven Rostedt Subject: [patch V2 62/64] seqcount: Add raw_write_seqcount_latch() References: <20140716205018.175419210@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Disposition: inline; filename=seqcount-add-raw-write-seqcount-latch.patch X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathieu Desnoyers For NMI safe access to clock monotonic we use the seqcount LSB as index of a timekeeper array. The update sequence looks like this: smp_wmb(); <- prior stores to a[1] seq++; smp_wmb(); <- seq increment before update of a[0] update(a[0]); smp_wmb(); <- update of a[0] seq++; smp_wmb(); <- seq increment before update of a[1] update(a[1]); To avoid open coded barriers, provide a helper function. [ tglx: Split out of a combo patch against the first implementation of the NMI safe accessor ] Signed-off-by: Mathieu Desnoyers Cc: John Stultz Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Steven Rostedt Signed-off-by: Thomas Gleixner --- include/linux/seqlock.h | 11 +++++++++++ 1 file changed, 11 insertions(+) Index: tip/include/linux/seqlock.h =================================================================== --- tip.orig/include/linux/seqlock.h +++ tip/include/linux/seqlock.h @@ -236,6 +236,17 @@ static inline void raw_write_seqcount_en } /* + * raw_write_seqcount_latch - redirect readers to even/odd copy + * @s: pointer to seqcount_t + */ +static inline void raw_write_seqcount_latch(seqcount_t *s) +{ + smp_wmb(); /* prior stores before incrementing "sequence" */ + s->sequence++; + smp_wmb(); /* increment "sequence" before following stores */ +} + +/* * Sequence counter only version assumes that callers are using their * own mutexing. */