mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-20 04:37:04 +00:00
BUG/MEDIUM: freq_ctr/threads: use the global_now_ms variable
In commit a1ecbca0a
("BUG/MINOR: freq_ctr/threads: make use of the last
updated global time"), for period-based counters, the millisecond part
of the global_now variable was used as the date for the new period. But
it's wrong, it only works with sub-second periods as it wraps every
second, and for other periods the counters never rotate anymore.
Let's make use of the newly introduced global_now_ms variable instead,
which contains the global monotonic time expressed in milliseconds.
This patch needs to be backported wherever the patch above is backported.
It depends on previous commit "MINOR: time: also provide a global,
monotonic global_now_ms timer".
This commit is contained in:
parent
6064b34be0
commit
8cc586c73f
@ -88,7 +88,7 @@ static inline unsigned int update_freq_ctr_period(struct freq_ctr_period *ctr,
|
|||||||
|
|
||||||
curr_tick = ctr->curr_tick;
|
curr_tick = ctr->curr_tick;
|
||||||
do {
|
do {
|
||||||
now_ms_tmp = (uint32_t)global_now / 1000;
|
now_ms_tmp = global_now_ms;
|
||||||
if (now_ms_tmp - curr_tick < period)
|
if (now_ms_tmp - curr_tick < period)
|
||||||
return _HA_ATOMIC_ADD(&ctr->curr_ctr, inc);
|
return _HA_ATOMIC_ADD(&ctr->curr_ctr, inc);
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ unsigned int read_freq_ctr_period(struct freq_ctr_period *ctr, unsigned int peri
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
remain = curr_tick + period - (uint32_t)global_now / 1000;
|
remain = curr_tick + period - global_now_ms;
|
||||||
if (unlikely((int)remain < 0)) {
|
if (unlikely((int)remain < 0)) {
|
||||||
/* We're past the first period, check if we can still report a
|
/* We're past the first period, check if we can still report a
|
||||||
* part of last period or if we're too far away.
|
* part of last period or if we're too far away.
|
||||||
@ -253,7 +253,7 @@ unsigned int freq_ctr_remain_period(struct freq_ctr_period *ctr, unsigned int pe
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
remain = curr_tick + period - (uint32_t)global_now / 1000;
|
remain = curr_tick + period - global_now_ms;
|
||||||
if (likely((int)remain < 0)) {
|
if (likely((int)remain < 0)) {
|
||||||
/* We're past the first period, check if we can still report a
|
/* We're past the first period, check if we can still report a
|
||||||
* part of last period or if we're too far away.
|
* part of last period or if we're too far away.
|
||||||
|
Loading…
Reference in New Issue
Block a user