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.

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>

authored by

Michael S. Tsirkin and committed by
Jakub Kicinski
c39d6d4d e8c4840d

+3 -3
+3 -3
include/linux/ptr_ring.h
··· 248 248 */ 249 249 static inline void __ptr_ring_zero_tail(struct ptr_ring *r, int consumer_head) 250 250 { 251 - int head = consumer_head - 1; 251 + int head = consumer_head; 252 252 253 253 /* Zero out entries in the reverse order: this way we touch the 254 254 * cache line that producer might currently be reading the last; 255 255 * producer won't make progress and touch other cache lines 256 256 * besides the first one until we write out all entries. 257 257 */ 258 - while (likely(head >= r->consumer_tail)) 259 - r->queue[head--] = NULL; 258 + while (likely(head > r->consumer_tail)) 259 + r->queue[--head] = NULL; 260 260 261 261 r->consumer_tail = consumer_head; 262 262 }