From patchwork Wed Apr 19 16:54:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 97659 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp411298qgf; Wed, 19 Apr 2017 09:54:50 -0700 (PDT) X-Received: by 10.98.205.14 with SMTP id o14mr3975523pfg.42.1492620890051; Wed, 19 Apr 2017 09:54:50 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c189si3292162pfa.137.2017.04.19.09.54.49; Wed, 19 Apr 2017 09:54:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967251AbdDSQyQ (ORCPT + 16 others); Wed, 19 Apr 2017 12:54:16 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:38462 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966954AbdDSQyL (ORCPT ); Wed, 19 Apr 2017 12:54:11 -0400 Received: by mail-wm0-f43.google.com with SMTP id r190so27757855wme.1 for ; Wed, 19 Apr 2017 09:54:10 -0700 (PDT) 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=x3kXuS/vNzTTpelx9Pe3p7EO9wNlUh97w1dv4a4U/bQ=; b=aT9POOBxuoMKhUXHdfTxvToLbhYdYjjdvdg2xpqb61z6VaQgcUZTVjavYJDLBi/UpJ Bng+0yMYCDsBKrzKT0PWTM3/GQ/l4jUoS9RGICWlbxTdccPTMAhuhU4gBbEOjuvLvAvf or4i5jnsbVfsIu8w33su6xAHp/u3FAy7vryI8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x3kXuS/vNzTTpelx9Pe3p7EO9wNlUh97w1dv4a4U/bQ=; b=n5Wr9KCne5Fcc4FuIfUvXF3rMraWPeqTaiKG21wAPiIxEK6wByvZBg+zFB83yU4FPs n57XnFm4pfyLKZN+4+71jqqw60VH7LxNfRfSTj1NIxDIjpci6rYYoTiQgUPM5nJ0WtKb LtZ+VUePWIML/hfUEZ7eNcKgFiq56ank5YRetYGA7r0fRnq2PU9DFSsx50yqaCN0yw/w NN4DlkcRCN0LufQdGqmh3CUUguFUWVPxzy4Lpmx50YN12M9s3LI9rrpS5PcGZq2qR0KC ZwPDsxho6tuv0VrNH2AnAqsgX9U6EKtR8vU7wzZTd4jpgYwehZCFxhAxZPmyA/YzrWuf MUgw== X-Gm-Message-State: AN3rC/7gpAmtsnN2qOwtLTQ+kyi5U26YwOiENqhalSAKhM+R31S/g+ea Dsbhv8CN3YuWBZOl X-Received: by 10.28.130.210 with SMTP id e201mr18480058wmd.128.1492620849255; Wed, 19 Apr 2017 09:54:09 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:f:6020:ddb5:fd5c:4a08:a3bc]) by smtp.gmail.com with ESMTPSA id g132sm20088299wmd.33.2017.04.19.09.54.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Apr 2017 09:54:08 -0700 (PDT) From: Vincent Guittot To: peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org Cc: dietmar.eggemann@arm.com, Morten.Rasmussen@arm.com, yuyang.du@intel.com, pjt@google.com, bsegall@google.com, Vincent Guittot Subject: [PATCH v2] sched/cfs: make util/load_avg more stable Date: Wed, 19 Apr 2017 18:54:04 +0200 Message-Id: <1492620844-30979-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492619370-29246-1-git-send-email-vincent.guittot@linaro.org> References: <1492619370-29246-1-git-send-email-vincent.guittot@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the current implementation of load/util_avg, we assume that the ongoing time segment has fully elapsed, and util/load_sum is divided by LOAD_AVG_MAX, even if part of the time segment still remains to run. As a consequence, this remaining part is considered as idle time and generates unexpected variations of util_avg of a busy CPU in the range ]1002..1024[ whereas util_avg should stay at 1023. In order to keep the metric stable, we should not consider the ongoing time segment when computing load/util_avg but only the segments that have already fully elapsed. Bu to not consider the current time segment adds unwanted latency in the load/util_avg responsivness especially when the time is scaled instead of the contribution. Instead of waiting for the current time segment to have fully elapsed before accounting it in load/util_avg, we can already account the elapsed part but change the range used to compute load/util_avg accordingly. At the very beginning of a new time segment, the past segments have been decayed and the max value is MAX_LOAD_AVG*y. At the very end of the current time segment, the max value becomes 1024(us) + MAX_LOAD_AVG*y which is equal to MAX_LOAD_AVG. In fact, the max value is sa->period_contrib + MAX_LOAD_AVG*y at any time in the time segment. Taking advantage of the fact that MAX_LOAD_AVG*y == MAX_LOAD_AVG-1024, the range becomes [0..MAX_LOAD_AVG-1024+sa->period_contrib]. As the elapsed part is already accounted in load/util_sum, we update the max value according to the current position in the time segment instead of removing its contribution. Suggested-by: Peter Zijlstra Signed-off-by: Vincent Guittot --- Fold both patches in one kernel/sched/fair.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 3f83a35..c3b8f0f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3017,12 +3017,12 @@ ___update_load_avg(u64 now, int cpu, struct sched_avg *sa, /* * Step 2: update *_avg. */ - sa->load_avg = div_u64(sa->load_sum, LOAD_AVG_MAX); + sa->load_avg = div_u64(sa->load_sum, LOAD_AVG_MAX - 1024 + sa->period_contrib); if (cfs_rq) { cfs_rq->runnable_load_avg = - div_u64(cfs_rq->runnable_load_sum, LOAD_AVG_MAX); + div_u64(cfs_rq->runnable_load_sum, LOAD_AVG_MAX - 1024 + sa->period_contrib); } - sa->util_avg = sa->util_sum / LOAD_AVG_MAX; + sa->util_avg = sa->util_sum / (LOAD_AVG_MAX - 1024 + sa->period_contrib); return 1; }