mirror of
http://git.haproxy.org/git/haproxy.git
synced 2026-02-17 19:26:55 +02:00
MINOR: sched: add TASK_F_WANTS_TIME to make the scheduler update the call date
Currently tasks being profiled have th_ctx->sched_call_date set to the current nanosecond in monotonic time. But there's no other way to have this, despite the scheduler being capable of it. Let's just declare a new task flag, TASK_F_WANTS_TIME, that makes the scheduler take the time just before calling the handler. This way, a task that needs nanosecond resolution on the call date will be able to be called with an up-to-date date without having to abuse now_mono_time() if not needed. In addition, if CLOCK_MONOTONIC is not supported (now_mono_time() always returns 0), the date is set to the most recently known now_ns, which is guaranteed to be atomic and is only updated once per poll loop. This date can be more conveniently retrieved using task_mono_time(). This can be useful, e.g. for pacing. The code was slightly adjusted so as to merge the common parts between the profiling case and this one.
This commit is contained in:
17
src/task.c
17
src/task.c
@@ -567,17 +567,24 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
|
||||
t->calls++;
|
||||
|
||||
th_ctx->sched_wake_date = t->wake_date;
|
||||
if (th_ctx->sched_wake_date) {
|
||||
uint32_t now_ns = now_mono_time();
|
||||
uint32_t lat = now_ns - th_ctx->sched_wake_date;
|
||||
if (th_ctx->sched_wake_date || (t->state & TASK_F_WANTS_TIME)) {
|
||||
/* take the most accurate clock we have, either
|
||||
* mono_time() or last now_ns (monotonic but only
|
||||
* incremented once per poll loop).
|
||||
*/
|
||||
th_ctx->sched_call_date = now_mono_time();
|
||||
if (unlikely(!th_ctx->sched_call_date))
|
||||
th_ctx->sched_call_date = now_ns;
|
||||
}
|
||||
|
||||
if (th_ctx->sched_wake_date) {
|
||||
t->wake_date = 0;
|
||||
th_ctx->sched_call_date = now_ns;
|
||||
profile_entry = sched_activity_entry(sched_activity, t->process, t->caller);
|
||||
th_ctx->sched_profile_entry = profile_entry;
|
||||
HA_ATOMIC_ADD(&profile_entry->lat_time, lat);
|
||||
HA_ATOMIC_ADD(&profile_entry->lat_time, (uint32_t)(th_ctx->sched_call_date - th_ctx->sched_wake_date));
|
||||
HA_ATOMIC_INC(&profile_entry->calls);
|
||||
}
|
||||
|
||||
__ha_barrier_store();
|
||||
|
||||
th_ctx->current = t;
|
||||
|
||||
Reference in New Issue
Block a user