^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) ======================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) Sequence counters and sequential locks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ======================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) Introduction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) Sequence counters are a reader-writer consistency mechanism with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) lockless readers (read-only retry loops), and no writer starvation. They
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) are used for data that's rarely written to (e.g. system time), where the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) reader wants a consistent set of information and is willing to retry if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) that information changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) A data set is consistent when the sequence count at the beginning of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) read side critical section is even and the same sequence count value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) read again at the end of the critical section. The data in the set must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) be copied out inside the read side critical section. If the sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) count has changed between the start and the end of the critical section,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) the reader must retry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) Writers increment the sequence count at the start and the end of their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) critical section. After starting the critical section the sequence count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) is odd and indicates to the readers that an update is in progress. At
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) the end of the write side critical section the sequence count becomes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) even again which lets readers make progress.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) A sequence counter write side critical section must never be preempted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) or interrupted by read side sections. Otherwise the reader will spin for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) the entire scheduler tick due to the odd sequence count value and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) interrupted writer. If that reader belongs to a real-time scheduling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) class, it can spin forever and the kernel will livelock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) This mechanism cannot be used if the protected data contains pointers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) as the writer can invalidate a pointer that the reader is following.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .. _seqcount_t:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) Sequence counters (``seqcount_t``)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) ==================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) This is the the raw counting mechanism, which does not protect against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) multiple writers. Write side critical sections must thus be serialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) by an external lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) If the write serialization primitive is not implicitly disabling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) preemption, preemption must be explicitly disabled before entering the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) write side section. If the read section can be invoked from hardirq or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) softirq contexts, interrupts or bottom halves must also be respectively
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) disabled before entering the write section.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) If it's desired to automatically handle the sequence counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) requirements of writer serialization and non-preemptibility, use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) :ref:`seqlock_t` instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) Initialization::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* dynamic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) seqcount_t foo_seqcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) seqcount_init(&foo_seqcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* static */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static seqcount_t foo_seqcount = SEQCNT_ZERO(foo_seqcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* C99 struct init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .seq = SEQCNT_ZERO(foo.seq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) } foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) Write path::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Serialized context with disabled preemption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) write_seqcount_begin(&foo_seqcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* ... [[write-side critical section]] ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) write_seqcount_end(&foo_seqcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) Read path::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) seq = read_seqcount_begin(&foo_seqcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* ... [[read-side critical section]] ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) } while (read_seqcount_retry(&foo_seqcount, seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .. _seqcount_locktype_t:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) Sequence counters with associated locks (``seqcount_LOCKNAME_t``)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) -----------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) As discussed at :ref:`seqcount_t`, sequence count write side critical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) sections must be serialized and non-preemptible. This variant of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) sequence counters associate the lock used for writer serialization at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) initialization time, which enables lockdep to validate that the write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) side critical sections are properly serialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) This lock association is a NOOP if lockdep is disabled and has neither
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) storage nor runtime overhead. If lockdep is enabled, the lock pointer is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) stored in struct seqcount and lockdep's "lock is held" assertions are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) injected at the beginning of the write side critical section to validate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) that it is properly protected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) For lock types which do not implicitly disable preemption, preemption
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) protection is enforced in the write side function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) The following sequence counters with associated locks are defined:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) - ``seqcount_spinlock_t``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) - ``seqcount_raw_spinlock_t``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) - ``seqcount_rwlock_t``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) - ``seqcount_mutex_t``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) - ``seqcount_ww_mutex_t``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) The sequence counter read and write APIs can take either a plain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) seqcount_t or any of the seqcount_LOCKNAME_t variants above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) Initialization (replace "LOCKNAME" with one of the supported locks)::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* dynamic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) seqcount_LOCKNAME_t foo_seqcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) seqcount_LOCKNAME_init(&foo_seqcount, &lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* static */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static seqcount_LOCKNAME_t foo_seqcount =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) SEQCNT_LOCKNAME_ZERO(foo_seqcount, &lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* C99 struct init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .seq = SEQCNT_LOCKNAME_ZERO(foo.seq, &lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) } foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) Write path: same as in :ref:`seqcount_t`, while running from a context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) with the associated write serialization lock acquired.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) Read path: same as in :ref:`seqcount_t`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .. _seqcount_latch_t:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) Latch sequence counters (``seqcount_latch_t``)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ----------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) Latch sequence counters are a multiversion concurrency control mechanism
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) where the embedded seqcount_t counter even/odd value is used to switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) between two copies of protected data. This allows the sequence counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) read path to safely interrupt its own write side critical section.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) Use seqcount_latch_t when the write side sections cannot be protected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) from interruption by readers. This is typically the case when the read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) side can be invoked from NMI handlers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) Check `raw_write_seqcount_latch()` for more information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .. _seqlock_t:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) Sequential locks (``seqlock_t``)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) This contains the :ref:`seqcount_t` mechanism earlier discussed, plus an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) embedded spinlock for writer serialization and non-preemptibility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) If the read side section can be invoked from hardirq or softirq context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) use the write side function variants which disable interrupts or bottom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) halves respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) Initialization::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* dynamic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) seqlock_t foo_seqlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) seqlock_init(&foo_seqlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* static */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static DEFINE_SEQLOCK(foo_seqlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* C99 struct init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .seql = __SEQLOCK_UNLOCKED(foo.seql)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) } foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) Write path::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) write_seqlock(&foo_seqlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* ... [[write-side critical section]] ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) write_sequnlock(&foo_seqlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) Read path, three categories:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 1. Normal Sequence readers which never block a writer but they must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) retry if a writer is in progress by detecting change in the sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) number. Writers do not wait for a sequence reader::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) seq = read_seqbegin(&foo_seqlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* ... [[read-side critical section]] ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) } while (read_seqretry(&foo_seqlock, seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 2. Locking readers which will wait if a writer or another locking reader
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) is in progress. A locking reader in progress will also block a writer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) from entering its critical section. This read lock is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) exclusive. Unlike rwlock_t, only one locking reader can acquire it::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) read_seqlock_excl(&foo_seqlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* ... [[read-side critical section]] ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) read_sequnlock_excl(&foo_seqlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 3. Conditional lockless reader (as in 1), or locking reader (as in 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) according to a passed marker. This is used to avoid lockless readers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) starvation (too much retry loops) in case of a sharp spike in write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) activity. First, a lockless read is tried (even marker passed). If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) that trial fails (odd sequence counter is returned, which is used as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) the next iteration marker), the lockless read is transformed to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) full locking read and no retry loop is necessary::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* marker; even initialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) int seq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) read_seqbegin_or_lock(&foo_seqlock, &seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* ... [[read-side critical section]] ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) } while (need_seqretry(&foo_seqlock, seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) done_seqretry(&foo_seqlock, seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) API documentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) =================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .. kernel-doc:: include/linux/seqlock.h