Optimize the seqlock implementation
authorBart Van Assche <bvanassche@acm.org>
Sun, 21 Jun 2020 21:24:36 +0000 (14:24 -0700)
committerBart Van Assche <bvanassche@acm.org>
Mon, 22 Jun 2020 02:47:25 +0000 (19:47 -0700)
Use atomic_load_acquire() and atomic_store_release() instead of barriers
where appropriate.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
lib/seqlock.h

index 762b6ec1d2dc7fa7ba5df9fe75d4e28da9a1c53b..afa9fd318fcaa3df5c7e30ef3e202473ffc20251 100644 (file)
@@ -18,13 +18,12 @@ static inline unsigned int read_seqlock_begin(struct seqlock *s)
        unsigned int seq;
 
        do {
-               seq = s->sequence;
+               seq = atomic_load_acquire(&s->sequence);
                if (!(seq & 1))
                        break;
                nop;
        } while (1);
 
-       read_barrier();
        return seq;
 }
 
@@ -36,14 +35,12 @@ static inline bool read_seqlock_retry(struct seqlock *s, unsigned int seq)
 
 static inline void write_seqlock_begin(struct seqlock *s)
 {
-       s->sequence++;
-       write_barrier();
+       s->sequence = atomic_load_acquire(&s->sequence) + 1;
 }
 
 static inline void write_seqlock_end(struct seqlock *s)
 {
-       write_barrier();
-       s->sequence++;
+       atomic_store_release(&s->sequence, s->sequence + 1);
 }
 
 #endif