]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: freq_ctr: add cpu_relax in the rotation loop of update_freq_ctr_period()
authorWilly Tarreau <w@1wt.eu>
Sat, 10 Apr 2021 23:18:39 +0000 (01:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 11 Apr 2021 09:12:57 +0000 (11:12 +0200)
When counters are rotated, there is contention between the threads which
can slow down the operation of the thread performing the rotation. Let's
apply a cpu_relax there to let the first thread finish faster.

include/haproxy/freq_ctr.h

index 9c10038a326b528c938354a3d63fe91408bed091..6b0cebff16e6f957019dfcc086da26397a1e0087 100644 (file)
@@ -50,7 +50,7 @@ static inline unsigned int update_freq_ctr_period(struct freq_ctr *ctr,
 
                /* remove the bit, used for the lock */
                curr_tick &= ~1;
-       } while (!_HA_ATOMIC_CAS(&ctr->curr_tick, &curr_tick, curr_tick | 0x1));
+       } while (!_HA_ATOMIC_CAS(&ctr->curr_tick, &curr_tick, curr_tick | 0x1) && __ha_cpu_relax());
        __ha_barrier_atomic_store();
 
        if (now_ms_tmp - curr_tick >= period) {