docs/litmus-tests: add BPF ringbuf MPSC litmus tests
Subsystems (4)
Hello Andrii,
This is quite exciting. Some comments below:
On Wed, May 27, 2020 at 11:24:08PM -0700, Andrii Nakryiko wrote:
[...]
Quoted 29 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +23
-0@@ -0,0 +1,91 @@ +C bpf-rb+1p1c+bounded + +(* + * Result: Always + * + * This litmus test validates BPF ring buffer implementation under the + * following assumptions: + * - 1 producer; + * - 1 consumer; + * - ring buffer has capacity for only 1 record. + * + * Expectations: + * - 1 record pushed into ring buffer; + * - 0 or 1 element is consumed. + * - no failures. + *) + +{ + atomic_t dropped; +} + +P0(int *lenFail, int *len1, int *cx, int *px) +{
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 33
Quoted 10 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +10
-0+ int *rLenPtr; + int rLen; + int rPx; + int rCx; + int rFail; + + rFail = 0; + + rCx = smp_load_acquire(cx); + rPx = smp_load_acquire(px);
Is it possible for you to put some more comments around which ACQUIRE is paired with which RELEASE? And, in general more comments around the reason for a certain memory barrier and what pairs with what. In the kernel sources, the barriers needs a comment anyway.
Quoted 23 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +23
-0+ if (rCx < rPx) { + if (rCx == 0) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + rLen = smp_load_acquire(rLenPtr); + if (rLen == 0) { + rFail = 1; + } else if (rLen == 1) { + rCx = rCx + 1; + smp_store_release(cx, rCx); + } + } +} + +P1(int *lenFail, int *len1, spinlock_t *rb_lock, int *px, int *cx, atomic_t *dropped) +{ + int rPx; + int rCx; + int rFail;
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 66
Quoted 10 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +10
-0+ int *rLenPtr; + + rFail = 0; + + rCx = smp_load_acquire(cx); + spin_lock(rb_lock); + + rPx = *px; + if (rPx - rCx >= 1) { + atomic_inc(dropped);
Why does 'dropped' need to be atomic if you are always incrementing under a lock?
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 76
Quoted 10 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +10
-0+ spin_unlock(rb_lock); + } else { + if (rPx == 0) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + *rLenPtr = -1;
Clarify please the need to set the length intermittently to -1. Thanks.
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+unbound.litmus
Quoted 20 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +15
-0+ smp_store_release(px, rPx + 1); + + spin_unlock(rb_lock); + + smp_store_release(rLenPtr, 1); + } +} + +exists ( + 0:rFail=0 /\ 1:rFail=0 + /\ + ( + (dropped=0 /\ px=1 /\ len1=1 /\ (cx=0 \/ cx=1)) + ) +)Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+unbound.litmus new file +0
-0
I wish there was a way to pass args to litmus tests, then perhaps it would have been possible to condense some of these tests. :-)
Quoted 5 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus new file +0
-0
[...]
Quoted 75 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus new file +75
-0+P0(int *lenFail, int *len1, int *cx, int *px) +{ + int *rLenPtr; + int rLen; + int rPx; + int rCx; + int rFail; + + rFail = 0; + + rCx = smp_load_acquire(cx); + rPx = smp_load_acquire(px); + if (rCx < rPx) { + if (rCx == 0) { + rLenPtr = len1; + } else if (rCx == 1) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + rLen = smp_load_acquire(rLenPtr); + if (rLen == 0) { + rFail = 1; + } else if (rLen == 1) { + rCx = rCx + 1; + smp_store_release(cx, rCx); + } + } + + rPx = smp_load_acquire(px); + if (rCx < rPx) { + if (rCx == 0) { + rLenPtr = len1; + } else if (rCx == 1) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + rLen = smp_load_acquire(rLenPtr); + if (rLen == 0) { + rFail = 1; + } else if (rLen == 1) { + rCx = rCx + 1; + smp_store_release(cx, rCx); + } + } +} + +P1(int *lenFail, int *len1, spinlock_t *rb_lock, int *px, int *cx, atomic_t *dropped) +{ + int rPx; + int rCx; + int rFail; + int *rLenPtr; + + rFail = 0; + rLenPtr = lenFail; + + rCx = smp_load_acquire(cx); + spin_lock(rb_lock); + + rPx = *px; + if (rPx - rCx >= 1) { + atomic_inc(dropped); + spin_unlock(rb_lock); + } else { + if (rPx == 0) { + rLenPtr = len1; + } else if (rPx == 1) { + rLenPtr = len1; + } else {
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus
Quoted 10 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus new file +10
-0+ rLenPtr = lenFail; + rFail = 1; + } + + *rLenPtr = -1; + smp_store_release(px, rPx + 1); + + spin_unlock(rb_lock); + + smp_store_release(rLenPtr, 1);
I ran a test replacing the last 2 statements above with the following and it still works:
spin_unlock(rb_lock);
WRITE_ONCE(*rLenPtr, 1);Wouldn't you expect the test to catch an issue? The spin_unlock is already a RELEASE barrier.
Suggestion: It is hard to review the patch because it is huge, it would be good to split this up into 4 patches for each of the tests. But upto you :)
thanks,
- Joel
[...]
Quoted 79 lines · Joel Fernandes
Hello Andrii,
This is quite exciting. Some comments below:On Wed, May 27, 2020 at 11:24:08PM -0700, Andrii Nakryiko wrote:
[...]Quoted 29 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +23
-0@@ -0,0 +1,91 @@ +C bpf-rb+1p1c+bounded + +(* + * Result: Always + * + * This litmus test validates BPF ring buffer implementation under the + * following assumptions: + * - 1 producer; + * - 1 consumer; + * - ring buffer has capacity for only 1 record. + * + * Expectations: + * - 1 record pushed into ring buffer; + * - 0 or 1 element is consumed. + * - no failures. + *) + +{ + atomic_t dropped; +} + +P0(int *lenFail, int *len1, int *cx, int *px) +{Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 33
Quoted 10 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +10
-0+ int *rLenPtr; + int rLen; + int rPx; + int rCx; + int rFail; + + rFail = 0; + + rCx = smp_load_acquire(cx); + rPx = smp_load_acquire(px);Is it possible for you to put some more comments around which ACQUIRE is paired with which RELEASE? And, in general more comments around the reason for a certain memory barrier and what pairs with what. In the kernel sources, the barriers needs a comment anyway.
Quoted 28 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +28
-0+ if (rCx < rPx) { + if (rCx == 0) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + rLen = smp_load_acquire(rLenPtr); + if (rLen == 0) { + rFail = 1; + } else if (rLen == 1) { + rCx = rCx + 1; + smp_store_release(cx, rCx); + } + } +} + +P1(int *lenFail, int *len1, spinlock_t *rb_lock, int *px, int *cx, atomic_t *dropped) +{ + int rPx; + int rCx; + int rFail; + int *rLenPtr; + + rFail = 0; + + rCx = smp_load_acquire(cx);
Quoted 8 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 66
Quoted 5 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +5
-0+ spin_lock(rb_lock); + + rPx = *px; + if (rPx - rCx >= 1) { + atomic_inc(dropped);Why does 'dropped' need to be atomic if you are always incrementing under a lock?
It doesn't, strictly speaking, but making it atomic in litmus test was just more convenient, especially that I initially also had a lock-less variant of this algorithm.
Quoted 12 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 76
Quoted 11 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +10
-0+ spin_unlock(rb_lock); + } else { + if (rPx == 0) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + *rLenPtr = -1;
Quoted 1 line
Clarify please the need to set the length intermittently to -1. Thanks.
This corresponds to setting a "busy bit" in kernel implementation. These litmus tests are supposed to be correlated with in-kernel implementation, I'm not sure I want to maintain extra 4 copies of comments here and in kernel code. Especially for 2-producer cases, there are 2 identical P1 and P2, which is unfortunate, but I haven't figured out how to have a re-usable pieces of code with litmus tests :)
Quoted 16 lines
Quoted 16 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +15
-0+ smp_store_release(px, rPx + 1); + + spin_unlock(rb_lock); + + smp_store_release(rLenPtr, 1); + } +} + +exists ( + 0:rFail=0 /\ 1:rFail=0 + /\ + ( + (dropped=0 /\ px=1 /\ len1=1 /\ (cx=0 \/ cx=1)) + ) +)
Quoted 8 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+unbound.litmus
Quoted 5 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+unbound.litmus new file +0
-0I wish there was a way to pass args to litmus tests, then perhaps it would have been possible to condense some of these tests. :-)
It wouldn't help much, actually, because litmus tests can't have arrays. See all those "if selectors" between len1 and len2, I had to do explicitly.
Quoted 96 lines
Quoted 6 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus new file +0
-0[...]
Quoted 75 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus new file +75
-0+P0(int *lenFail, int *len1, int *cx, int *px) +{ + int *rLenPtr; + int rLen; + int rPx; + int rCx; + int rFail; + + rFail = 0; + + rCx = smp_load_acquire(cx); + rPx = smp_load_acquire(px); + if (rCx < rPx) { + if (rCx == 0) { + rLenPtr = len1; + } else if (rCx == 1) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + rLen = smp_load_acquire(rLenPtr); + if (rLen == 0) { + rFail = 1; + } else if (rLen == 1) { + rCx = rCx + 1; + smp_store_release(cx, rCx); + } + } + + rPx = smp_load_acquire(px); + if (rCx < rPx) { + if (rCx == 0) { + rLenPtr = len1; + } else if (rCx == 1) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + rLen = smp_load_acquire(rLenPtr); + if (rLen == 0) { + rFail = 1; + } else if (rLen == 1) { + rCx = rCx + 1; + smp_store_release(cx, rCx); + } + } +} + +P1(int *lenFail, int *len1, spinlock_t *rb_lock, int *px, int *cx, atomic_t *dropped) +{ + int rPx; + int rCx; + int rFail; + int *rLenPtr; + + rFail = 0; + rLenPtr = lenFail; + + rCx = smp_load_acquire(cx); + spin_lock(rb_lock); + + rPx = *px; + if (rPx - rCx >= 1) { + atomic_inc(dropped); + spin_unlock(rb_lock); + } else { + if (rPx == 0) { + rLenPtr = len1; + } else if (rPx == 1) { + rLenPtr = len1; + } else {Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus
Quoted 10 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus new file +10
-0+ rLenPtr = lenFail; + rFail = 1; + } + + *rLenPtr = -1; + smp_store_release(px, rPx + 1); + + spin_unlock(rb_lock); + + smp_store_release(rLenPtr, 1);I ran a test replacing the last 2 statements above with the following and it still works:
Quoted 5 lines
spin_unlock(rb_lock); WRITE_ONCE(*rLenPtr, 1);Wouldn't you expect the test to catch an issue? The
spin_unlockis already a RELEASE barrier.
Well, apparently it's not an issue and WRITE_ONCE would work as well :) My original version actually used WRITE_ONCE here. See [0] and discussion in [1] after which I removed all the WRITE_ONCE/READ_ONCE in favor of store_release/load_acquire for consistency.
[0] https://patchwork.ozlabs.org/project/netdev/patch/[email protected]/
[1] https://patchwork.ozlabs.org/project/netdev/patch/[email protected]/
Quoted 3 lines
Suggestion: It is hard to review the patch because it is huge, it would be good to split this up into 4 patches for each of the tests. But upto you :)
Those 4 files are partial copies of each other, not sure splitting them actually would be easier. If anyone else thinks the same, though, I'll happily split.
Quoted 7 lines
thanks,
- Joel
[...]
Hi Andrii,
Quoted 37 lines · Andrii Nakryiko
Quoted 37 lines
[...]
Quoted 36 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +30
-0@@ -0,0 +1,91 @@ +C bpf-rb+1p1c+bounded + +(* + * Result: Always + * + * This litmus test validates BPF ring buffer implementation under the + * following assumptions: + * - 1 producer; + * - 1 consumer; + * - ring buffer has capacity for only 1 record. + * + * Expectations: + * - 1 record pushed into ring buffer; + * - 0 or 1 element is consumed. + * - no failures. + *) + +{ + atomic_t dropped; +} + +P0(int *lenFail, int *len1, int *cx, int *px) +{ + int *rLenPtr; + int rLen; + int rPx; + int rCx; + int rFail; + + rFail = 0;
Quoted 8 lines
Quoted 8 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 33
Quoted 3 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +3
-0+ + rCx = smp_load_acquire(cx); + rPx = smp_load_acquire(px);Is it possible for you to put some more comments around which ACQUIRE is paired with which RELEASE? And, in general more comments around the reason for a certain memory barrier and what pairs with what. In the kernel sources, the barriers needs a comment anyway.
This was the comment earlier that was missed.
Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +28
-0+ if (rCx < rPx) { + if (rCx == 0) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + rLen = smp_load_acquire(rLenPtr); + if (rLen == 0) { + rFail = 1; + } else if (rLen == 1) { + rCx = rCx + 1; + smp_store_release(cx, rCx); + } + } +} + +P1(int *lenFail, int *len1, spinlock_t *rb_lock, int *px, int *cx, atomic_t *dropped) +{ + int rPx; + int rCx; + int rFail; + int *rLenPtr; + + rFail = 0; + + rCx = smp_load_acquire(cx);Quoted 8 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 66
Quoted 5 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +5
-0+ spin_lock(rb_lock); + + rPx = *px; + if (rPx - rCx >= 1) { + atomic_inc(dropped);Why does 'dropped' need to be atomic if you are always incrementing under a lock?
Quoted 3 lines
It doesn't, strictly speaking, but making it atomic in litmus test was just more convenient, especially that I initially also had a lock-less variant of this algorithm.
Ok, that's fine.
Quoted 14 lines
Quoted 12 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 76
Quoted 11 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +10
-0+ spin_unlock(rb_lock); + } else { + if (rPx == 0) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + *rLenPtr = -1;Quoted 1 line
Clarify please the need to set the length intermittently to -1. Thanks.
Quoted 7 lines
This corresponds to setting a "busy bit" in kernel implementation. These litmus tests are supposed to be correlated with in-kernel implementation, I'm not sure I want to maintain extra 4 copies of comments here and in kernel code. Especially for 2-producer cases, there are 2 identical P1 and P2, which is unfortunate, but I haven't figured out how to have a re-usable pieces of code with litmus tests :)
I disagree that comments related to memory ordering are optional. IMHO, the documentation should be clear from a memory ordering standpoint. After all, good Documentation/ always clarifies something / some concept to the reader right? :-) Please have mercy on me, I am just trying to learn *your* Documentation ;-)
Quoted 1 line
Quoted 1 line
Quoted 1 line
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus +0
-0
[...]
Quoted 43 lines
Quoted 37 lines
Quoted 23 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus +23
-0+P1(int *lenFail, int *len1, spinlock_t *rb_lock, int *px, int *cx, atomic_t *dropped) +{ + int rPx; + int rCx; + int rFail; + int *rLenPtr; + + rFail = 0; + rLenPtr = lenFail; + + rCx = smp_load_acquire(cx); + spin_lock(rb_lock); + + rPx = *px; + if (rPx - rCx >= 1) { + atomic_inc(dropped); + spin_unlock(rb_lock); + } else { + if (rPx == 0) { + rLenPtr = len1; + } else if (rPx == 1) { + rLenPtr = len1; + } else {Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus
Quoted 10 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus +10
-0+ rLenPtr = lenFail; + rFail = 1; + } + + *rLenPtr = -1; + smp_store_release(px, rPx + 1); + + spin_unlock(rb_lock); + + smp_store_release(rLenPtr, 1);I ran a test replacing the last 2 statements above with the following and it still works:
Quoted 5 lines
spin_unlock(rb_lock); WRITE_ONCE(*rLenPtr, 1);Wouldn't you expect the test to catch an issue? The
spin_unlockis already a RELEASE barrier.
Quoted 7 lines
Well, apparently it's not an issue and
WRITE_ONCEwould work as well :) My original version actually usedWRITE_ONCEhere. See [0] and discussion in [1] after which I removed all the WRITE_ONCE/READ_ONCE in favor of store_release/load_acquire for consistency.[0] https://patchwork.ozlabs.org/project/netdev/patch/[email protected]/
[1] https://patchwork.ozlabs.org/project/netdev/patch/[email protected]/
Huh. So you are replacing the test to use WRITE_ONCE instead? Why did you favor the acquire/release memory barriers over the _ONCE annotations, if that was not really needed then?
Quoted 6 lines
Quoted 2 lines
Suggestion: It is hard to review the patch because it is huge, it would be good to split this up into 4 patches for each of the tests. But upto you :)
Those 4 files are partial copies of each other, not sure splitting them actually would be easier. If anyone else thinks the same, though, I'll happily split.
I personally disagree. It would be much easier IMHO to review 4 different files since some of them are also quite dissimilar. I frequently keep jumping between diffs to find a different file and it makes the review that much harder. But anything the LKMM experts decide in this regard is acceptable to me :)
thanks,
- Joel
Quoted 50 lines · Joel Fernandes
Hi Andrii,
Quoted 37 lines · Andrii Nakryiko
Quoted 37 lines
[...]
Quoted 36 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +30
-0@@ -0,0 +1,91 @@ +C bpf-rb+1p1c+bounded + +(* + * Result: Always + * + * This litmus test validates BPF ring buffer implementation under the + * following assumptions: + * - 1 producer; + * - 1 consumer; + * - ring buffer has capacity for only 1 record. + * + * Expectations: + * - 1 record pushed into ring buffer; + * - 0 or 1 element is consumed. + * - no failures. + *) + +{ + atomic_t dropped; +} + +P0(int *lenFail, int *len1, int *cx, int *px) +{ + int *rLenPtr; + int rLen; + int rPx; + int rCx; + int rFail; + + rFail = 0;Quoted 8 lines
Quoted 8 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 33
Quoted 3 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +3
-0+ + rCx = smp_load_acquire(cx); + rPx = smp_load_acquire(px);Is it possible for you to put some more comments around which ACQUIRE is paired with which RELEASE? And, in general more comments around the reason for a certain memory barrier and what pairs with what. In the kernel sources, the barriers needs a comment anyway.
Quoted 1 line
This was the comment earlier that was missed.
Right, I'll follow up extending kernel implementation comments, and will add some more to litmus tests.
Quoted 66 lines
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +28
-0+ if (rCx < rPx) { + if (rCx == 0) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + rLen = smp_load_acquire(rLenPtr); + if (rLen == 0) { + rFail = 1; + } else if (rLen == 1) { + rCx = rCx + 1; + smp_store_release(cx, rCx); + } + } +} + +P1(int *lenFail, int *len1, spinlock_t *rb_lock, int *px, int *cx, atomic_t *dropped) +{ + int rPx; + int rCx; + int rFail; + int *rLenPtr; + + rFail = 0; + + rCx = smp_load_acquire(cx);Quoted 8 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 66
Quoted 5 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +5
-0+ spin_lock(rb_lock); + + rPx = *px; + if (rPx - rCx >= 1) { + atomic_inc(dropped);Why does 'dropped' need to be atomic if you are always incrementing under a lock?
Quoted 3 lines
It doesn't, strictly speaking, but making it atomic in litmus test was just more convenient, especially that I initially also had a lock-less variant of this algorithm.
Ok, that's fine.
Quoted 14 lines
Quoted 12 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus line 76
Quoted 11 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+1p1c+bounded.litmus new file +10
-0+ spin_unlock(rb_lock); + } else { + if (rPx == 0) { + rLenPtr = len1; + } else { + rLenPtr = lenFail; + rFail = 1; + } + + *rLenPtr = -1;Quoted 1 line
Clarify please the need to set the length intermittently to -1. Thanks.
Quoted 7 lines
This corresponds to setting a "busy bit" in kernel implementation. These litmus tests are supposed to be correlated with in-kernel implementation, I'm not sure I want to maintain extra 4 copies of comments here and in kernel code. Especially for 2-producer cases, there are 2 identical P1 and P2, which is unfortunate, but I haven't figured out how to have a re-usable pieces of code with litmus tests :)
Quoted 5 lines
I disagree that comments related to memory ordering are optional. IMHO, the documentation should be clear from a memory ordering standpoint. After all, good
Documentation/always clarifies something / some concept to the reader right? :-) Please have mercy on me, I am just trying to learn *your* Documentation ;-)
My point was that reading litmus test without also reading ringbuf implementation is pointless and is harder than necessary. I'll add few comments to litmus tests, but ultimately I view kernel implementation as the source of truth and litmus test as a simplified model of it. So having extensive comments in litmus test is just a maintenance burden and more chance to get confusing, out-of-sync documentation.
Quoted 51 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus +0
-0[...]
Quoted 48 lines
Quoted 37 lines
Quoted 23 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus +23
-0+P1(int *lenFail, int *len1, spinlock_t *rb_lock, int *px, int *cx, atomic_t *dropped) +{ + int rPx; + int rCx; + int rFail; + int *rLenPtr; + + rFail = 0; + rLenPtr = lenFail; + + rCx = smp_load_acquire(cx); + spin_lock(rb_lock); + + rPx = *px; + if (rPx - rCx >= 1) { + atomic_inc(dropped); + spin_unlock(rb_lock); + } else { + if (rPx == 0) { + rLenPtr = len1; + } else if (rPx == 1) { + rLenPtr = len1; + } else {Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus
Quoted 10 lines
Documentation/litmus-tests/bpf-rb/bpf-rb+2p1c+bounded.litmus +10
-0+ rLenPtr = lenFail; + rFail = 1; + } + + *rLenPtr = -1; + smp_store_release(px, rPx + 1); + + spin_unlock(rb_lock); + + smp_store_release(rLenPtr, 1);I ran a test replacing the last 2 statements above with the following and it still works:
Quoted 5 lines
spin_unlock(rb_lock); WRITE_ONCE(*rLenPtr, 1);Wouldn't you expect the test to catch an issue? The
spin_unlockis already a RELEASE barrier.Well, apparently it's not an issue and
WRITE_ONCEwould work as well :) My original version actually usedWRITE_ONCEhere. See [0] and discussion in [1] after which I removed all the WRITE_ONCE/READ_ONCE in favor of store_release/load_acquire for consistency.
Quoted 6 lines
Quoted 2 lines
[0] https://patchwork.ozlabs.org/project/netdev/patch/[email protected]/
[1] https://patchwork.ozlabs.org/project/netdev/patch/[email protected]/Huh. So you are replacing the test to use
WRITE_ONCEinstead? Why did you favor the acquire/release memory barriers over the_ONCEannotations, if that was not really needed then?
I replaced WRITE_ONCE with store_release. There was a request on initial version to keep it simple and use store_release/load_acquire pairings consistently and not mix up WRITE_ONCE and load_acquire, so that's what I did. As I mentioned elsewhere, this might not be the weakest possible set of orderings and we might improve that, but it seems to work well.
Quoted 17 lines
Quoted 7 lines
Quoted 3 lines
Suggestion: It is hard to review the patch because it is huge, it would be good to split this up into 4 patches for each of the tests. But upto you :)
Those 4 files are partial copies of each other, not sure splitting them actually would be easier. If anyone else thinks the same, though, I'll happily split.
I personally disagree. It would be much easier IMHO to review 4 different files since some of them are also quite dissimilar. I frequently keep jumping between diffs to find a different file and it makes the review that much harder. But anything the LKMM experts decide in this regard is acceptable to me :)
thanks,
- Joel