]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: optimize fd_claim_tgid() for use in fd_insert()
authorWilly Tarreau <w@1wt.eu>
Thu, 13 Apr 2023 13:22:42 +0000 (15:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Apr 2023 14:57:51 +0000 (16:57 +0200)
fd_claim_tgid() uses a CAS to set the desired TGID on the FD. It's only
called from fd_insert() where in the vast majority of cases, the tgid
and refcount are zero before the call. However the loop was optimized
for the case where it was equal to the desired TGID, systematically
causing one extra round in the loop there. Better start assuming a
zero value.

include/haproxy/fd.h

index 984b151e929632f9ace526aacb2255ceb6b1b937..9c0768083be3e8a237b5f57a365b59e15d6fe953 100644 (file)
@@ -382,12 +382,12 @@ static inline void fd_claim_tgid(int fd, uint desired_tgid)
        BUG_ON(!desired_tgid);
 
        desired_tgid += 0x10000; // refcount=1
-       old = desired_tgid;
+       old = 0;                 // assume unused (most likely)
        while (1) {
-               old &= 0xffff;
                if (_HA_ATOMIC_CAS(&fdtab[fd].refc_tgid, &old, desired_tgid))
                        break;
                __ha_cpu_relax();
+               old &= 0xffff;
        }
 }