From 91a7c164b492454ec528fae7a539f4d4df678314 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 7 Jul 2022 15:25:40 +0200 Subject: [PATCH] MINOR: task: move the niced_tasks counter to the thread group context This one is only used as a hint to improve scheduling latency, so there is no more point in keeping it global since each thread group handles its own run q --- include/haproxy/task.h | 2 -- include/haproxy/tinfo-t.h | 2 ++ src/task.c | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/haproxy/task.h b/include/haproxy/task.h index 9bb09a486..2f3fe3d29 100644 --- a/include/haproxy/task.h +++ b/include/haproxy/task.h @@ -88,8 +88,6 @@ /* a few exported variables */ -extern unsigned int niced_tasks; /* number of niced tasks in the run queue */ - extern struct pool_head *pool_head_task; extern struct pool_head *pool_head_tasklet; extern struct pool_head *pool_head_notification; diff --git a/include/haproxy/tinfo-t.h b/include/haproxy/tinfo-t.h index 6df31f117..3a6570e48 100644 --- a/include/haproxy/tinfo-t.h +++ b/include/haproxy/tinfo-t.h @@ -73,6 +73,8 @@ struct tgroup_ctx { HA_RWLOCK_T wq_lock; /* RW lock related to the wait queue below */ struct eb_root timers; /* wait queue (sorted timers tree, global, accessed under wq_lock) */ + uint niced_tasks; /* number of niced tasks in this group's run queues */ + /* pad to cache line (64B) */ char __pad[0]; /* unused except to check remaining room */ char __end[0] __attribute__((aligned(64))); diff --git a/src/task.c b/src/task.c index 11a1b2ccd..0399a7110 100644 --- a/src/task.c +++ b/src/task.c @@ -34,8 +34,6 @@ DECLARE_POOL(pool_head_tasklet, "tasklet", sizeof(struct tasklet)); */ DECLARE_POOL(pool_head_notification, "notification", sizeof(struct notification)); -unsigned int niced_tasks = 0; /* number of niced tasks in the run queue */ - /* Flags the task for immediate destruction and puts it into its first * thread's shared tasklet list if not yet queued/running. This will bypass @@ -229,7 +227,7 @@ void __task_wakeup(struct task *t) if (likely(t->nice)) { int offset; - _HA_ATOMIC_INC(&niced_tasks); + _HA_ATOMIC_INC(&tg_ctx->niced_tasks); offset = t->nice * (int)global.tune.runqueue_depth; t->rq.key += offset; } @@ -736,7 +734,7 @@ void process_runnable_tasks() max_processed = global.tune.runqueue_depth; - if (likely(niced_tasks)) + if (likely(tg_ctx->niced_tasks)) max_processed = (max_processed + 3) / 4; if (max_processed < th_ctx->rq_total && th_ctx->rq_total <= 2*max_processed) { @@ -849,7 +847,7 @@ void process_runnable_tasks() } #endif if (t->nice) - _HA_ATOMIC_DEC(&niced_tasks); + _HA_ATOMIC_DEC(&tg_ctx->niced_tasks); /* Add it to the local task list */ LIST_APPEND(&tt->tasklets[TL_NORMAL], &((struct tasklet *)t)->list);