From patchwork Tue Jun 29 06:27:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 468295 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4666378jao; Mon, 28 Jun 2021 23:27:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcbhFZWTt+zWMOsGV2HjTjhTexrI6Xljom5XQN4og8uJaqI6YDtAicBu3d9akTU/HCQaE3 X-Received: by 2002:a92:90a:: with SMTP id y10mr16274181ilg.144.1624948036926; Mon, 28 Jun 2021 23:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624948036; cv=none; d=google.com; s=arc-20160816; b=Io3+gFtnyBFpxvi5XSp/sdrZH4BFfOtESJvR9JALHG3JDGSGjFRHIbT7QDnJKV6EwE AXTt62nA/I+9rqpED0zUcHWYJKAKRKwZvaeFzBasj3pYyp7EdULjDK7s1cMgHBqXR4aB 8X2+swN5y7qntSLEBPL/LakMLm5c6J4WLdQvLZQp12pzLl1OABZjlGiCSaEqz5NEFbk6 tUFgwk5WLbBcvi03tWMdg/jtkAmWRgLG9wDsHTxLsRlRljM0sPksNqZYsGRHJTi6yMBE fwhxNnlsySLxoyeU5PNQizNmEOXBvfjrKe29Ec17+mdNthGXDxkEoQh4bV3OuqgkhnDi KtCw== 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=BGISjnwzW7G32rpq49+fP993YgWTn6MVdEWTJjnFnqsTqB9ubZrhkXW+uxi/8lQ5fl HYqdfmMM7csIhY/82BGaRV+sARcbQxyaNjfhxTn/LLriTKHpVnrmtZsbfxMng3Azxo+T IwaVhmYRXRFCUClqh5Uckr8IHcps9wGtgbVysHhZ+kY5TKg3wX3Qlk40aivlr6pmWCsZ JF/V7mrg9JEsAa1RJ7LwKhKA0QrPY/CTpNPN56QyrtXdZ+BjqsQNMcdvpe+LYTjSWuZy JXHmdOgoWsMeTOJEqnDiNsyvimnX1I9FxvWNoS+/iuuhrCLtSkFkIwz8vOiRhzS3GIjc qM5w== 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-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 t14si21310638jan.114.2021.06.28.23.27.16; Mon, 28 Jun 2021 23:27:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-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-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 S232105AbhF2G3l (ORCPT + 8 others); Tue, 29 Jun 2021 02:29:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232067AbhF2G3k (ORCPT ); Tue, 29 Jun 2021 02:29:40 -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 C13DDC061760 for ; Mon, 28 Jun 2021 23:27:12 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id a7so6859416pga.1 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=MuhOPKGdUh0vMYni7jxGVW8PApfNwm+WBT/0c0KkX5mTu71vO8GjaCNT6bM0bdqLxC /DnA+BFuEDE2O2rWfrQyFhWIo3Qb4/3fqboBys09Ga0xMPazMBhHbiAF+CbbjJf0Zjpt LiL1Mu0dDmRaojauOsb2di/vZ8D+sWrGRJKLP5W+ou69Z4pPOFR1BOIAf5/2dbxxjPrc ZlZH0FS9Ke5ZptgvBwds6CwN0G4P46CGsjsEh+5l+ilgY+EQBnCPd0fXc3x700evT3Mr xqWiuvXsDqd6D2dUPMb03bUDnuCWpdZCoJ86908hB8ouZgf+pOewtO7+OZ/i06GwZoRO GujA== X-Gm-Message-State: AOAM531dEhmg5rhyE9tB58NVDCJOq08IPHLQyxxeKmZ3Q65+/6/YXC04 XFQ/N+DXVeLzljEi4sQlW0uJBw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-pm@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(-) -- 2.31.1.272.g89b43f80a514 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);