Lines Matching +full:- +full:section
1 /* SPDX-License-Identifier: GPL-2.0 */
6 * seqcount_t / seqlock_t - a reader-writer consistency mechanism with
7 * lockless readers (read-only retry loops), and no writer starvation.
12 * - Based on x86_64 vsyscall gettimeofday: Keith Owens, Andrea Arcangeli
13 * - Sequence counters with associated locks, (C) 2020 Linutronix GmbH
17 #include <linux/kcsan-checks.h>
32 * As a consequence, we take the following best-effort approach for raw usage
33 * via seqcount_t under KCSAN: upon beginning a seq-reader critical section,
47 lockdep_init_map(&s->dep_map, name, key, 0); in __seqcount_init()
48 s->sequence = 0; in __seqcount_init()
57 * seqcount_init() - runtime initializer for seqcount_t
72 seqcount_acquire_read(&l->dep_map, 0, 0, _RET_IP_); in seqcount_lockdep_reader_access()
73 seqcount_release(&l->dep_map, _RET_IP_); in seqcount_lockdep_reader_access()
84 * SEQCNT_ZERO() - static initializer for seqcount_t
94 * that the write side critical section is properly serialized.
105 * typedef seqcount_LOCKNAME_t - sequence counter with LOCKNAME associated
112 * that the write side critical section is properly serialized.
118 * seqcount_LOCKNAME_init() - runtime initializer for seqcount_LOCKNAME_t
126 seqcount_init(&____s->seqcount); \
127 __SEQ_LOCK(____s->lock = (_lock)); \
136 * SEQCOUNT_LOCKNAME() - Instantiate seqcount_LOCKNAME_t and helpers
137 * seqprop_LOCKNAME_*() - Property accessors for seqcount_LOCKNAME_t
148 return &s->seqcount; \
154 return &s->seqcount; \
160 unsigned seq = READ_ONCE(s->seqcount.sequence); \
166 __SEQ_LOCK(lockbase##_lock(s->lock)); \
167 __SEQ_LOCK(lockbase##_unlock(s->lock)); \
170 * Re-read the sequence counter since the (possibly \
173 seq = READ_ONCE(s->seqcount.sequence); \
192 __SEQ_LOCK(lockdep_assert_held(s->lock)); \
211 return READ_ONCE(s->sequence); in __seqprop_sequence()
233 * SEQCNT_LOCKNAME_ZERO - static initializer for seqcount_LOCKNAME_t in SEQCOUNT_LOCKNAME()
266 * __read_seqcount_begin() - begin a seqcount_t read section w/o barrier
272 * protected in this critical section.
291 * raw_read_seqcount_begin() - begin a seqcount_t read section w/o lockdep
305 * read_seqcount_begin() - begin a seqcount_t read critical section
317 * raw_read_seqcount() - read the raw seqcount_t counter value
320 * raw_read_seqcount opens a read critical section of the given
337 * raw_seqcount_begin() - begin a seqcount_t read critical section w/o
341 * raw_seqcount_begin opens a read critical section of the given
345 * section instead of stabilizing at the beginning of it.
347 * Use this only in special kernel hot paths where the read section is
363 * __read_seqcount_retry() - end a seqcount_t read section w/o barrier
370 * protected in this critical section.
375 * Return: true if a read section retry is required, else false
383 return unlikely(READ_ONCE(s->sequence) != start);
387 * read_seqcount_retry() - end a seqcount_t read critical section
391 * read_seqcount_retry closes the read critical section of given
392 * seqcount_t. If the critical section was invalid, it must be ignored
395 * Return: true if a read section retry is required, else false
407 * raw_write_seqcount_begin() - start a seqcount_t write section w/o lockdep
423 s->sequence++; in do_raw_write_seqcount_begin()
428 * raw_write_seqcount_end() - end a seqcount_t write section w/o lockdep
444 s->sequence++; in do_raw_write_seqcount_end()
449 * write_seqcount_begin_nested() - start a seqcount_t write section with
454 * See Documentation/locking/lockdep-design.rst
469 seqcount_acquire(&s->dep_map, subclass, 0, _RET_IP_); in do_write_seqcount_begin_nested()
474 * write_seqcount_begin() - start a seqcount_t write side critical section
478 * non-preemptible. Preemption will be automatically disabled if and
499 * write_seqcount_end() - end a seqcount_t write side critical section
502 * Context: Preemption will be automatically re-enabled if and only if
515 seqcount_release(&s->dep_map, _RET_IP_); in do_write_seqcount_end()
520 * raw_write_seqcount_barrier() - do a seqcount_t write barrier
525 * the two back-to-back wmb()s.
530 * meant to propagate to the reader critical section. This is necessary because
531 * neither writes before nor after the barrier are enclosed in a seq-writer
532 * critical section that would ensure readers are aware of ongoing writes::
566 s->sequence++; in do_raw_write_seqcount_barrier()
568 s->sequence++; in do_raw_write_seqcount_barrier()
573 * write_seqcount_invalidate() - invalidate in-progress seqcount_t read
587 s->sequence+=2; in do_write_seqcount_invalidate()
596 * typically NMIs, to safely interrupt the write side critical section.
606 * SEQCNT_LATCH_ZERO() - static initializer for seqcount_latch_t
614 * seqcount_latch_init() - runtime initializer for seqcount_latch_t
617 #define seqcount_latch_init(s) seqcount_init(&(s)->seqcount)
620 * raw_read_seqcount_latch() - pick even/odd latch data copy
636 return READ_ONCE(s->seqcount.sequence); in raw_read_seqcount_latch()
640 * raw_read_seqcount_latch_retry() - end a seqcount_latch_t read section
644 * Return: true if a read section retry is required, else false
650 return unlikely(READ_ONCE(s->seqcount.sequence) != start); in raw_read_seqcount_latch_retry()
654 * raw_write_seqcount_latch() - redirect latch readers to even/odd copy
658 * queries during non-atomic modifications. If you can guarantee queries never
659 * interrupt the modification -- e.g. the concurrency is strictly between CPUs
660 * -- you most likely do not need this.
664 * latch allows the same for non-atomic updates. The trade-off is doubling the
684 * latch->seq.sequence++;
687 * modify(latch->data[0], ...);
690 * latch->seq.sequence++;
693 * modify(latch->data[1], ...);
704 * seq = raw_read_seqcount_latch(&latch->seq);
707 * entry = data_query(latch->data[idx], ...);
710 * } while (raw_read_seqcount_latch_retry(&latch->seq, seq));
721 * The non-requirement for atomic modifications does _NOT_ include
737 s->seqcount.sequence++; in raw_write_seqcount_latch()
748 * seqlock_init() - dynamic initializer for seqlock_t
753 spin_lock_init(&(sl)->lock); \
754 seqcount_spinlock_init(&(sl)->seqcount, &(sl)->lock); \
758 * DEFINE_SEQLOCK(sl) - Define a statically allocated seqlock_t
765 * read_seqbegin() - start a seqlock_t read side critical section
772 unsigned ret = read_seqcount_begin(&sl->seqcount); in read_seqbegin()
774 kcsan_atomic_next(0); /* non-raw usage, assume closing read_seqretry() */ in read_seqbegin()
780 * read_seqretry() - end a seqlock_t read side section
784 * read_seqretry closes the read side critical section of given seqlock_t.
785 * If the critical section was invalid, it must be ignored (and typically
788 * Return: true if a read section retry is required, else false
794 * completing read critical section. in read_seqretry()
798 return read_seqcount_retry(&sl->seqcount, start); in read_seqretry()
808 * write_seqlock() - start a seqlock_t write side critical section
811 * write_seqlock opens a write side critical section for the given
814 * automatically serialized and non-preemptible.
816 * Context: if the seqlock_t read section, or other write side critical
822 spin_lock(&sl->lock); in write_seqlock()
823 do_write_seqcount_begin(&sl->seqcount.seqcount); in write_seqlock()
827 * write_sequnlock() - end a seqlock_t write side critical section
830 * write_sequnlock closes the (serialized and non-preemptible) write side
831 * critical section of given seqlock_t.
835 do_write_seqcount_end(&sl->seqcount.seqcount); in write_sequnlock()
836 spin_unlock(&sl->lock); in write_sequnlock()
840 * write_seqlock_bh() - start a softirqs-disabled seqlock_t write section
843 * _bh variant of write_seqlock(). Use only if the read side section, or
848 spin_lock_bh(&sl->lock); in write_seqlock_bh()
849 do_write_seqcount_begin(&sl->seqcount.seqcount); in write_seqlock_bh()
853 * write_sequnlock_bh() - end a softirqs-disabled seqlock_t write section
856 * write_sequnlock_bh closes the serialized, non-preemptible, and
857 * softirqs-disabled, seqlock_t write side critical section opened with
862 do_write_seqcount_end(&sl->seqcount.seqcount); in write_sequnlock_bh()
863 spin_unlock_bh(&sl->lock); in write_sequnlock_bh()
867 * write_seqlock_irq() - start a non-interruptible seqlock_t write section
870 * _irq variant of write_seqlock(). Use only if the read side section, or
875 spin_lock_irq(&sl->lock); in write_seqlock_irq()
876 do_write_seqcount_begin(&sl->seqcount.seqcount); in write_seqlock_irq()
880 * write_sequnlock_irq() - end a non-interruptible seqlock_t write section
883 * write_sequnlock_irq closes the serialized and non-interruptible
884 * seqlock_t write side section opened with write_seqlock_irq().
888 do_write_seqcount_end(&sl->seqcount.seqcount); in write_sequnlock_irq()
889 spin_unlock_irq(&sl->lock); in write_sequnlock_irq()
896 spin_lock_irqsave(&sl->lock, flags); in __write_seqlock_irqsave()
897 do_write_seqcount_begin(&sl->seqcount.seqcount); in __write_seqlock_irqsave()
902 * write_seqlock_irqsave() - start a non-interruptible seqlock_t write
903 * section
905 * @flags: Stack-allocated storage for saving caller's local interrupt
909 * section, or other write sections, can be invoked from hardirq context.
915 * write_sequnlock_irqrestore() - end non-interruptible seqlock_t write
916 * section
920 * write_sequnlock_irqrestore closes the serialized and non-interruptible
921 * seqlock_t write section previously opened with write_seqlock_irqsave().
926 do_write_seqcount_end(&sl->seqcount.seqcount); in write_sequnlock_irqrestore()
927 spin_unlock_irqrestore(&sl->lock, flags); in write_sequnlock_irqrestore()
931 * read_seqlock_excl() - begin a seqlock_t locking reader section
934 * read_seqlock_excl opens a seqlock_t locking reader critical section. A
940 * Context: if the seqlock_t write section, *or other read sections*, can
944 * The opened read section must be closed with read_sequnlock_excl().
948 spin_lock(&sl->lock); in read_seqlock_excl()
952 * read_sequnlock_excl() - end a seqlock_t locking reader critical section
957 spin_unlock(&sl->lock); in read_sequnlock_excl()
961 * read_seqlock_excl_bh() - start a seqlock_t locking reader section with
966 * seqlock_t write side section, *or other read sections*, can be invoked
971 spin_lock_bh(&sl->lock); in read_seqlock_excl_bh()
975 * read_sequnlock_excl_bh() - stop a seqlock_t softirq-disabled locking
976 * reader section
981 spin_unlock_bh(&sl->lock); in read_sequnlock_excl_bh()
985 * read_seqlock_excl_irq() - start a non-interruptible seqlock_t locking
986 * reader section
990 * write side section, *or other read sections*, can be invoked from a
995 spin_lock_irq(&sl->lock); in read_seqlock_excl_irq()
999 * read_sequnlock_excl_irq() - end an interrupts-disabled seqlock_t
1000 * locking reader section
1005 spin_unlock_irq(&sl->lock); in read_sequnlock_excl_irq()
1012 spin_lock_irqsave(&sl->lock, flags); in __read_seqlock_excl_irqsave()
1017 * read_seqlock_excl_irqsave() - start a non-interruptible seqlock_t
1018 * locking reader section
1020 * @flags: Stack-allocated storage for saving caller's local interrupt
1024 * write side section, *or other read sections*, can be invoked from a
1031 * read_sequnlock_excl_irqrestore() - end non-interruptible seqlock_t
1032 * locking reader section
1039 spin_unlock_irqrestore(&sl->lock, flags); in read_sequnlock_excl_irqrestore()
1043 * read_seqbegin_or_lock() - begin a seqlock_t lockless or locking reader
1053 * lockless seqlock_t read section first. If an odd counter is found, the
1061 * Context: if the seqlock_t write section, *or other read sections*, can
1069 * value must be checked with need_seqretry(). If the read section need to
1082 * need_seqretry() - validate seqlock_t "locking or lockless" read section
1086 * Return: true if a read section retry is required, false otherwise
1094 * done_seqretry() - end seqlock_t "locking or lockless" reader section
1098 * done_seqretry finishes the seqlock_t read side critical section started
1108 * read_seqbegin_or_lock_irqsave() - begin a seqlock_t lockless reader, or
1109 * a non-interruptible locking reader
1114 * the seqlock_t write section, *or other read sections*, can be invoked
1141 * done_seqretry_irqrestore() - end a seqlock_t lockless reader, or a
1142 * non-interruptible locking reader section
1148 * This is the _irqrestore variant of done_seqretry(). The read section