aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2018-01-10 09:03:05 -0500
committerDavid S. Miller <davem@davemloft.net>2018-01-15 13:19:12 -0500
commit66940f35d5a81d5969bb5543171c70a434fc5110 (patch)
tree3bf27497f8ddf563514733ad40e53d180b5aa6f2
parentd542296a4d0d9f41d0186edcac2baba1b674d02f (diff)
ptr_ring: document usage around __ptr_ring_peek
This explains why is the net usage of __ptr_ring_peek actually ok without locks. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/ptr_ring.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
index 6866df4f31b5..d72b2e7dd500 100644
--- a/include/linux/ptr_ring.h
+++ b/include/linux/ptr_ring.h
@@ -174,6 +174,15 @@ static inline int ptr_ring_produce_bh(struct ptr_ring *r, void *ptr)
174 * if they dereference the pointer - see e.g. PTR_RING_PEEK_CALL. 174 * if they dereference the pointer - see e.g. PTR_RING_PEEK_CALL.
175 * If ring is never resized, and if the pointer is merely 175 * If ring is never resized, and if the pointer is merely
176 * tested, there's no need to take the lock - see e.g. __ptr_ring_empty. 176 * tested, there's no need to take the lock - see e.g. __ptr_ring_empty.
177 * However, if called outside the lock, and if some other CPU
178 * consumes ring entries at the same time, the value returned
179 * is not guaranteed to be correct.
180 * In this case - to avoid incorrectly detecting the ring
181 * as empty - the CPU consuming the ring entries is responsible
182 * for either consuming all ring entries until the ring is empty,
183 * or synchronizing with some other CPU and causing it to
184 * execute __ptr_ring_peek and/or consume the ring enteries
185 * after the synchronization point.
177 */ 186 */
178static inline void *__ptr_ring_peek(struct ptr_ring *r) 187static inline void *__ptr_ring_peek(struct ptr_ring *r)
179{ 188{
@@ -182,10 +191,7 @@ static inline void *__ptr_ring_peek(struct ptr_ring *r)
182 return NULL; 191 return NULL;
183} 192}
184 193
185/* Note: callers invoking this in a loop must use a compiler barrier, 194/* See __ptr_ring_peek above for locking rules. */
186 * for example cpu_relax(). Callers must take consumer_lock
187 * if the ring is ever resized - see e.g. ptr_ring_empty.
188 */
189static inline bool __ptr_ring_empty(struct ptr_ring *r) 195static inline bool __ptr_ring_empty(struct ptr_ring *r)
190{ 196{
191 return !__ptr_ring_peek(r); 197 return !__ptr_ring_peek(r);