From patchwork Wed Jan 23 07:50:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 10776705 X-Patchwork-Delegate: rjw@sisk.pl 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 5CAF317F0 for ; Wed, 23 Jan 2019 07:50:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50F252B4BA for ; Wed, 23 Jan 2019 07:50:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F89B2B575; Wed, 23 Jan 2019 07:50:25 +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 EA21E2B581 for ; Wed, 23 Jan 2019 07:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727015AbfAWHuX (ORCPT ); Wed, 23 Jan 2019 02:50:23 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45507 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726954AbfAWHuW (ORCPT ); Wed, 23 Jan 2019 02:50:22 -0500 Received: by mail-wr1-f68.google.com with SMTP id t6so1164213wrr.12 for ; Tue, 22 Jan 2019 23:50:21 -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=dm1djdLVSS6M3bvErQJB+/zSgJ56gxH1n+KiZojviIM=; b=BUabxBkQ80rAjig3sHrjRpICpMA5l8DxYnd61NyX7VsUZaeF8Q+yY3sayjbTXdCDQx Ho7N26ZLjOaKxTeEN894vBwYx2rVgSmsjAngx0OVLrK3gq7P1LV6r4cLcmOI5yAn2ZWN GqlL9OnXaCzCyE0eo9/sz4z4z227wF84QCC5s= 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=dm1djdLVSS6M3bvErQJB+/zSgJ56gxH1n+KiZojviIM=; b=UczxK7akc3N/0KctnATgE+xXelteUcuUbml/CpNCW3tEuVX1SBruBzOCk9tBLwTxG7 RvQ3ppicyu2Sj7AmETVNU1CiWQeFWA/g+PKcHtAKzmH5RxlrCF1d0dYOpzHDRic+yIY5 rSjCPAx/DqaxKm1QI69jWbC84eNuZ/dGuheW8OYFhvxcre3fK2rEsWTw+exUJE8aTpFF cGKHWnTOUYGh3gwkZyddICpOYWxuDdfP9+GXIpDmX92WNswoCdCc7OFpDbhGakd/z8FE NrThXrXuBFjkbYOz7VejMnw5WTNkpf4odU07JcW+3L5c6MJYR0vV9W2fEIg9DdHVnktD 0AMA== X-Gm-Message-State: AJcUukeo6cdCWt0YbHyaBkLpi7LI6wItI980qw4RD25z+l6adM387CaP Th+QCWeI4ZxZda/TKUC75dy9BCc6dyaQFw== X-Google-Smtp-Source: ALg8bN4s0KYtXXBBeFBnpT/Xl0L1FkFFTtFdhD1CirE/gZvyOhrdWY3aDTvRofhEuD6XWg0LmsxXkw== X-Received: by 2002:a5d:4ccb:: with SMTP id c11mr1455765wrt.241.1548229820000; Tue, 22 Jan 2019 23:50:20 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:5ca6:2921:648b:56b6]) by smtp.gmail.com with ESMTPSA id i186sm70138787wmd.19.2019.01.22.23.50.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Jan 2019 23:50:18 -0800 (PST) From: Vincent Guittot To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, rjw@rjwysocki.net, thara.gopinath@linaro.org, linux@roeck-us.net Cc: ulf.hansson@linaro.org, Vincent Guittot Subject: [PATCH v7 1/2] PM-runtime: update accounting_timestamp only when enable Date: Wed, 23 Jan 2019 08:50:13 +0100 Message-Id: <1548229814-24913-2-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548229814-24913-1-git-send-email-vincent.guittot@linaro.org> References: <1548229814-24913-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 Initializing accounting_timestamp to something different from 0 during pm_runtime_init() doesn't make sense and put useless ordering constraint between timekeeping_init() and pm_runtime_init(). PM runtime should start accounting time only when it is enable and discard the period when disabled. Set accounting_timestamp to now when enabling PM runtime. Suggested-by: "Rafael J. Wysocki" Signed-off-by: Vincent Guittot --- drivers/base/power/runtime.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index fb5e2b6..eccd37f1 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1306,10 +1306,15 @@ void pm_runtime_enable(struct device *dev) spin_lock_irqsave(&dev->power.lock, flags); - if (dev->power.disable_depth > 0) + if (dev->power.disable_depth > 0) { dev->power.disable_depth--; - else + + /* About to enable runtime pm, set accounting_timestamp to now */ + if (!dev->power.disable_depth) + dev->power.accounting_timestamp = jiffies; + } else { dev_warn(dev, "Unbalanced %s!\n", __func__); + } WARN(!dev->power.disable_depth && dev->power.runtime_status == RPM_SUSPENDED && @@ -1506,7 +1511,7 @@ void pm_runtime_init(struct device *dev) dev->power.request_pending = false; dev->power.request = RPM_REQ_NONE; dev->power.deferred_resume = false; - dev->power.accounting_timestamp = jiffies; + dev->power.accounting_timestamp = 0; INIT_WORK(&dev->power.work, pm_runtime_work); dev->power.timer_expires = 0; From patchwork Wed Jan 23 07:50:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 10776707 X-Patchwork-Delegate: rjw@sisk.pl 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 8FE5A14E5 for ; Wed, 23 Jan 2019 07:50:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EBA02B587 for ; Wed, 23 Jan 2019 07:50:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72D6A2B4BE; Wed, 23 Jan 2019 07:50:26 +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 F02872B576 for ; Wed, 23 Jan 2019 07:50:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727029AbfAWHuZ (ORCPT ); Wed, 23 Jan 2019 02:50:25 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33834 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726986AbfAWHuX (ORCPT ); Wed, 23 Jan 2019 02:50:23 -0500 Received: by mail-wr1-f66.google.com with SMTP id f7so1229995wrp.1 for ; Tue, 22 Jan 2019 23:50:22 -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=6Uzfk3h9kJFsyoYLbkQfF/tuQMo4t3cWJwQxIwIcjck=; b=gYGSQgOgDb8NH7SMn/o6ov8ebwNQuRJGmIp7u6RfAwfYziW3ojqTYpYB5wkLSjeZup Y1AVm0w7xvHLOzMPVHfRXu/DeBg/p/dsPv+5R6UmXFFe2KaWonCWOEkMBjrA9Q2nYY5X l/1Adjon//t7gLiga9xzdDfsYYaybIR9BPcgA= 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=6Uzfk3h9kJFsyoYLbkQfF/tuQMo4t3cWJwQxIwIcjck=; b=eqIAD0NBi1b1pPDvS85IsYIxFwnugYt1wiDjmJDmyO28qrfRDtWfcr0lYtuRMvrdJK pYB5DTtRa7hMZcwiVX3JxHFzGjnEWzzzsEmSU70Ppz2IJfzaMRJ362i7u4iRTwDJ3gWX vmMrxrwkdcQ9Vi6ScJq+xoJrOWgZST1AzfTjFjZdCqkbLnhhioB2PjhrmqikNnyi2pbk CU1GYdOYYkWuG4akR1Lt0KLKXjCHFbpaXLxHpl2hbc0MioiwBppM9rOn59znDEEEJ5Me MNL0BxzVwhn34myGegaH6TVWeuuR6T0DghzUFHZ75ERUDKevscySG8Kh+CC0MtB7WKYs SUaw== X-Gm-Message-State: AJcUukedcW/hxURF6vc06cNy2r/ZScE2rhe7Ylopodk2JGYfx6jpmw7r WZ6LiKSzVsh6RCDJDzp5UFsLAG8p7wOnLg== X-Google-Smtp-Source: ALg8bN7Kd3EMuPn3o0RslF2EiwwGm3O/TrZQ/x9EBYWs9l5VwHkxRegpWdV91TUgpm2FhT+Vmo2TJw== X-Received: by 2002:a5d:480d:: with SMTP id l13mr1470005wrq.175.1548229821253; Tue, 22 Jan 2019 23:50:21 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:5ca6:2921:648b:56b6]) by smtp.gmail.com with ESMTPSA id i186sm70138787wmd.19.2019.01.22.23.50.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Jan 2019 23:50:20 -0800 (PST) From: Vincent Guittot To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, rjw@rjwysocki.net, thara.gopinath@linaro.org, linux@roeck-us.net Cc: ulf.hansson@linaro.org, Vincent Guittot Subject: [PATCH v7 2/2] PM-runtime: Replace jiffies based accounting with ktime-based accounting Date: Wed, 23 Jan 2019 08:50:14 +0100 Message-Id: <1548229814-24913-3-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548229814-24913-1-git-send-email-vincent.guittot@linaro.org> References: <1548229814-24913-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 From: Thara Gopinath This patch replaces jiffies based accounting for runtime_active_time and runtime_suspended_time with ktime-based accounting. This makes the runtime debug counters inline with genpd and other PM subsytems which use ktime-based accounting. Timekeeping is initialized before driver_init(). It's only at that time that PM runtime can be enabled. Signed-off-by: Thara Gopinath [switch from ktime to raw nsec] Signed-off-by: Vincent Guittot --- drivers/base/power/runtime.c | 17 +++++++++-------- drivers/base/power/sysfs.c | 11 ++++++++--- include/linux/pm.h | 6 +++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index eccd37f1..e9dae6d7 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -66,8 +66,8 @@ static int rpm_suspend(struct device *dev, int rpmflags); */ void update_pm_runtime_accounting(struct device *dev) { - unsigned long now = jiffies; - unsigned long delta; + u64 now = ktime_to_ns(ktime_get()); + u64 delta; delta = now - dev->power.accounting_timestamp; @@ -77,9 +77,9 @@ void update_pm_runtime_accounting(struct device *dev) return; if (dev->power.runtime_status == RPM_SUSPENDED) - dev->power.suspended_jiffies += delta; + dev->power.suspended_time += delta; else - dev->power.active_jiffies += delta; + dev->power.active_time += delta; } static void __update_runtime_status(struct device *dev, enum rpm_status status) @@ -90,16 +90,17 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status) u64 pm_runtime_suspended_time(struct device *dev) { - unsigned long flags, time; + u64 time; + unsigned long flags; spin_lock_irqsave(&dev->power.lock, flags); update_pm_runtime_accounting(dev); - time = dev->power.suspended_jiffies; + time = dev->power.suspended_time; spin_unlock_irqrestore(&dev->power.lock, flags); - return jiffies_to_nsecs(time); + return time; } EXPORT_SYMBOL_GPL(pm_runtime_suspended_time); @@ -1311,7 +1312,7 @@ void pm_runtime_enable(struct device *dev) /* About to enable runtime pm, set accounting_timestamp to now */ if (!dev->power.disable_depth) - dev->power.accounting_timestamp = jiffies; + dev->power.accounting_timestamp = ktime_to_ns(ktime_get()); } else { dev_warn(dev, "Unbalanced %s!\n", __func__); } diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index d713738..96c8a22 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c @@ -125,9 +125,12 @@ static ssize_t runtime_active_time_show(struct device *dev, struct device_attribute *attr, char *buf) { int ret; + u64 tmp; spin_lock_irq(&dev->power.lock); update_pm_runtime_accounting(dev); - ret = sprintf(buf, "%i\n", jiffies_to_msecs(dev->power.active_jiffies)); + tmp = dev->power.active_time; + do_div(tmp, NSEC_PER_MSEC); + ret = sprintf(buf, "%llu\n", tmp); spin_unlock_irq(&dev->power.lock); return ret; } @@ -138,10 +141,12 @@ static ssize_t runtime_suspended_time_show(struct device *dev, struct device_attribute *attr, char *buf) { int ret; + u64 tmp; spin_lock_irq(&dev->power.lock); update_pm_runtime_accounting(dev); - ret = sprintf(buf, "%i\n", - jiffies_to_msecs(dev->power.suspended_jiffies)); + tmp = dev->power.suspended_time; + do_div(tmp, NSEC_PER_MSEC); + ret = sprintf(buf, "%llu\n", tmp); spin_unlock_irq(&dev->power.lock); return ret; } diff --git a/include/linux/pm.h b/include/linux/pm.h index 0bd9de1..3d2cbf9 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -633,9 +633,9 @@ struct dev_pm_info { int runtime_error; int autosuspend_delay; u64 last_busy; - unsigned long active_jiffies; - unsigned long suspended_jiffies; - unsigned long accounting_timestamp; + u64 active_time; + u64 suspended_time; + u64 accounting_timestamp; #endif struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */ void (*set_latency_tolerance)(struct device *, s32);