mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Tony Lindgren <tony@atomide.com>
Cc: Felipe Balbi <balbi@ti.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	Andreas Fenkart <afenkart@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Huiquan Zhong <huiquan.zhong@intel.com>,
	Kevin Hilman <khilman@kernel.org>, NeilBrown <neilb@suse.de>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Nishanth Menon <nm@ti.com>,
	Peter Hurley <peter@hurleysoftware.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org, linux-omap@vger.kernel.org
Subject: Re: [PATCH 2/5] PM / Wakeirq: Add automated device wake IRQ handling
Date: Tue, 19 May 2015 16:04:43 +0200	[thread overview]
Message-ID: <3554198.gIGuGWK14O@vostro.rjw.lan> (raw)
In-Reply-To: <20150518234400.GN10274@atomide.com>

On Monday, May 18, 2015 04:44:01 PM Tony Lindgren wrote:
> * Tony Lindgren <tony@atomide.com> [150518 15:06]:
> > +/**
> > + * dev_pm_set_wake_irq - Attach device IO interrupt as wake IRQ
> > + * @dev: Device entry
> > + * @irq: Device IO interrupt
> > + *
> > + * Attach a device IO interrupt as a wake IRQ. The wake IRQ gets
> > + * automatically configured for wake-up from suspend  based
> > +void dev_pm_clear_wake_irq(struct device *dev)
> > +{
> > +	struct wake_irq *wirq = dev->power.wakeirq;
> > +	unsigned long flags;
> > +
> > +	if (!wirq)
> > +		return;
> > +
> > +	device_wakeup_detach_irq(dev);
> > +
> > +	spin_lock_irqsave(&dev->power.lock, flags);
> > +	if (wirq->manage_irq) {
> > +		free_irq(wirq->irq, wirq);
> > +		wirq->manage_irq = false;
> > +	}
> > +	dev->power.wakeirq = NULL;
> > +	spin_unlock_irqrestore(&dev->power.lock, flags);
> > +
> > +	wirq->irq = -EINVAL;
> > +	kfree(wirq);
> > +}
> 
> I just noticed most of the dev_pm_clear_wake_irq is no longer needed.
> We're now freeing it anyways. so it can be just:
> 
> void dev_pm_clear_wake_irq(struct device *dev)
> {
> 	struct wake_irq *wirq = dev->power.wakeirq;
> 	unsigned long flags;
> 
> 	if (!wirq)
> 		return;
> 
> 	spin_lock_irqsave(&dev->power.lock, flags);
> 	dev->power.wakeirq = NULL;
> 	spin_unlock_irqrestore(&dev->power.lock, flags);
> 
> 	device_wakeup_detach_irq(dev);
> 	if (wirq->manage_irq)
> 		free_irq(wirq->irq, wirq);
> 	kfree(wirq);
> }
> 
> 
> Regards,
> 
> Tony
> 
> 8< ---------------------
> From: Tony Lindgren <tony@atomide.com>
> Date: Mon, 18 May 2015 15:40:29 -0700
> Subject: [PATCH] PM / Wakeirq: Add automated device wake IRQ handling
> 
> Turns out we can automate the handling for the device_may_wakeup()
> quite a bit by using the kernel wakeup source list.
> 
> And as some hardware has separate dedicated wake-up interrupt
> in addition to the IO interrupt, we can automate the handling by
> adding a generic threaded interrupt handler that just calls the
> device PM runtime to wake up the device.
> 
> This allows dropping code from device drivers as we currently
> are doing it in multiple ways, and often wrong.
> 
> For most drivers, we should be able to drop the following
> boilerplate code from runtime_suspend and runtime_resume
> functions:
> 
> 	...
> 	device_init_wakeup(dev, true);
> 	...
> 	if (device_may_wakeup(dev)
> 		enable_irq_wake(irq);
> 	...
> 	if (device_may_wakeup(dev)
> 		enable_irq_wake(irq);

Closing parens are missin in the above two if () statements.

Also, should the second one be disable_irq_wake(irq)?

> 	...
> 	device_init_wakeup(dev, false);
> 	...
> 
> We can replace it with just the following init and exit
> time code:
> 
> 	...
> 	device_init_wakeup(dev, true);
> 	dev_pm_set_wake_irq(dev, irq);
> 	...
> 	dev_pm_clear_wake_irq(dev);
> 	device_init_wakeup(dev, false);
> 	...
> 
> And for hardware with dedicated wake-up interrupts:
> 
> 	...
> 	device_init_wakeup(dev, true);
> 	dev_pm_set_dedicated_wake_irq(dev, irq);
> 	...
> 	dev_pm_clear_wake_irq(dev);
> 	device_init_wakeup(dev, false);
> 	...
> 
> For now, let's only enable it for select PM_WAKEIRQ.

Why?  What would be wrong with doing that unconditionally?


> Signed-off-by: Tony Lindgren <tony@atomide.com>

Looks good overall, a couple of nits below.

[cut]

> +/**
> + * handle_threaded_wake_irq - Handler for dedicated wake-up interrupts
> + * @irq: Device dedicated wake-up interrupt
> + * @_wirq: Wake IRQ data
> + *
> + * Some devices have a separate wake-up interrupt in addition to the
> + * device IO interrupt. The wake-up interrupts signal that the device
> + * should be woken up from a idle state. This handler uses device
> + * specific pm_runtime functions to wake the device and then it's
> + * up to the device to do whatever it needs to. Note as the device
> + * may need to restore context and start up regulators, we use a
> + * threaded IRQ.
> + *
> + * Also note that we are not resending the lost device interrupts.
> + * We assume that the wake-up interrupt just needs to wake-up the
> + * device, and the device pm_runtime_resume() can deal with the
> + * situation.
> + */
> +static irqreturn_t handle_threaded_wake_irq(int irq, void *_wirq)
> +{
> +	struct wake_irq *wirq = _wirq;
> +
> +	/* We don't want RPM_ASYNC or RPM_NOWAIT here */
> +	return pm_runtime_resume(wirq->dev) ? IRQ_NONE : IRQ_HANDLED;

There are various reasons why pm_runtime_resume() may return error codes and
some of them don't mean that the interrupt was not legitimate.

Moreover, it returns 1 if the device is already active, in which case the above
check won't do any good to us.

Why not to return IRQ_HANDLED unconditionally from here?


[cut]

> diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
> index 7e01f78..d3735bd 100644
> --- a/kernel/power/Kconfig
> +++ b/kernel/power/Kconfig
> @@ -267,6 +267,10 @@ config PM_CLK
>  	def_bool y
>  	depends on PM && HAVE_CLK
>  
> +config PM_WAKEIRQ
> +	bool
> +	depends on PM_SLEEP
> +

If you really really want this (I'm still not sure why exactly, though), it
should depend on PM_SLEEP || PM_RUNTIME, because the latter uses it too.

>  config PM_GENERIC_DOMAINS
>  	bool
>  	depends on PM

Thanks,
Rafael


  reply	other threads:[~2015-05-19 13:39 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-13 23:36 [PATCHv3 0/5] Linux generic wakeirq handling Tony Lindgren
2015-05-13 23:36 ` [PATCH 1/5] PM / Runtime: Update last_busy in rpm_resume Tony Lindgren
2015-05-20  7:36   ` Ulf Hansson
2015-05-13 23:36 ` [PATCH 2/5] PM / Wakeirq: Add automated device wake IRQ handling Tony Lindgren
2015-05-14  2:06   ` Felipe Balbi
2015-05-14 15:51     ` Alan Stern
2015-05-14 15:54       ` Felipe Balbi
2015-05-14 15:59     ` Tony Lindgren
2015-05-14 16:09       ` Felipe Balbi
2015-05-14 16:28         ` Tony Lindgren
2015-05-14 17:51           ` Tony Lindgren
2015-05-14 21:15       ` Tony Lindgren
2015-05-14 21:25         ` Felipe Balbi
2015-05-14 22:00         ` Rafael J. Wysocki
2015-05-14 21:59           ` Tony Lindgren
2015-05-15 22:25             ` Tony Lindgren
2015-05-16  1:56               ` Felipe Balbi
2015-05-18 22:05                 ` Tony Lindgren
2015-05-18 23:44                   ` Tony Lindgren
2015-05-19 14:04                     ` Rafael J. Wysocki [this message]
2015-05-19 14:26                       ` Rafael J. Wysocki
2015-05-19 15:09                         ` Tony Lindgren
2015-05-19 18:18                           ` Tony Lindgren
2015-05-19 23:01                             ` Rafael J. Wysocki
2015-05-19 22:41                               ` Thomas Gleixner
2015-05-19 23:31                                 ` Rafael J. Wysocki
2015-05-19 23:27                                   ` Tony Lindgren
2015-05-20  0:25                                     ` Rafael J. Wysocki
2015-05-20  2:10                                       ` Tony Lindgren
2015-05-21  0:54                                         ` Rafael J. Wysocki
2015-05-21  0:35                                           ` Tony Lindgren
2015-05-21  1:40                                           ` Felipe Balbi
2015-05-19 15:15                       ` Tony Lindgren
2015-05-13 23:36 ` [PATCH 3/5] serial: omap: Switch wake-up interrupt to generic wakeirq Tony Lindgren
2015-05-28 14:56   ` Tony Lindgren
2015-05-31  7:16     ` Greg Kroah-Hartman
2015-06-01 22:05       ` Tony Lindgren
2015-05-13 23:36 ` [PATCH 4/5] serial: 8250_omap: Move " Tony Lindgren
2015-05-13 23:36 ` [PATCH 5/5] mmc: omap_hsmmc: Change wake-up interrupt to use " Tony Lindgren
2015-05-25  8:38   ` Ulf Hansson
2015-05-27 22:42     ` Rafael J. Wysocki
2015-05-27 22:45       ` Tony Lindgren
2015-05-28 14:36         ` Tony Lindgren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3554198.gIGuGWK14O@vostro.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=afenkart@gmail.com \
    --cc=balbi@ti.com \
    --cc=bigeasy@linutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=huiquan.zhong@intel.com \
    --cc=khilman@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=neilb@suse.de \
    --cc=nm@ti.com \
    --cc=peter@hurleysoftware.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=stern@rowland.harvard.edu \
    --cc=tglx@linutronix.de \
    --cc=tony@atomide.com \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®