]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ring: keep a few frequently used pointers in the local stack
authorWilly Tarreau <w@1wt.eu>
Fri, 22 Mar 2024 13:46:12 +0000 (14:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Mar 2024 17:34:19 +0000 (17:34 +0000)
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.

src/ring.c

index 0916b3f8f0b531f72f3b4eb094659e7dd65d91d8..1c01122b710a0a8927bfa4f7d02c39a38b3db992 100644 (file)
@@ -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,