MINOR: freq_ctr: simplify and improve the update function
authorWilly Tarreau <w@1wt.eu>
Sun, 11 Apr 2021 11:51:58 +0000 (13:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 11 Apr 2021 12:01:53 +0000 (14:01 +0200)
commitd46ed5c26b4797ea689415de0b4ae75ddc16d84a
treeea6a658797eb0e0c0b41a2372ef8cf5053ae9820
parent6339c19cacb2010d2bf71066e436f5cc27252746
MINOR: freq_ctr: simplify and improve the update function

update_freq_ctr_period() was still not very clean and didn't wait for
the rotation lock to be dropped before trying again, thus maintaining
the contention at a high level. In addition, the rotation update was
made in three steps, which are not very efficient in terms of bus
cycles.

Here the wait loop was reworked so that the fast path remains short
and that the contended path waits for the lock to be dropped before
attempting another write, but it only waits a relax cycle before
attempting a read. The rotation block was simplified to remove a
test that was already validated by the first loop, and so that the
retrieval of the current period, its reset and its increment are all
performed in a single atomic op and the store to the previous period
is performed immediately after.

All this results in significantly smaller code for the inline function
(~1kB total) and a shorter critical path.
include/haproxy/freq_ctr.h