From 0ea5a520f73ca31abc4c10b6d5bc14a884a0641b Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Wed, 16 Jul 2014 21:05:20 +0000 Subject: seqcount: Provide raw_read_seqcount() raw_read_seqcount opens a read critical section of the given seqcount without any lockdep checking and without checking or masking the LSB. Calling code is responsible for handling that. Preparatory patch to provide a NMI safe clock monotonic accessor function. Signed-off-by: Thomas Gleixner Cc: John Stultz Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Mathieu Desnoyers Signed-off-by: John Stultz --- include/linux/seqlock.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include/linux/seqlock.h') diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index 535f158977b9..dcc64b9bfc41 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -116,6 +116,22 @@ repeat: return ret; } +/** + * raw_read_seqcount - Read the raw seqcount + * @s: pointer to seqcount_t + * Returns: count to be passed to read_seqcount_retry + * + * raw_read_seqcount opens a read critical section of the given + * seqcount without any lockdep checking and without checking or + * masking the LSB. Calling code is responsible for handling that. + */ +static inline unsigned raw_read_seqcount(const seqcount_t *s) +{ + unsigned ret = ACCESS_ONCE(s->sequence); + smp_rmb(); + return ret; +} + /** * raw_read_seqcount_begin - start seq-read critical section w/o lockdep * @s: pointer to seqcount_t -- cgit From 9b0fd802e8c0545148324916055e7b40d97963fa Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 16 Jul 2014 21:05:21 +0000 Subject: seqcount: Add raw_write_seqcount_latch() 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 Signed-off-by: John Stultz --- include/linux/seqlock.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/linux/seqlock.h') diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index dcc64b9bfc41..cce6e7453592 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -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. -- cgit