Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1279823imm; Tue, 2 Oct 2018 05:54:45 -0700 (PDT) X-Google-Smtp-Source: ACcGV62FSTPSCaBQ0pPE9O1RtmilG9XzFP90dTP79Vhby9P34EnNQZcRqFoRJJpnrbNz5jZVzsf/ X-Received: by 2002:a62:184a:: with SMTP id 71-v6mr14477993pfy.246.1538484885401; Tue, 02 Oct 2018 05:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538484885; cv=none; d=google.com; s=arc-20160816; b=YLt09RwXBnsLsBhWFtNOfQ2e12ZQBz5RigZJfQ949ZSiIkUIqs/CMXbVQIfGhsCXWG 6U2Y97qkUceSc/OmVsb5rB1puMbcL8czJd5BIpHYhteZ+GVbwkKzB4RYWhCW1q+CuriH 1cW80GZ7DPiZ5uyQixiDzhjnstnDGyODv42rG8ikQZ3CXdWLZL6mEAFPNmMaOllA/8jM NwiZ/AdEskr92NZUSNJcla1w2iF2+BEZ72GG3/Bt7BXbRduBuhIGOS8pX+0Tn2jDV0hf AJZBosHNVPkyMybXznxTA7AC3OYQTaIBtWE1zuK8ynRVUZVEn79HtwagmywI84aIR/1L ceqQ== 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; bh=F709wPzxsh9NOZY7jGQsasKSeUqwgXIuRw5Z6WNiR9I=; b=1FmK8xsG9BkRWUw8fPgl59Yrp8LH2Pn5cX/MxAPGwRFyg72hCAL68QrMZf5Z3mRiar kwJ1NjM3Ebo589fnCwiFrrtwGf5iCYP+RR9dRTdbosQTJMsQWkaHd9o4ihSZ85OzCeWu gJnOc0rdgN+1HETpuzJ95r89WKMrgZPhwc6Fq+P9cJ1hWBJE1NbeCZbbR3isdegLeDDq CR2eGbjTerd7Tc3WlsGjAnP0pU/3dn37RiQL7CTaDi+ie5F3R/7KZUKw64eYseHVhSq7 CwSrFbqN4LbK2bH1Qrl0+DslYvvIgeQtaHduOWHZNEozbPexG5Ffm1tv3sMSL9RNdDmM 51Pg== 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 g10-v6si14983070plt.212.2018.10.02.05.54.29; Tue, 02 Oct 2018 05:54: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 S1727755AbeJBThg (ORCPT + 99 others); Tue, 2 Oct 2018 15:37:36 -0400 Received: from foss.arm.com ([217.140.101.70]:36690 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727644AbeJBThf (ORCPT ); Tue, 2 Oct 2018 15:37:35 -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 EACD47A9; Tue, 2 Oct 2018 05:54:22 -0700 (PDT) Received: from queper01-lin (queper01-lin.emea.arm.com [10.4.13.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CC9173F5B7; Tue, 2 Oct 2018 05:54:18 -0700 (PDT) Date: Tue, 2 Oct 2018 13:54:17 +0100 From: Quentin Perret To: Peter Zijlstra Cc: rjw@rjwysocki.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, 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 Subject: Re: [PATCH v7 03/14] PM: Introduce an Energy Model management framework Message-ID: <20181002125414.aufsalllqf25rwsq@queper01-lin> References: <20180912091309.7551-1-quentin.perret@arm.com> <20180912091309.7551-4-quentin.perret@arm.com> <20181002122535.GY3439@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181002122535.GY3439@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday 02 Oct 2018 at 14:25:35 (+0200), Peter Zijlstra wrote: > On Wed, Sep 12, 2018 at 10:12:58AM +0100, Quentin Perret wrote: > > +/** > > + * em_pd_energy() - Estimates the energy consumed by the CPUs of a perf. domain > > + * @pd : performance domain for which energy has to be estimated > > + * @max_util : highest utilization among CPUs of the domain > > + * @sum_util : sum of the utilization of all CPUs in the domain > > + * > > + * Return: the sum of the energy consumed by the CPUs of the domain assuming > > + * a capacity state satisfying the max utilization of the domain. > > + */ > > +static inline unsigned long em_pd_energy(struct em_perf_domain *pd, > > + unsigned long max_util, unsigned long sum_util) > > +{ > > + unsigned long freq, scale_cpu; > > + struct em_cap_state *cs; > > + int i, cpu; > > + > > + /* > > + * In order to predict the capacity state, map the utilization of the > > + * most utilized CPU of the performance domain to a requested frequency, > > + * like schedutil. > > + */ > > + cpu = cpumask_first(to_cpumask(pd->cpus)); > > + scale_cpu = arch_scale_cpu_capacity(NULL, cpu); > > + cs = &pd->table[pd->nr_cap_states - 1]; > > + freq = map_util_freq(max_util, cs->frequency, scale_cpu); > > + > > + /* > > + * Find the lowest capacity state of the Energy Model above the > > + * requested frequency. > > + */ > > + for (i = 0; i < pd->nr_cap_states; i++) { > > + cs = &pd->table[i]; > > + if (cs->frequency >= freq) > > + break; > > + } > > + > > + /* > > + * The capacity of a CPU in the domain at that capacity state (cs) > > + * can be computed as: > > + * > > + * cs->freq * scale_cpu > > + * cs->cap = -------------------- (1) > > + * cpu_max_freq > > + * > > + * So, the energy consumed by this CPU at that capacity state is: > > + * > > + * cs->power * cpu_util > > + * cpu_nrg = -------------------- (2) > > + * cs->cap > > + * > > + * since 'cpu_util / cs->cap' represents its percentage of busy time. > > + * > > + * NOTE: Although the result of this computation actually is in > > + * units of power, it can be manipulated as an energy value > > + * over a scheduling period, since it is assumed to be > > + * constant during that interval. > > + * > > + * By injecting (1) in (2), 'cpu_nrg' can be re-expressed as a product > > + * of two terms: > > + * > > + * cs->power * cpu_max_freq cpu_util > > + * cpu_nrg = ------------------------ * --------- (3) > > + * cs->freq scale_cpu > > + * > > + * The first term is static, and is stored in the em_cap_state struct > > + * as 'cs->cost'. > > + * > > + * Since all CPUs of the domain have the same micro-architecture, they > > + * share the same 'cs->cost', and the same CPU capacity. Hence, the > > + * total energy of the domain (which is the simple sum of the energy of > > + * all of its CPUs) can be factorized as: > > + * > > + * cs->cost * \Sum cpu_util > > + * pd_nrg = ------------------------ (4) > > + * scale_cpu > > + */ > > + return cs->cost * sum_util / scale_cpu; > > +} > > Should we explicitly mention that this ignores idle costs? More doc shouldn't hurt so I can add a little something if you feel it's needed. Thanks, Quentin