Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3834764ybl; Mon, 13 Jan 2020 03:30:45 -0800 (PST) X-Google-Smtp-Source: APXvYqxgs3jbbDyekykV7GzRVYIi3k1glstmAQZEc7H60t7nsBeVswmErSvCL0kEJxGJMKbpiZt2 X-Received: by 2002:a9d:6b12:: with SMTP id g18mr12114002otp.211.1578915044969; Mon, 13 Jan 2020 03:30:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578915044; cv=none; d=google.com; s=arc-20160816; b=vscDvBvXZzxZjIdcFthIiHEjpNBnN68Lsw4CJPGW2SkdLKHAnWHU33lklBc6O9HAD2 of/O8HlXdi4v+pilJq32v6IpvSanHyGgOOtPcMOr4cN3n64iO9RRheZwGG8nkOjK5hX5 wv6FsDNjnX4dNbC5jLsb/5DSXip+7xl8OYZOUCGCMahA8b1k0DXFNsr3jwtneyovaAq/ c14lcErEpHULTHnIWYJfXOqumNeiPHQ+ORankbzddFCSP4o6BMwZhPHEyWmxVUSmWTzG dDD0mOw53wfI1NKx4tPRsU6K6BEKgQQkDib/e/IYvzaJxO8BfsOoG8tA4BDGPLvMinBI Le/A== 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; bh=r+ec02nV9mDpO+QBktHH/qtGzNnybuxeNQDmuinCql4=; b=oC9aewgAidzWMdeDrKPzDFJkc+ZUaQQqiWplEH4HGdpb+wvleAds+0OaCSIOJdiT+R zMKX4Xnqi1UQF/VFzUq1790zRAcbvshWIfA5PWa01r9o4G799d3+BdvgM4AcNJ5vxOk1 8/WR7c9AwpCgF+Jlgh5Vv7iMx7YL1URiihv09wIq5SaZd/DURDCkEG3Z7H188/E0FcgI OJ5gigVmXov4TzIMn7SPPx+wCL36CcBYkW0oihTQqEmcskqIf9Alr9/IOVh1kcjtFR6b q+VBywb1rPlvYhktktiBwJq5pWbMeUNak3+yWDq5Nq3vOdaP9UUEbXz1M/8wWnwAkLJq 8gZQ== 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 z15si8180916otj.235.2020.01.13.03.30.31; Mon, 13 Jan 2020 03:30:44 -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 S1726878AbgAML3h convert rfc822-to-8bit (ORCPT + 99 others); Mon, 13 Jan 2020 06:29:37 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:56307 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725992AbgAML3h (ORCPT ); Mon, 13 Jan 2020 06:29:37 -0500 Received: from 79.184.255.90.ipv4.supernova.orange.pl (79.184.255.90) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.320) id 9ab51728271c6d21; Mon, 13 Jan 2020 12:29:34 +0100 From: "Rafael J. Wysocki" To: =?utf-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Cc: Greg Kroah-Hartman , Len Brown , Pavel Machek , Steven Rostedt , Ingo Molnar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] PM-runtime: add tracepoints for usage_count changes Date: Mon, 13 Jan 2020 12:29:33 +0100 Message-ID: <12840272.KYWuQ3LjJR@kreacher> In-Reply-To: <20200106100004.GA10946@qmqm.qmqm.pl> References: <20200104182123.GA1485543@kroah.com> <20200106100004.GA10946@qmqm.qmqm.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday, January 6, 2020 11:00:04 AM CET Michał Mirosław wrote: > On Sat, Jan 04, 2020 at 07:21:23PM +0100, Greg Kroah-Hartman wrote: > > On Sat, Jan 04, 2020 at 05:27:57PM +0100, Michał Mirosław wrote: > > > Add tracepoints to remaining places where device's power.usage_count > > > is changed. This helps debugging where and why autosuspend is prevented. > > > > > > Signed-off-by: Michał Mirosław > > > --- > > > drivers/base/power/runtime.c | 13 +++++++++++-- > > > include/trace/events/rpm.h | 6 ++++++ > > > 2 files changed, 17 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c > > > index 48616f358854..16134a69bf6f 100644 > > > --- a/drivers/base/power/runtime.c > > > +++ b/drivers/base/power/runtime.c > > > @@ -1006,8 +1006,10 @@ 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)) > > > + if (!atomic_dec_and_test(&dev->power.usage_count)) { > > > + trace_rpm_usage_rcuidle(dev, rpmflags); > > > > Who and what is really going to use these tracepoints? > > > > And putting them in these if statements seems odd, are you sure that's > > the correct place? What do these show to userspace? > > > > > return 0; > > > + } > > > } > > > > > > might_sleep_if(!(rpmflags & RPM_ASYNC) && !dev->power.irq_safe); > > > @@ -1038,8 +1040,10 @@ 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)) > > > + if (!atomic_dec_and_test(&dev->power.usage_count)) { > > > + trace_rpm_usage_rcuidle(dev, rpmflags); > > > return 0; > > > + } > > > } > > > > > > might_sleep_if(!(rpmflags & RPM_ASYNC) && !dev->power.irq_safe); > > > @@ -1101,6 +1105,7 @@ int pm_runtime_get_if_in_use(struct device *dev) > > > retval = dev->power.disable_depth > 0 ? -EINVAL : > > > dev->power.runtime_status == RPM_ACTIVE > > > && atomic_inc_not_zero(&dev->power.usage_count); > > > + trace_rpm_usage_rcuidle(dev, 0); > > > > Why this one? > > > > > > > spin_unlock_irqrestore(&dev->power.lock, flags); > > > return retval; > > > } > > > @@ -1434,6 +1439,8 @@ void pm_runtime_allow(struct device *dev) > > > dev->power.runtime_auto = true; > > > if (atomic_dec_and_test(&dev->power.usage_count)) > > > rpm_idle(dev, RPM_AUTO | RPM_ASYNC); > > > + else > > > + trace_rpm_usage_rcuidle(dev, RPM_AUTO | RPM_ASYNC); > > > > Are you sure this is correct? > > > > These feel odd... > > This covers all places where power.usage_count might have changed. > If atomic_dec_and_test() decrements usage_count but not to zero, > the new value will be traced in rpm_idle(). But if the value drops to > zero, then we need to trace it explicitly to be able to have all changes > accounted for in the trace. > > I actually used this patch to track down why USB storage device was > not autosuspending correctly. Fair enough, and the patch makes sense to me, so I'm queuing it up as 5.6 material. Thanks!