Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6444267imu; Wed, 30 Jan 2019 15:02:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN4SWZRahiRJsM9PUJ6+XNYUv3teExPOW8uDH0FBpVKXOHl4+6eImQGn88/kuI+jawRVyafe X-Received: by 2002:a62:ca05:: with SMTP id n5mr32533898pfg.154.1548889371671; Wed, 30 Jan 2019 15:02:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548889371; cv=none; d=google.com; s=arc-20160816; b=hAh+56I7mxH5zkQmTIwnzQBxd5A3yrxwleW4q7205mSo4ZSwKqPRrKbu//ROp9r477 GQWSLP8XBJp0xIPnAg73XxFT9L1EsCI3/SUa4qPnBXR0VCvgeWmCisVMMVjt8aaAwb6u S0qZKerTeNOLr6G6MgCU7pSRu7v1q+8tYW9dLqKJX99Q8DVUqT+o7BzeU/wamd3DgVJg lWKpUv67HRapgF0SFyP9gPozGIUCF/xKGJjnThnZ2n2tvWs02jYFp1MOh9GnY/VMpKzB Ghj/IMd7lI1R3zDcxBboTNoE8cQNnMBZG5Cx084TMs5Z9Po+GXAVNTpqQBSkNncI85KC K+9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=9ZVSqRcV1jofih5ZVRFxrHU6ngsfUBqAKmVNOBNTsCU=; b=Xz/PO3+tIvrI485lXASi/oMeUknQIovEXG6NT+CVCMWJU8fpT51R6/AzM5hbPbSCvv iazJIwQtX4HeeHapS2rwhczNgNV07ogGz0IEp9qjvP6MG+mx5U0XVxG9IxgAHjeW8XQO Fpm6oDxQRR2cc1pSHMYlpFHnfPjGD3OO98yS4965DWe1CroCo+o6bKkSQgfi5Ihq4tIJ 1PM5twQdUvbjTqGK1vauhqftGTnwaqOKn7zu4WSm4aXIZE9QWYiodHipkjLfXUIudvMW N1gZ9CCNmPIKxvFDFPJuMequQDa3R5fF/y3tyPoPhRDIrV1oQbxofmfKx0YT6SrJIGrr R5lg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x23si2519071pgj.247.2019.01.30.15.02.33; Wed, 30 Jan 2019 15:02:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388189AbfA3VkW (ORCPT + 99 others); Wed, 30 Jan 2019 16:40:22 -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-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.20.1