Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp710407pxv; Thu, 15 Jul 2021 14:07:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHyewEavtNiND7kjmdUvVvyNeobz7Ttd28Jb1xYGEwOyCDC/FII9YlTihnLiaW1WuAnosU X-Received: by 2002:a05:6602:2bdc:: with SMTP id s28mr4594426iov.70.1626383267535; Thu, 15 Jul 2021 14:07:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383267; cv=none; d=google.com; s=arc-20160816; b=ZpBQn0WYJELhSwg73Chlh3MA1OHltpjL3t2v0L6p3W1JaPvSQDN+immmy1pIfA9Jhm EO8AlgLpgqKuaZ3cVMkLGcHm3EAEZbRkXLuQ2FCsvla8an2NOfmGspp51zKXVKlx7CjX Lb0ZjJalTnQyyjq0G9RI3KAWrsFWTFBV4qDyh0i+k0PGd/hJNIIPAcSpjXWPxcqRtf1S bEkYEwGCRQH7KBV3VqauUvbhbX6vBjTOuDZQhi4I9kXEGKUSVrVmRfBrL57TVS/rfvje Tv+f9HqPGHM++A6HXXahv7fsJdVRKt4ffIeF6ySXDsYJa36rIWCKfRc9f2Y+cx2CkeHX 9s9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Gwx3iuD91Nkjz3pmA6fc2Mbfl03i5KeLdJYUyLc/mz0=; b=jsL1qh2BWN4t7huQL8n0cMlIc4qbdWhpHfq4fbpXhiS2/Qr/8PS1NTq6VMZHx4bEG+ lRWnVf4hJpIrROWNl4rjvkVk2j8fcN5bDmTYgxDxbAMgOxbsNPuoqfR75BXNvEatAQee rDQZ9CEERYyKp1yQwj3AENMLOF8dtrPvYs4ic2A7qg8YcwHmxK6De1tfZR7xIqZZ4SKu L41BIOneMSOVOrU6bdtaMmwDzO4zdXyX3Q1JZsQuTrT8mlpsj0qEN/dTcHP6Dm19Rh1O u3gqcT2UTNsN0Rzpu3ymAUweRJmeA+wpLdUo3bUZ+o/5Ed/6OyhMDx5IhHJd8GO9eQqL 7reg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lkuBn3fG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y7si7811802jae.125.2021.07.15.14.07.35; Thu, 15 Jul 2021 14:07:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lkuBn3fG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241094AbhGOTSj (ORCPT + 99 others); Thu, 15 Jul 2021 15:18:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:38158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242400AbhGOTDk (ORCPT ); Thu, 15 Jul 2021 15:03:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C6D2B613D7; Thu, 15 Jul 2021 18:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375579; bh=qkBu6LtwSHW6e9gJ6y7H1ZaKH79w7EKUPovML+t5HBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lkuBn3fGf2zFK3zEHgRDuE2jHSrJd5LyAmNaWo6vtEHwrMYagSCgcO9V15aEdOqSk tUzfpfP6lG7v8vetacGXifuZX8D0r6paZqYKBY2MVNfDMl+RD/IM47rhpSsGfPwsiS X/3WzHju2KgJ3xUvlvDuRtwzy6amSBlM269cwBxI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sachin Sant , Naresh Kamboju , Odin Ugedal , "Peter Zijlstra (Intel)" , Vincent Guittot , Sasha Levin Subject: [PATCH 5.12 146/242] sched/fair: Ensure _sum and _avg values stay consistent Date: Thu, 15 Jul 2021 20:38:28 +0200 Message-Id: <20210715182618.902752060@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Odin Ugedal [ Upstream commit 1c35b07e6d3986474e5635be566e7bc79d97c64d ] The _sum and _avg values are in general sync together with the PELT divider. They are however not always completely in perfect sync, resulting in situations where _sum gets to zero while _avg stays positive. Such situations are undesirable. This comes from the fact that PELT will increase period_contrib, also increasing the PELT divider, without updating _sum and _avg values to stay in perfect sync where (_sum == _avg * divider). However, such PELT change will never lower _sum, making it impossible to end up in a situation where _sum is zero and _avg is not. Therefore, we need to ensure that when subtracting load outside PELT, that when _sum is zero, _avg is also set to zero. This occurs when (_sum < _avg * divider), and the subtracted (_avg * divider) is bigger or equal to the current _sum, while the subtracted _avg is smaller than the current _avg. Reported-by: Sachin Sant Reported-by: Naresh Kamboju Signed-off-by: Odin Ugedal Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Vincent Guittot Tested-by: Sachin Sant Link: https://lore.kernel.org/r/20210624111815.57937-1-odin@uged.al Signed-off-by: Sasha Levin --- kernel/sched/fair.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 20ac5dff9a0c..572f312cc803 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3665,15 +3665,15 @@ update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq) r = removed_load; sub_positive(&sa->load_avg, r); - sub_positive(&sa->load_sum, r * divider); + sa->load_sum = sa->load_avg * divider; r = removed_util; sub_positive(&sa->util_avg, r); - sub_positive(&sa->util_sum, r * divider); + sa->util_sum = sa->util_avg * divider; r = removed_runnable; sub_positive(&sa->runnable_avg, r); - sub_positive(&sa->runnable_sum, r * divider); + sa->runnable_sum = sa->runnable_avg * divider; /* * removed_runnable is the unweighted version of removed_load so we -- 2.30.2