From: Willy Tarreau Date: Sat, 10 Apr 2021 23:18:39 +0000 (+0200) Subject: MINOR: freq_ctr: add cpu_relax in the rotation loop of update_freq_ctr_period() X-Git-Tag: v2.4-dev17~143 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6339c19cacb2010d2bf71066e436f5cc27252746;p=thirdparty%2Fhaproxy.git MINOR: freq_ctr: add cpu_relax in the rotation loop of update_freq_ctr_period() 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. --- diff --git a/include/haproxy/freq_ctr.h b/include/haproxy/freq_ctr.h index 9c10038a32..6b0cebff16 100644 --- a/include/haproxy/freq_ctr.h +++ b/include/haproxy/freq_ctr.h @@ -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) {