From 2a54ffbf434143e6f76c426c48f752e402e7d764 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 25 Feb 2021 09:32:58 +0100 Subject: [PATCH] MINOR: task: make tasklet wakeup latency measurements more accurate First, we don't want to measure wakeup times if the call date had not been set before profiling was enabled at run time. And second, we may only collect the value before clearing the TASK_IN_LIST bit, otherwise another wakeup might happen on another thread and replace the call date we're about to use, hence artificially lower the wakeup times. --- src/task.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/task.c b/src/task.c index e33120fcf..a9a6cc1a1 100644 --- a/src/task.c +++ b/src/task.c @@ -495,25 +495,32 @@ unsigned int run_tasks_from_lists(unsigned int budgets[]) _HA_ATOMIC_SUB(&sched->rq_total, 1); if (TASK_IS_TASKLET(t)) { + uint64_t before = 0; + LIST_DEL_INIT(&((struct tasklet *)t)->list); __ha_barrier_store(); - state = _HA_ATOMIC_XCHG(&t->state, state); - __ha_barrier_atomic_store(); if (unlikely(task_profiling_mask & tid_bit)) { - uint64_t before; - profile_entry = sched_activity_entry(sched_activity, t->process); before = now_mono_time(); #ifdef DEBUG_TASK - HA_ATOMIC_ADD(&profile_entry->lat_time, before - ((struct tasklet *)t)->call_date); + if (((struct tasklet *)t)->call_date) { + HA_ATOMIC_ADD(&profile_entry->lat_time, before - ((struct tasklet *)t)->call_date); + ((struct tasklet *)t)->call_date = 0; + } #endif - process(t, ctx, state); + } + + state = _HA_ATOMIC_XCHG(&t->state, state); + __ha_barrier_atomic_store(); + + process(t, ctx, state); + + if (unlikely(task_profiling_mask & tid_bit)) { HA_ATOMIC_ADD(&profile_entry->calls, 1); HA_ATOMIC_ADD(&profile_entry->cpu_time, now_mono_time() - before); - } else { - process(t, ctx, state); } + done++; sched->current = NULL; __ha_barrier_store();