From 217b7b33ccb29de90c6ab3ff0c43f55d6e31026d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 18 Jul 2019 18:30:15 +0200 Subject: [PATCH] pid1: order jobs that execute processes with lower priority We can meaningfully compare jobs for units which have cpu weight or nice set. But non-exec units those have those set. Starting non-exec jobs first allows us to get them out of the queue quickly, and consider more jobs for starting. If we have service A, and socket B, and service C which is after socket B, and we want to start both A and C, and C has higher cpu weight, if we get B out of the way first, we'll know that we can start both A and C, and we'll start C first. Also invert the comparisons using CMP() so they are always done left vs. right, and negate when returning instead. Follow-up for da8e178296. --- src/core/cgroup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 2ccdf2d6b2a..1366d11c060 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -3531,11 +3531,14 @@ int compare_job_priority(const void *a, const void *b) { uint64_t weight_x, weight_y; int ret; + if ((ret = CMP(x->unit->type, y->unit->type)) != 0) + return -ret; + weight_x = unit_get_cpu_weight(x->unit); weight_y = unit_get_cpu_weight(y->unit); - if ((ret = CMP(weight_y, weight_x)) != 0) - return ret; + if ((ret = CMP(weight_x, weight_y)) != 0) + return -ret; nice_x = unit_get_nice(x->unit); nice_y = unit_get_nice(y->unit); @@ -3543,9 +3546,6 @@ int compare_job_priority(const void *a, const void *b) { if ((ret = CMP(nice_x, nice_y)) != 0) return ret; - if ((ret = CMP(x->unit->type, y->unit->type)) != 0) - return ret; - return strcmp(x->unit->id, y->unit->id); } -- 2.47.3