Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

documentation: seqlock: fix the wrong documentation of read_seqbegin_or_lock/need_seqretry

The comments and pseudo code in Documentation/locking/seqlock.rst are wrong:

int seq = 0;
do {
read_seqbegin_or_lock(&foo_seqlock, &seq);

/* ... [[read-side critical section]] ... */

} while (need_seqretry(&foo_seqlock, seq));

read_seqbegin_or_lock() always returns with an even "seq" and need_seqretry()
doesn't change this counter. This means that seq is always even and thus the
locking pass is simply impossible.

IOW, "_or_lock" has no effect and this code doesn't differ from

do {
seq = read_seqbegin(&foo_seqlock);

/* ... [[read-side critical section]] ... */

} while (read_seqretry(&foo_seqlock, seq));

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

authored by

Oleg Nesterov and committed by
Peter Zijlstra
28a0ee31 44472d1b

+5 -4
+5 -4
Documentation/locking/seqlock.rst
··· 220 220 according to a passed marker. This is used to avoid lockless readers 221 221 starvation (too much retry loops) in case of a sharp spike in write 222 222 activity. First, a lockless read is tried (even marker passed). If 223 - that trial fails (odd sequence counter is returned, which is used as 224 - the next iteration marker), the lockless read is transformed to a 225 - full locking read and no retry loop is necessary:: 223 + that trial fails (sequence counter doesn't match), make the marker 224 + odd for the next iteration, the lockless read is transformed to a 225 + full locking read and no retry loop is necessary, for example:: 226 226 227 227 /* marker; even initialization */ 228 - int seq = 0; 228 + int seq = 1; 229 229 do { 230 + seq++; /* 2 on the 1st/lockless path, otherwise odd */ 230 231 read_seqbegin_or_lock(&foo_seqlock, &seq); 231 232 232 233 /* ... [[read-side critical section]] ... */