Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp216456ybh; Tue, 14 Jul 2020 23:31:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynFc5C2mAIDYfNHX8LepIhGIdbtH6CpUhJg3kPdWOKAc3IZbDvXiu4Zy5+lsQl9YpploMp X-Received: by 2002:a17:906:2b50:: with SMTP id b16mr8176429ejg.410.1594794670275; Tue, 14 Jul 2020 23:31:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594794670; cv=none; d=google.com; s=arc-20160816; b=MCXzmA1z7egFuN09ueFEG1KZ6SdML3nEuAfnC/+fZfcFyMNDdna6bTDG+zmFkrucZ9 kFAB+KB2SvDXSNyTUWs3eVPKcn7LTiQM8lx1py8psYIVnmBPpeBmkilvPJV/Zu+1p2Af CAVFVVmGaEu8TEU7uUOZ/CmEuMSciCyCV1D3p0xC5SqBwZda4QYtnjSXss6K+5ZL/hQQ +nnF+PYpFJsKU9KstNVtdHI9zEJVlHCphsC2GbyGdbp8XqkWxEhSwkOyr4USFRc3gD74 6WxRq4MICkA+NxCVQZv9NTb3nORi0y42q6r74eqxc2ggH7eSgqQljSqWAFDDxB/G2ooo ddkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=17ukb0d3q1uo/zWShTTaSesNlUF2TZitOThVbW68bRI=; b=j61Jw/dAeJ9BPU3zIyOCU84tjV3k/HcAyAuNxrngo3gfpbi+rLXkucs/ok/wD2picP CkHQO4yILgeXxEIALfHSd7sMwZOWsbSjGXvCul3ICXPcpkFSukchPA9VmopMf8pOziIW dSAp0ZNp0MkScseqhoL+zv6zBujlvXy6pTsX+PeZdticHiLs4aUJCntzE9DLIMvZIHuG tZ6jk5aLFiZymJH8+ZWuPU8e7avzFO1VgMh1TZk/2dP4H5YVUhaz6um50k3FTVavErsZ jE19ZfcpXLm5pB7XHXx0mB8abvAnBWdrf9pJ5wjFTippadYFCU9fjxEJT3Zp6HkDkRt+ 7wyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v16si707248edr.93.2020.07.14.23.30.47; Tue, 14 Jul 2020 23:31:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728643AbgGOG0t (ORCPT + 99 others); Wed, 15 Jul 2020 02:26:49 -0400 Received: from mga12.intel.com ([192.55.52.136]:37382 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725823AbgGOG0t (ORCPT ); Wed, 15 Jul 2020 02:26:49 -0400 IronPort-SDR: NeMlR0ECTuY5F83ySKZsgQ1xOS3ZsurH2vQ2NlHPI3OHK0/Xai/Jm2Rdgh3VJHWcVwvPfxQPcr HR6OZYEGA1kg== X-IronPort-AV: E=McAfee;i="6000,8403,9682"; a="128653576" X-IronPort-AV: E=Sophos;i="5.75,354,1589266800"; d="scan'208";a="128653576" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2020 23:26:48 -0700 IronPort-SDR: M9uLcZxTsXLulIi+jrO0+1t0W8JaYYGNdr+4FtwqsF7PmNWJID38zjJlmTt061ePX3N5L1n21D xdskanoS3TIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,354,1589266800"; d="scan'208";a="281986346" Received: from chenyu-office.sh.intel.com ([10.239.158.173]) by orsmga003.jf.intel.com with ESMTP; 14 Jul 2020 23:26:46 -0700 From: Chen Yu To: "Rafael J. Wysocki" , Len Brown Cc: Greg Kroah-Hartman , "Michal Miroslaw" , Zhang Rui , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Chen Yu Subject: [PATCH 2/2][RESEND v3] PM-runtime: change the tracepoints to cover all usage_count Date: Wed, 15 Jul 2020 14:28:03 +0800 Message-Id: <395187057e486df9a4328bc6d7d4ee912967fdb3.1594790493.git.yu.c.chen@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit d229290689ae ("PM-runtime: add tracepoints for usage_count changes") has added some tracepoints to monitor the change of runtime usage, and there is something to improve: 1. There are some places that adjust the usage count not been traced yet. For example, pm_runtime_get_noresume() and pm_runtime_put_noidle() 2. The change of the usage count will not be tracked if decreased from 1 to 0. This patch intends to adjust the logic to be consistent with the change of usage_counter, that is to say, only after the counter has been possibly modified, we record it. Besides, all usage changes will be shown using rpm_usage even if included by other trace points. And these changes has helped track down the e1000e runtime issue. Reviewed-by: Michał Mirosław Signed-off-by: Chen Yu --- drivers/base/power/runtime.c | 38 +++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 85a248e196ca..5789d2624513 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1004,10 +1004,11 @@ int __pm_runtime_idle(struct device *dev, int rpmflags) int retval; if (rpmflags & RPM_GET_PUT) { - if (!atomic_dec_and_test(&dev->power.usage_count)) { - trace_rpm_usage_rcuidle(dev, rpmflags); + bool non_zero = !atomic_dec_and_test(&dev->power.usage_count); + + trace_rpm_usage_rcuidle(dev, rpmflags); + if (non_zero) return 0; - } } might_sleep_if(!(rpmflags & RPM_ASYNC) && !dev->power.irq_safe); @@ -1038,10 +1039,12 @@ int __pm_runtime_suspend(struct device *dev, int rpmflags) int retval; if (rpmflags & RPM_GET_PUT) { - if (!atomic_dec_and_test(&dev->power.usage_count)) { - trace_rpm_usage_rcuidle(dev, rpmflags); + bool non_zero = !atomic_dec_and_test(&dev->power.usage_count); + + trace_rpm_usage_rcuidle(dev, rpmflags); + if (non_zero) return 0; - } + } might_sleep_if(!(rpmflags & RPM_ASYNC) && !dev->power.irq_safe); @@ -1073,8 +1076,10 @@ int __pm_runtime_resume(struct device *dev, int rpmflags) might_sleep_if(!(rpmflags & RPM_ASYNC) && !dev->power.irq_safe && dev->power.runtime_status != RPM_ACTIVE); - if (rpmflags & RPM_GET_PUT) + if (rpmflags & RPM_GET_PUT) { atomic_inc(&dev->power.usage_count); + trace_rpm_usage_rcuidle(dev, rpmflags); + } spin_lock_irqsave(&dev->power.lock, flags); retval = rpm_resume(dev, rpmflags); @@ -1433,6 +1438,7 @@ void pm_runtime_forbid(struct device *dev) dev->power.runtime_auto = false; atomic_inc(&dev->power.usage_count); + trace_rpm_usage_rcuidle(dev, 0); rpm_resume(dev, 0); out: @@ -1448,16 +1454,17 @@ EXPORT_SYMBOL_GPL(pm_runtime_forbid); */ void pm_runtime_allow(struct device *dev) { + bool is_zero; + spin_lock_irq(&dev->power.lock); if (dev->power.runtime_auto) goto out; dev->power.runtime_auto = true; - if (atomic_dec_and_test(&dev->power.usage_count)) + is_zero = atomic_dec_and_test(&dev->power.usage_count); + trace_rpm_usage_rcuidle(dev, RPM_AUTO | RPM_ASYNC); + if (is_zero) rpm_idle(dev, RPM_AUTO | RPM_ASYNC); - else - trace_rpm_usage_rcuidle(dev, RPM_AUTO | RPM_ASYNC); - out: spin_unlock_irq(&dev->power.lock); } @@ -1523,9 +1530,8 @@ static void update_autosuspend(struct device *dev, int old_delay, int old_use) /* If it used to be allowed then prevent it. */ if (!old_use || old_delay >= 0) { atomic_inc(&dev->power.usage_count); - rpm_resume(dev, 0); - } else { trace_rpm_usage_rcuidle(dev, 0); + rpm_resume(dev, 0); } } @@ -1533,8 +1539,10 @@ static void update_autosuspend(struct device *dev, int old_delay, int old_use) else { /* If it used to be prevented then allow it. */ - if (old_use && old_delay < 0) + if (old_use && old_delay < 0) { atomic_dec(&dev->power.usage_count); + trace_rpm_usage_rcuidle(dev, 0); + } /* Maybe we can autosuspend now. */ rpm_idle(dev, RPM_AUTO); @@ -1741,12 +1749,14 @@ void pm_runtime_drop_link(struct device *dev) void pm_runtime_get_noresume(struct device *dev) { atomic_inc(&dev->power.usage_count); + trace_rpm_usage_rcuidle(dev, 0); } EXPORT_SYMBOL_GPL(pm_runtime_get_noresume); void pm_runtime_put_noidle(struct device *dev) { atomic_add_unless(&dev->power.usage_count, -1, 0); + trace_rpm_usage_rcuidle(dev, 0); } EXPORT_SYMBOL_GPL(pm_runtime_put_noidle); -- 2.17.1