Skip to content

Commit 932e463

Browse files
a-darwishPeter Zijlstra
authored andcommitted
seqlock: Implement raw_seqcount_begin() in terms of raw_read_seqcount()
raw_seqcount_begin() has the same code as raw_read_seqcount(), with the exception of masking the sequence counter's LSB before returning it to the caller. Note, raw_seqcount_begin() masks the counter's LSB before returning it to the caller so that read_seqcount_retry() can fail if the counter is odd -- without the overhead of an extra branching instruction. Signed-off-by: Ahmed S. Darwish <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 89b8884 commit 932e463

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

include/linux/seqlock.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ static inline unsigned raw_read_seqcount(const seqcount_t *s)
199199
*/
200200
static inline unsigned raw_seqcount_begin(const seqcount_t *s)
201201
{
202-
unsigned ret = READ_ONCE(s->sequence);
203-
smp_rmb();
204-
kcsan_atomic_next(KCSAN_SEQLOCK_REGION_MAX);
205-
return ret & ~1;
202+
/*
203+
* If the counter is odd, let read_seqcount_retry() fail
204+
* by decrementing the counter.
205+
*/
206+
return raw_read_seqcount(s) & ~1;
206207
}
207208

208209
/**

0 commit comments

Comments
 (0)