From patchwork Mon Oct 17 08:51:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Morten Rasmussen X-Patchwork-Id: 77716 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp292250qge; Mon, 17 Oct 2016 01:53:03 -0700 (PDT) X-Received: by 10.66.245.98 with SMTP id xn2mr30179053pac.98.1476694383796; Mon, 17 Oct 2016 01:53:03 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i81si29904981pfk.69.2016.10.17.01.53.03; Mon, 17 Oct 2016 01:53:03 -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 S933222AbcJQIw6 (ORCPT + 27 others); Mon, 17 Oct 2016 04:52:58 -0400 Received: from foss.arm.com ([217.140.101.70]:56780 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932385AbcJQIwt (ORCPT ); Mon, 17 Oct 2016 04:52:49 -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 F0C7528; Mon, 17 Oct 2016 01:52:04 -0700 (PDT) Received: from e105550-lin.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 692FA3F32C; Mon, 17 Oct 2016 01:52:03 -0700 (PDT) Date: Mon, 17 Oct 2016 09:51:55 +0100 From: Morten Rasmussen To: peterz@infradead.org, mingo@redhat.com Cc: dietmar.eggemann@arm.com, yuyang.du@intel.com, vincent.guittot@linaro.org, mgalbraith@suse.de, sgurrappadi@nvidia.com, freedom.tan@mediatek.com, keita.kobayashi.ym@renesas.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 5/6] sched/fair: Track peak per-entity utilization Message-ID: <20161017085155.GA22817@e105550-lin.cambridge.arm.com> References: <1476452472-24740-1-git-send-email-morten.rasmussen@arm.com> <1476452472-24740-6-git-send-email-morten.rasmussen@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1476452472-24740-6-git-send-email-morten.rasmussen@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 14, 2016 at 02:41:11PM +0100, Morten Rasmussen wrote: > @@ -3515,6 +3517,10 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) > */ > if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) == DEQUEUE_SAVE) > update_min_vruntime(cfs_rq); > + > + /* Save peak PELT utilization for task to help wake-up decisions */ > + if (flags & DEQUEUE_SLEEP && entity_is_task(se)) > + se->avg.util_peak = se->avg.util_avg; > } > > /* The friendly kbuild robot swiftly pointed out that this doesn't build for !CONFIG_SMP. The below replacement patch moves this bit inside dequeue_entity_load_avg() which should be equivalent and not break !CONFIG_SMP. ----8<--- >From 36966c83cc3493332d92dcadb795eebc8c300558 Mon Sep 17 00:00:00 2001 From: Morten Rasmussen Date: Wed, 17 Aug 2016 15:30:43 +0100 Subject: [PATCH v5 5/6] sched/fair: Track peak per-entity utilization When using PELT (per-entity load tracking) utilization to place tasks at wake-up using the decayed utilization (due to sleep) leads to under-estimation of true utilization of the task. This could mean putting the task on a cpu with less available capacity than is actually needed. This issue can be mitigated by using 'peak' utilization instead of the decayed utilization for placement decisions, e.g. at task wake-up. The 'peak' utilization metric, util_peak, tracks util_avg when the task is running and retains its previous value while the task is blocked/waiting on the rq. It is instantly updated to track util_avg again as soon as the task running again. cc: Ingo Molnar cc: Peter Zijlstra Signed-off-by: Morten Rasmussen --- include/linux/sched.h | 2 +- kernel/sched/fair.c | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) -- 2.7.4 diff --git a/include/linux/sched.h b/include/linux/sched.h index ad51978ff15e..988d7f48604e 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1294,7 +1294,7 @@ struct load_weight { struct sched_avg { u64 last_update_time, load_sum; u32 util_sum, period_contrib; - unsigned long load_avg, util_avg; + unsigned long load_avg, util_avg, util_peak; }; #ifdef CONFIG_SCHEDSTATS diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index a5efafda23ef..84b767399d61 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -696,6 +696,7 @@ void init_entity_runnable_average(struct sched_entity *se) * At this point, util_avg won't be used in select_task_rq_fair anyway */ sa->util_avg = 0; + sa->util_peak = 0; sa->util_sum = 0; /* when this task enqueue'ed, it will contribute to its cfs_rq's load_avg */ } @@ -747,6 +748,7 @@ void post_init_entity_util_avg(struct sched_entity *se) } else { sa->util_avg = cap; } + sa->util_peak = sa->util_avg; sa->util_sum = sa->util_avg * LOAD_AVG_MAX; } @@ -3181,6 +3183,10 @@ dequeue_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) max_t(long, cfs_rq->runnable_load_avg - se->avg.load_avg, 0); cfs_rq->runnable_load_sum = max_t(s64, cfs_rq->runnable_load_sum - se->avg.load_sum, 0); + + /* Save peak PELT utilization for task to help wake-up decisions */ + if (entity_is_task(se)) + se->avg.util_peak = se->avg.util_avg; } #ifndef CONFIG_64BIT @@ -5203,7 +5209,7 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p, return 1; } -static inline int task_util(struct task_struct *p); +static inline int task_util_peak(struct task_struct *p); static int cpu_util_wake(int cpu, struct task_struct *p); static unsigned long capacity_spare_wake(int cpu, struct task_struct *p) @@ -5286,14 +5292,14 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, /* * The cross-over point between using spare capacity or least load * is too conservative for high utilization tasks on partially - * utilized systems if we require spare_capacity > task_util(p), + * utilized systems if we require spare_capacity > task_util_peak(p), * so we allow for some task stuffing by using - * spare_capacity > task_util(p)/2. + * spare_capacity > task_util_peak(p)/2. */ - if (this_spare > task_util(p) / 2 && + if (this_spare > task_util_peak(p) / 2 && imbalance*this_spare > 100*most_spare) return NULL; - else if (most_spare > task_util(p) / 2) + else if (most_spare > task_util_peak(p) / 2) return most_spare_sg; if (!idlest || 100*this_load < imbalance*min_load) @@ -5628,6 +5634,11 @@ static inline int task_util(struct task_struct *p) return p->se.avg.util_avg; } +static inline int task_util_peak(struct task_struct *p) +{ + return p->se.avg.util_peak; +} + /* * cpu_util_wake: Compute cpu utilization with any contributions from * the waking task p removed. @@ -5667,7 +5678,7 @@ static int wake_cap(struct task_struct *p, int cpu, int prev_cpu) /* Bring task utilization in sync with prev_cpu */ sync_entity_load_avg(&p->se); - return min_cap * 1024 < task_util(p) * capacity_margin; + return min_cap * 1024 < task_util_peak(p) * capacity_margin; } /*