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,
46 * Write side critical sections must be serialized and non-preemptible.
50 * entering the write section.
60 * serialization and non-preemptibility requirements, use a sequential
78 lockdep_init_map(&s->dep_map, name, key, 0); in __seqcount_init()
79 s->sequence = 0; in __seqcount_init()
88 * seqcount_init() - runtime initializer for seqcount_t
103 seqcount_acquire_read(&l->dep_map, 0, 0, _RET_IP_); in seqcount_lockdep_reader_access()
104 seqcount_release(&l->dep_map, _RET_IP_); in seqcount_lockdep_reader_access()
115 * SEQCNT_ZERO() - static initializer for seqcount_t
125 * that the write side critical section is properly serialized.
145 * lock. This will allow any possibly-preempted writer to make progress
146 * until the end of its writer serialization lock critical section.
148 * This lock-unlock technique must be implemented for all of PREEMPT_RT
158 * typedef seqcount_LOCKNAME_t - sequence counter with LOCKNAME associated
165 * that the write side critical section is properly serialized.
171 * seqcount_LOCKNAME_init() - runtime initializer for seqcount_LOCKNAME_t
179 seqcount_init(&____s->seqcount); \
180 __SEQ_LOCK(____s->lock = (_lock)); \
190 * SEQCOUNT_LOCKNAME() - Instantiate seqcount_LOCKNAME_t and helpers
191 * seqprop_LOCKNAME_*() - Property accessors for seqcount_LOCKNAME_t
209 return &s->seqcount; \
215 unsigned seq = READ_ONCE(s->seqcount.sequence); \
222 __SEQ_LOCK(lockbase##_unlock(s->lock)); \
225 * Re-read the sequence counter since the (possibly \
228 seq = READ_ONCE(s->seqcount.sequence); \
261 return READ_ONCE(s->sequence); in __seqprop_sequence()
276 …OUNT_LOCKNAME(raw_spinlock, raw_spinlock_t, false, s->lock, raw_spin, raw_spin_lock(s->…
277 SEQCOUNT_LOCKNAME(spinlock, spinlock_t, __SEQ_RT, s->lock, spin, spin_lock(s->l…
278 SEQCOUNT_LOCKNAME(rwlock, rwlock_t, __SEQ_RT, s->lock, read, read_lock(s->l…
279 SEQCOUNT_LOCKNAME(mutex, struct mutex, true, s->lock, mutex, mutex_lock(s->…
280 …UNT_LOCKNAME(ww_mutex, struct ww_mutex, true, &s->lock->base, ww_mutex, ww_mutex_lock(s->l…
283 * SEQCNT_LOCKNAME_ZERO - static initializer for seqcount_LOCKNAME_t
316 * __read_seqcount_begin() - begin a seqcount_t read section w/o barrier
322 * protected in this critical section.
341 * raw_read_seqcount_begin() - begin a seqcount_t read section w/o lockdep
355 * read_seqcount_begin() - begin a seqcount_t read critical section
367 * raw_read_seqcount() - read the raw seqcount_t counter value
370 * raw_read_seqcount opens a read critical section of the given
387 * raw_seqcount_begin() - begin a seqcount_t read critical section w/o
391 * raw_seqcount_begin opens a read critical section of the given
395 * section instead of stabilizing at the beginning of it.
397 * Use this only in special kernel hot paths where the read section is
413 * __read_seqcount_retry() - end a seqcount_t read section w/o barrier
420 * protected in this critical section.
425 * Return: true if a read section retry is required, else false
433 return unlikely(READ_ONCE(s->sequence) != start); in __read_seqcount_t_retry()
437 * read_seqcount_retry() - end a seqcount_t read critical section
441 * read_seqcount_retry closes the read critical section of given
442 * seqcount_t. If the critical section was invalid, it must be ignored
445 * Return: true if a read section retry is required, else false
457 * raw_write_seqcount_begin() - start a seqcount_t write section w/o lockdep
471 s->sequence++; in raw_write_seqcount_t_begin()
476 * raw_write_seqcount_end() - end a seqcount_t write section w/o lockdep
490 s->sequence++; in raw_write_seqcount_t_end()
495 * write_seqcount_begin_nested() - start a seqcount_t write section with
500 * See Documentation/locking/lockdep-design.rst
515 seqcount_acquire(&s->dep_map, subclass, 0, _RET_IP_); in write_seqcount_t_begin_nested()
519 * write_seqcount_begin() - start a seqcount_t write side critical section
522 * write_seqcount_begin opens a write side critical section of the given
526 * non-preemptible. If readers can be invoked from hardirq or softirq
545 * write_seqcount_end() - end a seqcount_t write side critical section
548 * The write section must've been opened with write_seqcount_begin().
560 seqcount_release(&s->dep_map, _RET_IP_); in write_seqcount_t_end()
565 * raw_write_seqcount_barrier() - do a seqcount_t write barrier
570 * the two back-to-back wmb()s.
575 * meant to propagate to the reader critical section. This is necessary because
576 * neither writes before and after the barrier are enclosed in a seq-writer
577 * critical section that would ensure readers are aware of ongoing writes::
611 s->sequence++; in raw_write_seqcount_t_barrier()
613 s->sequence++; in raw_write_seqcount_t_barrier()
618 * write_seqcount_invalidate() - invalidate in-progress seqcount_t read
632 s->sequence+=2; in write_seqcount_t_invalidate()
641 * typically NMIs, to safely interrupt the write side critical section.
651 * SEQCNT_LATCH_ZERO() - static initializer for seqcount_latch_t
659 * seqcount_latch_init() - runtime initializer for seqcount_latch_t
664 seqcount_init(&s->seqcount); in seqcount_latch_init()
668 * raw_read_seqcount_latch() - pick even/odd latch data copy
684 return READ_ONCE(s->seqcount.sequence); in raw_read_seqcount_latch()
688 * read_seqcount_latch_retry() - end a seqcount_latch_t read section
692 * Return: true if a read section retry is required, else false
697 return read_seqcount_retry(&s->seqcount, start); in read_seqcount_latch_retry()
701 * raw_write_seqcount_latch() - redirect latch readers to even/odd copy
705 * queries during non-atomic modifications. If you can guarantee queries never
706 * interrupt the modification -- e.g. the concurrency is strictly between CPUs
707 * -- you most likely do not need this.
711 * latch allows the same for non-atomic updates. The trade-off is doubling the
731 * latch->seq.sequence++;
734 * modify(latch->data[0], ...);
737 * latch->seq.sequence++;
740 * modify(latch->data[1], ...);
751 * seq = raw_read_seqcount_latch(&latch->seq);
754 * entry = data_query(latch->data[idx], ...);
757 * } while (read_seqcount_latch_retry(&latch->seq, seq));
768 * The non-requirement for atomic modifications does _NOT_ include
784 s->seqcount.sequence++; in raw_write_seqcount_latch()
792 * and non-preemptibility.
795 * - Comments on top of seqcount_t
796 * - Documentation/locking/seqlock.rst
814 * seqlock_init() - dynamic initializer for seqlock_t
819 spin_lock_init(&(sl)->lock); \
820 seqcount_spinlock_init(&(sl)->seqcount, &(sl)->lock); \
824 * DEFINE_SEQLOCK(sl) - Define a statically allocated seqlock_t
831 * read_seqbegin() - start a seqlock_t read side critical section
838 unsigned ret = read_seqcount_begin(&sl->seqcount); in read_seqbegin()
840 kcsan_atomic_next(0); /* non-raw usage, assume closing read_seqretry() */ in read_seqbegin()
846 * read_seqretry() - end a seqlock_t read side section
850 * read_seqretry closes the read side critical section of given seqlock_t.
851 * If the critical section was invalid, it must be ignored (and typically
854 * Return: true if a read section retry is required, else false
860 * completing read critical section. in read_seqretry()
864 return read_seqcount_retry(&sl->seqcount, start); in read_seqretry()
874 * write_seqlock() - start a seqlock_t write side critical section
877 * write_seqlock opens a write side critical section for the given
880 * automatically serialized and non-preemptible.
882 * Context: if the seqlock_t read section, or other write side critical
888 spin_lock(&sl->lock); in write_seqlock()
889 write_seqcount_t_begin(&sl->seqcount.seqcount); in write_seqlock()
893 * write_sequnlock() - end a seqlock_t write side critical section
896 * write_sequnlock closes the (serialized and non-preemptible) write side
897 * critical section of given seqlock_t.
901 write_seqcount_t_end(&sl->seqcount.seqcount); in write_sequnlock()
902 spin_unlock(&sl->lock); in write_sequnlock()
906 * write_seqlock_bh() - start a softirqs-disabled seqlock_t write section
909 * _bh variant of write_seqlock(). Use only if the read side section, or
914 spin_lock_bh(&sl->lock); in write_seqlock_bh()
915 write_seqcount_t_begin(&sl->seqcount.seqcount); in write_seqlock_bh()
919 * write_sequnlock_bh() - end a softirqs-disabled seqlock_t write section
922 * write_sequnlock_bh closes the serialized, non-preemptible, and
923 * softirqs-disabled, seqlock_t write side critical section opened with
928 write_seqcount_t_end(&sl->seqcount.seqcount); in write_sequnlock_bh()
929 spin_unlock_bh(&sl->lock); in write_sequnlock_bh()
933 * write_seqlock_irq() - start a non-interruptible seqlock_t write section
936 * _irq variant of write_seqlock(). Use only if the read side section, or
941 spin_lock_irq(&sl->lock); in write_seqlock_irq()
942 write_seqcount_t_begin(&sl->seqcount.seqcount); in write_seqlock_irq()
946 * write_sequnlock_irq() - end a non-interruptible seqlock_t write section
949 * write_sequnlock_irq closes the serialized and non-interruptible
950 * seqlock_t write side section opened with write_seqlock_irq().
954 write_seqcount_t_end(&sl->seqcount.seqcount); in write_sequnlock_irq()
955 spin_unlock_irq(&sl->lock); in write_sequnlock_irq()
962 spin_lock_irqsave(&sl->lock, flags); in __write_seqlock_irqsave()
963 write_seqcount_t_begin(&sl->seqcount.seqcount); in __write_seqlock_irqsave()
968 * write_seqlock_irqsave() - start a non-interruptible seqlock_t write
969 * section
971 * @flags: Stack-allocated storage for saving caller's local interrupt
975 * section, or other write sections, can be invoked from hardirq context.
981 * write_sequnlock_irqrestore() - end non-interruptible seqlock_t write
982 * section
986 * write_sequnlock_irqrestore closes the serialized and non-interruptible
987 * seqlock_t write section previously opened with write_seqlock_irqsave().
992 write_seqcount_t_end(&sl->seqcount.seqcount); in write_sequnlock_irqrestore()
993 spin_unlock_irqrestore(&sl->lock, flags); in write_sequnlock_irqrestore()
997 * read_seqlock_excl() - begin a seqlock_t locking reader section
1000 * read_seqlock_excl opens a seqlock_t locking reader critical section. A
1006 * Context: if the seqlock_t write section, *or other read sections*, can
1010 * The opened read section must be closed with read_sequnlock_excl().
1014 spin_lock(&sl->lock); in read_seqlock_excl()
1018 * read_sequnlock_excl() - end a seqlock_t locking reader critical section
1023 spin_unlock(&sl->lock); in read_sequnlock_excl()
1027 * read_seqlock_excl_bh() - start a seqlock_t locking reader section with
1032 * seqlock_t write side section, *or other read sections*, can be invoked
1037 spin_lock_bh(&sl->lock); in read_seqlock_excl_bh()
1041 * read_sequnlock_excl_bh() - stop a seqlock_t softirq-disabled locking
1042 * reader section
1047 spin_unlock_bh(&sl->lock); in read_sequnlock_excl_bh()
1051 * read_seqlock_excl_irq() - start a non-interruptible seqlock_t locking
1052 * reader section
1056 * write side section, *or other read sections*, can be invoked from a
1061 spin_lock_irq(&sl->lock); in read_seqlock_excl_irq()
1065 * read_sequnlock_excl_irq() - end an interrupts-disabled seqlock_t
1066 * locking reader section
1071 spin_unlock_irq(&sl->lock); in read_sequnlock_excl_irq()
1078 spin_lock_irqsave(&sl->lock, flags); in __read_seqlock_excl_irqsave()
1083 * read_seqlock_excl_irqsave() - start a non-interruptible seqlock_t
1084 * locking reader section
1086 * @flags: Stack-allocated storage for saving caller's local interrupt
1090 * write side section, *or other read sections*, can be invoked from a
1097 * read_sequnlock_excl_irqrestore() - end non-interruptible seqlock_t
1098 * locking reader section
1105 spin_unlock_irqrestore(&sl->lock, flags); in read_sequnlock_excl_irqrestore()
1109 * read_seqbegin_or_lock() - begin a seqlock_t lockless or locking reader
1119 * lockless seqlock_t read section first. If an odd counter is found, the
1127 * Context: if the seqlock_t write section, *or other read sections*, can
1135 * value must be checked with need_seqretry(). If the read section need to
1148 * need_seqretry() - validate seqlock_t "locking or lockless" read section
1152 * Return: true if a read section retry is required, false otherwise
1160 * done_seqretry() - end seqlock_t "locking or lockless" reader section
1164 * done_seqretry finishes the seqlock_t read side critical section started
1174 * read_seqbegin_or_lock_irqsave() - begin a seqlock_t lockless reader, or
1175 * a non-interruptible locking reader
1180 * the seqlock_t write section, *or other read sections*, can be invoked
1207 * done_seqretry_irqrestore() - end a seqlock_t lockless reader, or a
1208 * non-interruptible locking reader section
1214 * This is the _irqrestore variant of done_seqretry(). The read section