{
int elapsed;
unsigned int curr_sec;
+ uint32_t now_tmp;
/* we manipulate curr_ctr using atomic ops out of the lock, since
* same uncertainty as well.
*/
curr_sec = ctr->curr_sec;
- if (curr_sec == (now.tv_sec & 0x7fffffff))
- return _HA_ATOMIC_ADD(&ctr->curr_ctr, inc);
-
do {
+ now_tmp = global_now >> 32;
+ if (curr_sec == (now_tmp & 0x7fffffff))
+ return _HA_ATOMIC_ADD(&ctr->curr_ctr, inc);
+
/* remove the bit, used for the lock */
curr_sec &= 0x7fffffff;
} while (!_HA_ATOMIC_CAS(&ctr->curr_sec, &curr_sec, curr_sec | 0x80000000));
__ha_barrier_atomic_store();
- elapsed = (now.tv_sec & 0x7fffffff)- curr_sec;
+ elapsed = (now_tmp & 0x7fffffff) - curr_sec;
if (unlikely(elapsed > 0)) {
ctr->prev_ctr = ctr->curr_ctr;
_HA_ATOMIC_SUB(&ctr->curr_ctr, ctr->prev_ctr);
/* we missed more than one second */
ctr->prev_ctr = 0;
}
- curr_sec = now.tv_sec;
+ curr_sec = now_tmp;
}
/* release the lock and update the time in case of rotate. */
unsigned int period, unsigned int inc)
{
unsigned int curr_tick;
+ uint32_t now_ms_tmp;
curr_tick = ctr->curr_tick;
- if (now_ms - curr_tick < period)
- return _HA_ATOMIC_ADD(&ctr->curr_ctr, inc);
-
do {
+ now_ms_tmp = (uint32_t)global_now / 1000;
+ if (now_ms_tmp - curr_tick < period)
+ return _HA_ATOMIC_ADD(&ctr->curr_ctr, inc);
+
/* remove the bit, used for the lock */
curr_tick &= ~1;
} while (!_HA_ATOMIC_CAS(&ctr->curr_tick, &curr_tick, curr_tick | 0x1));
__ha_barrier_atomic_store();
- if (now_ms - curr_tick >= period) {
+ if (now_ms_tmp - curr_tick >= period) {
ctr->prev_ctr = ctr->curr_ctr;
_HA_ATOMIC_SUB(&ctr->curr_ctr, ctr->prev_ctr);
curr_tick += period;
- if (likely(now_ms - curr_tick >= period)) {
+ if (likely(now_ms_tmp - curr_tick >= period)) {
/* we missed at least two periods */
ctr->prev_ctr = 0;
- curr_tick = now_ms;
+ curr_tick = now_ms_tmp;
}
curr_tick &= ~1;
}
break;
}
- age = now.tv_sec - curr_sec;
+ age = (global_now >> 32) - curr_sec;
if (unlikely(age > 1))
return 0;
break;
}
- age = now.tv_sec - curr_sec;
+ age = (global_now >> 32) - curr_sec;
if (unlikely(age > 1))
curr = 0;
else {
break;
}
- age = now.tv_sec - curr_sec;
+ age = (global_now >> 32) - curr_sec;
if (unlikely(age > 1))
curr = 0;
else {
/* Reads a frequency counter taking history into account for missing time in
* current period. The period has to be passed in number of ticks and must
* match the one used to feed the counter. The counter value is reported for
- * current date (now_ms). The return value has the same precision as one input
+ * current global date. The return value has the same precision as one input
* data sample, so low rates over the period will be inaccurate but still
* appropriate for max checking. One trick we use for low values is to specially
* handle the case where the rate is between 0 and 1 in order to avoid flapping
break;
};
- remain = curr_tick + period - now_ms;
+ remain = curr_tick + period - (uint32_t)global_now / 1000;
if (unlikely((int)remain < 0)) {
/* We're past the first period, check if we can still report a
* part of last period or if we're too far away.
break;
};
- remain = curr_tick + period - now_ms;
+ remain = curr_tick + period - (uint32_t)global_now / 1000;
if (likely((int)remain < 0)) {
/* We're past the first period, check if we can still report a
* part of last period or if we're too far away.