From patchwork Fri Aug 25 10:20:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Bellasi X-Patchwork-Id: 110981 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp777434qge; Fri, 25 Aug 2017 03:21:09 -0700 (PDT) X-Received: by 10.98.216.2 with SMTP id e2mr8649579pfg.296.1503656469583; Fri, 25 Aug 2017 03:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503656469; cv=none; d=google.com; s=arc-20160816; b=ypinylq2fjvS6puPnxU8QtYgo3+F+1Q5X5+lFlCe5KxdYZ+ofz+P7Gi3O+xaJjZJIA WHPguWhpqxYi5zGDCJZmMfQc7yGR1pV8Lm1+QiGUnh5MlBV8MoPfgHx7smsUKypbbs6D UzTkLeTTZWqjEQ1HXu0bJHFFlRQnKXq3sktk+TV0Nmd4/UYb3acVoKpw5HWti50g1JbX 5vFXPI3IsLHuB/Q8KAVkH2FxYZ+QIB/Mlbzp8N727uR/pB780KmY8DJIXCgh3bL90NBG WmnlnPCEvtLfHNwo5HaB5fiDqAzGjJzl1OoU8B9MjImC7IMuMoFPPr4K+TYXvLOzYbA+ JAWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=S2oSX/KFg68aLUQB22v3gofmQ1GcZqM93AY0oWKo8Dg=; b=zyLCrzgCpFRabURKQUlXArcuMbOk11zJXtMFSFsuTQhaZnMqPZuC+KwPxmFRBJ7LjH 042+w9pM6z6hWTKGztM/GGBOxl4U1HNu/YlqtAvZ5xOBWz+7bpRI6wyA7Vr56AnoPthb I1qmov0I21TVMDdMSWkreVIK4yRkN2nVL9JdL4pc/iUxJYiOmWlks0+2eCiT6AKWbMZv Zvzx/DqeLixdP3ZHIPZBQTGGSMQ8s4TUamnNwKOsyVaicgtHdmAxMtmjfFKNCV4vVKSG ipyYaQVaaU6mCfDkoCVxTdt5rajtteFyFaw5rED/fRPEQR2fsHjt2MhPeRO/P+7cs1FB E92A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15si4443409pgr.29.2017.08.25.03.21.09; Fri, 25 Aug 2017 03:21:09 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755276AbdHYKVH (ORCPT + 26 others); Fri, 25 Aug 2017 06:21:07 -0400 Received: from foss.arm.com ([217.140.101.70]:52016 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754718AbdHYKUf (ORCPT ); Fri, 25 Aug 2017 06:20:35 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E8E2415BE; Fri, 25 Aug 2017 03:20:34 -0700 (PDT) Received: from e110439-lin.cambridge.arm.com (e110439-lin.cambridge.arm.com [10.1.210.68]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 217A63F540; Fri, 25 Aug 2017 03:20:31 -0700 (PDT) From: Patrick Bellasi To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , "Rafael J . Wysocki" , Paul Turner , Vincent Guittot , John Stultz , Morten Rasmussen , Dietmar Eggemann , Juri Lelli , Tim Murray , Todd Kjos , Andres Oportus , Joel Fernandes , Viresh Kumar Subject: [RFC 2/3] sched/fair: use util_est in LB Date: Fri, 25 Aug 2017 11:20:07 +0100 Message-Id: <20170825102008.4626-3-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170825102008.4626-1-patrick.bellasi@arm.com> References: <20170825102008.4626-1-patrick.bellasi@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the scheduler looks at the CPU utlization, the current PELT value for a CPU is returned straight away. In certain scenarios this can have undesired side effects on task placement. For example, since the task utilization is decayed at wakeup time, when a long sleeping big task is enqueued it does not add immediately a significant contribution to the target CPU. As a result we generate a race condition where other tasks can be placed on the same CPU which is still considered relatively empty. In order to reduce these kind of race conditions, this patch introduces the required support to integrate the usage of the CPU's estimated utilization in some load balancer path. The estimated utilization of a CPU is defined to be the maximum between its PELT's utilization and the sum of the estimated utilization of the tasks currently RUNNABLE on that CPU. This allows to properly represent the expected utilization of a CPU which, for example it has just got a big task running since a long sleep period. Signed-off-by: Patrick Bellasi Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Paul Turner Cc: Vincent Guittot Cc: Morten Rasmussen Cc: Rafael J. Wysocki Cc: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org --- kernel/sched/fair.c | 38 ++++++++++++++++++++++++++++++++++++-- kernel/sched/features.h | 4 ++++ 2 files changed, 40 insertions(+), 2 deletions(-) -- 2.14.1 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index a4ec1b8c4755..2593da1d1465 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5985,6 +5985,32 @@ static int cpu_util(int cpu) return (util >= capacity) ? capacity : util; } +/** + * cpu_util_est: estimated utilization for the specified CPU + * @cpu: the CPU to get the estimated utilization for + * + * The estimated utilization of a CPU is defined to be the maximum between its + * PELT's utilization and the sum of the estimated utilization of the tasks + * currently RUNNABLE on that CPU. + * + * This allows to properly represent the expected utilization of a CPU which + * has just got a big task running since a long sleep period. At the same time + * however it preserves the benefits of the "blocked load" in describing the + * potential for other tasks waking up on the same CPU. + * + * Return: the estimated utlization for the specified CPU + */ +static inline unsigned long cpu_util_est(int cpu) +{ + struct sched_avg *sa = &cpu_rq(cpu)->cfs.avg; + unsigned long util = cpu_util(cpu); + + if (!sched_feat(UTIL_EST)) + return util; + + return max(util, util_est(sa, UTIL_EST_LAST)); +} + static inline int task_util(struct task_struct *p) { return p->se.avg.util_avg; @@ -6007,11 +6033,19 @@ static int cpu_util_wake(int cpu, struct task_struct *p) /* Task has no contribution or is new */ if (cpu != task_cpu(p) || !p->se.avg.last_update_time) - return cpu_util(cpu); + return cpu_util_est(cpu); capacity = capacity_orig_of(cpu); util = max_t(long, cpu_rq(cpu)->cfs.avg.util_avg - task_util(p), 0); + /* + * Estimated utilization tracks only tasks already enqueued, but still + * sometimes can return a bigger value than PELT, for example when the + * blocked load is negligible wrt the estimated utilization of the + * already enqueued tasks. + */ + util = max_t(long, util, cpu_util_est(cpu)); + return (util >= capacity) ? capacity : util; } @@ -7539,7 +7573,7 @@ static inline void update_sg_lb_stats(struct lb_env *env, load = source_load(i, load_idx); sgs->group_load += load; - sgs->group_util += cpu_util(i); + sgs->group_util += cpu_util_est(i); sgs->sum_nr_running += rq->cfs.h_nr_running; nr_running = rq->nr_running; diff --git a/kernel/sched/features.h b/kernel/sched/features.h index d3fb15555291..dadae44be2ab 100644 --- a/kernel/sched/features.h +++ b/kernel/sched/features.h @@ -81,3 +81,7 @@ SCHED_FEAT(RT_RUNTIME_SHARE, true) SCHED_FEAT(LB_MIN, false) SCHED_FEAT(ATTACH_AGE_LOAD, true) +/* + * UtilEstimation. Use estimated CPU utiliation. + */ +SCHED_FEAT(UTIL_EST, false)