Skip to content

Commit c39d6d4

Browse files
mstsirkinkuba-moo
authored andcommitted
ptr_ring: __ptr_ring_zero_tail micro optimization
__ptr_ring_zero_tail currently does the - 1 operation twice: - during initialization of head - at each loop iteration Let's just do it in one place, all we need to do is adjust the loop condition. this is better: - a slightly clearer logic with less duplication - uses prefix -- we don't need to save the old value - one less - 1 operation - for example, when ring is empty we now don't do - 1 at all, existing code does it once Text size shrinks from 15081 to 15050 bytes. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/bcd630c7edc628e20d4f8e037341f26c90ab4365.1758976026.git.mst@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e8c4840 commit c39d6d4

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

include/linux/ptr_ring.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ static inline bool ptr_ring_empty_bh(struct ptr_ring *r)
248248
*/
249249
static inline void __ptr_ring_zero_tail(struct ptr_ring *r, int consumer_head)
250250
{
251-
int head = consumer_head - 1;
251+
int head = consumer_head;
252252

253253
/* Zero out entries in the reverse order: this way we touch the
254254
* cache line that producer might currently be reading the last;
255255
* producer won't make progress and touch other cache lines
256256
* besides the first one until we write out all entries.
257257
*/
258-
while (likely(head >= r->consumer_tail))
259-
r->queue[head--] = NULL;
258+
while (likely(head > r->consumer_tail))
259+
r->queue[--head] = NULL;
260260

261261
r->consumer_tail = consumer_head;
262262
}

0 commit comments

Comments
 (0)