From patchwork Wed Jul 13 20:25:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Muckle X-Patchwork-Id: 9228435 X-Patchwork-Delegate: rjw@sisk.pl 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 53BD860868 for ; Wed, 13 Jul 2016 20:26:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45BE327FBB for ; Wed, 13 Jul 2016 20:26:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A9432807E; Wed, 13 Jul 2016 20:26:00 +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=ham 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 795C82807B for ; Wed, 13 Jul 2016 20:25:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751160AbcGMUZ4 (ORCPT ); Wed, 13 Jul 2016 16:25:56 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:34295 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751001AbcGMUZr (ORCPT ); Wed, 13 Jul 2016 16:25:47 -0400 Received: by mail-pa0-f48.google.com with SMTP id fi15so20808038pac.1 for ; Wed, 13 Jul 2016 13:25:46 -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=PhavLCNBGelvbb10Wo49oOCXSXpQfQdWHYTea9DNCks=; b=fFaJkbigCqjbEyQQBQRc1gYxPMPMYaoR+ytJW+cXhzaSYMDK3TxseH9x+IShYISGkl hYHMpyDmemeVphEAD/i8g6AGlEixdQ0KOe5n8H/pF3jmTQWbbJskU7POWEUAH8zd0jlS VFuhKIMsVG7c1VfZl9QBAgDc7aMKj9dIqWT9Q= 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=PhavLCNBGelvbb10Wo49oOCXSXpQfQdWHYTea9DNCks=; b=Lz5aFgBIg26LXNn6MudUMvUQ5H1xD6svr7ewJUIwV99IWPRsZnXr7hFBrSbTxgJk1c XpBIFy9L0+8YQB0nNCpKg8z2KWSEIWDBgj0r/bcB+d3wDJh3pt1wffDetITV7erqhxTn qUG+G8klqCJGSSQGrmoT3yV9JlnKffjL4vdV8Am6ncSitx9Oywx3+OPU1qBS2ITeAnLb cm0xOwle1e9QB6QGMQu+JIQwzGywt+zSI6kmj6Dj0tQlLyG7751hmaOWWqYAlO/3MnRH UyfGRul8aiBz4YpPcaFnUT0AEBmZDxmtEeHcAsJhypQVapqaPL0VrQiyhjMNobCYMpOE 5rnw== X-Gm-Message-State: ALyK8tJpiwb/CJz7xRlv8lqDc+aWo36J+znz9m44+esJxMZmpawNoe5tmMGPKomZaI072gsn X-Received: by 10.66.232.37 with SMTP id tl5mr16540524pac.13.1468441540399; Wed, 13 Jul 2016 13:25:40 -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 o80sm115466pfa.67.2016.07.13.13.25.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Jul 2016 13:25:39 -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 , Steve Muckle Subject: [PATCH v3 1/3] cpufreq: add cpufreq_driver_resolve_freq() Date: Wed, 13 Jul 2016 13:25:25 -0700 Message-Id: <1468441527-23534-2-git-send-email-smuckle@linaro.org> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1468441527-23534-1-git-send-email-smuckle@linaro.org> References: <1468441527-23534-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 Cpufreq governors may need to know what a particular target frequency maps to in the driver without necessarily wanting to set the frequency. Support this operation via a new cpufreq API, cpufreq_driver_resolve_freq(). This API returns the lowest driver frequency equal or greater than the target frequency (CPUFREQ_RELATION_L), subject to any policy (min/max) or driver limitations. The mapping is also cached in the policy so that a subsequent fast_switch operation can avoid repeating the same lookup. The API will call a new cpufreq driver callback, resolve_freq(), if it has been registered by the driver. Otherwise the frequency is resolved via cpufreq_frequency_table_target(). Rather than require ->target() style drivers to provide a resolve_freq() callback it is left to the caller to ensure that the driver implements this callback if necessary to use cpufreq_driver_resolve_freq(). Suggested-by: Rafael J. Wysocki Signed-off-by: Steve Muckle --- drivers/cpufreq/cpufreq.c | 25 +++++++++++++++++++++++++ include/linux/cpufreq.h | 16 ++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 118b4f30a406..b696baeb249d 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -492,6 +492,29 @@ 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. + * @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) +{ + target_freq = clamp_val(target_freq, policy->min, policy->max); + policy->cached_target_freq = target_freq; + if (cpufreq_driver->resolve_freq) + return cpufreq_driver->resolve_freq(policy, target_freq); + policy->cached_resolved_idx = + cpufreq_frequency_table_target(policy, target_freq, + CPUFREQ_RELATION_L); + return policy->freq_table[policy->cached_resolved_idx].frequency; +} + /********************************************************************* * SYSFS INTERFACE * *********************************************************************/ @@ -2199,6 +2222,8 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, policy->min = new_policy->min; policy->max = new_policy->max; + policy->cached_target_freq = UINT_MAX; + pr_debug("new min and max freqs are %u - %u kHz\n", policy->min, policy->max); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index c6410b1b2490..631ba33bbe9f 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -120,6 +120,10 @@ struct cpufreq_policy { bool fast_switch_possible; bool fast_switch_enabled; + /* Cached frequency lookup from cpufreq_driver_resolve_freq. */ + unsigned int cached_target_freq; + int cached_resolved_idx; + /* Synchronization for frequency transitions */ bool transition_ongoing; /* Tracks transition status */ spinlock_t transition_lock; @@ -270,6 +274,16 @@ struct cpufreq_driver { unsigned int index); unsigned int (*fast_switch)(struct cpufreq_policy *policy, unsigned int target_freq); + + /* + * Caches and returns the lowest driver-supported frequency greater than + * or equal to the target frequency, subject to any driver limitations. + * Does not set the frequency. Only to be implemented for drivers with + * target(). + */ + unsigned int (*resolve_freq)(struct cpufreq_policy *policy, + unsigned int target_freq); + /* * Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION * unset. @@ -501,6 +515,8 @@ int cpufreq_driver_target(struct cpufreq_policy *policy, int __cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation); +unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, + unsigned int target_freq); int cpufreq_register_governor(struct cpufreq_governor *governor); void cpufreq_unregister_governor(struct cpufreq_governor *governor);