Received: by 10.213.65.68 with SMTP id h4csp1352147imn; Wed, 21 Mar 2018 08:37:45 -0700 (PDT) X-Google-Smtp-Source: AG47ELuKXDBSonpFsxTdIdQ32Xb7w9c47SnPTeZSpCe3gIyT2VpVXbsppZctlH+wqj0lzsyJDTut X-Received: by 10.99.173.7 with SMTP id g7mr309711pgf.170.1521646665133; Wed, 21 Mar 2018 08:37:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521646665; cv=none; d=google.com; s=arc-20160816; b=nYfcoBX9bqQLmPl1J7LqUFGajJHOW02l5BqWPKSlaVs476TYea2YXUN8BN9leuTbyQ OXKyRfj2+cwSCXiv3TgACv+2tWgMv/bwidFFpcvmn3MThX+jQXMSZA+JmP9E2WNA8G/N qQdzNlmyQF1y2C8drLGhNICsTsnhe+i1mKMWuQUG8uSVRm6zzcJokiQJLzqvurEy+RYI kOYZbi9sFqwUxuLh7tNMk630tX6xtE36gxxW6sBS510PHdnK55GU1k2obaMK6GGxTJJE G1BJU27LiKq2GzH6xLYmwEr0BRx8YYtYRwNg4bi2QpcRFyfkc5gNfy21e3LEGCVenf2H /Qzg== 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:arc-authentication-results; bh=R0o02IGDsfFyCYkY6xZ8cm+2SguBYgrj1kJHYaT+N5E=; b=YaQnQdNwL3JQ+iZKvW/1Zz3dNgupD07OgyV8bv34Cz3gv8oezCVnzZadhrxv/auCBk Ox6TkbgrKNk4K258c+XJCDdV81ORvec40gkA+lUNnd/5Dq7G377hy+619MEDB1QgMiE3 DNj02wO1riOj3dFQ09JffJkTBrLCVWMn1NCe47tt8dd87M+fXfx/WZYL4/RcL/nFU/YS df8+8NA1CEttAa3foF43NXnupwXBpS2CtIBAq/aOZ9+ovhWPk1aVvxCiI5rbMstSOH/U U/xth0Yzqh0Lt/TCaGMv66TGKa64S+JXIAM0TY3NMF/BAgrkkSpBje/sHJ7+2soHOB9y z96g== 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 61-v6si4114209plz.507.2018.03.21.08.37.31; Wed, 21 Mar 2018 08:37:45 -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 S1752864AbeCUPfa (ORCPT + 99 others); Wed, 21 Mar 2018 11:35:30 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:55098 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752823AbeCUPfY (ORCPT ); Wed, 21 Mar 2018 11:35:24 -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 77D8B80D; Wed, 21 Mar 2018 08:35:23 -0700 (PDT) Received: from e110439-lin (e110439-lin.cambridge.arm.com [10.1.210.68]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F0B553F24A; Wed, 21 Mar 2018 08:35:20 -0700 (PDT) Date: Wed, 21 Mar 2018 15:35:18 +0000 From: Patrick Bellasi To: Dietmar Eggemann Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Quentin Perret , Thara Gopinath , linux-pm@vger.kernel.org, Morten Rasmussen , Chris Redpath , Valentin Schneider , "Rafael J . Wysocki" , Greg Kroah-Hartman , Vincent Guittot , Viresh Kumar , Todd Kjos , Joel Fernandes Subject: Re: [RFC PATCH 5/6] sched/fair: Select an energy-efficient CPU on task wake-up Message-ID: <20180321153518.GC13951@e110439-lin> References: <20180320094312.24081-1-dietmar.eggemann@arm.com> <20180320094312.24081-6-dietmar.eggemann@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180320094312.24081-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 20-Mar 09:43, Dietmar Eggemann wrote: > From: Quentin Perret [...] > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 76bd46502486..65a1bead0773 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -6513,6 +6513,60 @@ static unsigned long compute_energy(struct task_struct *p, int dst_cpu) > return energy; > } > > +static bool task_fits(struct task_struct *p, int cpu) > +{ > + unsigned long next_util = cpu_util_next(cpu, p, cpu); > + > + return util_fits_capacity(next_util, capacity_orig_of(cpu)); ^^^^^^^^^^^^^^^^^^^^^ Since here we are at scheduling CFS tasks, should we not better use capacity_of() to account for RT/IRQ pressure ? > +} > + > +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; > + int cpu, best_cpu = prev_cpu; > + > + if (!task_util(p)) We are still waking up a task... what if the task was previously running on a big CPU which is now idle? I understand that from a _relative_ energy_diff standpoint there is not much to do for a 0 utilization task. However, for those tasks we can still try to return the most energy efficient CPU among the ones in their cpus_allowed mask. It should be a relatively low overhead (maybe contained in a fallback most_energy_efficient_cpu() kind of function) which allows, for example on ARM big.LITTLE systems, to consolidate those tasks on LITTLE CPUs instead for example keep running them on a big CPU. > + return prev_cpu; > + > + /* Compute the energy impact of leaving the task on prev_cpu. */ > + prev_energy = best_energy = compute_energy(p, prev_cpu); > + > + /* Look for the CPU that minimizes the energy. */ ^^^^^^^^^^ nit-pick: would say explicitly "best_energy" here, just to avoid confusion about (non) possible overflows in the following if check ;) > + for_each_cpu_and(cpu, &p->cpus_allowed, sched_domain_span(sd)) { > + if (!task_fits(p, cpu) || cpu == prev_cpu) nit-pick: to me it would read better as: if (cpu == prev_cpu) continue; if (!task_fits(p, cpu)) continue; but it's more matter of (personal) taste then efficiency. > + continue; > + cur_energy = compute_energy(p, cpu); > + if (cur_energy < best_energy) { > + best_energy = cur_energy; > + best_cpu = 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_cpu; > + > + return prev_cpu; > +} [...] > @@ -6555,6 +6613,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; > + Not entirely sure, but I was trying to understand if we can avoid to modify the definition of want_affine (in the previous chunk) and move this block before the previous "if (want_affine..." (in mainline but not in this chunk), which will became an else, e.g. if (want_energy && !sd_overutilized(tmp) && // ... else if (want_energy && !sd_overutilized(tmp) && // ... Isn't that the same? Maybe there is a code path I'm missing... but otherwise it seems a more self contained modification of select_task_rq_fair... > if (tmp->flags & sd_flag) > sd = tmp; > else if (!want_affine) > @@ -6586,6 +6652,8 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f > if (want_affine) > current->recent_used_cpu = cpu; > } > + } else if (energy_sd) { > + new_cpu = find_energy_efficient_cpu(energy_sd, p, prev_cpu); > } else { > new_cpu = find_idlest_cpu(sd, p, cpu, prev_cpu, sd_flag); > } -- #include Patrick Bellasi