Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2316864ybd; Thu, 27 Jun 2019 10:17:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAZ2ygmdL8VBWq0uJ4MJOmeIrHSC1BuHW4I9ZbJssvcbORs1wysU0KLKKLeYyYpbYZPYBi X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr6135953plb.30.1561655854432; Thu, 27 Jun 2019 10:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561655854; cv=none; d=google.com; s=arc-20160816; b=SIJm4yIlYJPoMCwY2dP7lKWQv/iMDKvj8IKdmWjAYeLAb5R1OypSimsM6OvIATLkBX 23+GqAmny8F657Ty2ztvayPXn1rfGQCfNUlyHQcAXk36pC1Uc0JamO4szoO4QhS4NkeM ckVnllI1jXEwadQuTDAbAWkYjFj5NdOZ5MEb7pKJlz3T1u4tj19M8ZIGqjDb9jAskP7t eQa+SWzDF/UGfqmH1ERznJE58U3wpIqgRCCd1GrZffwzetVYG0uZw2mGd+PS8Wvt2dxs ywy9B6xUeRYi21HgS62HlCJQEv5WsrMU1Jp1F8j2a8yOPAP6K+hBXBwuKnU11EWW3O46 tn2g== 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=fiG+F7sL4EBrgtREXygvjNGlGctvOYcRmCDzuSdryiw=; b=QNh1siL5Qa0I3GYYat5n+aeiqjbwaccOGPOpsSfBpgKu2euScPqsmtJSAsUc1LlMT+ QwoAfRnTcFMCz/JBcZz6OVDiDGPMPgbnx9KJnzrPlTnv1bGCJz+euObqHckbxUWcnf+u LkCUeuIf30KZ+TypEfNsOy709KXJ7VyTB+hSqVlb7Gpae4AENnu5qAM5i0DWvVcGfUQW lRPAcmVUWdwuoXfMkk5YkELHKU9DASuoP1aj1KdNuUjiehYjJEILrBaoB6imBfZOSc9c SlpJnyv04e5Y6GSQ1fGJunMNOq5+euoCvypomI1V9Q/3CqywxYGiiG8ueoTyfIpcVs9o vVGA== 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 u18si2503847pgk.506.2019.06.27.10.17.16; Thu, 27 Jun 2019 10:17:34 -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 S1726605AbfF0RQW (ORCPT + 99 others); Thu, 27 Jun 2019 13:16:22 -0400 Received: from foss.arm.com ([217.140.110.172]:59210 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbfF0RQU (ORCPT ); Thu, 27 Jun 2019 13:16:20 -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 68290D6E; Thu, 27 Jun 2019 10:16:19 -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 12E4A3F718; Thu, 27 Jun 2019 10:16:17 -0700 (PDT) From: Douglas RAILLARD To: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, rjw@rjwysocki.net, viresh.kumar@linaro.org, quentin.perret@arm.com, douglas.raillard@arm.com, patrick.bellasi@arm.com, dietmar.eggemann@arm.com Subject: [RFC PATCH v2 1/5] PM: Introduce em_pd_get_higher_freq() Date: Thu, 27 Jun 2019 18:15:59 +0100 Message-Id: <20190627171603.14767-2-douglas.raillard@arm.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190627171603.14767-1-douglas.raillard@arm.com> References: <20190627171603.14767-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 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. The efficiency of an OPP is measured as efficiency=capacity/power. OPPs with the same efficiency are assumed to be equivalent, since they will consume as much energy for a given amount of work to do. That may take more or less time depending on the frequency, but will consume the same energy. Signed-off-by: Douglas RAILLARD --- include/linux/energy_model.h | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index aa027f7bcb3e..cc9819967f8d 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; + 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 +229,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.22.0