From 7bbac6419d174c98cc6ea969b68fcfe0f9a9bab8 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Tue, 26 Dec 2023 22:30:56 -0500 Subject: [PATCH] Schedule fast taskqueue callouts on right CPU. With fast taskqueues using direct callouts we can reduce number of CPU wakeups by scheduling callout on current CPU if taskqueue calls taskqueue_enqueue_timeout() on itself. The trick won't work for regular taskqueues, since the callout thread will occupy the CPU. It also may not work in case of multiple threads since we do not know which thread will pick the task, and we do not want excessive callout migrations. So we optimize only the other cases we can. In practice this allows iichid(4) taskqueue to stay on CPU where underlying ig4(4) interrupts are routed and to not kick CPU 0 with timer interrupts on each sampling period (every 2nd/3rd sleep). MFC after: 1 month --- sys/kern/subr_taskqueue.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c index 5650f9d57a01..c4146922edc5 100644 --- a/sys/kern/subr_taskqueue.c +++ b/sys/kern/subr_taskqueue.c @@ -363,8 +363,14 @@ taskqueue_enqueue_timeout_sbt(struct taskqueue *queue, if (sbt > 0) { if (queue->tq_spin) flags |= C_DIRECT_EXEC; - callout_reset_sbt(&timeout_task->c, sbt, pr, - taskqueue_timeout_func, timeout_task, flags); + if (queue->tq_spin && queue->tq_tcount == 1 && + queue->tq_threads[0] == curthread) { + callout_reset_sbt_curcpu(&timeout_task->c, sbt, pr, + taskqueue_timeout_func, timeout_task, flags); + } else { + callout_reset_sbt(&timeout_task->c, sbt, pr, + taskqueue_timeout_func, timeout_task, flags); + } } TQ_UNLOCK(queue); }