MEDIUM: clock: collect the monotonic time in clock_local_update_date()

Now we collect this clock in clock_local_update_date(), the closest from
the poller, which is also used when busy-polling, and the values is set
into the thread's curr_mono_time which did not exist before. Later,
clock_leaving_poll() just sets the prev_mono_time value from the curr_
one instead of retrieving the time at this specific point. It also means
that the monotonic time will now also cover the time needed to update
the global time, which should be negligible. Note that we don't collect
the CPU time in the clock_local_update_date() function even though it's
tempting, because when doing busy-polling, it would be collected on each
round while being useless.

Doing so will make sure that the local time always knows the monotonic
time when it is available.
This commit is contained in:
Willy Tarreau 2024-09-08 18:10:25 +00:00
parent 42e699903e
commit f793845f4a
2 changed files with 7 additions and 1 deletions

View File

@ -169,6 +169,7 @@ struct thread_ctx {
uint64_t prev_cpu_time; /* previous per thread CPU time */ uint64_t prev_cpu_time; /* previous per thread CPU time */
uint64_t prev_mono_time; /* previous system wide monotonic time */ uint64_t prev_mono_time; /* previous system wide monotonic time */
uint64_t curr_mono_time; /* latest system wide monotonic time */
struct eb_root rqueue_shared; /* run queue fed by other threads */ struct eb_root rqueue_shared; /* run queue fed by other threads */
__decl_thread(HA_SPINLOCK_T rqsh_lock); /* lock protecting the shared runqueue */ __decl_thread(HA_SPINLOCK_T rqsh_lock); /* lock protecting the shared runqueue */

View File

@ -205,6 +205,8 @@ void clock_update_local_date(int max_wait, int interrupted)
gettimeofday(&date, NULL); gettimeofday(&date, NULL);
date_ns = tv_to_ns(&date); date_ns = tv_to_ns(&date);
th_ctx->curr_mono_time = now_mono_time();
/* compute the minimum and maximum local date we may have reached based /* compute the minimum and maximum local date we may have reached based
* on our past date and the associated timeout. There are three possible * on our past date and the associated timeout. There are three possible
* extremities: * extremities:
@ -296,6 +298,7 @@ void clock_update_global_date()
void clock_init_process_date(void) void clock_init_process_date(void)
{ {
now_offset = 0; now_offset = 0;
th_ctx->prev_mono_time = th_ctx->curr_mono_time = now_mono_time(); // 0 if not supported
gettimeofday(&date, NULL); gettimeofday(&date, NULL);
after_poll = before_poll = date; after_poll = before_poll = date;
now_ns = global_now_ns = tv_to_ns(&date); now_ns = global_now_ns = tv_to_ns(&date);
@ -332,6 +335,8 @@ void clock_init_thread_date(void)
now_ns = _HA_ATOMIC_LOAD(&global_now_ns); now_ns = _HA_ATOMIC_LOAD(&global_now_ns);
th_ctx->idle_pct = 100; th_ctx->idle_pct = 100;
th_ctx->prev_cpu_time = now_cpu_time(); th_ctx->prev_cpu_time = now_cpu_time();
th_ctx->prev_mono_time = now_mono_time();
th_ctx->curr_mono_time = th_ctx->prev_mono_time;
clock_update_date(0, 1); clock_update_date(0, 1);
} }
@ -391,7 +396,7 @@ void clock_leaving_poll(int timeout, int interrupted)
{ {
clock_measure_idle(); clock_measure_idle();
th_ctx->prev_cpu_time = now_cpu_time(); th_ctx->prev_cpu_time = now_cpu_time();
th_ctx->prev_mono_time = now_mono_time(); th_ctx->prev_mono_time = th_ctx->curr_mono_time;
} }
/* Collect date and time information before calling poll(). This will be used /* Collect date and time information before calling poll(). This will be used