Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp875011ybg; Fri, 18 Oct 2019 08:38:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoqGXWQpgKWPDmVczjkQpNqgoan7g8diPrHFDqodZngykfvx2zck4pAQ0t5WQrU3eE8m9s X-Received: by 2002:a17:906:edb7:: with SMTP id sa23mr9380854ejb.263.1571413119118; Fri, 18 Oct 2019 08:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571413119; cv=none; d=google.com; s=arc-20160816; b=KFGngHuqQ1PG7iieSm14Kp0YGRjvIYMsdRqOi9qwKQO+D376tY/x994WDcCKjDoBM1 YCQl1TqbG1PIa2DhWo4A3eeBWr6wdnMr96AoAy74Frq2ctZlG7M1zfKiySyQQ+Q6SXaR RE6ojqle2VZ6tFeyVlqq3VT36Rq+SfzPyj6jlx41fF9Hgxuc4iHs861xVzD7lCrXpbBB KAkS/gxjVXgxZ6Fix0LTOzFxygEfC9vVJ9fgk8xweWaEiu9QSrXFYbKKPs0DhGA5NUeF mwIQN4nxSISBRYzo7NIwCb10DeZTar+Jywf42rxvRx3P80/ZEAX+lv4KCzjhtJk0isJ7 Wtrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=koiOpZ1sf1C0Hhw524VzePFSwa0TMlY8sd+s+eTwddk=; b=N1VfrL0ELxaDdqOabcMqmHRHjIn1NAOJr9oxnwBXTWdgfnx7f2neEMCBgU0LxctXhy 3P/lLe3mauHYou+GF7PR7DUXfgVrwyJjFdjhjuQddTSIjBaL2UVYk6zoAy9WujjUCMba zJdA0LopyrpJdZzAl0PGOYwszJg+lMwID+MRELRPW/7ByiWQisQdXECxjbwa6y4rtw4M pSLBgDW6zd0upCvubW8wdvgwCP+regepaMeaJ11pgGoa9CKymfy/AL8+cRSbz4koCPyX cQPgJU8JDOGSgFMhCtOzCHo4qAvXViWl0xb7TqPhPxIX8Repsmz5Zphi/Dw4/ueOCcRt Kygg== 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 c21si3638244ejx.295.2019.10.18.08.38.16; Fri, 18 Oct 2019 08: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 S2502025AbfJQLKF (ORCPT + 99 others); Thu, 17 Oct 2019 07:10:05 -0400 Received: from [217.140.110.172] ([217.140.110.172]:39476 "EHLO foss.arm.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S2405285AbfJQLKF (ORCPT ); Thu, 17 Oct 2019 07:10:05 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68ED71BA8; Thu, 17 Oct 2019 04:09:40 -0700 (PDT) Received: from [10.1.195.43] (unknown [10.1.195.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C98223F718; Thu, 17 Oct 2019 04:09:38 -0700 (PDT) Subject: Re: [RFC PATCH v3 1/6] PM: Introduce em_pd_get_higher_freq() To: Dietmar Eggemann , linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, rjw@rjwysocki.net, viresh.kumar@linaro.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, qperret@qperret.net, patrick.bellasi@matbug.net, dh.han@samsung.com References: <20191011134500.235736-1-douglas.raillard@arm.com> <20191011134500.235736-2-douglas.raillard@arm.com> <5aa79534-7059-09e7-00b8-752f6699f9d4@arm.com> From: Douglas Raillard Organization: ARM Message-ID: <9cb03bd7-af7c-df8b-e9d0-cd5db3ddda0b@arm.com> Date: Thu, 17 Oct 2019 12:09:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: <5aa79534-7059-09e7-00b8-752f6699f9d4@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB-large Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dietmar, On 10/17/19 10:58 AM, Dietmar Eggemann wrote: > On 11/10/2019 15:44, Douglas RAILLARD wrote: > > [...] > >> diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h >> index d249b88a4d5a..dd6a35f099ea 100644 >> --- a/include/linux/energy_model.h >> +++ b/include/linux/energy_model.h >> @@ -159,6 +159,53 @@ static inline int em_pd_nr_cap_states(struct em_perf_domain *pd) >> return pd->nr_cap_states; >> } >> >> +#define EM_COST_MARGIN_SCALE 1024U >> + >> +/** >> + * em_pd_get_higher_freq() - Get the highest frequency that does not exceed the >> + * given cost margin compared to min_freq >> + * @pd : performance domain for which this must be done >> + * @min_freq : minimum frequency to return >> + * @cost_margin : allowed margin compared to min_freq, on the >> + * EM_COST_MARGIN_SCALE scale. >> + * >> + * Return: the chosen frequency, guaranteed to be at least as high as min_freq. >> + */ >> +static inline unsigned long em_pd_get_higher_freq(struct em_perf_domain *pd, >> + unsigned long min_freq, unsigned long cost_margin) >> +{ >> + unsigned long max_cost = 0; >> + struct em_cap_state *cs; >> + int i; >> + >> + if (!pd) >> + return min_freq; >> + >> + /* Compute the maximum allowed cost */ >> + for (i = 0; i < pd->nr_cap_states; i++) { >> + cs = &pd->table[i]; >> + if (cs->frequency >= min_freq) { >> + max_cost = cs->cost + >> + (cs->cost * cost_margin) / EM_COST_MARGIN_SCALE; > > Maybe you could mention in the header that this is the place where the > algorithm could be tuned. (even though it doesn't offer any tuning > interface, which is a good thing). I'm not sure what you mean, the patch "title" contains "em_pd_get_higher_freq()", should it also mention where exactly inside the function the margin logic is implemented ? >> + break; >> + } >> + } >> + >> + /* Find the highest frequency that will not exceed the cost margin */ >> + for (i = pd->nr_cap_states-1; i >= 0; i--) { >> + cs = &pd->table[i]; >> + if (cs->cost <= max_cost) >> + return cs->frequency; >> + } >> + >> + /* >> + * We should normally never reach here, unless min_freq was higher than >> + * the highest available frequency, which is not expected to happen. >> + */ > > Maybe add a WARN_ONCE(1, "foobar"); here to indicate this unlikely event > (CPUfreq and EM framwork out of sync)? Will do. > [...] >