]> git.ipfire.org Git - thirdparty/haproxy.git/commit
OPTIM: freq-ctr: don't take the date lock for most updates
authorWilly Tarreau <w@1wt.eu>
Sat, 25 May 2019 17:54:40 +0000 (19:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 25 May 2019 18:31:53 +0000 (20:31 +0200)
commit0d6c75d7495091a615603152993378a2274a76b5
treeff4ce48d1423ea2d2b5fb53208ef00e0dca7b3ac
parente242f3dfb8ae2f27de9d10d90a783df05d5c849b
OPTIM: freq-ctr: don't take the date lock for most updates

It's amazing that the value was still incremented under the date lock,
let's first use an atomic increment for the counter and move it out of
the date lock to reduce contention. These are just counters, we don't
need to take locks if we're not rotating, atomic ops are enough. This
patch does this, and leaves the lock for when the period is over. It's
important to note that some values might be added just before or just
after a rotation but this is not a problem since we don't care if a
value is counted in the previous or next period when it's exactly on
the edge. Great care was taken to ensure that the current counter is
always atomically updated.

Other minor cleanups were performed, such as avoiding to reload the
value from memory after a CAS, or using &~1 instead of two shifts to
remove the lowest bit.
include/proto/freq_ctr.h