seqcount: Add raw_write_seqcount_latch()
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 16 Jul 2014 21:05:21 +0000 (21:05 +0000)
committerJohn Stultz <john.stultz@linaro.org>
Wed, 23 Jul 2014 22:01:54 +0000 (15:01 -0700)
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 <mathieu.desnoyers@efficios.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
include/linux/seqlock.h

index dcc64b9bfc412392dd73a117b24e9020176834f8..cce6e7453592dbee0c33e2858f6c592bf1eeaf84 100644 (file)
@@ -235,6 +235,17 @@ static inline void raw_write_seqcount_end(seqcount_t *s)
        s->sequence++;
 }
 
+/*
+ * 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.