Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp311800pxj; Thu, 10 Jun 2021 01:04:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRnfpIe8L1FCU3voTMxWYWT+l6E6JeijWeRJxqEj8DFz3UhL63VT1UixZvseyIJfYRSZQR X-Received: by 2002:a05:6402:2707:: with SMTP id y7mr3467810edd.0.1623312255325; Thu, 10 Jun 2021 01:04:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623312255; cv=none; d=google.com; s=arc-20160816; b=QS5Mo1zejKRZiz8Vs/Zgma+sn2AhDalhxXLd/F2D223nEPgYT83c/BupGMNkajgQAQ p7ZdMdW0NLMOFg/gAfoTOytNDJQP1c0CaT91Ehx5TEtvNNTXr+KU0ItssJx3Bhtse899 PELPl7rc2AxRSvmV+2eVXQMJcr1ijKSIPVUddNzOPjGBir3aaWHBmMKkt0ly8gHF/9SK f/yiXMhnCI6XGtEk5dAnnoAEplh3fs3G5mr5RYOC0SccViUlOLbOX/1858Agzd1bhyFW rpBaEpHM7faMq4U+n4k0Mt2B6nO5j++RBEsZSIFBaG5b0FNrr0NezA6/Ogm/mAlfmXd8 t+PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=jnj374tBN1u0+7qzi9RKeRcyClGo5IdIx87fr4lI2T4=; b=J25IvTg/Ea4VZpK+vQ10tDovOkDB/VSRD34+cPs1e8dXCwhx07DHBwtIxPU0ANlNSi UyWgZn9EKR77sutWUKPvNx7HeLRxLrcM+PdKMK3jSGwwu9vZFrp2LV8eFzB+MgdriAG6 uxTfeTDzVPcEwXxXgRkO0H2hXIz6o/T1jwprp5elElU0EnKb5YJfF4GG0Ts+aLQdNcdy ovhxmkAwVP/4o97JRJTpZGojIGr58ytLbkCu9E25Oyc3m2X574GljtDf9VYL0LRDf500 UYE3I09qV1PJPVw28TTHc/sVLjDxHFGHBzAvAymgHj3tIGiz33Zmy3X0Nul2mhhjjJ0q +pdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nqcO9g0E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id dn13si1664683edb.501.2021.06.10.01.03.51; Thu, 10 Jun 2021 01:04:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nqcO9g0E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230230AbhFJIDb (ORCPT + 99 others); Thu, 10 Jun 2021 04:03:31 -0400 Received: from mail-lj1-f169.google.com ([209.85.208.169]:40870 "EHLO mail-lj1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbhFJIC7 (ORCPT ); Thu, 10 Jun 2021 04:02:59 -0400 Received: by mail-lj1-f169.google.com with SMTP id x14so3566763ljp.7 for ; Thu, 10 Jun 2021 01:01:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jnj374tBN1u0+7qzi9RKeRcyClGo5IdIx87fr4lI2T4=; b=nqcO9g0E4Qf3YS7ABNZtJzHFbs6Xy34fW1S4RMW7INVdY2S2dJUQwa4MGPys+j4iZ2 1hZfHyQ4x1DMc9DaryQ8C3U2ZyJCikaCzD0ZNFNuIg/bCHh+K4CV/yInNNA+4FPwoRJw y27fIdieonmaslTYC9fhiPSDCxUs7J5XhCVpAHdbbLQ/Gi4h4DWE20YQ1NopfnO+iV1w q/n70V4CR1RrixxYGS7u9oV3Ck5T3dtfW/gWOJLYaGoho5oLgNpC+Vow0jkIkfJK65Wl qtw3bXSDYKgjmsuoZ69n+R+h9itRC9rKu4kV2YYtiaTm61kKIioUXs+UmIhrRbr9Adk4 r2fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jnj374tBN1u0+7qzi9RKeRcyClGo5IdIx87fr4lI2T4=; b=YmKVQ046F/R985mqtaBNqB5eHzUt6UsIus/2O4Jehto165c+vJ0nySY/BrQRXxz4cK sIQ/2HCG8XERyEjgN7I3XARLrFy86TKsbahIe5wXCIhar55bRDVRoXULfhdl0911igfn HWmi7WSO02HlL0/aXeYNW0iXX+ZX6+/atYXoCD9rA2kQsLY9Y9Rt83cgpfVfxQuGmRL7 9KHIZp7/QR8BelYuBN+ECCHfRwe89dRWYbp82dh4DxmWrdCNrS5c2V+NFy6RLyyA07nW QAT56mMFXnLa0JFIcUBINjxRmAldKzTRRutzTT2X2YP5YZwNf6i9LKdRL7toNyIbeX09 7rMw== X-Gm-Message-State: AOAM530rsR2s42ov4vmEn7LloS3SCOFNs7dZuWh5EIQawtX+bz7OIEh6 78ZG4GvTgBlJ7Vwes3L/crghsN8ttwGYjj+vqt3BOQ== X-Received: by 2002:a05:651c:4cf:: with SMTP id e15mr1180751lji.401.1623312002168; Thu, 10 Jun 2021 01:00:02 -0700 (PDT) MIME-Version: 1.0 References: <20210604080954.13915-1-lukasz.luba@arm.com> <20210604080954.13915-2-lukasz.luba@arm.com> In-Reply-To: <20210604080954.13915-2-lukasz.luba@arm.com> From: Vincent Guittot Date: Thu, 10 Jun 2021 09:59:51 +0200 Message-ID: Subject: Re: [PATCH v2 1/2] sched/fair: Take thermal pressure into account while estimating energy To: Lukasz Luba Cc: linux-kernel , "open list:THERMAL" , Peter Zijlstra , "Rafael J. Wysocki" , Viresh Kumar , Quentin Perret , Dietmar Eggemann , Vincent Donnefort , Beata Michalska , Ingo Molnar , Juri Lelli , Steven Rostedt , segall@google.com, Mel Gorman , Daniel Bristot de Oliveira Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 4 Jun 2021 at 10:10, Lukasz Luba wrote: > > Energy Aware Scheduling (EAS) needs to be able to predict the frequency > requests made by the SchedUtil governor to properly estimate energy used > in the future. It has to take into account CPUs utilization and forecast > Performance Domain (PD) frequency. There is a corner case when the max > allowed frequency might be reduced due to thermal. SchedUtil is aware of > that reduced frequency, so it should be taken into account also in EAS > estimations. > > SchedUtil, as a CPUFreq governor, knows the maximum allowed frequency of > a CPU, thanks to cpufreq_driver_resolve_freq() and internal clamping > to 'policy::max'. SchedUtil is responsible to respect that upper limit > while setting the frequency through CPUFreq drivers. This effective > frequency is stored internally in 'sugov_policy::next_freq' and EAS has > to predict that value. > > In the existing code the raw value of arch_scale_cpu_capacity() is used > for clamping the returned CPU utilization from effective_cpu_util(). > This patch fixes issue with too big single CPU utilization, by introducing > clamping to the allowed CPU capacity. The allowed CPU capacity is a CPU > capacity reduced by thermal pressure signal. We rely on this load avg > geometric series in similar way as other mechanisms in the scheduler. > > Thanks to knowledge about allowed CPU capacity, we don't get too big value > for a single CPU utilization, which is then added to the util sum. The > util sum is used as a source of information for estimating whole PD energy. > To avoid wrong energy estimation in EAS (due to capped frequency), make > sure that the calculation of util sum is aware of allowed CPU capacity. > > Signed-off-by: Lukasz Luba > --- > kernel/sched/fair.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 161b92aa1c79..1aeddecabc20 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -6527,6 +6527,7 @@ compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd) > struct cpumask *pd_mask = perf_domain_span(pd); > unsigned long cpu_cap = arch_scale_cpu_capacity(cpumask_first(pd_mask)); > unsigned long max_util = 0, sum_util = 0; > + unsigned long _cpu_cap = cpu_cap; > int cpu; > > /* > @@ -6558,14 +6559,24 @@ compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd) > cpu_util_next(cpu, p, -1) + task_util_est(p); > } > > + /* > + * Take the thermal pressure from non-idle CPUs. They have > + * most up-to-date information. For idle CPUs thermal pressure > + * signal is not updated so often. What do you mean by "not updated so often" ? Do you have a value ? Thermal pressure is updated at the same rate as other PELT values of an idle CPU. Why is it a problem there ? > + */ > + if (!idle_cpu(cpu)) > + _cpu_cap = cpu_cap - thermal_load_avg(cpu_rq(cpu)); > + > /* > * Busy time computation: utilization clamping is not > * required since the ratio (sum_util / cpu_capacity) > * is already enough to scale the EM reported power > * consumption at the (eventually clamped) cpu_capacity. > */ > - sum_util += effective_cpu_util(cpu, util_running, cpu_cap, > - ENERGY_UTIL, NULL); > + cpu_util = effective_cpu_util(cpu, util_running, cpu_cap, > + ENERGY_UTIL, NULL); > + > + sum_util += min(cpu_util, _cpu_cap); > > /* > * Performance domain frequency: utilization clamping > @@ -6576,7 +6587,7 @@ compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd) > */ > cpu_util = effective_cpu_util(cpu, util_freq, cpu_cap, > FREQUENCY_UTIL, tsk); > - max_util = max(max_util, cpu_util); > + max_util = max(max_util, min(cpu_util, _cpu_cap)); > } > > return em_cpu_energy(pd->em_pd, max_util, sum_util); > -- > 2.17.1 >