From patchwork Tue Jul 7 18:24:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Morten Rasmussen X-Patchwork-Id: 6738241 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0EE1AC05AC for ; Tue, 7 Jul 2015 18:58:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 21ACE20626 for ; Tue, 7 Jul 2015 18:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2247D205BE for ; Tue, 7 Jul 2015 18:58:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933363AbbGGS6A (ORCPT ); Tue, 7 Jul 2015 14:58:00 -0400 Received: from foss.arm.com ([217.140.101.70]:37677 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932956AbbGGSXf (ORCPT ); Tue, 7 Jul 2015 14:23:35 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CB90860D; Tue, 7 Jul 2015 11:24:01 -0700 (PDT) Received: from e105550-lin.cambridge.arm.com (e105550-lin.cambridge.arm.com [10.2.131.193]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6C1693F23A; Tue, 7 Jul 2015 11:23:32 -0700 (PDT) From: Morten Rasmussen To: peterz@infradead.org, mingo@redhat.com Cc: vincent.guittot@linaro.org, daniel.lezcano@linaro.org, Dietmar Eggemann , yuyang.du@intel.com, mturquette@baylibre.com, rjw@rjwysocki.net, Juri Lelli , sgurrappadi@nvidia.com, pang.xunlei@zte.com.cn, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Viresh Kumar Subject: [RFCv5 PATCH 37/46] cpufreq: introduce cpufreq_driver_might_sleep Date: Tue, 7 Jul 2015 19:24:20 +0100 Message-Id: <1436293469-25707-38-git-send-email-morten.rasmussen@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436293469-25707-1-git-send-email-morten.rasmussen@arm.com> References: <1436293469-25707-1-git-send-email-morten.rasmussen@arm.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Michael Turquette Some architectures and platforms perform CPU frequency transitions through a non-blocking method, while some might block or sleep. This distinction is important when trying to change frequency from interrupt context or in any other non-interruptable context, such as from the Linux scheduler. Describe this distinction with a cpufreq driver flag, CPUFREQ_DRIVER_WILL_NOT_SLEEP. The default is to not have this flag set, thus erring on the side of caution. cpufreq_driver_might_sleep() is also introduced in this patch. Setting the above flag will allow this function to return false. Cc: Rafael J. Wysocki Cc: Viresh Kumar Signed-off-by: Michael Turquette --- drivers/cpufreq/cpufreq.c | 6 ++++++ include/linux/cpufreq.h | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 8ae655c..5753cb6 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -112,6 +112,12 @@ bool have_governor_per_policy(void) } EXPORT_SYMBOL_GPL(have_governor_per_policy); +bool cpufreq_driver_might_sleep(void) +{ + return !(cpufreq_driver->flags & CPUFREQ_DRIVER_WILL_NOT_SLEEP); +} +EXPORT_SYMBOL_GPL(cpufreq_driver_might_sleep); + struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy) { if (have_governor_per_policy()) diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 2ee4888..1f2c9a1 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -157,6 +157,7 @@ u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy); int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu); int cpufreq_update_policy(unsigned int cpu); bool have_governor_per_policy(void); +bool cpufreq_driver_might_sleep(void); struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy); #else static inline unsigned int cpufreq_get(unsigned int cpu) @@ -314,6 +315,14 @@ struct cpufreq_driver { */ #define CPUFREQ_NEED_INITIAL_FREQ_CHECK (1 << 5) +/* + * Set by drivers that will never block or sleep during their frequency + * transition. Used to indicate when it is safe to call cpufreq_driver_target + * from non-interruptable context. Drivers must opt-in to this flag, as the + * safe default is that they might sleep. + */ +#define CPUFREQ_DRIVER_WILL_NOT_SLEEP (1 << 6) + int cpufreq_register_driver(struct cpufreq_driver *driver_data); int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);