From: Willy Tarreau Date: Thu, 25 Feb 2021 08:32:58 +0000 (+0100) Subject: MINOR: task: make tasklet wakeup latency measurements more accurate X-Git-Tag: v2.4-dev10~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a54ffbf434143e6f76c426c48f752e402e7d764;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/task.c b/src/task.c index e33120fcf0..a9a6cc1a1b 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();