BUG/MEDIUM: freq-ctr: Don't compute overshoot value for empty counters

The function computing the excess of events of a frequency counter over the
current period for a target frequency must handle empty counters (no event
and no start date). In this case, no excess must be reported.

Because of this bug, long pauses may be experienced on the bandwith
limitation filter.

This patch must be backported to 2.7.
This commit is contained in:
Christopher Faulet 2022-12-14 10:38:01 +01:00
parent 04007cb08d
commit 427293420f

View File

@ -147,8 +147,9 @@ ullong freq_ctr_total(const struct freq_ctr *ctr, uint period, int pend)
}
/* Returns the excess of events (may be negative) over the current period for
* target frequency <freq>. It returns 0 if the counter is in the future. The
* result considers the position of the current time within the current period.
* target frequency <freq>. It returns 0 if the counter is in the future or if
* the counter is empty. The result considers the position of the current time
* within the current period.
*
* The caller may safely add new events if result is negative or null.
*/
@ -195,6 +196,11 @@ int freq_ctr_overshoot_period(const struct freq_ctr *ctr, uint period, uint freq
__ha_cpu_relax();
};
if (!curr && !tick) {
/* The counter is empty, there is no overshoot */
return 0;
}
elapsed = HA_ATOMIC_LOAD(&global_now_ms) - tick;
if (unlikely(elapsed < 0)) {
/* The counter is in the future, there is no overshoot */