mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
MINOR: time: avoid unneeded updates to now_offset
The time adjustment is very rare, even at high pool rates. Tests show that only 0.2% of tv_update_date() calls require a change of offset. Such concurrent writes to a shared variable have an important impact on future loads, so let's only update the variable if it changed.
This commit is contained in:
parent
a6f9c5d2a7
commit
481795de13
@ -184,7 +184,7 @@ void tv_update_date(int max_wait, int interrupted)
|
|||||||
unsigned int old_now_ms;
|
unsigned int old_now_ms;
|
||||||
unsigned long long old_now;
|
unsigned long long old_now;
|
||||||
unsigned long long new_now;
|
unsigned long long new_now;
|
||||||
ullong ofs = HA_ATOMIC_LOAD(&now_offset);
|
ullong ofs, ofs_new;
|
||||||
uint sec_ofs, usec_ofs;
|
uint sec_ofs, usec_ofs;
|
||||||
|
|
||||||
gettimeofday(&date, NULL);
|
gettimeofday(&date, NULL);
|
||||||
@ -203,6 +203,8 @@ void tv_update_date(int max_wait, int interrupted)
|
|||||||
_tv_ms_add(&min_deadline, &before_poll, max_wait);
|
_tv_ms_add(&min_deadline, &before_poll, max_wait);
|
||||||
_tv_ms_add(&max_deadline, &before_poll, max_wait + 100);
|
_tv_ms_add(&max_deadline, &before_poll, max_wait + 100);
|
||||||
|
|
||||||
|
ofs = HA_ATOMIC_LOAD(&now_offset);
|
||||||
|
|
||||||
if (unlikely(__tv_islt(&date, &before_poll) || // big jump backwards
|
if (unlikely(__tv_islt(&date, &before_poll) || // big jump backwards
|
||||||
(!interrupted && __tv_islt(&date, &min_deadline)) || // small jump backwards
|
(!interrupted && __tv_islt(&date, &min_deadline)) || // small jump backwards
|
||||||
__tv_islt(&max_deadline, &date))) { // big jump forwards
|
__tv_islt(&max_deadline, &date))) { // big jump forwards
|
||||||
@ -265,8 +267,9 @@ void tv_update_date(int max_wait, int interrupted)
|
|||||||
usec_ofs += 1000000;
|
usec_ofs += 1000000;
|
||||||
sec_ofs -= 1;
|
sec_ofs -= 1;
|
||||||
}
|
}
|
||||||
ofs = ((ullong)sec_ofs << 32) + usec_ofs;
|
ofs_new = ((ullong)sec_ofs << 32) + usec_ofs;
|
||||||
HA_ATOMIC_STORE(&now_offset, ofs);
|
if (ofs_new != ofs)
|
||||||
|
HA_ATOMIC_STORE(&now_offset, ofs_new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* must be called once at boot to initialize some global variables */
|
/* must be called once at boot to initialize some global variables */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user