BUG/MINOR: freq_ctr: use stricter barriers between updates and readings
authorWilly Tarreau <w@1wt.eu>
Thu, 15 Jul 2021 13:45:44 +0000 (15:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 1 Aug 2021 15:34:06 +0000 (17:34 +0200)
commit55a0975b1e957e9e23df8d9dd5400b40455c3fa9
tree39f760a52f2f56d7173108b896a2fca89dd52e9c
parent200bd50b73f8e0e3f27e83361dc456a69747a2b8
BUG/MINOR: freq_ctr: use stricter barriers between updates and readings

update_freq_ctr_period() was using relaxed atomics without using barriers,
which usually works fine on x86 but not everywhere else. In addition, some
values were read without being enclosed by barriers, allowing the compiler
to possibly prefetch them a bit earlier. Finally, freq_ctr_total() was also
reading these without enough barriers. Let's make explicit use of atomic
loads and atomic stores to get rid of this situation. This required to
slightly rearrange the freq_ctr_total() loop, which could possibly slightly
improve performance under extreme contention by avoiding to reread all
fields.

A backport may be done to 2.4 if a problem is encountered, but last tests
on arm64 with LSE didn't show any issue so this can possibly stay as-is.
include/haproxy/freq_ctr.h
src/freq_ctr.c