Received: by 10.192.165.156 with SMTP id m28csp199507imm; Tue, 17 Apr 2018 08:42:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+T3Di+ACPhe5USOSyI+e6YkLvVDOIEmdGK3LOHclw4WUlAXlsNVL6FudqY1CEI01O7BxNl X-Received: by 2002:a17:902:887:: with SMTP id 7-v6mr2557780pll.319.1523979773891; Tue, 17 Apr 2018 08:42:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523979773; cv=none; d=google.com; s=arc-20160816; b=LEIqkiPWyNXgZuBnfDS4vwtLL64pRtRLXaJqy9vENY00EcYNyuTeFXFKUJ/hiAIx8s uqdMsqnhhHVGLxlxAXTrKgyE+xGSZ2c9gopDV/+74YnJOPpF/MtFdpTRbaZyTZDKGvEa DRIvymWKeJbn9R08kQlgPP7ZbdcC+6CbjFzugCZZ+GW3c30y98S73KwVbOs1KqRJy0Px V23X6DFv6VxiWqhZ0k28osXkcP51/4E4bJtlqvbMfDoe1ONjldvsuVf9VsqxPUYNwDUJ hhOAPls29YuUQt8uD1OT5DyfhgRvwvwphsOiH089rJ2zXi//hfRfsDjV4OSVd10PnhfO qPqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=dxKvLoLexAqSueCh9j3qSQt3J8Xb9UQKqySm/dqQDlo=; b=qkgScvOoDlTH5NTfS2MesjKVX6XlKB22FtzUykQniLc2Gi7wT2Os5K8ejfYZXwDekT X1YHePNbcoJXdQDnnX5YkJHXaZGOGdbtL4fBzotCpx1zJ8D1YnIcOhAzNICZshKqwLoZ dq11KwpNsbGkd7Eg2WFHlm0UdUOPHLM9Huqrmyw322c5KpLKxKsXAcyqVAzVlaTSMwa0 ChJwF3VDDSc3C5huZH9j6ozSY2rAM10C3apSkLzjv2VvCh7LWoRt3P0/lwyqiRsFaJ/G CdJ/fvHD8E1LUFz7rznrcP0vHpilMiSYoFKb3aPnfrxXRx1JXSy59Io1nQfYdMikikGL rhyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JRPKhzHH; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y72si13204471pfi.46.2018.04.17.08.42.39; Tue, 17 Apr 2018 08:42: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; dkim=pass header.i=@linaro.org header.s=google header.b=JRPKhzHH; 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 S1752774AbeDQPkT (ORCPT + 99 others); Tue, 17 Apr 2018 11:40:19 -0400 Received: from mail-ot0-f194.google.com ([74.125.82.194]:42728 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752670AbeDQPkP (ORCPT ); Tue, 17 Apr 2018 11:40:15 -0400 Received: by mail-ot0-f194.google.com with SMTP id h55-v6so21843954ote.9 for ; Tue, 17 Apr 2018 08:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=dxKvLoLexAqSueCh9j3qSQt3J8Xb9UQKqySm/dqQDlo=; b=JRPKhzHHaY3QFiiT3vFOAsSNeqQcSokVCxIgSorEdSMaOlX93xqkqwT7wIIg0XadO6 h/1qjFL1o1tA39vzaUHpsNp70Nfp+enjg5RKgOBt0zwF+/2NBK2rN2Uafz7Ad8z3Ez6u AS8qicUXAqCjX8vH+Mg0sIG7XsDzPbR/nH8CA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=dxKvLoLexAqSueCh9j3qSQt3J8Xb9UQKqySm/dqQDlo=; b=pERcgib4OBp0LZyC3VeHeyS7sv+nqh2dRUwDTSQNlY7sGA8zoRBM9AUH626gQy58Z7 FWkgcqu5Da01ycXPOa8ldLAesQcsYW9S16Hce9LE+ALU9/B2+ifzjR6FMeK9QWN/aIib SPrdV34rNAlfHQoP5bFBpVnhrRNB+86YylFs3PS1WJqCvaHrhDdP/IwLss5AM9rJLV0r ZHPUGm/H2p55JAB4B043Eir8hkWUU/uPhQrvSevdzqQslumGOUlbipNbVfZXjQBjyBuS CRQBzGvreQA6kifsNKK/1isKlBI8fOMJDcDIwDPXzz6uxyd1eSK44vsuj1yO6UYnBGFs NDlA== X-Gm-Message-State: ALQs6tAa859y411hPwFmj9GPl3TBfhsdL8P+T89Kur7lktCl9gzzWSSI 6S8ZoOFQs7f3l5seDItNLrowSQ== X-Received: by 2002:a9d:3483:: with SMTP id g3-v6mr1471042otc.401.1523979615147; Tue, 17 Apr 2018 08:40:15 -0700 (PDT) Received: from leoy-ThinkPad-X240s (li973-238.members.linode.com. [45.33.19.238]) by smtp.gmail.com with ESMTPSA id j16-v6sm8744272oth.45.2018.04.17.08.39.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 08:40:13 -0700 (PDT) Date: Tue, 17 Apr 2018 23:39:44 +0800 From: Leo Yan To: Dietmar Eggemann Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Quentin Perret , Thara Gopinath , linux-pm@vger.kernel.org, Morten Rasmussen , Chris Redpath , Patrick Bellasi , Valentin Schneider , "Rafael J . Wysocki" , Greg Kroah-Hartman , Vincent Guittot , Viresh Kumar , Todd Kjos , Joel Fernandes , Juri Lelli , Steve Muckle , Eduardo Valentin Subject: Re: [RFC PATCH v2 5/6] sched/fair: Select an energy-efficient CPU on task wake-up Message-ID: <20180417153944.GD18509@leoy-ThinkPad-X240s> References: <20180406153607.17815-1-dietmar.eggemann@arm.com> <20180406153607.17815-6-dietmar.eggemann@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180406153607.17815-6-dietmar.eggemann@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, Apr 06, 2018 at 04:36:06PM +0100, Dietmar Eggemann wrote: > From: Quentin Perret > > In case an energy model is available, waking tasks are re-routed into a > new energy-aware placement algorithm. The eligible CPUs to be used in the > energy-aware wakeup path are restricted to the highest non-overutilized > sched_domain containing prev_cpu and this_cpu. If no such domain is found, > the tasks go through the usual wake-up path, hence energy-aware placement > happens only in lightly utilized scenarios. > > The selection of the most energy-efficient CPU for a task is achieved by > estimating the impact on system-level active energy resulting from the > placement of the task on the CPU with the highest spare capacity in each > frequency domain. The best CPU energy-wise is then selected if it saves > a large enough amount of energy with respect to prev_cpu. > > Although it has already shown significant benefits on some existing > targets, this approach cannot scale to platforms with numerous CPUs. > This patch is an attempt to do something useful as writing a fast > heuristic that performs reasonably well on a broad spectrum of > architectures isn't an easy task. As a consequence, the scope of > usability of the energy-aware wake-up path is restricted to systems > with the SD_ASYM_CPUCAPACITY flag set. These systems not only show the > most promising opportunities for saving energy but also typically > feature a limited number of logical CPUs. > > Moreover, the energy-aware wake-up path is accessible only if > sched_energy_enabled() is true. For systems which don't meet all > dependencies for EAS (CONFIG_PM_OPP for ex.) at compile time, > sched_enegy_enabled() defaults to a constant "false" value, hence letting > the compiler remove the unused EAS code entirely. > > Cc: Ingo Molnar > Cc: Peter Zijlstra > Signed-off-by: Quentin Perret > Signed-off-by: Dietmar Eggemann > --- > kernel/sched/fair.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 93 insertions(+), 4 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 8cb9fb04fff2..5ebb2d0306c7 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -6700,6 +6700,81 @@ static unsigned long compute_energy(struct task_struct *p, int dst_cpu) > return energy; > } > > +static int find_energy_efficient_cpu(struct sched_domain *sd, > + struct task_struct *p, int prev_cpu) > +{ > + unsigned long cur_energy, prev_energy, best_energy, cpu_cap; > + unsigned long task_util = task_util_est(p); > + int cpu, best_energy_cpu = prev_cpu; > + struct freq_domain *fd; > + > + if (!task_util) > + return prev_cpu; > + > + if (cpumask_test_cpu(prev_cpu, &p->cpus_allowed)) > + prev_energy = best_energy = compute_energy(p, prev_cpu); > + else > + prev_energy = best_energy = ULONG_MAX; > + > + for_each_freq_domain(fd) { > + unsigned long spare_cap, max_spare_cap = 0; > + int max_spare_cap_cpu = -1; > + unsigned long util; > + > + /* Find the CPU with the max spare cap in the freq. dom. */ > + for_each_cpu_and(cpu, freq_domain_span(fd), sched_domain_span(sd)) { > + if (!cpumask_test_cpu(cpu, &p->cpus_allowed)) > + continue; > + > + if (cpu == prev_cpu) > + continue; > + > + util = cpu_util_wake(cpu, p); > + cpu_cap = capacity_of(cpu); > + if (!util_fits_capacity(util + task_util, cpu_cap)) > + continue; > + > + spare_cap = cpu_cap - util; > + if (spare_cap > max_spare_cap) { > + max_spare_cap = spare_cap; > + max_spare_cap_cpu = cpu; > + } > + } If have two clusters, and if firstly iterate the big cluster, then max_spare_cap is a big value for big cluster and later LITTLE cluster has no chance to have higher value for spare_cap. For this case, the LITTLE CPU will be skipped for energy computation? > + > + /* Evaluate the energy impact of using this CPU. */ > + if (max_spare_cap_cpu >= 0) { > + cur_energy = compute_energy(p, max_spare_cap_cpu); > + if (cur_energy < best_energy) { > + best_energy = cur_energy; > + best_energy_cpu = max_spare_cap_cpu; > + } > + } > + } > + > + /* > + * We pick the best CPU only if it saves at least 1.5% of the > + * energy used by prev_cpu. > + */ > + if ((prev_energy - best_energy) > (prev_energy >> 6)) > + return best_energy_cpu; > + > + return prev_cpu; > +} > + > +static inline bool wake_energy(struct task_struct *p, int prev_cpu) > +{ > + struct sched_domain *sd; > + > + if (!sched_energy_enabled()) > + return false; > + > + sd = rcu_dereference_sched(cpu_rq(prev_cpu)->sd); > + if (!sd || sd_overutilized(sd)) > + return false; > + > + return true; > +} > + > /* > * 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, > @@ -6716,18 +6791,22 @@ static int > select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_flags) > { > struct sched_domain *tmp, *affine_sd = NULL, *sd = NULL; > + struct sched_domain *energy_sd = NULL; > int cpu = smp_processor_id(); > int new_cpu = prev_cpu; > - int want_affine = 0; > + int want_affine = 0, want_energy = 0; > int sync = (wake_flags & WF_SYNC) && !(current->flags & PF_EXITING); > > + rcu_read_lock(); > + > if (sd_flag & SD_BALANCE_WAKE) { > record_wakee(p); > + want_energy = wake_energy(p, prev_cpu); > want_affine = !wake_wide(p) && !wake_cap(p, cpu, prev_cpu) > - && cpumask_test_cpu(cpu, &p->cpus_allowed); > + && cpumask_test_cpu(cpu, &p->cpus_allowed) > + && !want_energy; > } > > - rcu_read_lock(); > for_each_domain(cpu, tmp) { > if (!(tmp->flags & SD_LOAD_BALANCE)) > break; > @@ -6742,6 +6821,14 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f > break; > } > > + /* > + * Energy-aware task placement is performed on the highest > + * non-overutilized domain spanning over cpu and prev_cpu. > + */ > + if (want_energy && !sd_overutilized(tmp) && > + cpumask_test_cpu(prev_cpu, sched_domain_span(tmp))) > + energy_sd = tmp; > + > if (tmp->flags & sd_flag) > sd = tmp; > else if (!want_affine) > @@ -6765,7 +6852,9 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f > sync_entity_load_avg(&p->se); > } > > - if (!sd) { > + if (energy_sd) { > + new_cpu = find_energy_efficient_cpu(energy_sd, p, prev_cpu); > + } else if (!sd) { > pick_cpu: > if (sd_flag & SD_BALANCE_WAKE) { /* XXX always ? */ > new_cpu = select_idle_sibling(p, prev_cpu, new_cpu); > -- > 2.11.0 >