Re: [linux-pm] [PATCH] PM: Make it possible to avoid wakeup eventsfrom being lost

From: Alan Stern
Date: Tue Jun 29 2010 - 15:57:30 EST


On Mon, 28 Jun 2010, David Brownell wrote:

> Did someone post the canonical driver changes
> to make use of this?

No, not really. The patch itself contains an example (PCI) but it
doesn't demonstrate the full range of possible usages.

> Something like
>
> suspend() { /* if wake-enabled, up count */ }
> resume() { /* if upcounted, downcount */ }
>
> is what first comes to mind.. expecting that
> the suspend/resume methods in the driver are
> already doing the right things for enabling
> and later disabling the "system wake" behavior
> on the various relevant hardware events...

The PCI example looks like this:

resume()
{
...
if (device_may_wakeup(dev))
pm_wakeup_event(dev, TIMEOUT_GUESS);
...
}

where TIMEOUT_GUESS is an estimate of how long to wait before allowing
the system to sleep.

For things like keyboards, an example would go more like this:

irq_handler()
{
...
if (key-press event occurred) {
...
if (input queue is empty)
pm_stay_awake(dev);
add event to input queue;
...
}
...
}

read_queue()
{
...
send queued data to userspace
if (input queue is empty)
pm_relax();
...
}

I left out the device_may_wakeup tests; things become rather
complicated if you can have more than one keyboard feeding the same
input queue and some of them are wakeup-enabled while others aren't.

Clearly the appropriate changes will depend on the subsystem and the
kind of event. They may also end up depending on the platform; perhaps
this will be used only on relatively small systems like an Android
phone.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/