From patchwork Tue Jan 22 14:24:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 156300 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp7638436jaa; Tue, 22 Jan 2019 06:24:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN7z+Ge+XZ7GffwXlur5+b4BBmadXqHjN854sNlPTPwrmmHYL5nEwHOLR/fCZAhKH+LVnjFr X-Received: by 2002:a17:902:48:: with SMTP id 66mr33562902pla.68.1548167083430; Tue, 22 Jan 2019 06:24:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548167083; cv=none; d=google.com; s=arc-20160816; b=dc2mydfcfMD4PU+gs37mZlQpxuafEFz6Z4UDHaWp84EAjIpbGX3CUmIdugftJisV+y AVSGlFoQPLn+2udnKGL+eFPp19ph9d871r8D4y9981gDtiewFuTdVGkTUdmhdaCDDrbp mb1S0nDgNXq+2cwd1ird0VCyfGU9/A6kXL3O4UQCogI5Mr5E8DAJ47Ax54qscZID57nw MdDkauSHjPJvEtNGO4dLLFOQFGiWn0mQ4ECDVEKOZ1P7ZAqY1ETDzmSzJO5XQGNUtn2h nKBLFkxGPS5m0Elsb/i6cK0axgV3OnDFRQ7rx/VBSYyHjaamUe3T66YDgG0J7Si56Nc9 2Gfw== 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=icRDkcXzioH9ylzj5h9mEPp6hJmlM4XW9bm5lCr6fE4=; b=wyTq8w3bwo01CJo4ih3QOzTTpvuI47SV1iKIEgmlHzgAujJ7IW9j9kzul862/Nwz6d p8rwNlOl7SvT/3TbMg9k1Gx6BZs72Zi93Fhkd2qzSFAkoJB7tUjDMydIHSL5PvHa0Vd2 /A0ww1eFhZB+z4i45O8QgcMGgk5RE3pFPoPTgCMHWbIi776N+jACtpgTQW5qct4HYjm5 ANe/4TaApswWR79BAmcDa2qLXtzhK3tFsTen5Bir8zeUaYozG7GI2Nfu03tAaQmlOJcl TB6lDE1RGFbyrE8HWlmW0yoAG3j8D+T5RvXgQ08l5p/g0iTeKIS2wsKtN8G2ihDICocj gOAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bXcLrQbe; 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 u6si205104pfb.92.2019.01.22.06.24.42; Tue, 22 Jan 2019 06:24:43 -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=bXcLrQbe; 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 S1728365AbfAVOYl (ORCPT + 11 others); Tue, 22 Jan 2019 09:24:41 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35260 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728764AbfAVOYi (ORCPT ); Tue, 22 Jan 2019 09:24:38 -0500 Received: by mail-wr1-f68.google.com with SMTP id 96so27606193wrb.2 for ; Tue, 22 Jan 2019 06:24:36 -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=icRDkcXzioH9ylzj5h9mEPp6hJmlM4XW9bm5lCr6fE4=; b=bXcLrQbemsaH8z1LwgrunyyYuupal+AFxADKh14R6FPQr47McexPFnhHEgomACyUjp UDJqmCvjET5MPN3mLwxyFxF1oar39NtCY4rtJQgpX9mFr6m4tzYX/aBmjhvDGVvXaPCL 2ro2nfJlHM2qlszBTo8MI5JXpXYxCGt1NtQkA= 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=icRDkcXzioH9ylzj5h9mEPp6hJmlM4XW9bm5lCr6fE4=; b=AhSWuAurPMkRBRiEvPD4DAOrhuySG1XNPQIj4xmHDevW27JtBGxbwnE2pYVJI1nxdI lf1HxFQORXvx03YZTpKjUKDlJ5umdSIkzTzQp/HyyqgTvdNaiAeEW1Ql8gRc7ZY4qAKv cALESA2wfC6JXxhW8qIumUTBeo4uyx2IYqERJmh3PnZU3uE1C6dy5j0sw5hJkzcL3RxR +tPvNdGyCOdCGWj1bhwuX5+W7JOsCQt4dJJKEQA2U9upbLnVzS5zZvMemvmTHkQV6sC7 5qswRmggqBgvg8/RaMcLYHoJBp8YLKNqFUVzlODQL8lNGgS32FUups854krrtOweC0ZJ Np0Q== X-Gm-Message-State: AJcUukem8gj3pXbp+cPx6UNrxCE4DDXuLHNAI6+ND+tF+jfhzKFwkKz3 /4N133wzxwdFjjULkPqAtU/Cr2M3JN5Q+Q== X-Received: by 2002:a5d:6450:: with SMTP id d16mr33154547wrw.64.1548167075610; Tue, 22 Jan 2019 06:24:35 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:609f:7896:d361:50c6]) by smtp.gmail.com with ESMTPSA id l19sm52620119wme.21.2019.01.22.06.24.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Jan 2019 06:24:34 -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 2/2] PM-runtime: Replace jiffies based accounting with ktime-based accounting Date: Tue, 22 Jan 2019 15:24:30 +0100 Message-Id: <1548167070-421-3-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548167070-421-1-git-send-email-vincent.guittot@linaro.org> References: <1548167070-421-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 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(-) -- 2.7.4 diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 7df1d05..e49b3a8 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); @@ -1308,7 +1309,7 @@ void pm_runtime_enable(struct device *dev) /* About to enable runtime pm, set accounting_timestamp to now */ if (dev->power.disable_depth == 1) - dev->power.accounting_timestamp = jiffies; + dev->power.accounting_timestamp = ktime_to_ns(ktime_get()); if (dev->power.disable_depth > 0) dev->power.disable_depth--; 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);