From: Willy Tarreau Date: Fri, 22 Mar 2024 13:46:12 +0000 (+0100) Subject: MINOR: ring: keep a few frequently used pointers in the local stack X-Git-Tag: v3.0-dev6~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=447189f2867936e124a173da704175904b135d42;p=thirdparty%2Fhaproxy.git MINOR: ring: keep a few frequently used pointers in the local stack Code disassembly shows that ring->storage->tail and ring->queue are accessed a lot and reloaded a lot due to aliasing. Let's just have variables for them in the local stack. It makes the code smaller and slightly faster. --- diff --git a/src/ring.c b/src/ring.c index 0916b3f8f0..1c01122b71 100644 --- a/src/ring.c +++ b/src/ring.c @@ -173,6 +173,7 @@ void ring_free(struct ring *ring) */ ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], size_t npfx, const struct ist msg[], size_t nmsg) { + size_t *tail_ptr = &ring->storage->tail; size_t head_ofs, tail_ofs, new_tail_ofs; size_t ring_size; char *ring_area; @@ -239,10 +240,10 @@ ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], siz * change (use it as a ticket). */ while (1) { - tail_ofs = HA_ATOMIC_FETCH_OR(&ring->storage->tail, RING_TAIL_LOCK); + tail_ofs = HA_ATOMIC_FETCH_OR(tail_ptr, RING_TAIL_LOCK); if (!(tail_ofs & RING_TAIL_LOCK)) break; - pl_wait_unlock_long(&ring->storage->tail, RING_TAIL_LOCK); + pl_wait_unlock_long(tail_ptr, RING_TAIL_LOCK); } head_ofs = HA_ATOMIC_LOAD(&ring->storage->head); @@ -291,7 +292,7 @@ ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], siz } /* and release other writers */ - HA_ATOMIC_STORE(&ring->storage->tail, new_tail_ofs); + HA_ATOMIC_STORE(tail_ptr, new_tail_ofs); if (vp_size(v1, v2) > ring_size - needed - 1 - 1) { /* we had to stop due to readers blocking the head,