Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4142678pxv; Mon, 28 Jun 2021 23:28:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVwUzDqWNKeoLQnnFIyJh1qtt9obtcF6+9muFgaEoRlmL1GXZAjWCIuWputCNveP3NfGHt X-Received: by 2002:a17:906:718b:: with SMTP id h11mr28396702ejk.418.1624948114543; Mon, 28 Jun 2021 23:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624948114; cv=none; d=google.com; s=arc-20160816; b=r3rwZlh9EIj9RPGeAQ13YB7/4fmG4KaoFSodwTwsN8BUAlPJ09rnV393VfgXq4OUfP EmeHV4yL/i9TGsB0vvEk2iqsQfO2DNwAkFI9peGoenI55PVj3N+jhX5EL7czrRM+4RU/ r5mLvINW9h9p9vsy4jI3z8JAtqy3cW5PjEsRMluMUlx4IgYWgxpN//HBoNZj7JeJZRWh lP29HKKZlKSx0wHQPCR9a95Ag9R4Uft0NBuSJ/3xynquThgRBhYJveAn28HQ1o5AJkKE HSQjWZ5sOULimpem/UZc2c0T8SN6Pc6W2kauJppzAcH4/WzojExxixWahAcQqK357WEK SSYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=90DPEws+T5jbJDd5gSYlJAos9OyAfId3/wh6BJdGeVI=; b=IFbn2NEL/u1VOi5YL5hactH7jl9Y6E0q/Su8TP29eyEEsqsdaAX/Q/+xpsIl27BsHX ydm9C4NGLI89jEuonP/8a6Ab5c0bNE8SMpt8e2qcd7f8ybI3FbSlRKF+sqNKx0fc5xPX cfYGSkwqw1Pi0ZP31ahw+pSijO9xdKVniHJv27xQOBCYPW3YmfHbBEVUa2vooIli8zXj UWsc4fjSOvu3vlAbO8f63smRKmuHXWyk+ptzDZmU9oObRznO9ocSk2D107cjF3737Yad jwE/w7HKITn6GXhdfSJjNJMcsDcoU2clolWvG2qVzgtR9rd5OE0hFMdlLxn4RegUoCfU 0d1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BXLrq2CS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id my47si2475535ejc.65.2021.06.28.23.28.10; Mon, 28 Jun 2021 23:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BXLrq2CS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231958AbhF2G3k (ORCPT + 99 others); Tue, 29 Jun 2021 02:29:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbhF2G3j (ORCPT ); Tue, 29 Jun 2021 02:29:39 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C137AC061574 for ; Mon, 28 Jun 2021 23:27:12 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id m2so17574240pgk.7 for ; Mon, 28 Jun 2021 23:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=90DPEws+T5jbJDd5gSYlJAos9OyAfId3/wh6BJdGeVI=; b=BXLrq2CSiwTpbmLAXk57CIlMkOyaNg5YEcH48MFFMMUWhOFMXWcMF81PHkXPhFuc5q YlgnxZIl/ml6fq4dN4aiod0P2+VePzZvb+klia3wsWgAUhxHjvJEAFpOdgLjnp4S3Gzq 7Gn6nkDfGeHzRmFi6WVfP4/Wu41okjMWGRV0HeZZmEeVpvsqDc+XM4QAPut+zVOx++jP G11/y8c2VcWGe+hHRiknlfhuTw8vlZw73LnNEiCa6Kky0mmqEjrbVC8CH55wUMEqvaxk jWVLw7DDgKqOjSgUaefXDD8vWktxm5nySRMRwnCtNYz9Pbwajx44QlMZgG47ey1UKzeE Bc9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=90DPEws+T5jbJDd5gSYlJAos9OyAfId3/wh6BJdGeVI=; b=UsqGnCgGQjWYOjoH2x7g2jFqxddajyWLLn6R4cWYkkc4eMdjXrliYzTp7k89PhI/4l ifkI9EZIi2HRn3rPuJ32KYPRPYfNqb+1B1hB4AQCGuMJF6pdmH6lSBW1wU+dB3b7Gb5G FD4CLc5mEBB+Dn6wHVJ33EkRyZOPDkDxtJeEMWWO3qkZchxAfC6mpUhLJoot48uKJDIv wBYdYzQUOmBzGCHEFlhG/rhlBnJ8iSSyg7vW7CNiv+kKTYjlLfLbW1Hu5IEZSERVkrNd X8kspqTjXZOe8QBe16d/E8bmOXiSCaL7lH+9d6sabsf4oAWlHoinERYW/6eswDOWEYx0 oAYw== X-Gm-Message-State: AOAM532C1+GBBREmVxd7G7uVi9hTP3W+YAfmvM3SFt7OSWg1CXcuJQLo eiQXrPYP9zkgx8Qiyl/7pyS9sg== X-Received: by 2002:a05:6a00:21c7:b029:2ec:2bfa:d0d1 with SMTP id t7-20020a056a0021c7b02902ec2bfad0d1mr28683696pfj.14.1624948032234; Mon, 28 Jun 2021 23:27:12 -0700 (PDT) Received: from localhost ([136.185.134.182]) by smtp.gmail.com with ESMTPSA id n4sm16811702pfo.188.2021.06.28.23.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 23:27:11 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , TungChen Shih , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] cpufreq: Reuse cpufreq_driver_resolve_freq() in __cpufreq_driver_target() Date: Tue, 29 Jun 2021 11:57:07 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __cpufreq_driver_target() open codes cpufreq_driver_resolve_freq(), lets make the former reuse the later. Separate out __resolve_freq() to accept relation as well as an argument and use it at both the locations. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 42 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 802abc925b2a..d691c6c97c79 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -524,19 +524,8 @@ void cpufreq_disable_fast_switch(struct cpufreq_policy *policy) } EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch); -/** - * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported - * one. - * @policy: associated policy to interrogate - * @target_freq: target frequency to resolve. - * - * The target to driver frequency mapping is cached in the policy. - * - * Return: Lowest driver-supported frequency greater than or equal to the - * given target_freq, subject to policy (min/max) and driver limitations. - */ -unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, - unsigned int target_freq) +static unsigned int __resolve_freq(struct cpufreq_policy *policy, + unsigned int target_freq, unsigned int relation) { target_freq = clamp_val(target_freq, policy->min, policy->max); policy->cached_target_freq = target_freq; @@ -545,7 +534,7 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, unsigned int idx; idx = cpufreq_frequency_table_target(policy, target_freq, - CPUFREQ_RELATION_L); + relation); policy->cached_resolved_idx = idx; return policy->freq_table[idx].frequency; } @@ -555,6 +544,23 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, return target_freq; } + +/** + * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported + * one. + * @policy: associated policy to interrogate + * @target_freq: target frequency to resolve. + * + * The target to driver frequency mapping is cached in the policy. + * + * Return: Lowest driver-supported frequency greater than or equal to the + * given target_freq, subject to policy (min/max) and driver limitations. + */ +unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, + unsigned int target_freq) +{ + return __resolve_freq(policy, target_freq, CPUFREQ_RELATION_L); +} EXPORT_SYMBOL_GPL(cpufreq_driver_resolve_freq); unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy) @@ -2225,13 +2231,11 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int relation) { unsigned int old_target_freq = target_freq; - int index; if (cpufreq_disabled()) return -ENODEV; - /* Make sure that target_freq is within supported range */ - target_freq = clamp_val(target_freq, policy->min, policy->max); + target_freq = __resolve_freq(policy, target_freq, relation); pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n", policy->cpu, target_freq, relation, old_target_freq); @@ -2252,9 +2256,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, if (!cpufreq_driver->target_index) return -EINVAL; - index = cpufreq_frequency_table_target(policy, target_freq, relation); - - return __target_index(policy, index); + return __target_index(policy, policy->cached_resolved_idx); } EXPORT_SYMBOL_GPL(__cpufreq_driver_target); -- 2.31.1.272.g89b43f80a514