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: 10789315 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 E25DC922 for ; Wed, 30 Jan 2019 21:40:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1BEE2FB8D for ; Wed, 30 Jan 2019 21:40:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5C282FE0E; Wed, 30 Jan 2019 21:40: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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8A95C2FB8D for ; Wed, 30 Jan 2019 21:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Niu30Pb2Wgd/kNYwzJX2P/1iKt38Bzi8AMV8VnAH0lA=; b=cz/CjvLdMn7vsk Jpt7Qp7L07ZsrQoe8deg95H5+wzXty4CpcLnvWyLqMjj/L6FR0qCFYlTqFhZ4dLiN85xwpUws1vh4 rKAlC3rT5b3gMBRKPV4X+/ea6n92UUrfm3ou8epVEbgNOeCdSpxntSS00w6Bju/0dR3h0MNMhFZb+ D3ehwLp2GSsJPfn9DS1vNhBfs2GjhheLL2QfSx9xru0MjXL8bxtGdKQig8p6mLKTk3Y7dbzhxIttC Y95rpJO/aeWx0nfovbyoxFb669Lnwp/JVi0+tB0ChT5wdxS2xqW+ibmjmRkSMr+szb314M6p3KtW7 wHAeU7ODFH2pQ9WYXosw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1goxap-0006uj-FR; Wed, 30 Jan 2019 21:40:23 +0000 Received: from eddie.linux-mips.org ([148.251.95.138] helo=cvs.linux-mips.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1goxam-0006uL-HH for linux-arm-kernel@lists.infradead.org; Wed, 30 Jan 2019 21:40:22 +0000 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992792AbfA3VkSjTYCh (ORCPT ); Wed, 30 Jan 2019 22:40:18 +0100 Date: Wed, 30 Jan 2019 22:40:17 +0100 From: Ladislav Michl To: "Rafael J. Wysocki" 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190130_134021_334091_31CFEF55 X-CRM114-Status: GOOD ( 13.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Vincent Guittot , Linux PM , Linux Kernel Mailing List , Biju Das , Linux-Renesas , Geert Uytterhoeven , Linux OMAP Mailing List , Linux ARM Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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);