From patchwork Fri Dec 21 10:33:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 154390 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp750544ljp; Fri, 21 Dec 2018 02:34:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN53QCPGXFX4NeIJnLKkeR9y84U9b8HBYm4/oNogQ8M1CQ0l2sZrywKvi9KWjQYtc58GbRgj X-Received: by 2002:a63:eb0e:: with SMTP id t14mr1850278pgh.445.1545388455416; Fri, 21 Dec 2018 02:34:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545388455; cv=none; d=google.com; s=arc-20160816; b=dKFvl4gFwg/y2eCAnRifOzk2liY94FNA0/lJnyEF9sfVC8Lzc2TbNJ/KgoKVOpXuJC +ZzruboOQ5DR1Qk4WJZ8VrIkQTLFYzBosptZG6fxm74J9E6od1Es4a8YBiSe9sk6Gvsf 9rj+zs3YkC7ZIYvtVYsy/JFLCokgAj2a9NxR9WUTCrpWIqLvJZTaLfskS6pxIxXhTumP P/iqaR4uVrVmp0TqZT8GBTDglYLFabivHLPmJcVmpIdKXrZdIaE+fRp1WAq3L9J83+7a LAkzL1qNbM+0EOYTucRbTovVEV3748+RXB0kKoDCYNmnowtUxXgUcF3xv4tON2cPoFVs pxQg== 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=bPgIAywPM9tC5+7zzbz0/QmHiK8KUKT68feND5QntSw=; b=tRF4pKCHa6lUUOARPcgg6AZjrj27vCTgSA6XAUKQICq3tKd+0ACVgNGGPcZLjgGZGH BTnheu03RmwvhAlQWQkPNrE4qb1whlm21fkwjVbxN1Rih2jZwEy2UCLU/UjEM+i+QGc3 Mr+fWhgkQ7u5fKaE5zQtKcwPPiGwSsDWZy9SN51l/kTJa8rNaaKgCUNzVRaClDuAxHQ1 mfgIQ+fWLdz6gKrv6osokvkyowf0mf6QkbJpVlLpvLuwCcwePHXqHobapF3ABrBstgjr 7yNUtKyAYmsk65K80UnvO1nxzd1lzSoXfDhgtzCOjxdpZGdglO1jpJH5S7wftkEQ29Py RkRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W6DQXHCC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 f13si21289358plm.393.2018.12.21.02.34.15; Fri, 21 Dec 2018 02:34:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=W6DQXHCC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S2389830AbeLUKeO (ORCPT + 31 others); Fri, 21 Dec 2018 05:34:14 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34605 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389775AbeLUKeI (ORCPT ); Fri, 21 Dec 2018 05:34:08 -0500 Received: by mail-wm1-f65.google.com with SMTP id y185so13917664wmd.1 for ; Fri, 21 Dec 2018 02:34:07 -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=bPgIAywPM9tC5+7zzbz0/QmHiK8KUKT68feND5QntSw=; b=W6DQXHCChdKP+2o+Oh49fa6lIRh71HkGhUICeVCvPMojy06LmGOUQMvIdx1GSd+GET 8H21LLIhAcuz+Rbh6uFaBXPQZlJmzy5BdbdOsjES2cX1E/c9qvIJunumoj1n3VyYx8bE 0hCDpcrvgRLc9HD4Ryt8OWk/GGvCZYbjmTFSA= 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=bPgIAywPM9tC5+7zzbz0/QmHiK8KUKT68feND5QntSw=; b=rnM501bmlP5c4buoFJy3ZVTViejg8Z3ReB2GJkDPKx0qubz1x9ZYxsGQ9tSmfqcVzO VnU4lZerpV0neM9p1qNBYCqsvEi/njxe+gQgZpvjGPX6oPjEgIs9nL9ZwP6fik+Vb31e ObsTvsfJABWCn3oL5PAFMQb02qaoVK/u06Nw1vcCSJ+Xa8xBb59VRERRRmDIdVHFTsCq WuoUWiCckM9FKFi8N3lQnaQV/0qANVuK4BAex7DaTokwLMsVVa2ivXILsRbiu72LkZgl mslB9Ip/z6jLx/4Sr3oe3c/J3u6hQKMxPkFwrgCSrBvju1FFwFWJqlss1rt0M57FRLA5 CKpw== X-Gm-Message-State: AA+aEWa0v0sSTiWIaXM8YdrOLXpShMa3aM9OsTNHgGVsEYP37MdaSV/U BgZwwE6FrvA2rgDv+KLGBd49FA== X-Received: by 2002:a1c:570d:: with SMTP id l13mr2344052wmb.139.1545388446921; Fri, 21 Dec 2018 02:34:06 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:ac05:2372:f02d:b03f]) by smtp.gmail.com with ESMTPSA id h10sm10573685wmf.44.2018.12.21.02.34.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Dec 2018 02:34:06 -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: [PATCH v5 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting Date: Fri, 21 Dec 2018 11:33:56 +0100 Message-Id: <1545388436-7489-4-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545388436-7489-1-git-send-email-vincent.guittot@linaro.org> References: <1545388436-7489-1-git-send-email-vincent.guittot@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thara Gopinath This patch replaces jiffies based accounting for runtime_active_time and runtime_suspended_time with ktime base accounting. This makes the runtime debug counters inline with genpd and other pm subsytems which uses ktime based accounting. timekeeping is initialized before pm_runtime_init() so ktime_get() will be ready before first call. In fact, timekeeping_init() is called early in start_kernel() which is way before driver_init() (and that's when devices can start to be initialized) called from rest_init() via kernel_init_freeable() and do_basic_setup(). Signed-off-by: Thara Gopinath [move 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 e695544..f700524 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -64,8 +64,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; @@ -75,9 +75,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) @@ -88,17 +88,18 @@ 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); @@ -1503,7 +1504,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 = ktime_to_ns(ktime_get()); INIT_WORK(&dev->power.work, pm_runtime_work); dev->power.timer_expires = 0; 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 e723b78..e5a34e2 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -632,9 +632,9 @@ struct dev_pm_info { int runtime_error; int autosuspend_delay; unsigned long 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);