From patchwork Wed Jan 30 21:40:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 10789313 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 E5D65922 for ; Wed, 30 Jan 2019 21:40:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02BB82FA36 for ; Wed, 30 Jan 2019 21:40:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAFB92FC95; Wed, 30 Jan 2019 21:40:22 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY 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 7846B2FCF8 for ; Wed, 30 Jan 2019 21:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727315AbfA3VkV (ORCPT ); Wed, 30 Jan 2019 16:40:21 -0500 Received: from eddie.linux-mips.org ([148.251.95.138]:49372 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725890AbfA3VkV (ORCPT ); Wed, 30 Jan 2019 16:40:21 -0500 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992792AbfA3VkSjTYCh (ORCPT + 3 others); Wed, 30 Jan 2019 22:40:18 +0100 Date: Wed, 30 Jan 2019 22:40:17 +0100 From: Ladislav Michl To: "Rafael J. Wysocki" Cc: Linux PM , Linux Kernel Mailing List , Linux ARM , Linux OMAP Mailing List , Ulf Hansson , Biju Das , Geert Uytterhoeven , Linux-Renesas , Vincent Guittot Subject: [PATCH] PM/runtime: Optimize pm_runtime_autosuspend_expiration() Message-ID: <20190130214017.GA5038@lenoch> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pm_runtime_autosuspend_expiration calls ktime_get_mono_fast_ns even when its returned value may be unused. Therefore get current time later and remove gotos while there. Signed-off-by: Ladislav Michl Acked-by: Tony Lindgren Acked-by: Vincent Guittot --- This patch is based on top of bleeding-edge branch, where "[PATCH v2 ] PM-runtime: fix deadlock with ktime" is sitting. I expect v3 of that patch, which should not harm this one. It is meant to replace "PM/runtime: Do not needlessly call ktime_get" sent earlier. drivers/base/power/runtime.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 65e2b5f48e0c..7bbe28faca8d 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -145,24 +145,21 @@ static void pm_runtime_cancel_pending(struct device *dev) u64 pm_runtime_autosuspend_expiration(struct device *dev) { int autosuspend_delay; - u64 last_busy, expires = 0; - u64 now = ktime_get_mono_fast_ns(); + u64 expires; if (!dev->power.use_autosuspend) - goto out; + return 0; autosuspend_delay = READ_ONCE(dev->power.autosuspend_delay); if (autosuspend_delay < 0) - goto out; - - last_busy = READ_ONCE(dev->power.last_busy); + return 0; - expires = last_busy + (u64)autosuspend_delay * NSEC_PER_MSEC; - if (expires <= now) - expires = 0; /* Already expired. */ + expires = READ_ONCE(dev->power.last_busy); + expires += (u64)autosuspend_delay * NSEC_PER_MSEC; + if (expires > ktime_get_mono_fast_ns()) + return expires; /* Expires in the future */ - out: - return expires; + return 0; } EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration);