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: 10735811 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 27B52746 for ; Tue, 18 Dec 2018 14:55:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1731D2A7C2 for ; Tue, 18 Dec 2018 14:55:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ACD72A829; Tue, 18 Dec 2018 14:55:37 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 AA1212A7C2 for ; Tue, 18 Dec 2018 14:55:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726743AbeLROzf (ORCPT ); Tue, 18 Dec 2018 09:55:35 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35454 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726744AbeLROze (ORCPT ); Tue, 18 Dec 2018 09:55:34 -0500 Received: by mail-wm1-f68.google.com with SMTP id c126so3117208wmh.0 for ; Tue, 18 Dec 2018 06:55:33 -0800 (PST) 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=s74m+Lr1EiptSBHBVzfFna+tA9cO0B3xmfsEojfvWLo=; b=b+0NUBHBg7fsbJjDW4sdaIepSE86T/4spu7357R8/qFfySNIgASF5b6eLW5lmMQm3v YmZ2jznvjymXqzbRYRtmhQoSfiSifaPzMmJuQNhtu3m2R1eOCqyO48suzvqPBIhI9KKS mpUIueTZZqBYJRk6NTdGJxqNowtffxhr/JIEQ= 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=nSegeBCt7bPLZLY7yY7TPJ+OCvDjFhcqxJFo5yV0dgMHJx7JG4Jvpzda2KAkUKCO1P 8KsHJX9lqfPt/UDUsvJw1Y9ieGw+N7/3qVNMFdVHZAxYZ5985mLK2pqK3phgaCxmUH3x xM1iJ4TOOvALWMzzCAg73ioVLjpIIQU3x/WybtG64jp9LfTU/pkU2rLJfC7jIEGt0mEZ mqXPKgSil5EI2N6Bf9hXWwUtxUe1XwmEinoblnVXwAmau5l02BTajz3Fgi2agjbcwYmC fBpHbJV7nje9KcTTkRoo6iEbDFlAS/QPU+PHGsHg6aV8RHg1BuWune4NJ5rxU0HPrqmJ waLw== X-Gm-Message-State: AA+aEWY+7asWbe1lL6YQZNJeF/JmV+LUHUlySiLsoDOenU2hnFih+zXI q7e1nHbdAUfzC6Aws7gTODayVdbXCXyA2A== 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 Cc: ulf.hansson@linaro.org, Vincent Guittot 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> 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 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; }