• Home
  • Raw
  • Download

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>
31 * As a consequence, we take the following best-effort approach for raw usage
32 * via seqcount_t under KCSAN: upon beginning a seq-reader critical section,
45 * Write side critical sections must be serialized and non-preemptible.
49 * entering the write section.
59 * serialization and non-preemptibility requirements, use a sequential
77 lockdep_init_map(&s->dep_map, name, key, 0); in __seqcount_init()
78 s->sequence = 0; in __seqcount_init()
87 * seqcount_init() - runtime initializer for seqcount_t
102 seqcount_acquire_read(&l->dep_map, 0, 0, _RET_IP_); in seqcount_lockdep_reader_access()
103 seqcount_release(&l->dep_map, _RET_IP_); in seqcount_lockdep_reader_access()
114 * SEQCNT_ZERO() - static initializer for seqcount_t
124 * that the write side critical section is properly serialized.
144 * lock. This will allow any possibly-preempted writer to make progress
145 * until the end of its writer serialization lock critical section.
147 * This lock-unlock technique must be implemented for all of PREEMPT_RT
157 * typedef seqcount_LOCKNAME_t - sequence counter with LOCKNAME associated
164 * that the write side critical section is properly serialized.
170 * seqcount_LOCKNAME_init() - runtime initializer for seqcount_LOCKNAME_t
178 seqcount_init(&____s->seqcount); \
179 __SEQ_LOCK(____s->lock = (_lock)); \
188 * SEQCOUNT_LOCKNAME() - Instantiate seqcount_LOCKNAME_t and helpers
189 * seqprop_LOCKNAME_*() - Property accessors for seqcount_LOCKNAME_t
207 return &s->seqcount; \
213 unsigned seq = READ_ONCE(s->seqcount.sequence); \
220 __SEQ_LOCK(lockbase##_unlock(s->lock)); \
223 * Re-read the sequence counter since the (possibly \
226 seq = READ_ONCE(s->seqcount.sequence); \
259 return READ_ONCE(s->sequence); in __seqprop_sequence()
274 …OUNT_LOCKNAME(raw_spinlock, raw_spinlock_t, false, s->lock, raw_spin, raw_spin_lock(s->…
275 SEQCOUNT_LOCKNAME(spinlock, spinlock_t, __SEQ_RT, s->lock, spin, spin_lock(s->l…
276 SEQCOUNT_LOCKNAME(rwlock, rwlock_t, __SEQ_RT, s->lock, read, read_lock(s->l…
277 SEQCOUNT_LOCKNAME(mutex, struct mutex, true, s->lock, mutex, mutex_lock(s->…
280 * SEQCNT_LOCKNAME_ZERO - static initializer for seqcount_LOCKNAME_t
312 * __read_seqcount_begin() - begin a seqcount_t read section w/o barrier
318 * protected in this critical section.
337 * raw_read_seqcount_begin() - begin a seqcount_t read section w/o lockdep
351 * read_seqcount_begin() - begin a seqcount_t read critical section
363 * raw_read_seqcount() - read the raw seqcount_t counter value
366 * raw_read_seqcount opens a read critical section of the given
383 * raw_seqcount_begin() - begin a seqcount_t read critical section w/o
387 * raw_seqcount_begin opens a read critical section of the given
391 * section instead of stabilizing at the beginning of it.
393 * Use this only in special kernel hot paths where the read section is
409 * __read_seqcount_retry() - end a seqcount_t read section w/o barrier
416 * protected in this critical section.
421 * Return: true if a read section retry is required, else false
429 return unlikely(READ_ONCE(s->sequence) != start); in do___read_seqcount_retry()
433 * read_seqcount_retry() - end a seqcount_t read critical section
437 * read_seqcount_retry closes the read critical section of given
438 * seqcount_t. If the critical section was invalid, it must be ignored
441 * Return: true if a read section retry is required, else false
453 * raw_write_seqcount_begin() - start a seqcount_t write section w/o lockdep
469 s->sequence++; in do_raw_write_seqcount_begin()
474 * raw_write_seqcount_end() - end a seqcount_t write section w/o lockdep
490 s->sequence++; in do_raw_write_seqcount_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 do_write_seqcount_begin_nested()
520 * write_seqcount_begin() - start a seqcount_t write side critical section
524 * non-preemptible. Preemption will be automatically disabled if and
545 * write_seqcount_end() - end a seqcount_t write side critical section
548 * Context: Preemption will be automatically re-enabled if and only if
561 seqcount_release(&s->dep_map, _RET_IP_); in do_write_seqcount_end()
566 * raw_write_seqcount_barrier() - do a seqcount_t write barrier
571 * the two back-to-back wmb()s.
576 * meant to propagate to the reader critical section. This is necessary because
577 * neither writes before and after the barrier are enclosed in a seq-writer
578 * critical section that would ensure readers are aware of ongoing writes::
612 s->sequence++; in do_raw_write_seqcount_barrier()
614 s->sequence++; in do_raw_write_seqcount_barrier()
619 * write_seqcount_invalidate() - invalidate in-progress seqcount_t read
633 s->sequence+=2; in do_write_seqcount_invalidate()
642 * typically NMIs, to safely interrupt the write side critical section.
652 * SEQCNT_LATCH_ZERO() - static initializer for seqcount_latch_t
660 * seqcount_latch_init() - runtime initializer for seqcount_latch_t
663 #define seqcount_latch_init(s) seqcount_init(&(s)->seqcount)
666 * raw_read_seqcount_latch() - pick even/odd latch data copy
682 return READ_ONCE(s->seqcount.sequence); in raw_read_seqcount_latch()
686 * raw_read_seqcount_latch_retry() - end a seqcount_latch_t read section
690 * Return: true if a read section retry is required, else false
696 return unlikely(READ_ONCE(s->seqcount.sequence) != start); in raw_read_seqcount_latch_retry()
700 * raw_write_seqcount_latch() - redirect latch readers to even/odd copy
704 * queries during non-atomic modifications. If you can guarantee queries never
705 * interrupt the modification -- e.g. the concurrency is strictly between CPUs
706 * -- you most likely do not need this.
710 * latch allows the same for non-atomic updates. The trade-off is doubling the
730 * latch->seq.sequence++;
733 * modify(latch->data[0], ...);
736 * latch->seq.sequence++;
739 * modify(latch->data[1], ...);
750 * seq = raw_read_seqcount_latch(&latch->seq);
753 * entry = data_query(latch->data[idx], ...);
756 * } while (raw_read_seqcount_latch_retry(&latch->seq, seq));
767 * The non-requirement for atomic modifications does _NOT_ include
783 s->seqcount.sequence++; in raw_write_seqcount_latch()
791 * and non-preemptibility.
794 * - Comments on top of seqcount_t
795 * - Documentation/locking/seqlock.rst
813 * seqlock_init() - dynamic initializer for seqlock_t
818 spin_lock_init(&(sl)->lock); \
819 seqcount_spinlock_init(&(sl)->seqcount, &(sl)->lock); \
823 * DEFINE_SEQLOCK(sl) - Define a statically allocated seqlock_t
830 * read_seqbegin() - start a seqlock_t read side critical section
837 unsigned ret = read_seqcount_begin(&sl->seqcount); in read_seqbegin()
839 kcsan_atomic_next(0); /* non-raw usage, assume closing read_seqretry() */ in read_seqbegin()
845 * read_seqretry() - end a seqlock_t read side section
849 * read_seqretry closes the read side critical section of given seqlock_t.
850 * If the critical section was invalid, it must be ignored (and typically
853 * Return: true if a read section retry is required, else false
859 * completing read critical section. in read_seqretry()
863 return read_seqcount_retry(&sl->seqcount, start); in read_seqretry()
873 * write_seqlock() - start a seqlock_t write side critical section
876 * write_seqlock opens a write side critical section for the given
879 * automatically serialized and non-preemptible.
881 * Context: if the seqlock_t read section, or other write side critical
887 spin_lock(&sl->lock); in write_seqlock()
888 do_write_seqcount_begin(&sl->seqcount.seqcount); in write_seqlock()
892 * write_sequnlock() - end a seqlock_t write side critical section
895 * write_sequnlock closes the (serialized and non-preemptible) write side
896 * critical section of given seqlock_t.
900 do_write_seqcount_end(&sl->seqcount.seqcount); in write_sequnlock()
901 spin_unlock(&sl->lock); in write_sequnlock()
905 * write_seqlock_bh() - start a softirqs-disabled seqlock_t write section
908 * _bh variant of write_seqlock(). Use only if the read side section, or
913 spin_lock_bh(&sl->lock); in write_seqlock_bh()
914 do_write_seqcount_begin(&sl->seqcount.seqcount); in write_seqlock_bh()
918 * write_sequnlock_bh() - end a softirqs-disabled seqlock_t write section
921 * write_sequnlock_bh closes the serialized, non-preemptible, and
922 * softirqs-disabled, seqlock_t write side critical section opened with
927 do_write_seqcount_end(&sl->seqcount.seqcount); in write_sequnlock_bh()
928 spin_unlock_bh(&sl->lock); in write_sequnlock_bh()
932 * write_seqlock_irq() - start a non-interruptible seqlock_t write section
935 * _irq variant of write_seqlock(). Use only if the read side section, or
940 spin_lock_irq(&sl->lock); in write_seqlock_irq()
941 do_write_seqcount_begin(&sl->seqcount.seqcount); in write_seqlock_irq()
945 * write_sequnlock_irq() - end a non-interruptible seqlock_t write section
948 * write_sequnlock_irq closes the serialized and non-interruptible
949 * seqlock_t write side section opened with write_seqlock_irq().
953 do_write_seqcount_end(&sl->seqcount.seqcount); in write_sequnlock_irq()
954 spin_unlock_irq(&sl->lock); in write_sequnlock_irq()
961 spin_lock_irqsave(&sl->lock, flags); in __write_seqlock_irqsave()
962 do_write_seqcount_begin(&sl->seqcount.seqcount); in __write_seqlock_irqsave()
967 * write_seqlock_irqsave() - start a non-interruptible seqlock_t write
968 * section
970 * @flags: Stack-allocated storage for saving caller's local interrupt
974 * section, or other write sections, can be invoked from hardirq context.
980 * write_sequnlock_irqrestore() - end non-interruptible seqlock_t write
981 * section
985 * write_sequnlock_irqrestore closes the serialized and non-interruptible
986 * seqlock_t write section previously opened with write_seqlock_irqsave().
991 do_write_seqcount_end(&sl->seqcount.seqcount); in write_sequnlock_irqrestore()
992 spin_unlock_irqrestore(&sl->lock, flags); in write_sequnlock_irqrestore()
996 * read_seqlock_excl() - begin a seqlock_t locking reader section
999 * read_seqlock_excl opens a seqlock_t locking reader critical section. A
1005 * Context: if the seqlock_t write section, *or other read sections*, can
1009 * The opened read section must be closed with read_sequnlock_excl().
1013 spin_lock(&sl->lock); in read_seqlock_excl()
1017 * read_sequnlock_excl() - end a seqlock_t locking reader critical section
1022 spin_unlock(&sl->lock); in read_sequnlock_excl()
1026 * read_seqlock_excl_bh() - start a seqlock_t locking reader section with
1031 * seqlock_t write side section, *or other read sections*, can be invoked
1036 spin_lock_bh(&sl->lock); in read_seqlock_excl_bh()
1040 * read_sequnlock_excl_bh() - stop a seqlock_t softirq-disabled locking
1041 * reader section
1046 spin_unlock_bh(&sl->lock); in read_sequnlock_excl_bh()
1050 * read_seqlock_excl_irq() - start a non-interruptible seqlock_t locking
1051 * reader section
1055 * write side section, *or other read sections*, can be invoked from a
1060 spin_lock_irq(&sl->lock); in read_seqlock_excl_irq()
1064 * read_sequnlock_excl_irq() - end an interrupts-disabled seqlock_t
1065 * locking reader section
1070 spin_unlock_irq(&sl->lock); in read_sequnlock_excl_irq()
1077 spin_lock_irqsave(&sl->lock, flags); in __read_seqlock_excl_irqsave()
1082 * read_seqlock_excl_irqsave() - start a non-interruptible seqlock_t
1083 * locking reader section
1085 * @flags: Stack-allocated storage for saving caller's local interrupt
1089 * write side section, *or other read sections*, can be invoked from a
1096 * read_sequnlock_excl_irqrestore() - end non-interruptible seqlock_t
1097 * locking reader section
1104 spin_unlock_irqrestore(&sl->lock, flags); in read_sequnlock_excl_irqrestore()
1108 * read_seqbegin_or_lock() - begin a seqlock_t lockless or locking reader
1118 * lockless seqlock_t read section first. If an odd counter is found, the
1126 * Context: if the seqlock_t write section, *or other read sections*, can
1134 * value must be checked with need_seqretry(). If the read section need to
1147 * need_seqretry() - validate seqlock_t "locking or lockless" read section
1151 * Return: true if a read section retry is required, false otherwise
1159 * done_seqretry() - end seqlock_t "locking or lockless" reader section
1163 * done_seqretry finishes the seqlock_t read side critical section started
1173 * read_seqbegin_or_lock_irqsave() - begin a seqlock_t lockless reader, or
1174 * a non-interruptible locking reader
1179 * the seqlock_t write section, *or other read sections*, can be invoked
1206 * done_seqretry_irqrestore() - end a seqlock_t lockless reader, or a
1207 * non-interruptible locking reader section
1213 * This is the _irqrestore variant of done_seqretry(). The read section