From patchwork Mon Feb 4 16:25:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 10796067 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 0CD3913B4 for ; Mon, 4 Feb 2019 16:26:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F00912BBF9 for ; Mon, 4 Feb 2019 16:26:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E40AB2BBFC; Mon, 4 Feb 2019 16:26:12 +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=unavailable 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 983D22BBF5 for ; Mon, 4 Feb 2019 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731057AbfBDQ0G (ORCPT ); Mon, 4 Feb 2019 11:26:06 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37866 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730768AbfBDQ0C (ORCPT ); Mon, 4 Feb 2019 11:26:02 -0500 Received: by mail-wm1-f68.google.com with SMTP id g67so540348wmd.2 for ; Mon, 04 Feb 2019 08:26:01 -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=9lKepzvlFqSdyTmpHqFOS3txG3e1Qlnve7EeoiMfLO0=; b=aVSLiJosF7nsn2YlMbkWjfe/sQt+HQvDzUEKw4RhgQWgOVm70k9HPSiS5kbBVP/nE1 uxICapIcLqWzWM7keOzeU4tTM3C0LF+hWtIqKxl8GXPDB84dVtX59Ewhs+KjNoSXstgm a7axZ2Vk2Aky3bhhwgyM5lpXXxhrlCVDzQPX4= 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=9lKepzvlFqSdyTmpHqFOS3txG3e1Qlnve7EeoiMfLO0=; b=uQkT0LUf0dSWqunxgS7KLVZHIxjWnTGyvWr3X6RKRIXepuJkGzvJXq4+egfETF3Sid nxgAcaRbstle+iKcrXJkX9fMCy1oJYIlE2mekCsc2b6J1PmfTAVqLNY4Oz1Up7IOzeJt 9qXlRyJ9Q8Gn9zI/pfDs+ko2QAuOcQ9kcemqBlihwIzKrTKmfV5+gkDa2MNgFczurE6V ujaxoEjeeAwKUvvUgYbBSrP6ivQpxl3YmnlwmJRqsuwpjy+z9gsd9jaA8D+q+Wzu5Q2I nnhWl/BPayToAhMrQCVbnCmwjKeWLKB/HpT3GqVBG6It1DGYxqJzpGsjaeJqBS/0fLf6 vu6g== X-Gm-Message-State: AHQUAuZCuRQYpXaa/6Fyo7Hkaoph1W6/uevju669B6U/y7hpR/4Ow0jA Xfuwhgc87CSeHikFRJ5DnCP/CTtYM8A= X-Google-Smtp-Source: AHgI3IZ7M0ze84wTX8DLxUv882QQUfhGHmbTLyFg1PCjFq7A45aNiEqTtsmhl2YBtsRd3HsDJdr2vw== X-Received: by 2002:a1c:b456:: with SMTP id d83mr127459wmf.115.1549297559980; Mon, 04 Feb 2019 08:25:59 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:70b6:b9c6:89e2:36a]) by smtp.gmail.com with ESMTPSA id a4sm1251992wrt.37.2019.02.04.08.25.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Feb 2019 08:25:59 -0800 (PST) From: Vincent Guittot To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, rjw@rjwysocki.net, ulf.hansson@linaro.org, biju.das@bp.renesas.com Cc: linux-arm-kernel@lists.infradead.org, geert@linux-m68k.org, thara.gopinath@linaro.org, linux-renesas-soc@vger.kernel.org, Vincent Guittot Subject: [PATCH 2/2] PM-runtime: update time accounting only when enabled Date: Mon, 4 Feb 2019 17:25:53 +0100 Message-Id: <1549297553-17647-3-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549297553-17647-1-git-send-email-vincent.guittot@linaro.org> References: <1549297553-17647-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 Update accounting_timestamp field only when PM runtime is enable and don't forget to account the last state before disabling it. Suggested-by: Ulf Hansson Signed-off-by: Vincent Guittot Reviewed-by: Ulf Hansson --- drivers/base/power/runtime.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 50740da..ed62cca 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -66,11 +66,14 @@ static int rpm_suspend(struct device *dev, int rpmflags); */ void update_pm_runtime_accounting(struct device *dev) { - u64 now = ktime_get_mono_fast_ns(); - u64 last = dev->power.accounting_timestamp; - u64 delta; + u64 now, last, delta; - dev->power.accounting_timestamp = now; + if (dev->power.disable_depth > 0) + return; + + last = dev->power.accounting_timestamp; + + dev->power.accounting_timestamp = now = ktime_get_mono_fast_ns(); /* * Because ktime_get_mono_fast_ns() is not monotonic during @@ -82,9 +85,6 @@ void update_pm_runtime_accounting(struct device *dev) delta = now - last; - if (dev->power.disable_depth > 0) - return; - if (dev->power.runtime_status == RPM_SUSPENDED) dev->power.suspended_time += delta; else @@ -1298,6 +1298,9 @@ void __pm_runtime_disable(struct device *dev, bool check_resume) pm_runtime_put_noidle(dev); } + /* Update time accounting before disabling pm runtime */ + update_pm_runtime_accounting(dev); + if (!dev->power.disable_depth++) __pm_runtime_barrier(dev); @@ -1521,7 +1524,6 @@ 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 = 0; INIT_WORK(&dev->power.work, pm_runtime_work); dev->power.timer_expires = 0;