Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3672457imm; Mon, 20 Aug 2018 02:47:08 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwYrm9S+rsfVyFaCLk2v8D/RfMdujX90LwCpDosifCW5NF4v2PIphxupwHZwyni5MPyKN9F X-Received: by 2002:a17:902:758a:: with SMTP id j10-v6mr44619630pll.281.1534758428554; Mon, 20 Aug 2018 02:47:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534758428; cv=none; d=google.com; s=arc-20160816; b=P4MdJNsXVmBRJnoG8pvw/hSEpa5Aw6oxVwU4an5CGqiwYUek4f4M5UdaRvv5DxQhAS WqlfFlDpJpv76KfdJ2AG3nFEqHJbQMnmbDldlzbrzAg9CF15MQimx23p3iQVvnkD/vM5 uZQOjmrUzE8noibQlLLOesmG0zsS/BUEVUcKiNaa6q3mBoU5zuDWKHOTsCbbP9Rmx7lb drbyGRDi5fOOYkRqJyBwfBxS8th7w6PGwJkV78cJNVcVklGF5xIYgxlNrIPhWYdLuhp0 UFUv1jbC3WcUS1p1rKJZNQbf1CSOdzPxUz3wIjwxwqPYf1HdcBUd+oC4VoQBTmo0gAJE NL+A== 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=j22cqd6RM/Nf+TgdpjZYyciGirHooa4NBbQG6y+jdYg=; b=09gkbFlp5/nTc0RFTmF5OYEbEABB0wWyFX1Dyb3ekendSRLvFcugMnKqh/4u5tC2eM DTW9F4LlXfzfHAtymifmbva0e7DkJuGsNTxS9H2fFWW0fM2GehHJfP/OLQtJ47jxP47a hmfjDmSmX7NBL0Rdwe5ZS8jj39QIkf7Iw+9M9AwRBz2vCPt8TFY2Yggx02abfpz6PfrY MCsH3xlYL/2Vz8KiVK+WsdY/O1C8lW90edZHWEJDCQqxS5s5YHqYBKpQlHL7wK/hxL4Y fElP8jW0C8kRHrEsV81IGQA6J/wsU+KIRfkyuZajWb/bibKA5jIQosuDG5mM8J98+YPi PUdQ== 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 c1-v6si9612701pli.145.2018.08.20.02.46.53; Mon, 20 Aug 2018 02:47:08 -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 S1726849AbeHTNAQ (ORCPT + 99 others); Mon, 20 Aug 2018 09:00:16 -0400 Received: from foss.arm.com ([217.140.101.70]:35098 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbeHTNAP (ORCPT ); Mon, 20 Aug 2018 09:00:15 -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 546DA80D; Mon, 20 Aug 2018 02:45:21 -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 3D79C3F2EA; Mon, 20 Aug 2018 02:45:17 -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 v6 11/14] sched/fair: Introduce an energy estimation helper function Date: Mon, 20 Aug 2018 10:44:17 +0100 Message-Id: <20180820094420.26590-12-quentin.perret@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180820094420.26590-1-quentin.perret@arm.com> References: <20180820094420.26590-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 00729ff55fa3..c4e34368795b 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.17.1