From patchwork Thu May 26 02:53:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Muckle X-Patchwork-Id: 9136507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F373A607DA for ; Thu, 26 May 2016 02:54:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E65FD27EE9 for ; Thu, 26 May 2016 02:54:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB418280E5; Thu, 26 May 2016 02:54:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6767428195 for ; Thu, 26 May 2016 02:54:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753255AbcEZCyB (ORCPT ); Wed, 25 May 2016 22:54:01 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:34873 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752861AbcEZCxH (ORCPT ); Wed, 25 May 2016 22:53:07 -0400 Received: by mail-pa0-f49.google.com with SMTP id fy7so8379337pac.2 for ; Wed, 25 May 2016 19:53:07 -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; bh=xiVrgWSeyy4+A9RuCea6pwDW6mbPDu6jZk9RSyqKHVc=; b=BK19QwhoYSuE/nu3apDUEesaMEuTyccOhCJk4p/4Gm3wv9cc4EFxJnBghev+UlbzOb tpYbA4BAmT1u2cOQrHIvaOD8CKso21yEDXQT4JLLoT1HL0ZdgVhIOwkoKu2QaTnxsA5x qsc+bwVCjmtxXI1c9KqfUfsoPnH76WlOc5+yQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xiVrgWSeyy4+A9RuCea6pwDW6mbPDu6jZk9RSyqKHVc=; b=FJBfEQCEblDLk0xaOO+PLALZUgRpMF4oawB4J9Q3SWsPLH3aE3xTTv7zcSfWw98M8F NMOFeWD0Zsuv4QTl1ctsDtFLwo873ISYY7ovPJtYA/AQlD+4SjX0l9A5vedamI/ZcMuU FoE1F04KmPlnh1yadvUyZ9fwLgwInqzmwefBsIbrmGeOKSzq7vArzi6AIjjzlUQcRjPX SM5kzGuln+D2mvM23DlXK+4ZQmJyb+1m9N8Y3lh+qraUDzqT0fI/HYvBMRbcBC1DpwuZ 48aWdtkzpvufUnjI8dPKcNYGcfQymBWseXHYOvDOfUIf8YATGUYUTp4diMZGf5ErUI9f Pvvw== X-Gm-Message-State: ALyK8tJ/2oPDoL9EEBDyTIspqZSUPLAzUYUsrqTEUlTjGmSnXm57Hz/80all3I9FoaTMKKGn X-Received: by 10.66.222.202 with SMTP id qo10mr10288103pac.141.1464231186356; Wed, 25 May 2016 19:53:06 -0700 (PDT) Received: from graphite.smuckle.net (cpe-76-167-105-107.san.res.rr.com. [76.167.105.107]) by smtp.gmail.com with ESMTPSA id g82sm1540634pfj.22.2016.05.25.19.53.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 May 2016 19:53:05 -0700 (PDT) From: Steve Muckle X-Google-Original-From: Steve Muckle To: Peter Zijlstra , Ingo Molnar , "Rafael J. Wysocki" , Viresh Kumar Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Juri Lelli , Patrick Bellasi , Michael Turquette Subject: [PATCH v2 2/3] cpufreq: acpi-cpufreq: add resolve_freq callback Date: Wed, 25 May 2016 19:53:00 -0700 Message-Id: <1464231181-30741-3-git-send-email-smuckle@linaro.org> X-Mailer: git-send-email 2.4.10 In-Reply-To: <1464231181-30741-1-git-send-email-smuckle@linaro.org> References: <1464231181-30741-1-git-send-email-smuckle@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Support the new resolve_freq cpufreq callback which resolves a target frequency to a driver-supported frequency without actually setting it. The target frequency and resolved frequency table entry are cached so that a subsequent fast_switch operation may avoid the frequency table walk assuming the requested target frequency is the same. Suggested-by: Rafael J. Wysocki Signed-off-by: Steve Muckle --- drivers/cpufreq/acpi-cpufreq.c | 56 ++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c index 7f38fb55f223..d87962eda1ed 100644 --- a/drivers/cpufreq/acpi-cpufreq.c +++ b/drivers/cpufreq/acpi-cpufreq.c @@ -66,6 +66,8 @@ enum { struct acpi_cpufreq_data { struct cpufreq_frequency_table *freq_table; + unsigned int cached_lookup_freq; + struct cpufreq_frequency_table *cached_lookup_entry; unsigned int resume; unsigned int cpu_feature; unsigned int acpi_perf_cpu; @@ -458,26 +460,53 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy, return result; } -unsigned int acpi_cpufreq_fast_switch(struct cpufreq_policy *policy, - unsigned int target_freq) +/* + * Find the closest frequency above target_freq. + * + * The table is sorted in the reverse order with respect to the + * frequency and all of the entries are valid (see the initialization). + */ +static inline struct cpufreq_frequency_table +*lookup_freq(struct cpufreq_frequency_table *table, unsigned int target_freq) { - struct acpi_cpufreq_data *data = policy->driver_data; - struct acpi_processor_performance *perf; - struct cpufreq_frequency_table *entry; - unsigned int next_perf_state, next_freq, freq; + struct cpufreq_frequency_table *entry = table; + unsigned int freq; - /* - * Find the closest frequency above target_freq. - * - * The table is sorted in the reverse order with respect to the - * frequency and all of the entries are valid (see the initialization). - */ - entry = data->freq_table; do { entry++; freq = entry->frequency; } while (freq >= target_freq && freq != CPUFREQ_TABLE_END); entry--; + + return entry; +} + +unsigned int acpi_cpufreq_resolve_freq(struct cpufreq_policy *policy, + unsigned int target_freq) +{ + struct acpi_cpufreq_data *data = policy->driver_data; + struct cpufreq_frequency_table *entry; + + data->cached_lookup_freq = target_freq; + entry = lookup_freq(data->freq_table, target_freq); + data->cached_lookup_entry = entry; + + return entry->frequency; +} + +unsigned int acpi_cpufreq_fast_switch(struct cpufreq_policy *policy, + unsigned int target_freq) +{ + struct acpi_cpufreq_data *data = policy->driver_data; + struct acpi_processor_performance *perf; + struct cpufreq_frequency_table *entry; + unsigned int next_perf_state, next_freq; + + if (data->cached_lookup_entry && + data->cached_lookup_freq == target_freq) + entry = data->cached_lookup_entry; + else + entry = lookup_freq(data->freq_table, target_freq); next_freq = entry->frequency; next_perf_state = entry->driver_data; @@ -918,6 +947,7 @@ static struct cpufreq_driver acpi_cpufreq_driver = { .verify = cpufreq_generic_frequency_table_verify, .target_index = acpi_cpufreq_target, .fast_switch = acpi_cpufreq_fast_switch, + .resolve_freq = acpi_cpufreq_resolve_freq, .bios_limit = acpi_processor_get_bios_limit, .init = acpi_cpufreq_cpu_init, .exit = acpi_cpufreq_cpu_exit,