Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp692049imm; Sat, 7 Jul 2018 06:39:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcnVxkUB19vDHMUhPAFIvNGNVCpe+OqsIBCyk9K8LEkPKMCm8IjUmmHWWJwc7SAkI6FktMT X-Received: by 2002:a63:1a20:: with SMTP id a32-v6mr6507963pga.446.1530970748235; Sat, 07 Jul 2018 06:39:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530970748; cv=none; d=google.com; s=arc-20160816; b=lDGHnAuRDDj27N9FXEDJCcvT1mu/CE6iS+t3qKNTs4TgbNKZJ9rpnQ7v20FEjjyKIn 6Dw5k1mGasUe2LuuSCvWkCE/NYi1iSglBKJmm5ERQnoGNin8uxybEV0hRJ/YVazOj+0m AE4B+oekVUc4yNeDTlE6mRY+LKVa4ZWBmdOKKB22qHaWHyF0XPN5bXua+rVcb1st1I1z Cqe+j0riylxAMi83rSPZO3YI4+mApRp++cIQV+/H2kf85b5xu6VLBk5AwznNTGR5wSnx Ojuq9VamHXsQj7O2xAHP0ei6GdlG24pWeWMAO1OVED3VSq/arsfbFjOaJv0zKJ4+tjym Kp7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=xgeRa7G+MstQsLzNfRiOVbcDMgXnIfKKdn34UjRsAfM=; b=TIgbrSpeeLeDs6+6OH3cCk69hYZBDPEPKCDi2puuqDAjjpH7ErSUyjdgjQWB2ifwaj 9zDprnUf/BwfbhdiXzL8QWWGfRoGZfQmpPqBO69FsV22aKL5Z27tM2mT/Csk3mcA+njN HbRqKoM340SQJA6ZmM5BMpKA+PCbTUzFrRU8cLuCYNkT1wE8YV2qa3D7piv1WeIQyUxm Mpt67wwvNQlbdt3eYR1MSw3WjKsGVQkVuXn9NBrWVb9wuL2pHK6vFIhqrHGKDTW4CAQq ZrKuMkRS7nY0lbZpHYPS6cpBS7shAXUPiWeZ8judAQW7UYwm9j8g1nk9XOGke5Bz6TIz 2kpg== 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 c7-v6si10036886pgt.220.2018.07.07.06.38.53; Sat, 07 Jul 2018 06:39:08 -0700 (PDT) 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 S1753567AbeGGNiS (ORCPT + 99 others); Sat, 7 Jul 2018 09:38:18 -0400 Received: from bmailout2.hostsharing.net ([83.223.90.240]:50905 "EHLO bmailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751964AbeGGNiR (ORCPT ); Sat, 7 Jul 2018 09:38:17 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout2.hostsharing.net (Postfix) with ESMTPS id 7F6E92801E50B; Sat, 7 Jul 2018 15:38:15 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 24D1C36A1B; Sat, 7 Jul 2018 15:38:15 +0200 (CEST) Date: Sat, 7 Jul 2018 15:38:15 +0200 From: Lukas Wunner To: Mika Westerberg Cc: linux-kernel@vger.kernel.org, Andreas Noever , Michael Jamet , Yehezkel Bernat , "Rafael J. Wysocki" , Christian Kellner , Mario Limonciello Subject: Re: [PATCH 5/5] thunderbolt: Add support for runtime PM Message-ID: <20180707133815.GA6656@wunner.de> References: <20180618110731.57427-1-mika.westerberg@linux.intel.com> <20180618110731.57427-6-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180618110731.57427-6-mika.westerberg@linux.intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 18, 2018 at 02:07:31PM +0300, Mika Westerberg wrote: > --- a/drivers/thunderbolt/domain.c > +++ b/drivers/thunderbolt/domain.c > @@ -132,6 +133,8 @@ static ssize_t boot_acl_show(struct device *dev, struct device_attribute *attr, > if (!uuids) > return -ENOMEM; > > + pm_runtime_get_sync(&tb->dev); > + > if (mutex_lock_interruptible(&tb->lock)) { > ret = -ERESTARTSYS; > goto out; [snip] > @@ -426,6 +437,13 @@ int tb_domain_add(struct tb *tb) > /* This starts event processing */ > mutex_unlock(&tb->lock); > > + pm_runtime_no_callbacks(&tb->dev); > + pm_runtime_set_active(&tb->dev); > + pm_runtime_enable(&tb->dev); > + pm_runtime_set_autosuspend_delay(&tb->dev, TB_AUTOSUSPEND_DELAY); > + pm_runtime_mark_last_busy(&tb->dev); > + pm_runtime_use_autosuspend(&tb->dev); > + > return 0; > > err_domain_del: You're setting pm_runtime_no_callbacks() on the domain. A side effect of setting this flag is that whenever the domain's device is runtime resumed, it's parent (the NHI) is *not* runtime resumed, see this comment in rpm_resume(): /* * See if we can skip waking up the parent. This is safe only if * power.no_callbacks is set, because otherwise we don't know whether * the resume will actually succeed. */ Above, you're runtime resuming the domain in boot_acl_show(). So if the NHI is runtime suspended while that sysfs attribute is accessed, it won't be runtime resumed. Is that actually what you want? > @@ -514,6 +532,28 @@ void tb_domain_complete(struct tb *tb) > tb->cm_ops->complete(tb); > } > > +int tb_domain_runtime_suspend(struct tb *tb) > +{ > + if (tb->cm_ops->runtime_suspend) { > + int ret = tb->cm_ops->runtime_suspend(tb); > + if (ret) > + return ret; > + } > + tb_ctl_stop(tb->ctl); > + return 0; > +} > + > +int tb_domain_runtime_resume(struct tb *tb) > +{ > + tb_ctl_start(tb->ctl); > + if (tb->cm_ops->runtime_resume) { > + int ret = tb->cm_ops->runtime_resume(tb); > + if (ret) > + return ret; > + } > + return 0; > +} > + > /** > * tb_domain_approve_switch() - Approve switch > * @tb: Domain the switch belongs to > --- a/drivers/thunderbolt/nhi.c > +++ b/drivers/thunderbolt/nhi.c > @@ -900,7 +900,32 @@ static void nhi_complete(struct device *dev) > struct pci_dev *pdev = to_pci_dev(dev); > struct tb *tb = pci_get_drvdata(pdev); > > - tb_domain_complete(tb); > + /* > + * If we were runtime suspended when system suspend started, > + * schedule runtime resume now. It should bring the domain back > + * to functional state. > + */ > + if (pm_runtime_suspended(&pdev->dev)) > + pm_runtime_resume(&pdev->dev); > + else > + tb_domain_complete(tb); > +} > + > +static int nhi_runtime_suspend(struct device *dev) > +{ > + struct pci_dev *pdev = to_pci_dev(dev); > + struct tb *tb = pci_get_drvdata(pdev); > + > + return tb_domain_runtime_suspend(tb); > +} > + > +static int nhi_runtime_resume(struct device *dev) > +{ > + struct pci_dev *pdev = to_pci_dev(dev); > + struct tb *tb = pci_get_drvdata(pdev); > + > + nhi_enable_int_throttling(tb->nhi); > + return tb_domain_runtime_resume(tb); > } You're invoking tb_domain_runtime_suspend() from nhi_runtime_suspend(), same for ->runtime_resume. Wouldn't it make more sense to make tb_domain_runtime_suspend() the ->runtime_suspend callback of the domain instead of mixing it together with NHI runtime suspend? BTW, what's the purpose of nhi_enable_int_throttling()? > --- a/drivers/thunderbolt/switch.c > +++ b/drivers/thunderbolt/switch.c > +/* > + * Currently only need to provide the callbacks. Everything else is handled > + * in the connection manager. > + */ > +static int __maybe_unused tb_switch_runtime_suspend(struct device *dev) > +{ > + return 0; > +} > + > +static int __maybe_unused tb_switch_runtime_resume(struct device *dev) > +{ > + return 0; > +} > + > +static const struct dev_pm_ops tb_switch_pm_ops = { > + SET_RUNTIME_PM_OPS(tb_switch_runtime_suspend, tb_switch_runtime_resume, > + NULL) > +}; > + > struct device_type tb_switch_type = { > .name = "thunderbolt_device", > .release = tb_switch_release, > + .pm = &tb_switch_pm_ops, > }; Looking at the call sites of RPM_GET_CALLBACK(), I'm under the impression that if no callbacks are defined, the PM core will simply assume success. Then you don't need to define any PM callbacks for tb_switch. Am I missing something? Thanks, Lukas