History

seqlock: Add kernel-doc for seqcount_t and seqlock_t APIs

seqlock.h is now included by kernel's RST documentation, but a small number of the the exported seqlock.h functions are kernel-doc annotated. Add kernel-doc for all seqlock.h exported APIs.

Ahmed S. Darwish committed 6 years ago

Commit 89b88841 parent f4a27cb1 file · +348 −77Browse files

Showing the changes to include/linux (1 of 1 file). Show all

Unified · Split

include/linux/seqlock.h+348−77
@@ -75,6 +75,10 @@ static inline void __seqcount_init(seqcount_t *s, const char *name, · 74 unmodified lines
7575 # define SEQCOUNT_DEP_MAP_INIT(lockname) \
7676 .dep_map = { .name = #lockname } \
7777
78+/**
79+ * seqcount_init() - runtime initializer for seqcount_t
80+ * @s: Pointer to the seqcount_t instance
81+ */
7882 # define seqcount_init(s) \
7983 do { \
8084 static struct lock_class_key __key; \
@@ -98,13 +102,15 @@ static inline void seqcount_lockdep_reader_access(const seqcount_t *s) · 17 unmodified lines
98102 # define seqcount_lockdep_reader_access(x)
99103 #endif
100104
101−#define SEQCNT_ZERO(lockname) { .sequence = 0, SEQCOUNT_DEP_MAP_INIT(lockname)}
102−
105+/**
106+ * SEQCNT_ZERO() - static initializer for seqcount_t
107+ * @name: Name of the seqcount_t instance
108+ */
109+#define SEQCNT_ZERO(name) { .sequence = 0, SEQCOUNT_DEP_MAP_INIT(name) }
103110
104111 /**
105− * __read_seqcount_begin - begin a seq-read critical section (without barrier)
106− * @s: pointer to seqcount_t
107− * Returns: count to be passed to read_seqcount_retry
112+ * __read_seqcount_begin() - begin a seqcount_t read section w/o barrier
113+ * @s: Pointer to seqcount_t
108114 *
109115 * __read_seqcount_begin is like read_seqcount_begin, but has no smp_rmb()
110116 * barrier. Callers should ensure that smp_rmb() or equivalent ordering is
@@ -113,6 +119,8 @@ static inline void seqcount_lockdep_reader_access(const seqcount_t *s) · 2 unmodified lines
113119 *
114120 * Use carefully, only in critical code, and comment how the barrier is
115121 * provided.
122+ *
123+ * Return: count to be passed to read_seqcount_retry()
116124 */
117125 static inline unsigned __read_seqcount_begin(const seqcount_t *s)
118126 {
@@ -129,13 +137,10 @@ repeat: · 10 unmodified lines
129137 }
130138
131139 /**
132− * raw_read_seqcount_begin - start seq-read critical section w/o lockdep
133− * @s: pointer to seqcount_t
134− * Returns: count to be passed to read_seqcount_retry
140+ * raw_read_seqcount_begin() - begin a seqcount_t read section w/o lockdep
141+ * @s: Pointer to seqcount_t
135142 *
136− * raw_read_seqcount_begin opens a read critical section of the given
137− * seqcount, but without any lockdep checking. Validity of the critical
138− * section is tested by checking read_seqcount_retry function.
143+ * Return: count to be passed to read_seqcount_retry()
139144 */
140145 static inline unsigned raw_read_seqcount_begin(const seqcount_t *s)
141146 {
@@ -145,13 +150,10 @@ static inline unsigned raw_read_seqcount_begin(const seqcount_t *s) · 3 unmodified lines
145150 }
146151
147152 /**
148− * read_seqcount_begin - begin a seq-read critical section
149− * @s: pointer to seqcount_t
150− * Returns: count to be passed to read_seqcount_retry
153+ * read_seqcount_begin() - begin a seqcount_t read critical section
154+ * @s: Pointer to seqcount_t
151155 *
152− * read_seqcount_begin opens a read critical section of the given seqcount.
153− * Validity of the critical section is tested by checking read_seqcount_retry
154− * function.
156+ * Return: count to be passed to read_seqcount_retry()
155157 */
156158 static inline unsigned read_seqcount_begin(const seqcount_t *s)
157159 {
@@ -160,13 +162,15 @@ static inline unsigned read_seqcount_begin(const seqcount_t *s) · 2 unmodified lines
160162 }
161163
162164 /**
163− * raw_read_seqcount - Read the raw seqcount
164− * @s: pointer to seqcount_t
165− * Returns: count to be passed to read_seqcount_retry
165+ * raw_read_seqcount() - read the raw seqcount_t counter value
166+ * @s: Pointer to seqcount_t
166167 *
167168 * raw_read_seqcount opens a read critical section of the given
168− * seqcount without any lockdep checking and without checking or
169− * masking the LSB. Calling code is responsible for handling that.
169+ * seqcount_t, without any lockdep checking, and without checking or
170+ * masking the sequence counter LSB. Calling code is responsible for
171+ * handling that.
172+ *
173+ * Return: count to be passed to read_seqcount_retry()
170174 */
171175 static inline unsigned raw_read_seqcount(const seqcount_t *s)
172176 {
@@ -177,18 +181,21 @@ static inline unsigned raw_read_seqcount(const seqcount_t *s) · 4 unmodified lines
177181 }
178182
179183 /**
180− * raw_seqcount_begin - begin a seq-read critical section
181− * @s: pointer to seqcount_t
182− * Returns: count to be passed to read_seqcount_retry
184+ * raw_seqcount_begin() - begin a seqcount_t read critical section w/o
185+ * lockdep and w/o counter stabilization
186+ * @s: Pointer to seqcount_t
183187 *
184− * raw_seqcount_begin opens a read critical section of the given seqcount.
185− * Validity of the critical section is tested by checking read_seqcount_retry
186− * function.
188+ * raw_seqcount_begin opens a read critical section of the given
189+ * seqcount_t. Unlike read_seqcount_begin(), this function will not wait
190+ * for the count to stabilize. If a writer is active when it begins, it
191+ * will fail the read_seqcount_retry() at the end of the read critical
192+ * section instead of stabilizing at the beginning of it.
187193 *
188− * Unlike read_seqcount_begin(), this function will not wait for the count
189− * to stabilize. If a writer is active when we begin, we will fail the
190− * read_seqcount_retry() instead of stabilizing at the beginning of the
191− * critical section.
194+ * Use this only in special kernel hot paths where the read section is
195+ * small and has a high probability of success through other external
196+ * means. It will save a single branching instruction.
197+ *
198+ * Return: count to be passed to read_seqcount_retry()
192199 */
193200 static inline unsigned raw_seqcount_begin(const seqcount_t *s)
194201 {
@@ -199,10 +206,9 @@ static inline unsigned raw_seqcount_begin(const seqcount_t *s) · 4 unmodified lines
199206 }
200207
201208 /**
202− * __read_seqcount_retry - end a seq-read critical section (without barrier)
203− * @s: pointer to seqcount_t
204− * @start: count, from read_seqcount_begin
205− * Returns: 1 if retry is required, else 0
209+ * __read_seqcount_retry() - end a seqcount_t read section w/o barrier
210+ * @s: Pointer to seqcount_t
211+ * @start: count, from read_seqcount_begin()
206212 *
207213 * __read_seqcount_retry is like read_seqcount_retry, but has no smp_rmb()
208214 * barrier. Callers should ensure that smp_rmb() or equivalent ordering is
@@ -211,6 +217,8 @@ static inline unsigned raw_seqcount_begin(const seqcount_t *s) · 2 unmodified lines
211217 *
212218 * Use carefully, only in critical code, and comment how the barrier is
213219 * provided.
220+ *
221+ * Return: true if a read section retry is required, else false
214222 */
215223 static inline int __read_seqcount_retry(const seqcount_t *s, unsigned start)
216224 {
@@ -219,14 +227,15 @@ static inline int __read_seqcount_retry(const seqcount_t *s, unsigned start) · 2 unmodified lines
219227 }
220228
221229 /**
222− * read_seqcount_retry - end a seq-read critical section
223− * @s: pointer to seqcount_t
224− * @start: count, from read_seqcount_begin
225− * Returns: 1 if retry is required, else 0
230+ * read_seqcount_retry() - end a seqcount_t read critical section
231+ * @s: Pointer to seqcount_t
232+ * @start: count, from read_seqcount_begin()
226233 *
227− * read_seqcount_retry closes a read critical section of the given seqcount.
228− * If the critical section was invalid, it must be ignored (and typically
229− * retried).
234+ * read_seqcount_retry closes the read critical section of given
235+ * seqcount_t. If the critical section was invalid, it must be ignored
236+ * (and typically retried).
237+ *
238+ * Return: true if a read section retry is required, else false
230239 */
231240 static inline int read_seqcount_retry(const seqcount_t *s, unsigned start)
232241 {
@@ -234,6 +243,10 @@ static inline int read_seqcount_retry(const seqcount_t *s, unsigned start) · 1 unmodified line
234243 return __read_seqcount_retry(s, start);
235244 }
236245
246+/**
247+ * raw_write_seqcount_begin() - start a seqcount_t write section w/o lockdep
248+ * @s: Pointer to seqcount_t
249+ */
237250 static inline void raw_write_seqcount_begin(seqcount_t *s)
238251 {
239252 kcsan_nestable_atomic_begin();
@@ -241,6 +254,10 @@ static inline void raw_write_seqcount_begin(seqcount_t *s) · 1 unmodified line
241254 smp_wmb();
242255 }
243256
257+/**
258+ * raw_write_seqcount_end() - end a seqcount_t write section w/o lockdep
259+ * @s: Pointer to seqcount_t
260+ */
244261 static inline void raw_write_seqcount_end(seqcount_t *s)
245262 {
246263 smp_wmb();
@@ -248,17 +265,42 @@ static inline void raw_write_seqcount_end(seqcount_t *s) · 1 unmodified line
248265 kcsan_nestable_atomic_end();
249266 }
250267
268+/**
269+ * write_seqcount_begin_nested() - start a seqcount_t write section with
270+ * custom lockdep nesting level
271+ * @s: Pointer to seqcount_t
272+ * @subclass: lockdep nesting level
273+ *
274+ * See Documentation/locking/lockdep-design.rst
275+ */
251276 static inline void write_seqcount_begin_nested(seqcount_t *s, int subclass)
252277 {
253278 raw_write_seqcount_begin(s);
254279 seqcount_acquire(&s->dep_map, subclass, 0, _RET_IP_);
255280 }
256281
282+/**
283+ * write_seqcount_begin() - start a seqcount_t write side critical section
284+ * @s: Pointer to seqcount_t
285+ *
286+ * write_seqcount_begin opens a write side critical section of the given
287+ * seqcount_t.
288+ *
289+ * Context: seqcount_t write side critical sections must be serialized and
290+ * non-preemptible. If readers can be invoked from hardirq or softirq
291+ * context, interrupts or bottom halves must be respectively disabled.
292+ */
257293 static inline void write_seqcount_begin(seqcount_t *s)
258294 {
259295 write_seqcount_begin_nested(s, 0);
260296 }
261297
298+/**
299+ * write_seqcount_end() - end a seqcount_t write side critical section
300+ * @s: Pointer to seqcount_t
301+ *
302+ * The write section must've been opened with write_seqcount_begin().
303+ */
262304 static inline void write_seqcount_end(seqcount_t *s)
263305 {
264306 seqcount_release(&s->dep_map, _RET_IP_);
@@ -266,12 +308,12 @@ static inline void write_seqcount_end(seqcount_t *s) · 1 unmodified line
266308 }
267309
268310 /**
269− * raw_write_seqcount_barrier - do a seq write barrier
270− * @s: pointer to seqcount_t
311+ * raw_write_seqcount_barrier() - do a seqcount_t write barrier
312+ * @s: Pointer to seqcount_t
271313 *
272− * This can be used to provide an ordering guarantee instead of the
273− * usual consistency guarantee. It is one wmb cheaper, because we can
274− * collapse the two back-to-back wmb()s.
314+ * This can be used to provide an ordering guarantee instead of the usual
315+ * consistency guarantee. It is one wmb cheaper, because it can collapse
316+ * the two back-to-back wmb()s.
275317 *
276318 * Note that writes surrounding the barrier should be declared atomic (e.g.
277319 * via WRITE_ONCE): a) to ensure the writes become visible to other threads
@@ -316,11 +358,12 @@ static inline void raw_write_seqcount_barrier(seqcount_t *s) · 38 unmodified lines
316358 }
317359
318360 /**
319− * write_seqcount_invalidate - invalidate in-progress read-side seq operations
320− * @s: pointer to seqcount_t
361+ * write_seqcount_invalidate() - invalidate in-progress seqcount_t read
362+ * side operations
363+ * @s: Pointer to seqcount_t
321364 *
322− * After write_seqcount_invalidate, no read-side seq operations will complete
323− * successfully and see data older than this.
365+ * After write_seqcount_invalidate, no seqcount_t read side operations
366+ * will complete successfully and see data older than this.
324367 */
325368 static inline void write_seqcount_invalidate(seqcount_t *s)
326369 {
@@ -330,6 +373,21 @@ static inline void write_seqcount_invalidate(seqcount_t *s) · 3 unmodified lines
330373 kcsan_nestable_atomic_end();
331374 }
332375
376+/**
377+ * raw_read_seqcount_latch() - pick even/odd seqcount_t latch data copy
378+ * @s: Pointer to seqcount_t
379+ *
380+ * Use seqcount_t latching to switch between two storage places protected
381+ * by a sequence counter. Doing so allows having interruptible, preemptible,
382+ * seqcount_t write side critical sections.
383+ *
384+ * Check raw_write_seqcount_latch() for more details and a full reader and
385+ * writer usage example.
386+ *
387+ * Return: sequence counter raw value. Use the lowest bit as an index for
388+ * picking which data copy to read. The full counter value must then be
389+ * checked with read_seqcount_retry().
390+ */
333391 static inline int raw_read_seqcount_latch(seqcount_t *s)
334392 {
335393 /* Pairs with the first smp_wmb() in raw_write_seqcount_latch() */
@@ -338,8 +396,8 @@ static inline int raw_read_seqcount_latch(seqcount_t *s) · 2 unmodified lines
338396 }
339397
340398 /**
341− * raw_write_seqcount_latch - redirect readers to even/odd copy
342− * @s: pointer to seqcount_t
399+ * raw_write_seqcount_latch() - redirect readers to even/odd copy
400+ * @s: Pointer to seqcount_t
343401 *
344402 * The latch technique is a multiversion concurrency control method that allows
345403 * queries during non-atomic modifications. If you can guarantee queries never
@@ -446,17 +504,28 @@ typedef struct { · 100 unmodified lines
446504 .lock = __SPIN_LOCK_UNLOCKED(lockname) \
447505 }
448506
449−#define seqlock_init(x) \
507+/**
508+ * seqlock_init() - dynamic initializer for seqlock_t
509+ * @sl: Pointer to the seqlock_t instance
510+ */
511+#define seqlock_init(sl) \
450512 do { \
451− seqcount_init(&(x)->seqcount); \
452− spin_lock_init(&(x)->lock); \
513+ seqcount_init(&(sl)->seqcount); \
514+ spin_lock_init(&(sl)->lock); \
453515 } while (0)
454516
455−#define DEFINE_SEQLOCK(x) \
456− seqlock_t x = __SEQLOCK_UNLOCKED(x)
517+/**
518+ * DEFINE_SEQLOCK() - Define a statically allocated seqlock_t
519+ * @sl: Name of the seqlock_t instance
520+ */
521+#define DEFINE_SEQLOCK(sl) \
522+ seqlock_t sl = __SEQLOCK_UNLOCKED(sl)
457523
458−/*
459− * Read side functions for starting and finalizing a read side section.
524+/**
525+ * read_seqbegin() - start a seqlock_t read side critical section
526+ * @sl: Pointer to seqlock_t
527+ *
528+ * Return: count, to be passed to read_seqretry()
460529 */
461530 static inline unsigned read_seqbegin(const seqlock_t *sl)
462531 {
@@ -467,6 +536,17 @@ static inline unsigned read_seqbegin(const seqlock_t *sl) · 4 unmodified lines
467536 return ret;
468537 }
469538
539+/**
540+ * read_seqretry() - end a seqlock_t read side section
541+ * @sl: Pointer to seqlock_t
542+ * @start: count, from read_seqbegin()
543+ *
544+ * read_seqretry closes the read side critical section of given seqlock_t.
545+ * If the critical section was invalid, it must be ignored (and typically
546+ * retried).
547+ *
548+ * Return: true if a read section retry is required, else false
549+ */
470550 static inline unsigned read_seqretry(const seqlock_t *sl, unsigned start)
471551 {
472552 /*
@@ -478,10 +558,18 @@ static inline unsigned read_seqretry(const seqlock_t *sl, unsigned start) · 5 unmodified lines
478558 return read_seqcount_retry(&sl->seqcount, start);
479559 }
480560
481−/*
482− * Lock out other writers and update the count.
483− * Acts like a normal spin_lock/unlock.
484− * Don't need preempt_disable() because that is in the spin_lock already.
561+/**
562+ * write_seqlock() - start a seqlock_t write side critical section
563+ * @sl: Pointer to seqlock_t
564+ *
565+ * write_seqlock opens a write side critical section for the given
566+ * seqlock_t. It also implicitly acquires the spinlock_t embedded inside
567+ * that sequential lock. All seqlock_t write side sections are thus
568+ * automatically serialized and non-preemptible.
569+ *
570+ * Context: if the seqlock_t read section, or other write side critical
571+ * sections, can be invoked from hardirq or softirq contexts, use the
572+ * _irqsave or _bh variants of this function instead.
485573 */
486574 static inline void write_seqlock(seqlock_t *sl)
487575 {
@@ -489,30 +577,66 @@ static inline void write_seqlock(seqlock_t *sl) · 1 unmodified line
489577 write_seqcount_begin(&sl->seqcount);
490578 }
491579
580+/**
581+ * write_sequnlock() - end a seqlock_t write side critical section
582+ * @sl: Pointer to seqlock_t
583+ *
584+ * write_sequnlock closes the (serialized and non-preemptible) write side
585+ * critical section of given seqlock_t.
586+ */
492587 static inline void write_sequnlock(seqlock_t *sl)
493588 {
494589 write_seqcount_end(&sl->seqcount);
495590 spin_unlock(&sl->lock);
496591 }
497592
593+/**
594+ * write_seqlock_bh() - start a softirqs-disabled seqlock_t write section
595+ * @sl: Pointer to seqlock_t
596+ *
597+ * _bh variant of write_seqlock(). Use only if the read side section, or
598+ * other write side sections, can be invoked from softirq contexts.
599+ */
498600 static inline void write_seqlock_bh(seqlock_t *sl)
499601 {
500602 spin_lock_bh(&sl->lock);
501603 write_seqcount_begin(&sl->seqcount);
502604 }
503605
606+/**
607+ * write_sequnlock_bh() - end a softirqs-disabled seqlock_t write section
608+ * @sl: Pointer to seqlock_t
609+ *
610+ * write_sequnlock_bh closes the serialized, non-preemptible, and
611+ * softirqs-disabled, seqlock_t write side critical section opened with
612+ * write_seqlock_bh().
613+ */
504614 static inline void write_sequnlock_bh(seqlock_t *sl)
505615 {
506616 write_seqcount_end(&sl->seqcount);
507617 spin_unlock_bh(&sl->lock);
508618 }
509619
620+/**
621+ * write_seqlock_irq() - start a non-interruptible seqlock_t write section
622+ * @sl: Pointer to seqlock_t
623+ *
624+ * _irq variant of write_seqlock(). Use only if the read side section, or
625+ * other write sections, can be invoked from hardirq contexts.
626+ */
510627 static inline void write_seqlock_irq(seqlock_t *sl)
511628 {
512629 spin_lock_irq(&sl->lock);
513630 write_seqcount_begin(&sl->seqcount);
514631 }
515632
633+/**
634+ * write_sequnlock_irq() - end a non-interruptible seqlock_t write section
635+ * @sl: Pointer to seqlock_t
636+ *
637+ * write_sequnlock_irq closes the serialized and non-interruptible
638+ * seqlock_t write side section opened with write_seqlock_irq().
639+ */
516640 static inline void write_sequnlock_irq(seqlock_t *sl)
517641 {
518642 write_seqcount_end(&sl->seqcount);
@@ -528,9 +652,28 @@ static inline unsigned long __write_seqlock_irqsave(seqlock_t *sl) · 9 unmodified lines
528652 return flags;
529653 }
530654
655+/**
656+ * write_seqlock_irqsave() - start a non-interruptible seqlock_t write
657+ * section
658+ * @lock: Pointer to seqlock_t
659+ * @flags: Stack-allocated storage for saving caller's local interrupt
660+ * state, to be passed to write_sequnlock_irqrestore().
661+ *
662+ * _irqsave variant of write_seqlock(). Use it only if the read side
663+ * section, or other write sections, can be invoked from hardirq context.
664+ */
531665 #define write_seqlock_irqsave(lock, flags) \
532666 do { flags = __write_seqlock_irqsave(lock); } while (0)
533667
668+/**
669+ * write_sequnlock_irqrestore() - end non-interruptible seqlock_t write
670+ * section
671+ * @sl: Pointer to seqlock_t
672+ * @flags: Caller's saved interrupt state, from write_seqlock_irqsave()
673+ *
674+ * write_sequnlock_irqrestore closes the serialized and non-interruptible
675+ * seqlock_t write section previously opened with write_seqlock_irqsave().
676+ */
534677 static inline void
535678 write_sequnlock_irqrestore(seqlock_t *sl, unsigned long flags)
536679 {
@@ -538,36 +681,79 @@ write_sequnlock_irqrestore(seqlock_t *sl, unsigned long flags) · 1 unmodified line
538681 spin_unlock_irqrestore(&sl->lock, flags);
539682 }
540683
541−/*
542− * A locking reader exclusively locks out other writers and locking readers,
543− * but doesn't update the sequence number. Acts like a normal spin_lock/unlock.
544− * Don't need preempt_disable() because that is in the spin_lock already.
684+/**
685+ * read_seqlock_excl() - begin a seqlock_t locking reader section
686+ * @sl: Pointer to seqlock_t
687+ *
688+ * read_seqlock_excl opens a seqlock_t locking reader critical section. A
689+ * locking reader exclusively locks out *both* other writers *and* other
690+ * locking readers, but it does not update the embedded sequence number.
691+ *
692+ * Locking readers act like a normal spin_lock()/spin_unlock().
693+ *
694+ * Context: if the seqlock_t write section, *or other read sections*, can
695+ * be invoked from hardirq or softirq contexts, use the _irqsave or _bh
696+ * variant of this function instead.
697+ *
698+ * The opened read section must be closed with read_sequnlock_excl().
545699 */
546700 static inline void read_seqlock_excl(seqlock_t *sl)
547701 {
548702 spin_lock(&sl->lock);
549703 }
550704
705+/**
706+ * read_sequnlock_excl() - end a seqlock_t locking reader critical section
707+ * @sl: Pointer to seqlock_t
708+ */
551709 static inline void read_sequnlock_excl(seqlock_t *sl)
552710 {
553711 spin_unlock(&sl->lock);
554712 }
555713
714+/**
715+ * read_seqlock_excl_bh() - start a seqlock_t locking reader section with
716+ * softirqs disabled
717+ * @sl: Pointer to seqlock_t
718+ *
719+ * _bh variant of read_seqlock_excl(). Use this variant only if the
720+ * seqlock_t write side section, *or other read sections*, can be invoked
721+ * from softirq contexts.
722+ */
556723 static inline void read_seqlock_excl_bh(seqlock_t *sl)
557724 {
558725 spin_lock_bh(&sl->lock);
559726 }
560727
728+/**
729+ * read_sequnlock_excl_bh() - stop a seqlock_t softirq-disabled locking
730+ * reader section
731+ * @sl: Pointer to seqlock_t
732+ */
561733 static inline void read_sequnlock_excl_bh(seqlock_t *sl)
562734 {
563735 spin_unlock_bh(&sl->lock);
564736 }
565737
738+/**
739+ * read_seqlock_excl_irq() - start a non-interruptible seqlock_t locking
740+ * reader section
741+ * @sl: Pointer to seqlock_t
742+ *
743+ * _irq variant of read_seqlock_excl(). Use this only if the seqlock_t
744+ * write side section, *or other read sections*, can be invoked from a
745+ * hardirq context.
746+ */
566747 static inline void read_seqlock_excl_irq(seqlock_t *sl)
567748 {
568749 spin_lock_irq(&sl->lock);
569750 }
570751
752+/**
753+ * read_sequnlock_excl_irq() - end an interrupts-disabled seqlock_t
754+ * locking reader section
755+ * @sl: Pointer to seqlock_t
756+ */
571757 static inline void read_sequnlock_excl_irq(seqlock_t *sl)
572758 {
573759 spin_unlock_irq(&sl->lock);
@@ -581,9 +767,26 @@ static inline unsigned long __read_seqlock_excl_irqsave(seqlock_t *sl) · 7 unmodified lines
581767 return flags;
582768 }
583769
770+/**
771+ * read_seqlock_excl_irqsave() - start a non-interruptible seqlock_t
772+ * locking reader section
773+ * @lock: Pointer to seqlock_t
774+ * @flags: Stack-allocated storage for saving caller's local interrupt
775+ * state, to be passed to read_sequnlock_excl_irqrestore().
776+ *
777+ * _irqsave variant of read_seqlock_excl(). Use this only if the seqlock_t
778+ * write side section, *or other read sections*, can be invoked from a
779+ * hardirq context.
780+ */
584781 #define read_seqlock_excl_irqsave(lock, flags) \
585782 do { flags = __read_seqlock_excl_irqsave(lock); } while (0)
586783
784+/**
785+ * read_sequnlock_excl_irqrestore() - end non-interruptible seqlock_t
786+ * locking reader section
787+ * @sl: Pointer to seqlock_t
788+ * @flags: Caller saved interrupt state, from read_seqlock_excl_irqsave()
789+ */
587790 static inline void
588791 read_sequnlock_excl_irqrestore(seqlock_t *sl, unsigned long flags)
589792 {
@@ -591,14 +794,35 @@ read_sequnlock_excl_irqrestore(seqlock_t *sl, unsigned long flags) · 1 unmodified line
591794 }
592795
593796 /**
594− * read_seqbegin_or_lock - begin a sequence number check or locking block
595− * @lock: sequence lock
596− * @seq : sequence number to be checked
597− *
598− * First try it once optimistically without taking the lock. If that fails,
599− * take the lock. The sequence number is also used as a marker for deciding
600− * whether to be a reader (even) or writer (odd).
601− * N.B. seq must be initialized to an even number to begin with.
797+ * read_seqbegin_or_lock() - begin a seqlock_t lockless or locking reader
798+ * @lock: Pointer to seqlock_t
799+ * @seq : Marker and return parameter. If the passed value is even, the
800+ * reader will become a *lockless* seqlock_t reader as in read_seqbegin().
801+ * If the passed value is odd, the reader will become a *locking* reader
802+ * as in read_seqlock_excl(). In the first call to this function, the
803+ * caller *must* initialize and pass an even value to @seq; this way, a
804+ * lockless read can be optimistically tried first.
805+ *
806+ * read_seqbegin_or_lock is an API designed to optimistically try a normal
807+ * lockless seqlock_t read section first. If an odd counter is found, the
808+ * lockless read trial has failed, and the next read iteration transforms
809+ * itself into a full seqlock_t locking reader.
810+ *
811+ * This is typically used to avoid seqlock_t lockless readers starvation
812+ * (too much retry loops) in the case of a sharp spike in write side
813+ * activity.
814+ *
815+ * Context: if the seqlock_t write section, *or other read sections*, can
816+ * be invoked from hardirq or softirq contexts, use the _irqsave or _bh
817+ * variant of this function instead.
818+ *
819+ * Check Documentation/locking/seqlock.rst for template example code.
820+ *
821+ * Return: the encountered sequence counter value, through the @seq
822+ * parameter, which is overloaded as a return parameter. This returned
823+ * value must be checked with need_seqretry(). If the read section need to
824+ * be retried, this returned value must also be passed as the @seq
825+ * parameter of the next read_seqbegin_or_lock() iteration.
602826 */
603827 static inline void read_seqbegin_or_lock(seqlock_t *lock, int *seq)
604828 {
@@ -608,17 +832,52 @@ static inline void read_seqbegin_or_lock(seqlock_t *lock, int *seq) · 3 unmodified lines
608832 read_seqlock_excl(lock);
609833 }
610834
835+/**
836+ * need_seqretry() - validate seqlock_t "locking or lockless" read section
837+ * @lock: Pointer to seqlock_t
838+ * @seq: sequence count, from read_seqbegin_or_lock()
839+ *
840+ * Return: true if a read section retry is required, false otherwise
841+ */
611842 static inline int need_seqretry(seqlock_t *lock, int seq)
612843 {
613844 return !(seq & 1) && read_seqretry(lock, seq);
614845 }
615846
847+/**
848+ * done_seqretry() - end seqlock_t "locking or lockless" reader section
849+ * @lock: Pointer to seqlock_t
850+ * @seq: count, from read_seqbegin_or_lock()
851+ *
852+ * done_seqretry finishes the seqlock_t read side critical section started
853+ * with read_seqbegin_or_lock() and validated by need_seqretry().
854+ */
616855 static inline void done_seqretry(seqlock_t *lock, int seq)
617856 {
618857 if (seq & 1)
619858 read_sequnlock_excl(lock);
620859 }
621860
861+/**
862+ * read_seqbegin_or_lock_irqsave() - begin a seqlock_t lockless reader, or
863+ * a non-interruptible locking reader
864+ * @lock: Pointer to seqlock_t
865+ * @seq: Marker and return parameter. Check read_seqbegin_or_lock().
866+ *
867+ * This is the _irqsave variant of read_seqbegin_or_lock(). Use it only if
868+ * the seqlock_t write section, *or other read sections*, can be invoked
869+ * from hardirq context.
870+ *
871+ * Note: Interrupts will be disabled only for "locking reader" mode.
872+ *
873+ * Return:
874+ *
875+ * 1. The saved local interrupts state in case of a locking reader, to
876+ * be passed to done_seqretry_irqrestore().
877+ *
878+ * 2. The encountered sequence counter value, returned through @seq
879+ * overloaded as a return parameter. Check read_seqbegin_or_lock().
880+ */
622881 static inline unsigned long
623882 read_seqbegin_or_lock_irqsave(seqlock_t *lock, int *seq)
624883 {
@@ -632,6 +891,18 @@ read_seqbegin_or_lock_irqsave(seqlock_t *lock, int *seq) · 7 unmodified lines
632891 return flags;
633892 }
634893
894+/**
895+ * done_seqretry_irqrestore() - end a seqlock_t lockless reader, or a
896+ * non-interruptible locking reader section
897+ * @lock: Pointer to seqlock_t
898+ * @seq: Count, from read_seqbegin_or_lock_irqsave()
899+ * @flags: Caller's saved local interrupt state in case of a locking
900+ * reader, also from read_seqbegin_or_lock_irqsave()
901+ *
902+ * This is the _irqrestore variant of done_seqretry(). The read section
903+ * must've been opened with read_seqbegin_or_lock_irqsave(), and validated
904+ * by need_seqretry().
905+ */
635906 static inline void
636907 done_seqretry_irqrestore(seqlock_t *lock, int seq, unsigned long flags)
637908 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t