From patchwork Tue Dec 18 14:55:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 10735815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE36F924 for ; Tue, 18 Dec 2018 14:55:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D0492A7C2 for ; Tue, 18 Dec 2018 14:55:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90D472A829; Tue, 18 Dec 2018 14:55:40 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4ABEF2A7C2 for ; Tue, 18 Dec 2018 14:55:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 203B16EC0C; Tue, 18 Dec 2018 14:55:35 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by gabe.freedesktop.org (Postfix) with ESMTPS id D39F86EC0B for ; Tue, 18 Dec 2018 14:55:33 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id g67so3105804wmd.2 for ; Tue, 18 Dec 2018 06:55:33 -0800 (PST) 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; bh=s74m+Lr1EiptSBHBVzfFna+tA9cO0B3xmfsEojfvWLo=; b=qkBMbyNcCOuA4ZWqrVFaK8yZMG4v9O6eX3N6GsWANCfqY2DhiwQo5t+bacjeKpCb8O w0uAJ8GiMigvILAIyKZZWKXqE/tqFA3LSU2N9b3Tz8fHp4mpvi6+HGD1mplqmUTuUEu/ 1jnYZZ0CRNsXWMEjUONgCe8TmAh2+ir7jZpbYUJ20Wr6vGbFfXSlme5t4LiLmGQzhWE4 sUZ+oSY1CtVBwx7+nFUrii9DMZxDGJUjEoUUWebIepAORwiFTpSXjIPLFijetJSX2B9S u84uVVVeD2Tv1ndT2KUqja9Zf5Zxkgo3iVkvRG62URvWF6/HqJraWcS2nOoCjpVqWZus VziA== X-Gm-Message-State: AA+aEWbSQLZpOx/I3qOqyu9mD3MQB7D73S+HpPCj8sYWFiNbTn+S2wj+ lVPdcRm/fN4/cTYSn+GdAnjxLA== X-Google-Smtp-Source: AFSGD/VbG5obJ6y3EElJe4H6iuiUTdFIAn/CLiMO7pbQolzgSzQ8bfP8WyIBcO42MityIVQc2Ogmkw== X-Received: by 2002:a1c:ab87:: with SMTP id u129mr3536429wme.104.1545144932374; Tue, 18 Dec 2018 06:55:32 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:85e9:25c5:6cbd:73e9]) by smtp.gmail.com with ESMTPSA id n20sm1579956wmi.11.2018.12.18.06.55.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Dec 2018 06:55:31 -0800 (PST) From: Vincent Guittot To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, rjw@rjwysocki.net, thara.gopinath@linaro.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, airlied@linux.ie, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [RFC v3 1/3] PM/runtime: Add a new interface to get accounted time Date: Tue, 18 Dec 2018 15:55:21 +0100 Message-Id: <1545144923-31546-2-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545144923-31546-1-git-send-email-vincent.guittot@linaro.org> References: <1545144923-31546-1-git-send-email-vincent.guittot@linaro.org> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ulf.hansson@linaro.org, Vincent Guittot MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Some drivers (like i915/drm) need to get the accounted suspended time. pm_runtime_accounted_time_get() will return the suspended or active accounted time until now. Signed-off-by: Vincent Guittot --- drivers/base/power/runtime.c | 26 ++++++++++++++++++++++++++ include/linux/pm_runtime.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 7062469..6461469 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -88,6 +88,32 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status) dev->power.runtime_status = status; } +u64 pm_runtime_accounted_time_get(struct device *dev, enum rpm_status status, bool update) +{ + u64 now = ktime_to_ns(ktime_get()); + u64 delta = 0, time = 0; + unsigned long flags; + + spin_lock_irqsave(&dev->power.lock, flags); + + if (dev->power.disable_depth > 0) + goto unlock; + + /* Add ongoing state if requested */ + if (update && dev->power.runtime_status == status) + delta = now - dev->power.accounting_timestamp; + + if (status == RPM_SUSPENDED) + time = dev->power.suspended_time + delta; + else + time = dev->power.active_time + delta; + +unlock: + spin_unlock_irqrestore(&dev->power.lock, flags); + + return time; +} + /** * pm_runtime_deactivate_timer - Deactivate given device's suspend timer. * @dev: Device to handle. diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index 54af4ee..86f21f9 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -113,6 +113,8 @@ static inline bool pm_runtime_is_irq_safe(struct device *dev) return dev->power.irq_safe; } +extern u64 pm_runtime_accounted_time_get(struct device *dev, enum rpm_status status, bool update); + #else /* !CONFIG_PM */ static inline bool queue_pm_work(struct work_struct *work) { return false; }