From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1427173AbcBSISW (ORCPT ); Fri, 19 Feb 2016 03:18:22 -0500 Received: from mga04.intel.com ([192.55.52.120]:65372 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1427038AbcBSISS (ORCPT ); Fri, 19 Feb 2016 03:18:18 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,469,1449561600"; d="scan'208";a="749234260" Date: Fri, 19 Feb 2016 10:18:04 +0200 From: Mika Westerberg To: Julian Calaby Cc: linux-block@vger.kernel.org, Jens Axboe , Tejun Heo , James Bottomley , "Martin K . Petersen" , "linux-kernel@vger.kernel.org" , linux-ide@vger.kernel.org, linux-scsi Subject: Re: [PATCH 3/7] scsi: Drop runtime PM usage count after host is added Message-ID: <20160219081804.GC1491@lahna.fi.intel.com> References: <1455785657-22924-1-git-send-email-mika.westerberg@linux.intel.com> <1455785657-22924-4-git-send-email-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 19, 2016 at 09:50:50AM +1100, Julian Calaby wrote: > Hi Mika, > > On Thu, Feb 18, 2016 at 7:54 PM, Mika Westerberg > wrote: > > Runtime PM of the SCSI host is already handled by calls to > > scsi_autopm_get_host() and scsi_autopm_put_host() from appropriate places > > whenever the host needs to be powered on. This works fine when there is > > device connected to the host as once it runtime suspends the host will too. > > > > However, if there is no device connected the host is never runtime > > suspended (the usage counter is always 0). > > > > Allow runtime suspend of host even if it has no devices connected by > > calling scsi_autopm_put_host() at the end of scsi_add_host_with_dma(). We > > temporarily increase runtime PM usage counter first so call to > > scsi_autopm_put_host() will result idle request to be scheduled for the > > device. > > > > Signed-off-by: Mika Westerberg > > --- > > drivers/scsi/hosts.c | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c > > index 82ac1cd818ac..e46bf4d152a0 100644 > > --- a/drivers/scsi/hosts.c > > +++ b/drivers/scsi/hosts.c > > @@ -250,6 +250,12 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, > > if (error) > > goto out_destroy_freelist; > > > > + /* > > + * Increase usage count temporarily here so that calling > > + * scsi_autopm_put_host() will trigger runtime idle if there is > > + * nothing else preventing suspending the device. > > + */ > > + pm_runtime_get_noresume(&shost->shost_gendev); > > pm_runtime_set_active(&shost->shost_gendev); > > pm_runtime_enable(&shost->shost_gendev); > > device_enable_async_suspend(&shost->shost_gendev); > > @@ -290,6 +296,7 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, > > goto out_destroy_host; > > > > scsi_proc_host_add(shost); > > + scsi_autopm_put_host(shost); > > Would it be cleaner to export the code that runs when the usage > counter decrements and call it here? There actually is no code to run. This just ensures that the device runtime_idle gets called which allows the parent device to runtime suspend (as it returns 0). Alternative way would be just to call pm_request_idle() directly here.