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: 154146 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3805492ljp; Tue, 18 Dec 2018 06:55:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/W5Rg2U8AvToyz7yfXnvLFMuPF8eE8g7ORXZBWIgci4ooC+2yIdVO6UobPIRAQ4qbm+/0G/ X-Received: by 2002:a63:60cf:: with SMTP id u198mr16198989pgb.323.1545144937816; Tue, 18 Dec 2018 06:55:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545144937; cv=none; d=google.com; s=arc-20160816; b=00jz3Lmz47QotzgUXapRcpequOAvPhY9vh6yQnBqgaYPHOQ5I1Kp/lTiE9CNS55+QL vmdj6a9a68rwcck1F2IY6/z9+wzmDJCCfUpRuxvCvcuJGZgxMNqvVHT4Gwp5biIvsACS cNwbCELZe825oBO4ZBk0nn4F4u1IKQttlTtB43xkWB8FfqDHr6XnrlqeArInp0F5uDRY u8P0Seoa5Do9/HNHjs2kFjZl3VvBuNiqthIVAvBW0L4NGqlW2t7y7acnn8Au0C2ZohgL 3Cvaiv79HQFl2yRplqu7GhJXDq4+c2CIgK+M1TtXJjZcMYTW5I9KA3phngEqkU8HvSv4 8XxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=s74m+Lr1EiptSBHBVzfFna+tA9cO0B3xmfsEojfvWLo=; b=ULeUEVhbtq0alcKDnAlDz7yaAxhkshR4p5jRq2fpG54JC6dYuK/ezhDj+Q7YIf9WcX 1nI857pR/NNYQmH19l+cwbn2MDz/XF7L/TxeuuqbMdCTYJ+k9tjSlZ4F/Lt6gjQIi9YM zcxOayeCbMRRTF/FxnFvJS6kh2hXi166vYaH5xh+VI4eEd6kvj6rYCZii16gfKSPHYDh GChMh8RXFmcKqUHKZD+Qae1bdYJpmetDhF7CHs13CDHKWXl61hPwS5/Ox9y/EjzoUSIE 7pruBTUCSoOU5cg5Q1Lu/bIYz319JYjjTFGJSLwgPiBE6008cTDtlJKHMyNxvFZusnZU IVvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b+0NUBHB; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k18si13655032pfd.241.2018.12.18.06.55.37; Tue, 18 Dec 2018 06:55:37 -0800 (PST) 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; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b+0NUBHB; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726743AbeLROzf (ORCPT + 11 others); 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-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 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(+) -- 2.7.4 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; }