From patchwork Tue Oct 6 21:57:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 54565 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 009E422FC5 for ; Tue, 6 Oct 2015 21:57:56 +0000 (UTC) Received: by wicuu12 with SMTP id uu12sf651919wic.2 for ; Tue, 06 Oct 2015 14:57:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=MDl3q+mr+JCrNJHZ+r7QvaotzlMM2RGI/7tM0K0re/o=; b=FMLAjd1ZWemDty6DhwU0vogBjmQtxdjb7H9JZ+crPUQUGylcIyT0cLD609GZpsoaO0 LpPFJE0dIkAFc8xy/7P6o5WZhLUQeeOo9G8824ukeFY8D6Wrbu1NUkeYkW20bEhbNf8y 43OT7CAU8XQp2O+MnCN2zMr94+35dk37tEBbbpXdlWxpplv3affOnAk7blAY9EpZcobR bWtoNmKbxUptfl/rXVnq05En7m2woOaUlt/j1QzC7R+8bnLhRrMGY+/WDTtXs4Ovbzj5 NwwfQgUSBWtJakRW2NhtF42cypM5NvSvj95iKm2afJwh9MqzYb08c+DXgr5nbgmLPJ7L +68Q== X-Gm-Message-State: ALoCoQlT8+HBGvxrFfKn5ijXzHzgmfarJpkBEZOTQe9+faGUoucaaOk61LtOJzkKU5agCRXmGOvz X-Received: by 10.112.12.132 with SMTP id y4mr6875385lbb.0.1444168675249; Tue, 06 Oct 2015 14:57:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.160.75 with SMTP id j72ls552697lfe.106.gmail; Tue, 06 Oct 2015 14:57:54 -0700 (PDT) X-Received: by 10.112.198.198 with SMTP id je6mr16149537lbc.31.1444168674963; Tue, 06 Oct 2015 14:57:54 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id rf9si22587237lbb.47.2015.10.06.14.57.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Oct 2015 14:57:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbcao8 with SMTP id ao8so84447377lbc.3 for ; Tue, 06 Oct 2015 14:57:54 -0700 (PDT) X-Received: by 10.25.86.213 with SMTP id k204mr10385276lfb.36.1444168674839; Tue, 06 Oct 2015 14:57:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2088177lbq; Tue, 6 Oct 2015 14:57:53 -0700 (PDT) X-Received: by 10.69.0.132 with SMTP id ay4mr48791826pbd.87.1444168673627; Tue, 06 Oct 2015 14:57:53 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bk2si52085307pbc.78.2015.10.06.14.57.53; Tue, 06 Oct 2015 14:57:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752663AbbJFV5w (ORCPT + 12 others); Tue, 6 Oct 2015 17:57:52 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:36240 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752313AbbJFV5w (ORCPT ); Tue, 6 Oct 2015 17:57:52 -0400 Received: by pablk4 with SMTP id lk4so220829410pab.3 for ; Tue, 06 Oct 2015 14:57:51 -0700 (PDT) X-Received: by 10.68.240.73 with SMTP id vy9mr11507300pbc.24.1444168671784; Tue, 06 Oct 2015 14:57:51 -0700 (PDT) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id c16sm35342076pbu.37.2015.10.06.14.57.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Oct 2015 14:57:50 -0700 (PDT) From: Lina Iyer To: linux-pm@vger.kernel.org Cc: grygorii.strashko@ti.com, ulf.hansson@linaro.org, khilman@linaro.org, daniel.lezcano@linaro.org, tglx@linutronix.de, geert+renesas@glider.be, lorenzo.pieralisi@arm.com, sboyd@codeaurora.org, Lina Iyer Subject: [RFC PATCH 1/2] PM / runtime: Add CPU runtime PM suspend/resume api Date: Tue, 6 Oct 2015 15:57:35 -0600 Message-Id: <1444168656-6576-2-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1444168656-6576-1-git-send-email-lina.iyer@linaro.org> References: <1444168656-6576-1-git-send-email-lina.iyer@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lina.iyer@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , CPU devices that use runtime PM, have the followign characteristics - - Runs in a IRQs disabled context - Every CPU does its own runtime PM - CPUs do not access other CPU's runtime PM - The runtime PM state of the CPU is determined by the CPU These allow for some interesting optimizations - - The CPUs have a limited runtime PM states - The runtime state of CPU need not be protected by spinlocks - Options like auto-suspend/async are not relevant to CPU devices A simplified runtime PM would therefore provide all that is needed for the CPU devices. After making a quick check for the usage count of the CPU devices (to allow for the CPU to not power down the domain), the runtime PM could just call the PM callbacks for the CPU devices. Locking is also avoided. Signed-off-by: Lina Iyer --- drivers/base/power/runtime.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_runtime.h | 3 ++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index e1a10a0..5f7512c 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -13,6 +13,7 @@ #include #include #include "power.h" +#include typedef int (*pm_callback_t)(struct device *); @@ -577,6 +578,66 @@ static int rpm_suspend(struct device *dev, int rpmflags) goto out; } +void cpu_pm_runtime_suspend(void) +{ + int ret; + int (*callback)(struct device *); + struct device *dev = get_cpu_device(smp_processor_id()); + + trace_rpm_suspend(dev, 0); + + /** + * Use device usage_count to disallow bubbling up suspend. + * This CPU has already decided to suspend, we cannot + * prevent it here. + */ + if (!atomic_dec_and_test(&dev->power.usage_count)) + return 0; + + ret = rpm_check_suspend_allowed(dev); + if (ret) + return ret; + + __update_runtime_status(dev, RPM_SUSPENDING); + + pm_runtime_cancel_pending(dev); + callback = RPM_GET_CALLBACK(dev, runtime_suspend); + + ret = callback(dev); + if (!ret) + __update_runtime_status(dev, RPM_SUSPENDED); + else + __update_runtime_status(dev, RPM_ACTIVE); + + trace_rpm_return_int(dev, _THIS_IP_, ret); +} + +void cpu_pm_runtime_resume(void) +{ + int ret; + int (*callback)(struct device *); + struct device *dev = get_cpu_device(smp_processor_id()); + + trace_rpm_resume(dev, 0); + + if (dev->power.runtime_status == RPM_ACTIVE) + return 1; + + atomic_inc(&dev->power.usage_count); + + __update_runtime_status(dev, RPM_RESUMING); + + callback = RPM_GET_CALLBACK(dev, runtime_resume); + + ret = callback(dev); + if (!ret) + __update_runtime_status(dev, RPM_ACTIVE); + else + __update_runtime_status(dev, RPM_SUSPENDED); + + trace_rpm_return_int(dev, _THIS_IP_, ret); +} + /** * rpm_resume - Carry out runtime resume of given device. * @dev: Device to resume. diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index 3bdbb41..3655ead 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -31,6 +31,8 @@ static inline bool queue_pm_work(struct work_struct *work) return queue_work(pm_wq, work); } +extern void cpu_pm_runtime_suspend(void); +extern void cpu_pm_runtime_resume(void); extern int pm_generic_runtime_suspend(struct device *dev); extern int pm_generic_runtime_resume(struct device *dev); extern int pm_runtime_force_suspend(struct device *dev); @@ -273,5 +275,4 @@ static inline void pm_runtime_dont_use_autosuspend(struct device *dev) { __pm_runtime_use_autosuspend(dev, false); } - #endif