From patchwork Wed Jun 19 11:35:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 167226 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp500685ock; Wed, 19 Jun 2019 04:36:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBXVe2Ox7IWnvcRfQPMk+jQ/KdDDQXpFURv9MHy+BLMQ2Z43h37E0lH5YrxfxzVsO+VbOl X-Received: by 2002:a62:e71a:: with SMTP id s26mr78861190pfh.89.1560944166678; Wed, 19 Jun 2019 04:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560944166; cv=none; d=google.com; s=arc-20160816; b=bPxTPmzsf+c4XgD5kk11GDfWBaIq+yARhMZvLs+zzEHgrjyVAR5aVw5uHr8B7+PshV EZZfSPNz0f7MMhGBZ8+REEdpIFiZo2GzrhhF/Gx4l5ez5SnpUCQ8U5hau9A7BCSbzFso 82Pp/+Fdd0kmaoAM2hns64WlXuPsHn2b/Yel0O+GXo9ZhZ0RvlyV9DQIu12t3VfmeYl8 rEksTDJJnhm/pRca7vk4SEwzEq2mxIdMcEjvX5U6HumE8XD7I+k449kXmY0ezgz3Kuxp yUKN6IN/u/ohO0IZRLsJR6zkkXkua8ZJtzBpEDbChLLXW1Hpn2Ubt4uBFywFPh+vWNrY qr4g== 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 :dkim-signature; bh=TMflq8N+0gjwZQm7aaR4fEWjevpmJ2Km/I3/aGC/zcs=; b=Bg5oV/YsK0J06fnXeTzZYdM7L3r1FuRfTeAsfyyCwJ6L05Tfg2XmjHTKu74db+XUPQ +rqP9Vhs4ZyXDdXOWJ0RQMPKDKdGbJF5lLKNOzBuNeo30uKtGjGl3SWbcDfxTO4NhW89 9e5IqZtHSMAX39wDtoDWUkr6ocJ8AizbHbhtX+gFEsG4bXovZ+kCxVYJ5/qhiXF3+og+ zTdUZOO58CA+tc2eYUjms8T2rPLcD6eqSlyvMrsdllxCB6CuWqZi8U1ea7RkDRrV8nJ2 otD4KM6ZO4C+JNzA+rxW1ptpOVt6JMCeZOGIlNYxNsPEa2Sb0I4MVJrbc9GkgZdSIxVn BwyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FdhMZ5VF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t14si2866146pgh.51.2019.06.19.04.36.06; Wed, 19 Jun 2019 04:36:06 -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; dkim=pass header.i=@linaro.org header.s=google header.b=FdhMZ5VF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731741AbfFSLgE (ORCPT + 30 others); Wed, 19 Jun 2019 07:36:04 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:33546 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731730AbfFSLgC (ORCPT ); Wed, 19 Jun 2019 07:36:02 -0400 Received: by mail-pg1-f196.google.com with SMTP id k187so9517726pga.0 for ; Wed, 19 Jun 2019 04:36:02 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=TMflq8N+0gjwZQm7aaR4fEWjevpmJ2Km/I3/aGC/zcs=; b=FdhMZ5VF0ZlGiskIF3jgzAyN072YIAf8CvQqewDd0mnEaGbolSAhEnuX5Cq4LC5zRH aM31xTVnkg/TW7axh+cs9Fv1mqqGwLcliyaPdxkndf1u8/v1fc8dTAFuywqoCTp6QaLg 1QC1rXXUqHbJzrxS/e1mHKXet73M40N7pRUVBDVWIPaXoveXLHOZlNtBQM9lLKigUjMi YJZQuUY8NO6X4y28v4rZ0+exHioxdYQBGU4gzqp1Rp5Bdv4BopUg/slx70RceyBLWPrl 5pk8DEg5vDKH/ADqzJCnW0631EQGKVXqwnO41gTFGtOQJeZKB8RYvk26d89wm4YcT7gw Td4w== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=TMflq8N+0gjwZQm7aaR4fEWjevpmJ2Km/I3/aGC/zcs=; b=t7MvC1iOUafpv7xC6n95Oylrb7iTyuu4JnEROxTWaTDcq35Oqtri5m1t79LiBdLCsq b8rjUnDRHN1imDxCQmz45rFuR8DqBF8zarmD6o5ltURlHikQ0zQmCVI6xVnWTwv1l+u+ qpHK22LbLYmKbBQFkwLzaLlYyef7J/+BO/bZhE9NS11hXS5m5HJWaK9arqECeS64SlbT XpW8CyfsVjjtmweiOM4S3DOaVE1KewafIcqBlnbEzsFosCZDBkxCW9nRdZaoOPEdj4bI b5F7oBsI4SMVN7q1tvrlaFG7Xtr2SKBJGBvpsBYBnz3AldAv1C6jV7++QZDbBzZ3wSMa XEDQ== X-Gm-Message-State: APjAAAUI5RvGMK7B/DKrXwDpNuBu+z07DTCgwz84r+0yMbWcZueM0ZIZ iISAaQNeuQt26Y+B11FvRO85Lg== X-Received: by 2002:aa7:9a8a:: with SMTP id w10mr9164646pfi.66.1560944162249; Wed, 19 Jun 2019 04:36:02 -0700 (PDT) Received: from localhost ([122.172.66.84]) by smtp.gmail.com with ESMTPSA id s24sm18124738pfh.133.2019.06.19.04.36.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jun 2019 04:36:01 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 5/6] cpufreq: Reuse cpufreq_update_current_freq() in __cpufreq_get() Date: Wed, 19 Jun 2019 17:05:41 +0530 Message-Id: <3887524d339664c31b763963f1b34bda490cb1ac.1560944014.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Their implementations are quite similar, lets modify cpufreq_update_current_freq() a little and use it from __cpufreq_get(). Also rename cpufreq_update_current_freq() to cpufreq_verify_current_freq(), as that's what it is doing. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 70 ++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 42 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 5f5c7a516c74..4556a53fc764 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1547,6 +1547,30 @@ static void cpufreq_out_of_sync(struct cpufreq_policy *policy, cpufreq_freq_transition_end(policy, &freqs, 0); } +static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, bool update) +{ + unsigned int new_freq; + + new_freq = cpufreq_driver->get(policy->cpu); + if (!new_freq) + return 0; + + /* + * If fast frequency switching is used with the given policy, the check + * against policy->cur is pointless, so skip it in that case. + */ + if (policy->fast_switch_enabled || !has_target()) + return new_freq; + + if (policy->cur != new_freq) { + cpufreq_out_of_sync(policy, new_freq); + if (update) + schedule_work(&policy->update); + } + + return new_freq; +} + /** * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur * @cpu: CPU number @@ -1602,30 +1626,10 @@ EXPORT_SYMBOL(cpufreq_quick_get_max); static unsigned int __cpufreq_get(struct cpufreq_policy *policy) { - unsigned int ret_freq = 0; - if (unlikely(policy_is_inactive(policy))) - return ret_freq; - - ret_freq = cpufreq_driver->get(policy->cpu); - - /* - * If fast frequency switching is used with the given policy, the check - * against policy->cur is pointless, so skip it in that case too. - */ - if (policy->fast_switch_enabled) - return ret_freq; - - if (has_target() && ret_freq && policy->cur) { - /* verify no discrepancy between actual and - saved value exists */ - if (unlikely(ret_freq != policy->cur)) { - cpufreq_out_of_sync(policy, ret_freq); - schedule_work(&policy->update); - } - } + return 0; - return ret_freq; + return cpufreq_verify_current_freq(policy, true); } /** @@ -1652,24 +1656,6 @@ unsigned int cpufreq_get(unsigned int cpu) } EXPORT_SYMBOL(cpufreq_get); -static unsigned int cpufreq_update_current_freq(struct cpufreq_policy *policy) -{ - unsigned int new_freq; - - new_freq = cpufreq_driver->get(policy->cpu); - if (!new_freq) - return 0; - - if (!policy->cur) { - pr_debug("cpufreq: Driver did not initialize current freq\n"); - policy->cur = new_freq; - } else if (policy->cur != new_freq && has_target()) { - cpufreq_out_of_sync(policy, new_freq); - } - - return new_freq; -} - static struct subsys_interface cpufreq_interface = { .name = "cpufreq", .subsys = &cpu_subsys, @@ -2151,7 +2137,7 @@ static int cpufreq_start_governor(struct cpufreq_policy *policy) pr_debug("%s: for CPU %u\n", __func__, policy->cpu); if (cpufreq_driver->get) - cpufreq_update_current_freq(policy); + cpufreq_verify_current_freq(policy, false); if (policy->governor->start) { ret = policy->governor->start(policy); @@ -2402,7 +2388,7 @@ void cpufreq_update_policy(unsigned int cpu) * -> ask driver for current freq and notify governors about a change */ if (cpufreq_driver->get && has_target() && - (cpufreq_suspended || WARN_ON(!cpufreq_update_current_freq(policy)))) + (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false)))) goto unlock; pr_debug("updating policy for CPU %u\n", cpu);