Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5332434yba; Wed, 8 May 2019 11:29:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTu+HScqBUc1r46kxnGMtMQSPhpvfGrm+jwFay8yGBEHUwngne9QQ3EOI9D7HHVdfLcmfM X-Received: by 2002:a65:6091:: with SMTP id t17mr48632781pgu.328.1557340140974; Wed, 08 May 2019 11:29:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557340140; cv=none; d=google.com; s=arc-20160816; b=jSlaLt0WDMIHV9VNj4BKPhUjbRYTpPymupfYTcCGATwyAiaPP2nsb7AlulEsNaTDkd O3y+rp1QZ76Zxmm6FTqcmpn88WI1u3jGWYQwuVXNJgdhLeghtPmZBpqlCCdctDMSkLyf lByzM8GXZCaYOuvRcCDpUIgd81iTVMdgs4aHST2fQroQgMa5GfkUXKR78S6oZtDCLqGG wxUraCqTeI4QZWy8vX5lT6jc7FQHC6olSunr7SNVaPLB5SrUx9yc+FtzU7LSCaTjdkr+ YFkVS4rpwXM4gqe8LQRhI21SuqQpiSJjJVoNwFatB3jKwggIC0aib2jrVQX9fS/vd+Yp XE7g== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=QIKGSCtQyvXIq4ncrclLdVJA+1ppoTRASjrW56+yr/c=; b=D00vGxnY1YHrXLeVKgANO6tJEWGZ2r7BBAkZ5huVCLmHc1uf2BwLcdXaT8TQ5NWNPW Rww3OD4RkebsySyM/Ro/n11Z5aSkjtX9lPPBjL4KO3JHwe4s2UU+UPEHPDnauPPiASpp 8wYfLvLTaWJctLlhL5cSUSmlBCDpo0m4196rkGtckiBQaO+2cCB7ouDkPPkLmTMbEpS6 XTGl12Chnr/95XFdqpnPkAYJfjICSdRYfWtYhCoV3WRS6764LU5SYJIba2+XX9jukeBz /4aSffMxyX6cBjv7TuHFb3GhrpcMXERBvZcgxybhJkcYKdSdclkCyKXqSsMG3qofy/xd NNEA== 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 o15si13659122pgh.181.2019.05.08.11.28.43; Wed, 08 May 2019 11:29:00 -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 S1729064AbfEHRnM (ORCPT + 99 others); Wed, 8 May 2019 13:43:12 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:41792 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725910AbfEHRnK (ORCPT ); Wed, 8 May 2019 13:43:10 -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 16EC8A78; Wed, 8 May 2019 10:43:10 -0700 (PDT) Received: from e107049-lin.arm.com (e107049-lin.cambridge.arm.com [10.1.195.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 909CD3F575; Wed, 8 May 2019 10:43:08 -0700 (PDT) From: douglas.raillard@arm.com To: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, quentin.perret@arm.com, douglas.raillard@arm.com, patrick.bellasi@arm.com, dietmar.eggemann@arm.com Subject: [RFC PATCH 1/7] PM: Introduce em_pd_get_higher_freq() Date: Wed, 8 May 2019 18:42:55 +0100 Message-Id: <20190508174301.4828-2-douglas.raillard@arm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190508174301.4828-1-douglas.raillard@arm.com> References: <20190508174301.4828-1-douglas.raillard@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Douglas RAILLARD em_pd_get_higher_freq() returns a frequency greater or equal to the provided one while taking into account a given cost margin. It also skips inefficient OPPs that have a higher cost than another one with a higher frequency. Signed-off-by: Douglas RAILLARD --- include/linux/energy_model.h | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index aa027f7bcb3e..797b4e0f758c 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -159,6 +159,48 @@ static inline int em_pd_nr_cap_states(struct em_perf_domain *pd) return pd->nr_cap_states; } +/** + * 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, as a per-1024 value. + * + * 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) / 1024; + 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. + */ + return min_freq; +} + #else struct em_perf_domain {}; struct em_data_callback {}; @@ -182,6 +224,12 @@ static inline int em_pd_nr_cap_states(struct em_perf_domain *pd) { return 0; } + +static inline unsigned long em_pd_get_higher_freq(struct em_perf_domain *pd, + unsigned long min_freq, unsigned long cost_margin) +{ + return min_freq; +} #endif #endif -- 2.21.0