]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: use a common thr_idx from the reference listener
authorWilly Tarreau <w@1wt.eu>
Wed, 29 Mar 2023 15:02:17 +0000 (17:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 21 Apr 2023 15:41:26 +0000 (17:41 +0200)
Instead of seeing each listener use its own thr_idx, let's use the same
for all those from a shard. It should provide more accurate and smoother
thread allocation.

src/listener.c

index f97e2d7d1580850b2fbf9cdac5e0e5a1a90c7574..8e8a1f1327d9bc437ae4b84a806e4314dc09e9fe 100644 (file)
@@ -1190,6 +1190,7 @@ void listener_accept(struct listener *l)
                        uint n0, n1, n2, r1, r2, t, t1, t2;
                        const struct tgroup_info *g1, *g2;
                        ulong m1, m2;
+                       uint *thr_idx_ptr;
 
                        /* The principle is that we have two running indexes,
                         * each visiting in turn all threads bound to this
@@ -1215,7 +1216,8 @@ void listener_accept(struct listener *l)
                        /* keep a copy for the final update. thr_idx is composite
                         * and made of (n2<<16) + n1.
                         */
-                       n0 = l->thr_idx;
+                       thr_idx_ptr = l->rx.shard_info ? &((struct listener *)(l->rx.shard_info->ref->owner))->thr_idx : &l->thr_idx;
+                       n0 = _HA_ATOMIC_LOAD(thr_idx_ptr);
                        while (1) {
                                int q1, q2;
 
@@ -1392,7 +1394,7 @@ void listener_accept(struct listener *l)
                                n1 += (n2 << 16);
 
                                /* try to update the index */
-                               if (likely(_HA_ATOMIC_CAS(&l->thr_idx, &n0, n1)))
+                               if (likely(_HA_ATOMIC_CAS(thr_idx_ptr, &n0, n1)))
                                        break;
                        } /* end of main while() loop */