Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp904140imm; Wed, 6 Jun 2018 07:38:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIdPdYG5m8oCgmX4P9M+emXzy9iiq8y4gkuH9wOCdCR+ZaUnqmf/vSEunjNmBc1IsbRs03Y X-Received: by 2002:a62:9f16:: with SMTP id g22-v6mr2659204pfe.207.1528295919781; Wed, 06 Jun 2018 07:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528295919; cv=none; d=google.com; s=arc-20160816; b=N1Sa1oCZmkzkSedkQKfzWqw0WLtO6LluhGIKtzj9ChlVkWu+2d5k9ENu6S7tLVU37K KaeNnmCqDwDL4jhjyeB6k8iz6Clva3UTRxijMMvwV/fEIYNlMzhRBfsDfHl3gBVlQO+f hCAAYqe4ohINxz+mkQ7PuWT8VWkwW5sw9+L9qbKH3qsEkEegq2NouFXUWJyoubZ01UQC jEmKRVWptNo2xkFNoZV98iVmAR657uZlvYbqSKeho/PEVb5dQHc860eyVCiEd0b3aAt5 Y3c8rsGidKbwMSBTbVj9eXgCxoxIOtxy0kCyc4kR+hwvomQeh9JnUiuEOzLRZCxZYX77 hoQQ== 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=rpnF3qX8KDZyBqn5/hpd/okyfMSi92smCrNeHlaLLHY=; b=JRzXwaNxGxt8+e/emBx3HjVlrJkJ3UDrOtyZEQhGPRIhvdElaCqlWuMNdYQcJ6TAIf KiX4HQSUXKkHVq24L6ZIE7iPj3A9KJJAhceb5iXSPM81y56KLJxPT05XrbUMHY1y2c+O ykl/8NXUJNem/QdiHmG5HRt9/nsBokWnFZM7zU00X1OHDwZv7uhZdTaIEJ3zzBTSwBZt b4JoHlosVNIY21SgGk62Mi/3+ReDjXZe7Hn8OSxYC67QKNKL2g29W7eAqyPuZdmYHiuT PX+JIiGGvQyqtVK9uZ6OzCdtcN/Ekd5BAzWjRvDUNmzJR1wqsbeqopBU3ZcU8hnkRX3q nUjw== 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 w33-v6si1275610plb.591.2018.06.06.07.38.24; Wed, 06 Jun 2018 07:38:39 -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 S1752227AbeFFOhq (ORCPT + 99 others); Wed, 6 Jun 2018 10:37:46 -0400 Received: from foss.arm.com ([217.140.101.70]:41150 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752114AbeFFOhp (ORCPT ); Wed, 6 Jun 2018 10:37:45 -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 1975280D; Wed, 6 Jun 2018 07:37:45 -0700 (PDT) Received: from e108498-lin.cambridge.arm.com (e108498-lin.cambridge.arm.com [10.1.210.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 268353F5A0; Wed, 6 Jun 2018 07:37:41 -0700 (PDT) Date: Wed, 6 Jun 2018 15:37:39 +0100 From: Quentin Perret To: Dietmar Eggemann Cc: peterz@infradead.org, rjw@rjwysocki.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, mingo@redhat.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, joelaf@google.com, smuckle@google.com, adharmap@quicinc.com, skannan@quicinc.com, pkondeti@codeaurora.org, juri.lelli@redhat.com, edubezval@gmail.com, srinivas.pandruvada@linux.intel.com, currojerez@riseup.net, javi.merino@kernel.org Subject: Re: [RFC PATCH v3 03/10] PM: Introduce an Energy Model management framework Message-ID: <20180606143739.GF10870@e108498-lin.cambridge.arm.com> References: <20180521142505.6522-1-quentin.perret@arm.com> <20180521142505.6522-4-quentin.perret@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dietmar, On Wednesday 06 Jun 2018 at 15:12:15 (+0200), Dietmar Eggemann wrote: > > +static void fd_update_cs_table(struct em_cs_table *cs_table, int cpu) > > +{ > > + unsigned long cmax = arch_scale_cpu_capacity(NULL, cpu); > > + int max_cap_state = cs_table->nr_cap_states - 1; > > + unsigned long fmax = cs_table->state[max_cap_state].frequency; > > + int i; > > + > > + for (i = 0; i < cs_table->nr_cap_states; i++) > > + cs_table->state[i].capacity = cmax * > > + cs_table->state[i].frequency / fmax; > > +} > > This has issues on a 32bit system. cs_table->state[i].capacity (unsigned > long) overflows with the frequency values stored in Hz. Ah, thank you very much for pointing this out ! I haven't tried on a 32bit machine yet, my bad. I'll fix that for v4. > > Maybe something like this to cure it: > > diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c > index 6ad53f1cf7e6..c13b3eb8bf35 100644 > --- a/kernel/power/energy_model.c > +++ b/kernel/power/energy_model.c > @@ -144,9 +144,11 @@ static void fd_update_cs_table(struct em_cs_table *cs_table, int cpu) > unsigned long fmax = cs_table->state[max_cap_state].frequency; > int i; > > - for (i = 0; i < cs_table->nr_cap_states; i++) > - cs_table->state[i].capacity = cmax * > - cs_table->state[i].frequency / fmax; > + for (i = 0; i < cs_table->nr_cap_states; i++) { > + u64 val = (u64)cmax * cs_table->state[i].frequency; > + do_div(val, fmax); > + cs_table->state[i].capacity = (unsigned long)val; > + } > } Hmmm yes, that should work. > > This brings me to another question. Let's say there are multiple users of > the Energy Model in the system. Shouldn't the units of frequency and power > not standardized, maybe Mhz and mW? > The task scheduler doesn't care since it is only interested in power diffs > but other user might do. So the good thing about specifying units is that we can probably assume ranges on the values. If the power is in mW, assuming that we're talking about a single CPU, it'll probably fit in 16 bits. 65W/core should be a reasonable upper-bound ? But there are also vendors who might not be happy with disclosing absolute values ... These are sometimes considered sensitive and only relative numbers are discussed publicly. Now, you can also argue that we already have units specified in IPA for ex, and that it doesn't really matter if a driver "lies" about the real value, as long as the ratios are correct. And I guess that anyone can do measurement on the hardware and get those values anyway. So specifying a unit (mW) for the power is probably a good idea. For the frequency, I would rather keep it consistent with what CPUFreq manages. But that should be specified somewhere, I agree. What do you think ? Thanks ! Quentin