From nobody Tue Jun 30 19:07:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66A2FC433F5 for ; Tue, 11 Jan 2022 13:47:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241027AbiAKNrP (ORCPT ); Tue, 11 Jan 2022 08:47:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241007AbiAKNrO (ORCPT ); Tue, 11 Jan 2022 08:47:14 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2257C06173F for ; Tue, 11 Jan 2022 05:47:13 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id c126-20020a1c9a84000000b00346f9ebee43so1840935wme.4 for ; Tue, 11 Jan 2022 05:47:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nP+CSE9iEIzwFG5+V5deqlDlAk8XkEcUa0ABGWq3KOQ=; b=HzW+ELs2Jece1l9cxsUSv3nMDlAa9v7FnQq4OZ6HmYhTZekh3dvBXvz09BFW0iiaLG F1ufmpq2GrDqZr95cKKUQy/YANyGbj9HV+6ruFgk7V7lpGiA1367GXH7miZm6yugItBn v6/Zx/Cv4E/NlWbB3nZw8Zf8y484+tqHY08EqlOd2An94V8elG4WQFRkLg3KfXJLVO4/ g/cj5cE2p0oFaHdpJvyrMZom7En/ZaJfkxZxyFANl/QLyFbKcMGKye/W4DTleD4PFana jcrenQAXVyTxLWTfB1N/p4gkFciMc2Unf8v2sPV79GGTVXneAvHzOSF9L4ie/ttzKHm1 pMFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nP+CSE9iEIzwFG5+V5deqlDlAk8XkEcUa0ABGWq3KOQ=; b=Fu51/JObj/Ge5FzLS+GrDuwJgm7hUmzUsiomLsLqEd+c34aTmKYVC0GQaHJ5e6EZDx Mtn8AKU9HbMnSpt6zcWjPYprtOB7u99s4sYdmDHELDsC5Gtlk6ZeDNpU4XA4tZ8a9gaJ gv5CZw03tgggA8qT4e7oDcQttbU5Yf+vvWBZPWManl/a8A32FIflwCmS8oTKs2V7b9D9 pquOS+FHA0qDWM5FhDTAULyiMtWNETBqY0tHz9pCdi5rhAxSNw5LytnfRKFql94I5uz6 nNT7jJJ5exmEGO7cbp0rNkqWNWJHVH81GrgFeasbupaPLRQDv2vPXw8IxaiLx84bou9V LVeg== X-Gm-Message-State: AOAM533bzQkMHVJWcpo5Tkno0ZJJcduv4G73mP2exUcJaY6ZqJWkFwR1 GSmN0ku/3yo0s+FEl0/ycofHtQ== X-Google-Smtp-Source: ABdhPJz3w8uSkdsGUVQx1VkTmLsEhuryoyJeypweawRS0nabC6RJPzC2SeGlFk5KddqAAdn5MFpaUw== X-Received: by 2002:a05:600c:354c:: with SMTP id i12mr2531988wmq.90.1641908832380; Tue, 11 Jan 2022 05:47:12 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:44fe:4c24:d946:283b]) by smtp.gmail.com with ESMTPSA id az1sm9618411wrb.104.2022.01.11.05.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 05:47:11 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org, rickyiu@google.com, odin@uged.al Cc: sachinp@linux.vnet.ibm.com, naresh.kamboju@linaro.org, Vincent Guittot Subject: [PATCH 3 1/4] sched/pelt: Relax the sync of util_sum with util_avg Date: Tue, 11 Jan 2022 14:46:56 +0100 Message-Id: <20220111134659.24961-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220111134659.24961-1-vincent.guittot@linaro.org> References: <20220111134659.24961-1-vincent.guittot@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rick reported performance regressions in bugzilla because of cpu frequency being lower than before: https://bugzilla.kernel.org/show_bug.cgi?id=3D215045 He bisected the problem to: commit 1c35b07e6d39 ("sched/fair: Ensure _sum and _avg values stay consiste= nt") This commit forces util_sum to be synced with the new util_avg after removing the contribution of a task and before the next periodic sync. By doing so util_sum is rounded to its lower bound and might lost up to LOAD_AVG_MAX-1 of accumulated contribution which has not yet been reflected in util_avg. Instead of always setting util_sum to the low bound of util_avg, which can significantly lower the utilization of root cfs_rq after propagating the change down into the hierarchy, we revert the change of util_sum and propagate the difference. In addition, we also check that cfs's util_sum always stays above the lower bound for a given util_avg as it has been observed that sched_entity's util_sum is sometimes above cfs one. Reported-by: Rick Yiu Fixes: 1c35b07e6d39 ("sched/fair: Ensure _sum and _avg values stay consiste= nt") Signed-off-by: Vincent Guittot Reviewed-by: Dietmar Eggemann Tested-by: Sachin Sant --- kernel/sched/fair.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 095b0aa378df..ed35255fdb85 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3381,6 +3381,7 @@ void set_task_rq_fair(struct sched_entity *se, se->avg.last_update_time =3D n_last_update_time; } =20 +#define MIN_DIVIDER (LOAD_AVG_MAX - 1024) =20 /* * When on migration a sched_entity joins/leaves the PELT hierarchy, we ne= ed to @@ -3449,7 +3450,6 @@ void set_task_rq_fair(struct sched_entity *se, * XXX: only do this for the part of runnable > running ? * */ - static inline void update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct = cfs_rq *gcfs_rq) { @@ -3681,7 +3681,19 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_r= q) =20 r =3D removed_util; sub_positive(&sa->util_avg, r); - sa->util_sum =3D sa->util_avg * divider; + sub_positive(&sa->util_sum, r * divider); + /* + * Because of rounding, se->util_sum might ends up being +1 more than + * cfs->util_sum. Although this is not a problem by itself, detaching + * a lot of tasks with the rounding problem between 2 updates of + * util_avg (~1ms) can make cfs->util_sum becoming null whereas + * cfs_util_avg is not. + * Check that util_sum is still above its lower bound for the new + * util_avg. Given that period_contrib might have moved since the last + * sync, we are only sure that util_sum must be above or equal to + * util_avg * minimum possible divider + */ + sa->util_sum =3D max_t(u32, sa->util_sum, sa->util_avg * MIN_DIVIDER); =20 r =3D removed_runnable; sub_positive(&sa->runnable_avg, r); --=20 2.17.1 From nobody Tue Jun 30 19:07:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4D17C433EF for ; Tue, 11 Jan 2022 13:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241062AbiAKNrR (ORCPT ); Tue, 11 Jan 2022 08:47:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241037AbiAKNrP (ORCPT ); Tue, 11 Jan 2022 08:47:15 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53B62C06173F for ; Tue, 11 Jan 2022 05:47:15 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id k30so15491578wrd.9 for ; Tue, 11 Jan 2022 05:47:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=evuXX/v2gImyPX1SOtO3snHEFUv8GN/ZKm3pGyafoe8=; b=Gn2RKgLREKnM4ChkGpQSG5QfWDSjRykiTGWuwk7FrsHCDyAfP2o9C34Gq6NQ/lgeoZ MGP73uq5p0c8sIU/NeO1kTHvlOz9FXQMxTBBGpuPqLyrfDQ1IRyHGcXEe2E/q+BqGVhA bVw5qLsUeHAu96OrHlpI0uTQJFqRU2QvMCFQcjFL264eset0p02hUbEvAN0DqZKOOCy4 Wh/qubQ6AKUSrEMzAAE3lUubedk8ayKnHXL4a+9BNgMwyuLZqMgJ76Mx+ksDA9vI6aau FXjD2NcjSTZkfGL3MmPXnfHjAPvnu3+AYVuSL/xTEjniX4iZULdGibG1CRXMfSrCqJx5 zARg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=evuXX/v2gImyPX1SOtO3snHEFUv8GN/ZKm3pGyafoe8=; b=YZRqd48NczngMyCon0A82sBLcZmi4hy2pTxXRNX6XdjP45XYOEnUH2eRobk23tANPP 9zS81B9hjA2NWLoy/N27aeAKqskjcdJj2M5KadvCYXvvrpahQx8UFPo7lsTLovWPI7is Kd0dkJY0ZkqFbMHNYozuHu7AIPFebz5WZJg0na9Xjtc5Tb1AbEgKrW3exSeEkYrx6WTT rJoGl5l5Ci98odXWRFLis7MiwMq+HgjBeYjNkiuLZ+XxR/JsB39uOBuPsx+apPpmlw4m +01q0kV9H05eM92gX/Cv7mYOrNegosDB/DvuTEIZMKNyfvem/wY7+ik7olzE8Jt4kAtq od3A== X-Gm-Message-State: AOAM531whKbcShAWzjfHSr/71rJwiGTxmFcg8pUZc65WmL6jGP8g8gkM sOE6PsYwZeG9eQSvRqXxOVTUXA== X-Google-Smtp-Source: ABdhPJxBD6uv5PhlQA3LpyKuYZR6goOAPSBTcPPS6K0ws6uniDQ9RtuWUmXWjh2rTnMAyd8KdtGH9A== X-Received: by 2002:adf:f303:: with SMTP id i3mr3799413wro.413.1641908833906; Tue, 11 Jan 2022 05:47:13 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:44fe:4c24:d946:283b]) by smtp.gmail.com with ESMTPSA id az1sm9618411wrb.104.2022.01.11.05.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 05:47:12 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org, rickyiu@google.com, odin@uged.al Cc: sachinp@linux.vnet.ibm.com, naresh.kamboju@linaro.org, Vincent Guittot Subject: [PATCH v3 2/4] sched/pelt: Continue to relax the sync of util_sum with util_avg Date: Tue, 11 Jan 2022 14:46:57 +0100 Message-Id: <20220111134659.24961-3-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220111134659.24961-1-vincent.guittot@linaro.org> References: <20220111134659.24961-1-vincent.guittot@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rick reported performance regressions in bugzilla because of cpu frequency being lower than before: https://bugzilla.kernel.org/show_bug.cgi?id=3D215045 He bisected the problem to: commit 1c35b07e6d39 ("sched/fair: Ensure _sum and _avg values stay consiste= nt") This commit forces util_sum to be synced with the new util_avg after removing the contribution of a task and before the next periodic sync. By doing so util_sum is rounded to its lower bound and might lost up to LOAD_AVG_MAX-1 of accumulated contribution which has not yet been reflected in util_avg. update_tg_cfs_util() is not the only place where we round util_sum and lost some accumulated contributions that are not already reflected in util_avg. Modify update_tg_cfs_util() and detach_entity_load_avg() to not sync util_sum with the new util_avg. Instead of always setting util_sum to the low bound of util_avg, which can significantly lower the utilization, we propagate the difference. In addition, we also check that cfs's util_sum always stays above the lower bound for a given util_avg as it has been observed that sched_entity's util_sum is sometimes above cfs one. Signed-off-by: Vincent Guittot Reviewed-by: Dietmar Eggemann Tested-by: Sachin Sant --- kernel/sched/fair.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index ed35255fdb85..3eb73ce6ef13 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3453,11 +3453,11 @@ void set_task_rq_fair(struct sched_entity *se, static inline void update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct = cfs_rq *gcfs_rq) { - long delta =3D gcfs_rq->avg.util_avg - se->avg.util_avg; - u32 divider; + long delta_sum, delta_avg =3D gcfs_rq->avg.util_avg - se->avg.util_avg; + u32 new_sum, divider; =20 /* Nothing to update */ - if (!delta) + if (!delta_avg) return; =20 /* @@ -3466,13 +3466,20 @@ update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sc= hed_entity *se, struct cfs_rq */ divider =3D get_pelt_divider(&cfs_rq->avg); =20 + /* Set new sched_entity's utilization */ se->avg.util_avg =3D gcfs_rq->avg.util_avg; - se->avg.util_sum =3D se->avg.util_avg * divider; + new_sum =3D se->avg.util_avg * divider; + delta_sum =3D (long)new_sum - (long)se->avg.util_sum; + se->avg.util_sum =3D new_sum; =20 /* Update parent cfs_rq utilization */ - add_positive(&cfs_rq->avg.util_avg, delta); - cfs_rq->avg.util_sum =3D cfs_rq->avg.util_avg * divider; + add_positive(&cfs_rq->avg.util_avg, delta_avg); + add_positive(&cfs_rq->avg.util_sum, delta_sum); + + /* See update_cfs_rq_load_avg() */ + cfs_rq->avg.util_sum =3D max_t(u32, cfs_rq->avg.util_sum, + cfs_rq->avg.util_avg * MIN_DIVIDER); } =20 static inline void @@ -3792,7 +3799,11 @@ static void detach_entity_load_avg(struct cfs_rq *cf= s_rq, struct sched_entity *s =20 dequeue_load_avg(cfs_rq, se); sub_positive(&cfs_rq->avg.util_avg, se->avg.util_avg); - cfs_rq->avg.util_sum =3D cfs_rq->avg.util_avg * divider; + sub_positive(&cfs_rq->avg.util_sum, se->avg.util_sum); + /* See update_cfs_rq_load_avg() */ + cfs_rq->avg.util_sum =3D max_t(u32, cfs_rq->avg.util_sum, + cfs_rq->avg.util_avg * MIN_DIVIDER); + sub_positive(&cfs_rq->avg.runnable_avg, se->avg.runnable_avg); cfs_rq->avg.runnable_sum =3D cfs_rq->avg.runnable_avg * divider; =20 --=20 2.17.1 From nobody Tue Jun 30 19:07:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5233C433EF for ; Tue, 11 Jan 2022 13:47:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241065AbiAKNrV (ORCPT ); Tue, 11 Jan 2022 08:47:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241038AbiAKNrR (ORCPT ); Tue, 11 Jan 2022 08:47:17 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BF0BC06173F for ; Tue, 11 Jan 2022 05:47:17 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id v123so11074330wme.2 for ; Tue, 11 Jan 2022 05:47:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=w+4pWCkbc5+/uOsA877Kk9lzlaHC1gngeuGc+JbN+s4=; b=HlcDeQuNG9XdkZLn6fFhutXjktn7sYn6cln+iG7CRb2Q7HpaJs4s1SibSz7DrYaDwK MuEN5xplHr89BE5hcSgJEOlv3Ld4MRQW/A2ECQ9lYSlbDOevmUPHY3xwS+mVRbxeZM5f /a8jCACFTccu5Xaq+73kU3/VJsOIDpa35kWeySbFR+xswZsxl9KV+3E+E+r1orHStUa8 fkJdP3W+NYvEKBuUZWB7MSFgJQBS7Z6rL3HFNxaq25wOtreHAgolLo/9jiCxfOFrfYyL 7WJQZiovToc76ID0+GVx1wDuFcGET8QE+frpkLbHk/aH+tItxxS0bcSiRkoVeu0Qa0bd H0WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=w+4pWCkbc5+/uOsA877Kk9lzlaHC1gngeuGc+JbN+s4=; b=aigIovhxnEOeKQy3Rusivr08aCw3/0T2VsHEF07SRCBHbZgr5zejvRoyLY96L5S3AB cSSpChDs6Y4rqtvzghc1QRs87XJBA0f3cSfUbmAbYQUtbIQj06mM/ejzUstjujrfcpEG 9vdcGxrwBWka15fiFeC0Nj75/mPGaTHODSl8bidTegTEanHgYIseP6pdzyfEBei38O5S aiQRJ9wwR0QZmq7wT2SsoRTLB+jg9osTYKLJ+Y8SYOWwc4koA3nGtXG9seQdPN/H6fQ2 12D5xC3YX3Ro3Go+JQ1FEoEfUjdzFwtwtBHsC9Qv6I6VxvnQMcUwZyDtMsfqeaOJ8jgs iBNw== X-Gm-Message-State: AOAM5338ZgXUuGmE7a8fSx9tX6/QWSA6seIvby7/mEWzxb/U96o0i3CG piXj+gVN5UI/CnwlEWiBdrxqHA== X-Google-Smtp-Source: ABdhPJx1RWrb3mlwqoWW+g5yUOam0f4FahwfjAVAAa02bp8IjxnmyPasCGV8na+5KP3WeWpccyV4RQ== X-Received: by 2002:a05:600c:4991:: with SMTP id h17mr2591827wmp.14.1641908835607; Tue, 11 Jan 2022 05:47:15 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:44fe:4c24:d946:283b]) by smtp.gmail.com with ESMTPSA id az1sm9618411wrb.104.2022.01.11.05.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 05:47:14 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org, rickyiu@google.com, odin@uged.al Cc: sachinp@linux.vnet.ibm.com, naresh.kamboju@linaro.org, Vincent Guittot Subject: [PATCH v3 3/4] sched/pelt: Relax the sync of runnable_sum with runnable_avg Date: Tue, 11 Jan 2022 14:46:58 +0100 Message-Id: <20220111134659.24961-4-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220111134659.24961-1-vincent.guittot@linaro.org> References: <20220111134659.24961-1-vincent.guittot@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Similarly to util_avg and util_sum, don't sync runnable_sum with the low bound of runnable_avg but only ensure that runnable_sum stays in the correct range. Signed-off-by: Vincent Guittot Reviewed-by: Dietmar Eggemann Tested-by: Sachin Sant --- kernel/sched/fair.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 3eb73ce6ef13..e34de721a630 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3485,11 +3485,11 @@ update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sc= hed_entity *se, struct cfs_rq static inline void update_tg_cfs_runnable(struct cfs_rq *cfs_rq, struct sched_entity *se, str= uct cfs_rq *gcfs_rq) { - long delta =3D gcfs_rq->avg.runnable_avg - se->avg.runnable_avg; - u32 divider; + long delta_sum, delta_avg =3D gcfs_rq->avg.runnable_avg - se->avg.runnabl= e_avg; + u32 new_sum, divider; =20 /* Nothing to update */ - if (!delta) + if (!delta_avg) return; =20 /* @@ -3500,11 +3500,16 @@ update_tg_cfs_runnable(struct cfs_rq *cfs_rq, struc= t sched_entity *se, struct cf =20 /* Set new sched_entity's runnable */ se->avg.runnable_avg =3D gcfs_rq->avg.runnable_avg; - se->avg.runnable_sum =3D se->avg.runnable_avg * divider; + new_sum =3D se->avg.runnable_avg * divider; + delta_sum =3D (long)new_sum - (long)se->avg.runnable_sum; + se->avg.runnable_sum =3D new_sum; =20 /* Update parent cfs_rq runnable */ - add_positive(&cfs_rq->avg.runnable_avg, delta); - cfs_rq->avg.runnable_sum =3D cfs_rq->avg.runnable_avg * divider; + add_positive(&cfs_rq->avg.runnable_avg, delta_avg); + add_positive(&cfs_rq->avg.runnable_sum, delta_sum); + /* See update_cfs_rq_load_avg() */ + cfs_rq->avg.runnable_sum =3D max_t(u32, cfs_rq->avg.runnable_sum, + cfs_rq->avg.runnable_avg * MIN_DIVIDER); } =20 static inline void @@ -3704,7 +3709,10 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_r= q) =20 r =3D removed_runnable; sub_positive(&sa->runnable_avg, r); - sa->runnable_sum =3D sa->runnable_avg * divider; + sub_positive(&sa->runnable_sum, r * divider); + /* See sa->util_sum above */ + sa->runnable_sum =3D max_t(u32, sa->runnable_sum, + sa->runnable_avg * MIN_DIVIDER); =20 /* * removed_runnable is the unweighted version of removed_load so we @@ -3791,12 +3799,6 @@ static void attach_entity_load_avg(struct cfs_rq *cf= s_rq, struct sched_entity *s */ static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_ent= ity *se) { - /* - * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. - * See ___update_load_avg() for details. - */ - u32 divider =3D get_pelt_divider(&cfs_rq->avg); - dequeue_load_avg(cfs_rq, se); sub_positive(&cfs_rq->avg.util_avg, se->avg.util_avg); sub_positive(&cfs_rq->avg.util_sum, se->avg.util_sum); @@ -3805,7 +3807,10 @@ static void detach_entity_load_avg(struct cfs_rq *cf= s_rq, struct sched_entity *s cfs_rq->avg.util_avg * MIN_DIVIDER); =20 sub_positive(&cfs_rq->avg.runnable_avg, se->avg.runnable_avg); - cfs_rq->avg.runnable_sum =3D cfs_rq->avg.runnable_avg * divider; + sub_positive(&cfs_rq->avg.runnable_sum, se->avg.runnable_sum); + /* See update_cfs_rq_load_avg() */ + cfs_rq->avg.runnable_sum =3D max_t(u32, cfs_rq->avg.runnable_sum, + cfs_rq->avg.runnable_avg * MIN_DIVIDER); =20 add_tg_cfs_propagate(cfs_rq, -se->avg.load_sum); =20 --=20 2.17.1 From nobody Tue Jun 30 19:07:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CAD2C433F5 for ; Tue, 11 Jan 2022 13:47:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241043AbiAKNr0 (ORCPT ); Tue, 11 Jan 2022 08:47:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241091AbiAKNrT (ORCPT ); Tue, 11 Jan 2022 08:47:19 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BDE3C061748 for ; Tue, 11 Jan 2022 05:47:18 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id o3so33049928wrh.10 for ; Tue, 11 Jan 2022 05:47:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vuj6hMsLmlTFc4S+ebtak6Be/P54+GKB/p//j3m8mec=; b=vNr23HM5zMPvr7nJM5odVjgZyNOfWJ1bZtiLXnV/wG23uLY1KD+RBeRmMNlf6BSlLI QU22gPiPziUl05CjRsIKE9LAtcd7WH3QLq6dA986GdUeMb/6ljP5l2dGPfGDA8zB1Thk yZmmN0czslXSBXVSr9aAeVatC4iq90XRj6lNO+SbArhx6CYom2hgi3eQkelf8F4Sf818 Cb3ALYwe/Rhz5CSD0jHh9VO1CWdADdfJMg8zCCx9ZKAu7+3g7Y20vVKwMynpyf0z6aRA McTcMLodPouvJd7rw0XC35qinruB7pzvK3vQsaLjMqMaQskhs3w5zrUtVSi6euOMinIY /TgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vuj6hMsLmlTFc4S+ebtak6Be/P54+GKB/p//j3m8mec=; b=O/9o18C0mgXP16Z9emDNnkPSNXFz7UXSH2KRQdLz2wJInErbVS6lHtLYzcgK6FJUJ/ yPxQ9JX//6miuQBrxXgrWdn7AqRYKtrpdIcPxUWeolXkEiY6b5Kbgh5MDZZFHrD7CKAn CGwaAyVzpYTsjRmj5F4//vPYPx31Vl2KOMFdn+TYcKuUcglUlMR/t2GJctLSt8oi1uhK xKP2YILzGBilkzBGlRKTM/rZNd81GGdYII+Rc6xceTiZTstK9bwkbETO5qY+ELvf83YU 6FhGj5gpOfaMGH14mk6lISUYMs0SPqZQf2xw6HiwXsUx2iKGAZ7W8y4SP8QOLIjX9GSI BpEw== X-Gm-Message-State: AOAM532KtZTSuenmzDcod33jKJruXKv0xF2I8iU/srDU0HCr5CU1Nb28 SFRBk/hNsDqxbkJNKdcc7hTJUg== X-Google-Smtp-Source: ABdhPJx6JOMrVRczm0P0IhKHjVS2xxieqE/YRqn1yYqP0Gm+WuCaOXfKR2UnDgUuV0HPu8kWLkwk7g== X-Received: by 2002:a5d:4201:: with SMTP id n1mr2736310wrq.239.1641908837191; Tue, 11 Jan 2022 05:47:17 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:44fe:4c24:d946:283b]) by smtp.gmail.com with ESMTPSA id az1sm9618411wrb.104.2022.01.11.05.47.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 05:47:16 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org, rickyiu@google.com, odin@uged.al Cc: sachinp@linux.vnet.ibm.com, naresh.kamboju@linaro.org, Vincent Guittot Subject: [PATCH v3 4/4] sched/pelt: Relax the sync of load_sum with load_avg Date: Tue, 11 Jan 2022 14:46:59 +0100 Message-Id: <20220111134659.24961-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220111134659.24961-1-vincent.guittot@linaro.org> References: <20220111134659.24961-1-vincent.guittot@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Similarly to util_avg and util_sum, don't sync load_sum with the low bound of load_avg but only ensure that load_sum stays in the correct range. Signed-off-by: Vincent Guittot Reviewed-by: Dietmar Eggemann Tested-by: Sachin Sant --- kernel/sched/fair.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e34de721a630..12d139fed1f7 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3025,12 +3025,17 @@ enqueue_load_avg(struct cfs_rq *cfs_rq, struct sche= d_entity *se) cfs_rq->avg.load_sum +=3D se_weight(se) * se->avg.load_sum; } =20 +#define MIN_DIVIDER (LOAD_AVG_MAX - 1024) + static inline void dequeue_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) { - u32 divider =3D get_pelt_divider(&se->avg); sub_positive(&cfs_rq->avg.load_avg, se->avg.load_avg); - cfs_rq->avg.load_sum =3D cfs_rq->avg.load_avg * divider; + sub_positive(&cfs_rq->avg.load_sum, se_weight(se) * se->avg.load_sum); + /* See update_cfs_rq_load_avg() */ + cfs_rq->avg.load_sum =3D max_t(u32, cfs_rq->avg.load_sum, + cfs_rq->avg.load_avg * MIN_DIVIDER); + } #else static inline void @@ -3381,8 +3386,6 @@ void set_task_rq_fair(struct sched_entity *se, se->avg.last_update_time =3D n_last_update_time; } =20 -#define MIN_DIVIDER (LOAD_AVG_MAX - 1024) - /* * When on migration a sched_entity joins/leaves the PELT hierarchy, we ne= ed to * propagate its contribution. The key to this propagation is the invariant @@ -3515,9 +3518,10 @@ update_tg_cfs_runnable(struct cfs_rq *cfs_rq, struct= sched_entity *se, struct cf static inline void update_tg_cfs_load(struct cfs_rq *cfs_rq, struct sched_entity *se, struct = cfs_rq *gcfs_rq) { - long delta, running_sum, runnable_sum =3D gcfs_rq->prop_runnable_sum; + long delta_avg, running_sum, runnable_sum =3D gcfs_rq->prop_runnable_sum; unsigned long load_avg; u64 load_sum =3D 0; + s64 delta_sum; u32 divider; =20 if (!runnable_sum) @@ -3544,7 +3548,7 @@ update_tg_cfs_load(struct cfs_rq *cfs_rq, struct sche= d_entity *se, struct cfs_rq * assuming all tasks are equally runnable. */ if (scale_load_down(gcfs_rq->load.weight)) { - load_sum =3D div_s64(gcfs_rq->avg.load_sum, + load_sum =3D div_u64(gcfs_rq->avg.load_sum, scale_load_down(gcfs_rq->load.weight)); } =20 @@ -3561,19 +3565,22 @@ update_tg_cfs_load(struct cfs_rq *cfs_rq, struct sc= hed_entity *se, struct cfs_rq running_sum =3D se->avg.util_sum >> SCHED_CAPACITY_SHIFT; runnable_sum =3D max(runnable_sum, running_sum); =20 - load_sum =3D (s64)se_weight(se) * runnable_sum; - load_avg =3D div_s64(load_sum, divider); + load_sum =3D se_weight(se) * runnable_sum; + load_avg =3D div_u64(load_sum, divider); =20 - se->avg.load_sum =3D runnable_sum; - - delta =3D load_avg - se->avg.load_avg; - if (!delta) + delta_avg =3D load_avg - se->avg.load_avg; + if (!delta_avg) return; =20 - se->avg.load_avg =3D load_avg; + delta_sum =3D load_sum - (s64)se_weight(se) * se->avg.load_sum; =20 - add_positive(&cfs_rq->avg.load_avg, delta); - cfs_rq->avg.load_sum =3D cfs_rq->avg.load_avg * divider; + se->avg.load_sum =3D runnable_sum; + se->avg.load_avg =3D load_avg; + add_positive(&cfs_rq->avg.load_avg, delta_avg); + add_positive(&cfs_rq->avg.load_sum, delta_sum); + /* See update_cfs_rq_load_avg() */ + cfs_rq->avg.load_sum =3D max_t(u32, cfs_rq->avg.load_sum, + cfs_rq->avg.load_avg * MIN_DIVIDER); } =20 static inline void add_tg_cfs_propagate(struct cfs_rq *cfs_rq, long runnab= le_sum) @@ -3689,7 +3696,9 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq) =20 r =3D removed_load; sub_positive(&sa->load_avg, r); - sa->load_sum =3D sa->load_avg * divider; + sub_positive(&sa->load_sum, r * divider); + /* See sa->util_sum below */ + sa->load_sum =3D max_t(u32, sa->load_sum, sa->load_avg * MIN_DIVIDER); =20 r =3D removed_util; sub_positive(&sa->util_avg, r); --=20 2.17.1