Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5180960imm; Wed, 12 Sep 2018 02:14:53 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda4izBd+X/Cw2Li9Q6Ckq8uGznktNC3uSGQr1SsparSkIiJ/1s7ZtT8kfomO8oqcjitJ9iJ X-Received: by 2002:a62:8186:: with SMTP id t128-v6mr1126424pfd.192.1536743693275; Wed, 12 Sep 2018 02:14:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536743693; cv=none; d=google.com; s=arc-20160816; b=0Ca/JaMQKthUg1kp4I73WjotaPxTnLevXv/US4zlMFfm9zolKfoEUp/FmR3z+eiIQZ oaYlIgkgol3J3ZDl1fGVHOMZcNfhKnKZXLH6WVNp0ddNtx6gFjUrhDDXw+e337BDHn3W 04+GkdiGQByYYzrfOr6PfqvknvH8cKJkCMI33p5bkH2gDzH4x0cUi2xj7xouL7HQwDEj 94VNq4QGR5mqaOBplYvt1CEgJTiujICQmgYPcPpyuWOKwQ+UEAUrg2UPLldnWyE/HoEx e7h4evDTMuEXxqCcRD6iJNBhL3JYV4kcJ2UhgFqUvozjtLRj9ZjPZV6Bl6qFMtmQ3fsY 867w== 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; bh=GXwn6vMBvYmkO/Z8/Uu8gXurCy1R2MAsD5OQwDT+Ur4=; b=j43ka8ZxnzH3n9aGtDr9N+THvij6JVzuBtK3W/FynDSflaFls7IAWU2gGYtPdNVQmt 55guWjtcunKojn2MLvJGVoXn3Ey/uDDY1QW71GMZTBNST3t1DWUwUUGaa6qse4fj31PX 2nk7iIgXOZbIsfVN9SGuWGydT1ZxSK2Ku+EvFr0fznvyZsBPW+aIzx3QwxG+xfTGndQT UU+2tswfX3tLvbsOHPFpqKj7J+FWQuEmczyWQuaemlyzY3VrUZJaDS2E/unI/gzh9m9k 5onzYYQEpZ3bb08JGs0oDfj2X16RsZR02h4MWkafJ18SctYFUNGI5HGwa1XuU4sg06RO OO7g== 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 k195-v6si525446pgc.53.2018.09.12.02.14.38; Wed, 12 Sep 2018 02:14:53 -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 S1728294AbeILORr (ORCPT + 99 others); Wed, 12 Sep 2018 10:17:47 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:56038 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727391AbeILORq (ORCPT ); Wed, 12 Sep 2018 10:17:46 -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 5A69A1596; Wed, 12 Sep 2018 02:14:09 -0700 (PDT) Received: from queper01-lin.local (queper01-lin.emea.arm.com [10.4.13.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 42D473F703; Wed, 12 Sep 2018 02:14:05 -0700 (PDT) From: Quentin Perret To: peterz@infradead.org, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: gregkh@linuxfoundation.org, mingo@redhat.com, dietmar.eggemann@arm.com, morten.rasmussen@arm.com, chris.redpath@arm.com, patrick.bellasi@arm.com, valentin.schneider@arm.com, vincent.guittot@linaro.org, thara.gopinath@linaro.org, viresh.kumar@linaro.org, tkjos@google.com, joel@joelfernandes.org, smuckle@google.com, adharmap@codeaurora.org, skannan@codeaurora.org, pkondeti@codeaurora.org, juri.lelli@redhat.com, edubezval@gmail.com, srinivas.pandruvada@linux.intel.com, currojerez@riseup.net, javi.merino@kernel.org, quentin.perret@arm.com Subject: [PATCH v7 11/14] sched/fair: Introduce an energy estimation helper function Date: Wed, 12 Sep 2018 10:13:06 +0100 Message-Id: <20180912091309.7551-12-quentin.perret@arm.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180912091309.7551-1-quentin.perret@arm.com> References: <20180912091309.7551-1-quentin.perret@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for the definition of an energy-aware wakeup path, introduce a helper function to estimate the consequence on system energy when a specific task wakes-up on a specific CPU. compute_energy() estimates the capacity state to be reached by all performance domains and estimates the consumption of each online CPU according to its Energy Model and its percentage of busy time. Cc: Ingo Molnar Cc: Peter Zijlstra Signed-off-by: Quentin Perret --- kernel/sched/fair.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 648482f35458..7ee3e43cdaf2 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6262,6 +6262,83 @@ static int wake_cap(struct task_struct *p, int cpu, int prev_cpu) return !task_fits_capacity(p, min_cap); } +/* + * Predicts what cpu_util(@cpu) would return if @p was migrated (and enqueued) + * to @dst_cpu. + */ +static unsigned long cpu_util_next(int cpu, struct task_struct *p, int dst_cpu) +{ + struct cfs_rq *cfs_rq = &cpu_rq(cpu)->cfs; + unsigned long util_est, util = READ_ONCE(cfs_rq->avg.util_avg); + + /* + * If @p migrates from @cpu to another, remove its contribution. Or, + * if @p migrates from another CPU to @cpu, add its contribution. In + * the other cases, @cpu is not impacted by the migration, so the + * util_avg should already be correct. + */ + if (task_cpu(p) == cpu && dst_cpu != cpu) + util = max_t(long, util - task_util(p), 0); + else if (task_cpu(p) != cpu && dst_cpu == cpu) + util += task_util(p); + + if (sched_feat(UTIL_EST)) { + util_est = READ_ONCE(cfs_rq->avg.util_est.enqueued); + + /* + * During wake-up, the task isn't enqueued yet and doesn't + * appear in the cfs_rq->avg.util_est.enqueued of any rq, + * so just add it (if needed) to "simulate" what will be + * cpu_util() after the task has been enqueued. + */ + if (dst_cpu == cpu) + util_est += _task_util_est(p); + + util = max(util, util_est); + } + + return min_t(unsigned long, util, capacity_orig_of(cpu)); +} + +/* + * compute_energy(): Estimates the energy that would be consumed if @p was + * migrated to @dst_cpu. compute_energy() predicts what will be the utilization + * landscape of the * CPUs after the task migration, and uses the Energy Model + * to compute what would be the energy if we decided to actually migrate that + * task. + */ +static long compute_energy(struct task_struct *p, int dst_cpu, + struct perf_domain *pd) +{ + long util, max_util, sum_util, energy = 0; + int cpu; + + while (pd) { + max_util = sum_util = 0; + /* + * The capacity state of CPUs of the current rd can be driven by + * CPUs of another rd if they belong to the same performance + * domain. So, account for the utilization of these CPUs too + * by masking pd with cpu_online_mask instead of the rd span. + * + * If an entire performance domain is outside of the current rd, + * it will not appear in its pd list and will not be accounted + * by compute_energy(). + */ + for_each_cpu_and(cpu, perf_domain_span(pd), cpu_online_mask) { + util = cpu_util_next(cpu, p, dst_cpu); + util = schedutil_freq_util(cpu, util, ENERGY_UTIL); + max_util = max(util, max_util); + sum_util += util; + } + + energy += em_pd_energy(pd->obj, max_util, sum_util); + pd = pd->next; + } + + return energy; +} + /* * select_task_rq_fair: Select target runqueue for the waking task in domains * that have the 'sd_flag' flag set. In practice, this is SD_BALANCE_WAKE, -- 2.18.0