]> git.kaiwu.me - haproxy.git/commitdiff
DO NOT MERGE: fairer scheduling for less nice tasks 20260319-haload
authorFrederic Lecaille <flecaille@haproxy.com>
Thu, 7 May 2026 15:30:06 +0000 (17:30 +0200)
committerFrederic Lecaille <flecaille@haproxy.com>
Tue, 12 May 2026 18:54:09 +0000 (20:54 +0200)
This ensures high priority for the <mtask> task, which must display statistics
every second without being delayed by other tasks.

src/task.c

index 1cf9b6d3cea237725cdb0d5e945ef72bad19922f..4803075fb1ba1b27bdc24e9379cc9df4d30dd91d 100644 (file)
@@ -152,8 +152,8 @@ void __tasklet_wakeup_on(struct tasklet *tl, int thr)
                        th_ctx->tl_class_mask |= 1 << TL_BULK;
                }
                else if (th_ctx->current_queue < 0) {
-                       LIST_APPEND(&th_ctx->tasklets[TL_URGENT], &tl->list);
-                       th_ctx->tl_class_mask |= 1 << TL_URGENT;
+                       LIST_APPEND(&th_ctx->tasklets[TL_NORMAL], &tl->list);
+                       th_ctx->tl_class_mask |= 1 << TL_NORMAL;
                }
                else {
                        LIST_APPEND(&th_ctx->tasklets[TL_NORMAL], &tl->list);
@@ -351,6 +351,7 @@ void wake_expired_tasks()
                        /* expired task, wake it up */
                        __task_unlink_wq(task);
                        _task_wakeup(task, TASK_WOKEN_TIMER, 0);
+                       //printf("#(%p)\n", task);
                }
                else if (task->expire != eb->key) {
                        /* task is not expired but its key doesn't match so let's
@@ -436,6 +437,7 @@ void wake_expired_tasks()
                        __task_unlink_wq(task);
                        HA_RWLOCK_WRTOSK(TASK_WQ_LOCK, &wq_lock);
                        task_drop_running(task, TASK_WOKEN_TIMER);
+                       //printf("$\n");
                }
                else if (task->expire != eb->key) {
                        /* task is not expired but its key doesn't match so let's
@@ -884,7 +886,13 @@ void process_runnable_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);
+               if (t->nice < 0) {
+                       LIST_APPEND(&tt->tasklets[TL_URGENT], &((struct tasklet *)t)->list);
+                       tt->tl_class_mask |= 1 << TL_URGENT;
+                       //printf(".\n");
+               }
+               else
+                       LIST_APPEND(&tt->tasklets[TL_NORMAL], &((struct tasklet *)t)->list);
        }
 
        /* release the rqueue lock */