diff options
| author | Michael S. Tsirkin <mst@redhat.com> | 2025-09-27 08:29:35 -0400 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2025-09-29 18:13:10 -0700 |
| commit | c39d6d4d933381714b6e5d735545256558ec6c05 (patch) | |
| tree | 6980bc86e94659c058f7e8d912204cadeb74c0ac | |
| parent | e8c4840d0c198215866728626b5c197048d4368b (diff) | |
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>
| -rw-r--r-- | include/linux/ptr_ring.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h index a736b16859a6..534531807d95 100644 --- a/include/linux/ptr_ring.h +++ b/include/linux/ptr_ring.h @@ -248,15 +248,15 @@ static inline bool ptr_ring_empty_bh(struct ptr_ring *r) */ static inline void __ptr_ring_zero_tail(struct ptr_ring *r, int consumer_head) { - int head = consumer_head - 1; + int head = consumer_head; /* Zero out entries in the reverse order: this way we touch the * cache line that producer might currently be reading the last; * producer won't make progress and touch other cache lines * besides the first one until we write out all entries. */ - while (likely(head >= r->consumer_tail)) - r->queue[head--] = NULL; + while (likely(head > r->consumer_tail)) + r->queue[--head] = NULL; r->consumer_tail = consumer_head; } |