All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] dynamic device power management proposal
@ 2007-03-19  9:08 Shaohua Li
  2007-03-19 15:44 ` Alan Stern
                   ` (2 more replies)
  0 siblings, 3 replies; 42+ messages in thread
From: Shaohua Li @ 2007-03-19  9:08 UTC (permalink / raw)
  To: linux-pm

[-- Attachment #1: Type: text/plain, Size: 6813 bytes --]

Runtime device power management or dynamic device power management
(dpm).

Why dpm: 
     1. put an idle device into low power state to save power 
     2. speed up S3/S4. In resume time, we could resume devices only as
        the devices are used. In suspend time, we could skip suspended
        devices. (suspend/resume a device equals to change device state)

Basically we need device driver support, a kernel framework and a policy
(determine when to change a device’s power state).

I think we need answer below questions:
1. How to present device’s power info/control interface to policy.
Unlike ACPI Dx state, a device’s power state might depend on several
parameters, like voltage/clock. We must change several parameters in the
meantime to switch device’s power state.
2. How to handle devices dependences. For example, for a PCI endpoint
and a pci bridge above the pci endpoint, we should suspend pci endpoint
device first and then suspend pci bridge and vice versa in resume. On
the other hand, two devices might not have such relationship. Two
devices might haven’t any bus relationship. Eg, in embedded system, a
clock might drive several devices under different buses.
3. How to detect if a device is idle.
4. where should policy be, kernel/userspace. Userspace policy is
flexible, but userspace policy has some limitations like being swapped
out. The limitations don’t impact suspend device, but resume device
should be quick, eg suspended device should be resumed quickly soon
after new service request is coming.

My proposal: 
     1. device’s power parameters. If a device’s power state depends on
        several parameters, we can map different parameters combining
         to a single index, which looks like ACPI Dx state. In this way,
        dpm framework and policy have a generic interface to get/set
        device’s state. Each state exports some info, including this
        state’s power consumption/latency. Device driver can export
        extra info to policy, dpm framework doesn’t handle the extra
        info, but policy can. 
     2. The device dependence varies from different systems especially
        for embedded system. The idea is dpm framework handles device
        dependence (like, resume a device’s parent before resume the
        device itself), and policy inputs the dependence data to dpm
        framework. As device dependence exists, device driver shouldn’t
        directly resume a device. Instead, let dpm framework resumes the
        device and handle dependence in the meantime. To input
        dependence data, policy should know device’s unique name and dpm
        framework can get corresponding dpm device from the name.
        Different buses have different device naming methods. To assign
        a unified name to each device, I just give each device an id
        regardless which bus the device is on. 
     3. detect if a device is idle. The idea is each device has a busy
        timestamp. Every time the driver wants to handle the device,
        driver will update the timestamp. Policy can poll the timestamp
        to determine if the device is idle. 
     4. policy position. The idea is policy resides on userspace. Dpm
        framework exports device’s busy timestamp, state info,
        dependence setting to userspace. According to the info, policy
        suspends a device in specific time. Resuming a device is
        directly done by dpm framework in kernel.

So in my proposal, dpm framework will provide some APIs for device
driver and export some info to userspace and a userspace policy
determines when to suspend a device. Attached code is my prototype to
demonstrate my idea (it even can’t be compiled).  With the framework,
driver/policy should do:
===================device driver==========================
int foo() //all service routines of the driver should do
{ 
            //wakeup the device if it’s suspended
            dpm_active_device();
            … //do service
            /* if necessary, mark the device busy to not suspend the
device */
            dpm_mark_device_busy();
            …//do service
}

struct dpm_driver my_driver {
            .init = xxx_init, //initialize the dpm device, eg. the
device’s state info
            .get_state = xxx_get_state, //get current device’s power
state
            .set_state = xxx_set_state, //set current device’s power
state. Maybe just use .suspend/.resume here
};

driver_init()
{
            dpm_device_bind_driver(dev->dpm, &my_driver);
}

=================user interface======================
Dpm framework will export below sysfs info for every dpm device:
            ../dpm/
                        `id      /*dpm device’s unique id*/
                        `state0     /*all device states’ info*/
                                    `power
                                    `latency
                        `stateX
                                    `power
                                    `latency
                        `state       /* get/set device state */
                        `busy_timestamp   /* device’s busy timestamp */
                        `set_dependence  /* interface to set device
dependence */
                        `status        /* device’s status */
===================policy===========================
/* initialize device dependences */
Write one device’s id to other device’s set_dependence sysfs file.

We consider two type devices:
1. for soundcard, policy does:
a. Setup a timer, the timer polls soundcard’s busy_timestamp sysfs file.
b. if the timer found soundcard is idle for a long time, write the
device’s state sysfs file, and sound card to low power state.
c. policy does nothing to resume soundcard. Soundcard driver’s service
routine will call ’dpm_active_device’ to resume the device
 
2. For keyboard or mouse, policy does:
a. setup a timer, the timer polls keyboard’s busy_timestamp sysfs file.
b. if the timer found keyboard is idle for a long time, write LCD’s
state sysfs file to close LCD.
c. After LCD is closed, policy polls keyboard’s busy_timestamp sysfs
file.
d. if the content changed of the file (maybe using inotify), policy will
open LCD

==================suspend/resume (S3/S4)=====================
1. Device suspend follows current Linux scheme, but ignore suspended
device
2. in resume, don’t do device resume. Device will automatically resume
on demand. No policy application involved in the process, as dpm
framework will be responsible for device resume.

This is my preliminary design, and I’d like to listen to your opinions.

Thanks,
Shaohua

[-- Attachment #2: pm.tgz --]
[-- Type: application/x-compressed-tar, Size: 2367 bytes --]

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-19  9:08 [RFC] dynamic device power management proposal Shaohua Li
@ 2007-03-19 15:44 ` Alan Stern
  2007-03-20  1:06   ` Shaohua Li
                     ` (2 more replies)
  2007-03-20 18:30 ` Pavel Machek
  2007-03-22 20:02 ` David Brownell
  2 siblings, 3 replies; 42+ messages in thread
From: Alan Stern @ 2007-03-19 15:44 UTC (permalink / raw)
  To: Shaohua Li; +Cc: linux-pm

On Mon, 19 Mar 2007, Shaohua Li wrote:

> Runtime device power management or dynamic device power management
> (dpm).
> 
> Why dpm: 
>      1. put an idle device into low power state to save power 
>      2. speed up S3/S4. In resume time, we could resume devices only as
>         the devices are used. In suspend time, we could skip suspended
>         devices. (suspend/resume a device equals to change device state)
> 
> Basically we need device driver support, a kernel framework and a policy
> (determine when to change a device’s power state).

A lot of development along these lines has already been going on in the 
USB subsystem.  It isn't complete yet, but a lot of the ideas you raise 
have already been implemented.

> I think we need answer below questions:
> 1. How to present device’s power info/control interface to policy.
> Unlike ACPI Dx state, a device’s power state might depend on several
> parameters, like voltage/clock. We must change several parameters in the
> meantime to switch device’s power state.
> 2. How to handle devices dependences. For example, for a PCI endpoint
> and a pci bridge above the pci endpoint, we should suspend pci endpoint
> device first and then suspend pci bridge and vice versa in resume. On
> the other hand, two devices might not have such relationship. Two
> devices might haven’t any bus relationship. Eg, in embedded system, a
> clock might drive several devices under different buses.
> 3. How to detect if a device is idle.

These issues are where you are liable to run into trouble.  There are 
extremely dependent on the type of platform, bus, and device.  USB is 
particularly simple in this respect.

> 4. where should policy be, kernel/userspace. Userspace policy is
> flexible, but userspace policy has some limitations like being swapped
> out. The limitations don’t impact suspend device, but resume device
> should be quick, eg suspended device should be resumed quickly soon
> after new service request is coming.
> 
> My proposal: 
>      1. device’s power parameters. If a device’s power state depends on
>         several parameters, we can map different parameters combining
>          to a single index, which looks like ACPI Dx state. In this way,
>         dpm framework and policy have a generic interface to get/set
>         device’s state. Each state exports some info, including this
>         state’s power consumption/latency. Device driver can export
>         extra info to policy, dpm framework doesn’t handle the extra
>         info, but policy can. 
>      2. The device dependence varies from different systems especially
>         for embedded system. The idea is dpm framework handles device
>         dependence (like, resume a device’s parent before resume the
>         device itself), and policy inputs the dependence data to dpm
>         framework. As device dependence exists, device driver shouldn’t
>         directly resume a device. Instead, let dpm framework resumes the
>         device and handle dependence in the meantime. To input
>         dependence data, policy should know device’s unique name and dpm
>         framework can get corresponding dpm device from the name.
>         Different buses have different device naming methods. To assign
>         a unified name to each device, I just give each device an id
>         regardless which bus the device is on. 
>      3. detect if a device is idle. The idea is each device has a busy
>         timestamp. Every time the driver wants to handle the device,
>         driver will update the timestamp. Policy can poll the timestamp
>         to determine if the device is idle. 

That's not how the USB implementation works.  Although a timestamp like 
the one you describe is going to be added.

>      4. policy position. The idea is policy resides on userspace. Dpm
>         framework exports device’s busy timestamp, state info,
>         dependence setting to userspace. According to the info, policy
>         suspends a device in specific time. Resuming a device is
>         directly done by dpm framework in kernel.

In USB, we export the idle-time delay value (device is autosuspended 
when it has been idle longer than this) and an administrative power-level 
atttribute: on, auto, or suspend.  When set to "on" the device will not 
autosuspend; when set to "auto" the device will autosuspend and autoresume 
according to the delay setting; when set to "suspend" the device will be 
suspended and will not autoresume.

(This is cutting-edge stuff, not all present even in the development
trees.  But we're getting there.)

The API design is documented, so far as it exists, by the kerneldoc in 
drivers/usb/core/driver.c.

Alan Stern

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-19 15:44 ` Alan Stern
@ 2007-03-20  1:06   ` Shaohua Li
  2007-03-20 14:58     ` Alan Stern
  2007-03-22  4:42   ` Len Brown
  2007-03-22 19:58   ` David Brownell
  2 siblings, 1 reply; 42+ messages in thread
From: Shaohua Li @ 2007-03-20  1:06 UTC (permalink / raw)
  To: Alan Stern; +Cc: linux-pm

On Mon, 2007-03-19 at 23:44 +0800, Alan Stern wrote:
> On Mon, 19 Mar 2007, Shaohua Li wrote:
> 
> > Runtime device power management or dynamic device power management
> > (dpm).
> >
> > Why dpm:
> >      1. put an idle device into low power state to save power
> >      2. speed up S3/S4. In resume time, we could resume devices only
> as
> >         the devices are used. In suspend time, we could skip
> suspended
> >         devices. (suspend/resume a device equals to change device
> state)
> >
> > Basically we need device driver support, a kernel framework and a
> policy
> > (determine when to change a device’s power state).
> 
> A lot of development along these lines has already been going on in
> the
> USB subsystem.  It isn't complete yet, but a lot of the ideas you
> raise
> have already been implemented.
Ok, I'll look at the USB implementation. On the other hand, I think
there should be a generic framework for all bus types.

> >      4. policy position. The idea is policy resides on userspace.
> Dpm
> >         framework exports device’s busy timestamp, state info,
> >         dependence setting to userspace. According to the info,
> policy
> >         suspends a device in specific time. Resuming a device is
> >         directly done by dpm framework in kernel.
> 
> In USB, we export the idle-time delay value (device is autosuspended
> when it has been idle longer than this) and an administrative
> power-level
> atttribute: on, auto, or suspend.  When set to "on" the device will
> not
> autosuspend; when set to "auto" the device will autosuspend and
> autoresume
> according to the delay setting; when set to "suspend" the device will
> be
> suspended and will not autoresume.
Doing suspend in the driver level isn't flexible. See in the case 'close
console if keyboard/mouse hasn't input', it's hard to do in a driver.

Thanks,
Shaohua
_______________________________________________
linux-pm mailing list
linux-pm@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-20  1:06   ` Shaohua Li
@ 2007-03-20 14:58     ` Alan Stern
  2007-03-21  1:43       ` Shaohua Li
  0 siblings, 1 reply; 42+ messages in thread
From: Alan Stern @ 2007-03-20 14:58 UTC (permalink / raw)
  To: Shaohua Li; +Cc: linux-pm

On Tue, 20 Mar 2007, Shaohua Li wrote:

> > A lot of development along these lines has already been going on in
> > the
> > USB subsystem.  It isn't complete yet, but a lot of the ideas you
> > raise
> > have already been implemented.
> Ok, I'll look at the USB implementation. On the other hand, I think
> there should be a generic framework for all bus types.

I agree, but only to the extent that the concepts can usefully be shared.  
What works for USB might very well not work for a different subsystem.  

My approach has been first to get something that does work in one
subsystem, and then to see about moving it into other subsystems or the PM
core.  I haven't finished the first step yet.  :-)  So it may be a little 
premature to try defining a full-blown dynamic power management solution 
that can apply to everything.

> Doing suspend in the driver level isn't flexible. See in the case 'close
> console if keyboard/mouse hasn't input', it's hard to do in a driver.

I'm a little confused by this.  If you want to suspend a device, surely 
you have to ask the device's driver to do the actual work?

Maybe you mean that the _decision_ to suspend a device sometimes must be 
made by code other than the device's driver.  I agree; nothing I said 
before was meant to rule out such things.  In fact, USB already contains 
several instances where non-driver code decides to suspend a device.  For 
example, when a device's file in the usbfs filesystem is closed, the 
filesystem code attempts to suspend the device.

Alan Stern

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-19  9:08 [RFC] dynamic device power management proposal Shaohua Li
  2007-03-19 15:44 ` Alan Stern
@ 2007-03-20 18:30 ` Pavel Machek
  2007-03-21  1:34   ` Shaohua Li
  2007-03-22 20:02 ` David Brownell
  2 siblings, 1 reply; 42+ messages in thread
From: Pavel Machek @ 2007-03-20 18:30 UTC (permalink / raw)
  To: Shaohua Li; +Cc: linux-pm

Hi!

> Runtime device power management or dynamic device power management
> (dpm).
> 
> Why dpm: 
>      1. put an idle device into low power state to save power 
>      2. speed up S3/S4. In resume time, we could resume devices only as
>         the devices are used. In suspend time, we could skip suspended
>         devices. (suspend/resume a device equals to change device state)
> 
> Basically we need device driver support, a kernel framework and a policy
> (determine when to change a device???s power state).

So far so good, but please use ascii ' for '.

> I think we need answer below questions:
> 1. How to present device???s power info/control interface to policy.
...

Depends on bus, I'm afraid. We do not want to do this in generic code.

> 2. How to handle devices dependences. For example, for a PCI endpoint
...

USB gets the dependencies right, just copy that.

> 3. How to detect if a device is idle.

USB gets this right. It is driver specific, but core can provide some
helpers.

> int foo() //all service routines of the driver should do
> { 
>             //wakeup the device if it???s suspended
>             dpm_active_device();

No, we do not want this kind of interface. It should be something like
mod_timer(my_timer, HZ+10);

We can talk about generic device attribute "powerdown_timeout" in
sysfs... but I'd prefer few more drivers that do powersave before we
do that.

> We consider two type devices:
> 1. for soundcard, policy does:
> a. Setup a timer, the timer polls soundcard???s busy_timestamp sysfs file.
> b. if the timer found soundcard is idle for a long time, write the
> device???s state sysfs file, and sound card to low power state.
> c. policy does nothing to resume soundcard. Soundcard driver???s service
> routine will call ???dpm_active_device??? to resume the device

No, that's not how it works; look at hda_audio, it already has
powersave. Just power down audio card 5 seconds after its control file
is closed.

> 2. For keyboard or mouse, policy does:
> a. setup a timer, the timer polls keyboard???s busy_timestamp sysfs file.
> b. if the timer found keyboard is idle for a long time, write LCD???s
> state sysfs file to close LCD.
> c. After LCD is closed, policy polls keyboard???s busy_timestamp sysfs
> file.
> d. if the content changed of the file (maybe using inotify), policy will
> open LCD

This already works for usb keyboard/mice.

> This is my preliminary design, and I???d like to listen to your opinions.

"Seriously overdesigned".
									Pavel


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-20 18:30 ` Pavel Machek
@ 2007-03-21  1:34   ` Shaohua Li
  2007-03-21 15:21     ` Amit Kucheria
  2007-03-21 21:39     ` Pavel Machek
  0 siblings, 2 replies; 42+ messages in thread
From: Shaohua Li @ 2007-03-21  1:34 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-pm

On Wed, 2007-03-21 at 02:30 +0800, Pavel Machek wrote:
> Hi!
> 
> > Runtime device power management or dynamic device power management
> > (dpm).
> >
> > Why dpm:
> >      1. put an idle device into low power state to save power
> >      2. speed up S3/S4. In resume time, we could resume devices only
> as
> >         the devices are used. In suspend time, we could skip
> suspended
> >         devices. (suspend/resume a device equals to change device
> state)
> >
> > Basically we need device driver support, a kernel framework and a
> policy
> > (determine when to change a device???s power state).
> 
> So far so good, but please use ascii ' for '.
> 
> > I think we need answer below questions:
> > 1. How to present device???s power info/control interface to policy.
> ...
> 
> Depends on bus, I'm afraid. We do not want to do this in generic code.
Agree it depends on bus. But it's better a framework can abstract the
interface

> > 2. How to handle devices dependences. For example, for a PCI
> endpoint
> ...
> 
> USB gets the dependencies right, just copy that.
Does USB include all kinds of dependence, eg non parent-children
dependence?

> > 3. How to detect if a device is idle.
> 
> USB gets this right. It is driver specific, but core can provide some
> helpers.
Sure, this doesn't conflict with my idea.

> > int foo() //all service routines of the driver should do
> > {
> >             //wakeup the device if it???s suspended
> >             dpm_active_device();
> 
> No, we do not want this kind of interface. It should be something like
> mod_timer(my_timer, HZ+10);
1. the device might suspend already here, we should resume it.
2. mod_timer is a bad idea. It's too heavy, if the routine is called
very frequently, mod_timer will be a big overload. That's why I use a
timestamp. Updating a timestamp hasn't any overload.

> We can talk about generic device attribute "powerdown_timeout" in
> sysfs... but I'd prefer few more drivers that do powersave before we
> do that.
Using this you will have a timer in the driver, and the timer's callback
will suspend the device. This approach has some issues. 1. it's better
driver doesn't handle device dependence. This approach requires driver
handle dependence. 2. It's better a userspace policy to directly suspend
a device and driver just provides control interface. A userspace is
definitely flexible and make driver simpler.

> > We consider two type devices:
> > 1. for soundcard, policy does:
> > a. Setup a timer, the timer polls soundcard???s busy_timestamp sysfs
> file.
> > b. if the timer found soundcard is idle for a long time, write the
> > device???s state sysfs file, and sound card to low power state.
> > c. policy does nothing to resume soundcard. Soundcard driver???s
> service
> > routine will call ???dpm_active_device??? to resume the device
> 
> No, that's not how it works; look at hda_audio, it already has
> powersave. Just power down audio card 5 seconds after its control file
> is closed.
It's another case of doing policy in a driver.

Thanks,
Shaohua

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-20 14:58     ` Alan Stern
@ 2007-03-21  1:43       ` Shaohua Li
  2007-03-21 14:44         ` Alan Stern
  0 siblings, 1 reply; 42+ messages in thread
From: Shaohua Li @ 2007-03-21  1:43 UTC (permalink / raw)
  To: Alan Stern; +Cc: linux-pm

On Tue, 2007-03-20 at 22:58 +0800, Alan Stern wrote:
> On Tue, 20 Mar 2007, Shaohua Li wrote:
> 
> > > A lot of development along these lines has already been going on
> in
> > > the
> > > USB subsystem.  It isn't complete yet, but a lot of the ideas you
> > > raise
> > > have already been implemented.
> > Ok, I'll look at the USB implementation. On the other hand, I think
> > there should be a generic framework for all bus types.
> 
> I agree, but only to the extent that the concepts can usefully be
> shared. 
> What works for USB might very well not work for a different
> subsystem. 
> 
> My approach has been first to get something that does work in one
> subsystem, and then to see about moving it into other subsystems or
> the PM
> core.  I haven't finished the first step yet.  :-)  So it may be a
> little
> premature to try defining a full-blown dynamic power management
> solution
> that can apply to everything.
This makes sense.

> > Doing suspend in the driver level isn't flexible. See in the case
> 'close
> > console if keyboard/mouse hasn't input', it's hard to do in a
> driver.
> 
> I'm a little confused by this.  If you want to suspend a device,
> surely
> you have to ask the device's driver to do the actual work?
> 
> Maybe you mean that the _decision_ to suspend a device sometimes must
> be
> made by code other than the device's driver.  
Yep.
> I agree; nothing I said
> before was meant to rule out such things.  In fact, USB already
> contains
> several instances where non-driver code decides to suspend a device.
> For
> example, when a device's file in the usbfs filesystem is closed, the
> filesystem code attempts to suspend the device.
This is another question. Should we make decision in kernel layer?

Thanks,
Shaohua

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-21  1:43       ` Shaohua Li
@ 2007-03-21 14:44         ` Alan Stern
  0 siblings, 0 replies; 42+ messages in thread
From: Alan Stern @ 2007-03-21 14:44 UTC (permalink / raw)
  To: Shaohua Li; +Cc: linux-pm

On Wed, 21 Mar 2007, Shaohua Li wrote:

> > I agree; nothing I said
> > before was meant to rule out such things.  In fact, USB already
> > contains
> > several instances where non-driver code decides to suspend a device.
> > For
> > example, when a device's file in the usbfs filesystem is closed, the
> > filesystem code attempts to suspend the device.
> This is another question. Should we make decision in kernel layer?

Why not?  If the only reason the device is in use is because the kernel 
layer has opened its device file, then when the kernel layer closes the 
file the device will be idle and so it should be suspended.

Alan Stern

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-21  1:34   ` Shaohua Li
@ 2007-03-21 15:21     ` Amit Kucheria
  2007-03-21 21:49       ` Dmitry Krivoschekov
  2007-03-21 21:39     ` Pavel Machek
  1 sibling, 1 reply; 42+ messages in thread
From: Amit Kucheria @ 2007-03-21 15:21 UTC (permalink / raw)
  To: Shaohua Li; +Cc: linux-pm, Pavel Machek

On 3/21/07, Shaohua Li <shaohua.li@intel.com> wrote:
> On Wed, 2007-03-21 at 02:30 +0800, Pavel Machek wrote:

> > No, that's not how it works; look at hda_audio, it already has
> > powersave. Just power down audio card 5 seconds after its control file
> > is closed.
> It's another case of doing policy in a driver.
>

IMHO, this kind of policy is best handled inside the driver because it
is specific to the hardware. This will ensure that the driver will
just work on every distro without some userspace policy being present
and setup _correctly_.

In the above case if the driver runs on a single architecture, chances
are you can figure out what the best value (5s) for that arch is and
hardwire it.

If the driver indeed runs on multiple architectures that have
drastically different notions of the optimum values, then I guess it
could be exposed through sysfs.  Even then, it doesn't seem likely
that the value would be changed from what it is initialized to.

I have yet to come across drivers where you change these values
several times at runtime. If I am simply being ignorant, I would
appreciate some examples.

Regards,
Amit
--
Amit Kucheria, NOKIA

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-21  1:34   ` Shaohua Li
  2007-03-21 15:21     ` Amit Kucheria
@ 2007-03-21 21:39     ` Pavel Machek
  2007-03-22  3:09       ` Shaohua Li
  2007-03-22 19:20       ` David Brownell
  1 sibling, 2 replies; 42+ messages in thread
From: Pavel Machek @ 2007-03-21 21:39 UTC (permalink / raw)
  To: Shaohua Li; +Cc: linux-pm

Hi!

> > So far so good, but please use ascii ' for '.
> > 
> > > I think we need answer below questions:
> > > 1. How to present device???s power info/control interface to policy.
> > ...
> > 
> > Depends on bus, I'm afraid. We do not want to do this in generic code.
> Agree it depends on bus. But it's better a framework can abstract the
> interface

Parse error. Anyway, feel free to suggest framework to improve USB.

> > > 2. How to handle devices dependences. For example, for a PCI
> > endpoint
> > ...
> > 
> > USB gets the dependencies right, just copy that.
> Does USB include all kinds of dependence, eg non parent-children
> dependence?

No, probably not, as USB was designed properly. How common are those
cross dependencies? Do we really want to solve them generically?

> > > int foo() //all service routines of the driver should do
> > > {
> > >             //wakeup the device if it???s suspended
> > >             dpm_active_device();
> > 
> > No, we do not want this kind of interface. It should be something like
> > mod_timer(my_timer, HZ+10);
> 1. the device might suspend already here, we should resume it.
> 2. mod_timer is a bad idea. It's too heavy, if the routine is called
> very frequently, mod_timer will be a big overload. That's why I use a
> timestamp. Updating a timestamp hasn't any overload.

Heh, if mod_timer is bad idea, we'll fix mod_timer. Anyway, if you use
timestamp, you'll have to add polling, and that means overhead even
when idle.

Anyway, we do not have to decide that at this point.

> > We can talk about generic device attribute "powerdown_timeout" in
> > sysfs... but I'd prefer few more drivers that do powersave before we
> > do that.
> Using this you will have a timer in the driver, and the timer's callback
> will suspend the device. This approach has some issues. 1. it's better
> driver doesn't handle device dependence. This approach requires driver
> handle dependence. 

Why not?

> 2. It's better a userspace policy to directly suspend
> a device and driver just provides control interface. A userspace is
> definitely flexible and make driver simpler.

No.

> > No, that's not how it works; look at hda_audio, it already has
> > powersave. Just power down audio card 5 seconds after its control file
> > is closed.
> It's another case of doing policy in a driver.

Yes, but in this case we want it there, as someone already explained.

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-21 15:21     ` Amit Kucheria
@ 2007-03-21 21:49       ` Dmitry Krivoschekov
  2007-03-21 22:54         ` Pavel Machek
  0 siblings, 1 reply; 42+ messages in thread
From: Dmitry Krivoschekov @ 2007-03-21 21:49 UTC (permalink / raw)
  To: Amit Kucheria; +Cc: linux-pm, Pavel Machek

Amit Kucheria wrote:
> On 3/21/07, Shaohua Li <shaohua.li@intel.com> wrote:
>> On Wed, 2007-03-21 at 02:30 +0800, Pavel Machek wrote:
>
>>> No, that's not how it works; look at hda_audio, it already has
>>> powersave. Just power down audio card 5 seconds after its control file
>>> is closed.
>> It's another case of doing policy in a driver.
>>
>
> IMHO, this kind of policy is best handled inside the driver because it
> is specific to the hardware. This will ensure that the driver will
> just work on every distro without some userspace policy being present
> and setup _correctly_.

It some circumstances this policy may increase power consumption
but not decrease it. Consider the case of repeatable operation,
something like periodic sound beep, with period of 5s.
In this case, a driver implementing the policy will periodically
suspend/resume a number of devices - audio controller, codec, ADC,
but the operation  itself (suspending/resuming) will consume
more power than power consumed by these devices in case they
left running for a 5s. In such a case you may want to change
the predefined  value or  just  disable the policy.

Yes, we may just not close a sound device file, but phone
applications I've seen, do close the file.

And, my example is applicable not for audio drivers only,
keep the file opened may be impossible for some reason.

 

Thanks,
Dmitry

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-21 21:49       ` Dmitry Krivoschekov
@ 2007-03-21 22:54         ` Pavel Machek
  0 siblings, 0 replies; 42+ messages in thread
From: Pavel Machek @ 2007-03-21 22:54 UTC (permalink / raw)
  To: Dmitry Krivoschekov; +Cc: linux-pm

On Thu 2007-03-22 00:49:51, Dmitry Krivoschekov wrote:
> Amit Kucheria wrote:
> > On 3/21/07, Shaohua Li <shaohua.li@intel.com> wrote:
> >> On Wed, 2007-03-21 at 02:30 +0800, Pavel Machek wrote:
> >
> >>> No, that's not how it works; look at hda_audio, it already has
> >>> powersave. Just power down audio card 5 seconds after its control file
> >>> is closed.
> >> It's another case of doing policy in a driver.
> >>
> >
> > IMHO, this kind of policy is best handled inside the driver because it
> > is specific to the hardware. This will ensure that the driver will
> > just work on every distro without some userspace policy being present
> > and setup _correctly_.
> 
> It some circumstances this policy may increase power consumption
> but not decrease it. Consider the case of repeatable operation,

And what... that happens. Lets not break our design because you can
think of very contrieved corner case.

> something like periodic sound beep, with period of 5s.
> In this case, a driver implementing the policy will periodically
> suspend/resume a number of devices - audio controller, codec, ADC,
> but the operation  itself (suspending/resuming) will consume
> more power than power consumed by these devices in case they
> left running for a 5s. In such a case you may want to change
> the predefined  value or  just  disable the policy.

> Yes, we may just not close a sound device file, but phone
> applications I've seen, do close the file.

Fix the app, then.

								Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-21 21:39     ` Pavel Machek
@ 2007-03-22  3:09       ` Shaohua Li
  2007-03-22 13:13         ` Pavel Machek
  2007-03-22 19:20       ` David Brownell
  1 sibling, 1 reply; 42+ messages in thread
From: Shaohua Li @ 2007-03-22  3:09 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-pm

On Thu, 2007-03-22 at 05:39 +0800, Pavel Machek wrote:
> > > > int foo() //all service routines of the driver should do
> > > > {
> > > >             //wakeup the device if it???s suspended
> > > >             dpm_active_device();
> > >
> > > No, we do not want this kind of interface. It should be something
> like
> > > mod_timer(my_timer, HZ+10);
> > 1. the device might suspend already here, we should resume it.
> > 2. mod_timer is a bad idea. It's too heavy, if the routine is called
> > very frequently, mod_timer will be a big overload. That's why I use
> a
> > timestamp. Updating a timestamp hasn't any overload.
> 
> Heh, if mod_timer is bad idea, we'll fix mod_timer. Anyway, if you use
> timestamp, you'll have to add polling, and that means overhead even
> when idle.
No, we don't need poll the timestamp frequently (maybe 1 minute or 5
minute one time depends on your requirement)

> Anyway, we do not have to decide that at this point.
> 
> > > We can talk about generic device attribute "powerdown_timeout" in
> > > sysfs... but I'd prefer few more drivers that do powersave before
> we
> > > do that.
> > Using this you will have a timer in the driver, and the timer's
> callback
> > will suspend the device. This approach has some issues. 1. it's
> better
> > driver doesn't handle device dependence. This approach requires
> driver
> > handle dependence.
> 
> Why not?
This will make driver complex. Driver should be as simple as possible.

Thanks,
Shaohua

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-19 15:44 ` Alan Stern
  2007-03-20  1:06   ` Shaohua Li
@ 2007-03-22  4:42   ` Len Brown
  2007-03-22 11:56     ` Jim Gettys
                       ` (2 more replies)
  2007-03-22 19:58   ` David Brownell
  2 siblings, 3 replies; 42+ messages in thread
From: Len Brown @ 2007-03-22  4:42 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-pm

On Monday 19 March 2007 11:44, Alan Stern wrote:
> On Mon, 19 Mar 2007, Shaohua Li wrote:
> 
> > Runtime device power management or dynamic device power management
> > (dpm).
> > 
> > Why dpm: 
> >      1. put an idle device into low power state to save power 
> >      2. speed up S3/S4. In resume time, we could resume devices only as
> >         the devices are used. In suspend time, we could skip suspended
> >         devices. (suspend/resume a device equals to change device state)

Today on system suspend we suspend all devices.
Today on system resume, we resume all devices.
In the future we need to recognize that upon system suspend,
some devices are already suspended.
We need to remember that, so upon resume we can restove
them to their suspended state, rather than blindly resuming everything.

> > Basically we need device driver support, a kernel framework and a policy
> > (determine when to change a device’s power state).
> 
> A lot of development along these lines has already been going on in the 
> USB subsystem.  It isn't complete yet, but a lot of the ideas you raise 
> have already been implemented.

Of course we should avoid the acronym "DPM",
as that already means something else:-)

> > I think we need answer below questions:
> > 1. How to present device’s power info/control interface to policy.
> > Unlike ACPI Dx state, a device’s power state might depend on several
> > parameters, like voltage/clock. We must change several parameters in the
> > meantime to switch device’s power state.

> > 2. How to handle devices dependences. For example, for a PCI endpoint
> > and a pci bridge above the pci endpoint, we should suspend pci endpoint
> > device first and then suspend pci bridge and vice versa in resume. On
> > the other hand, two devices might not have such relationship. Two
> > devices might haven’t any bus relationship. Eg, in embedded system, a
> > clock might drive several devices under different buses.

The embedded devices which have a lot of complicated
platform specific dependencies.  These devices effectively get
a custom distribution -- custom kernel, and custom management application.

I think we'd create a big mess if we try to figure out these dependencies
at boot time with generic kernel code that runs on everything.

Instead I think we should focus on exporting the appropriate APIs
so that a management application with platform specific knowledge can
efficiently get the kernel/drivers to implement its policies.

I think that for laptops/desktops/servers with industry standard
components we _do_ need the generic kernel to figure out the dependencies
at boot time.

> > 3. How to detect if a device is idle.
> 
> These issues are where you are liable to run into trouble.  There are 
> extremely dependent on the type of platform, bus, and device.  USB is 
> particularly simple in this respect.
> 
> > 4. where should policy be, kernel/userspace. Userspace policy is
> > flexible, but userspace policy has some limitations like being swapped
> > out. The limitations don’t impact suspend device, but resume device
> > should be quick, eg suspended device should be resumed quickly soon
> > after new service request is coming.
> > 
> > My proposal: 
> >      1. device’s power parameters. If a device’s power state depends on
> >         several parameters, we can map different parameters combining
> >          to a single index, which looks like ACPI Dx state. In this way,
> >         dpm framework and policy have a generic interface to get/set
> >         device’s state. Each state exports some info, including this
> >         state’s power consumption/latency. Device driver can export
> >         extra info to policy, dpm framework doesn’t handle the extra
> >         info, but policy can. 

I don't think it is realistic for devices to export power numbers to user-space.
Sure, it would be great, I just don't think it is realistic.

Latencies?  maybe.

In general, no API has a chance until somebody actually tries it out
and programs to it.

> >      2. The device dependence varies from different systems especially
> >         for embedded system. The idea is dpm framework handles device
> >         dependence (like, resume a device’s parent before resume the
> >         device itself), and policy inputs the dependence data to dpm
> >         framework. As device dependence exists, device driver shouldn’t
> >         directly resume a device. Instead, let dpm framework resumes the
> >         device and handle dependence in the meantime. To input
> >         dependence data, policy should know device’s unique name and dpm
> >         framework can get corresponding dpm device from the name.
> >         Different buses have different device naming methods. To assign
> >         a unified name to each device, I just give each device an id
> >         regardless which bus the device is on. 

I'm skeptical about an additional framework in the kernel to track
dependencies, as I don't think we should even try to track embedded system
dependencies in the kernel.  For laptop/desktop/server, perhaps we can
focus on making the existing device tree be 90% of what we need and
augment it with the missing 10%, like the relationship between
PCI devices and the devices that control hotplug on the slots
that they're plugged into...

> >      3. detect if a device is idle. The idea is each device has a busy
> >         timestamp. Every time the driver wants to handle the device,
> >         driver will update the timestamp. Policy can poll the timestamp
> >         to determine if the device is idle. 
> 
> That's not how the USB implementation works.  Although a timestamp like 
> the one you describe is going to be added.

I sort of like this idea -- it seems that it is low overhead.
Of course it requires every device driver to be changed.
Instead we could maybe hook the generic driver entry points
and do this in the framework -- dunno if that is viable.

> >      4. policy position. The idea is policy resides on userspace. Dpm
> >         framework exports device’s busy timestamp, state info,
> >         dependence setting to userspace. According to the info, policy
> >         suspends a device in specific time. Resuming a device is
> >         directly done by dpm framework in kernel.
> 
> In USB, we export the idle-time delay value (device is autosuspended 
> when it has been idle longer than this) and an administrative power-level 
> atttribute: on, auto, or suspend.  When set to "on" the device will not 
> autosuspend; when set to "auto" the device will autosuspend and autoresume 
> according to the delay setting; when set to "suspend" the device will be 
> suspended and will not autoresume.
> 
> (This is cutting-edge stuff, not all present even in the development
> trees.  But we're getting there.)
> 
> The API design is documented, so far as it exists, by the kerneldoc in 
> drivers/usb/core/driver.c.

This is the "intelligent device driver" model -- the driver actually has a clue
and can do the work internally.  Probably we need some combination of this
plus the simple timeout/user-policy-manager for dumber drivers if we are to
cover the whole system.

-Len

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22  4:42   ` Len Brown
@ 2007-03-22 11:56     ` Jim Gettys
  2007-03-22 19:28       ` David Brownell
  2007-03-22 13:20     ` Pavel Machek
  2007-03-22 19:41     ` David Brownell
  2 siblings, 1 reply; 42+ messages in thread
From: Jim Gettys @ 2007-03-22 11:56 UTC (permalink / raw)
  To: Len Brown; +Cc: linux-pm, linux-pm

On Thu, 2007-03-22 at 00:42 -0400, Len Brown wrote:

> Today on system suspend we suspend all devices.
> Today on system resume, we resume all devices.
> In the future we need to recognize that upon system suspend,
> some devices are already suspended.
> We need to remember that, so upon resume we can restove
> them to their suspended state, rather than blindly resuming everything.

On system suspend, we may not want to suspend all devices; we may need
to leave certain devices alone, and only power down the host interface
to them.

Upon system resume, therefore, devices may also *not* need to be
resumed; only the host interface to them powered up again.

We have two devices in the OLPC machine in this class: our screen, and
our wireless, both of which will often/usually be left on while the rest
of the sysetm is suspended.
                                          - Jim


-- 
Jim Gettys
One Laptop Per Child

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22  3:09       ` Shaohua Li
@ 2007-03-22 13:13         ` Pavel Machek
  0 siblings, 0 replies; 42+ messages in thread
From: Pavel Machek @ 2007-03-22 13:13 UTC (permalink / raw)
  To: Shaohua Li; +Cc: linux-pm

Hi!

> > Heh, if mod_timer is bad idea, we'll fix mod_timer. Anyway, if you use
> > timestamp, you'll have to add polling, and that means overhead even
> > when idle.
> No, we don't need poll the timestamp frequently (maybe 1 minute or 5
> minute one time depends on your requirement)

Hmm, so instead of powering down soundcard 5 seconds after its last
use, we'll power it down 5 _minutes_ after that?

> > Anyway, we do not have to decide that at this point.
> > 
> > > > We can talk about generic device attribute "powerdown_timeout" in
> > > > sysfs... but I'd prefer few more drivers that do powersave before
> > we
> > > > do that.
> > > Using this you will have a timer in the driver, and the timer's
> > callback
> > > will suspend the device. This approach has some issues. 1. it's
> > better
> > > driver doesn't handle device dependence. This approach requires
> > driver
> > > handle dependence.
> > 
> > Why not?
> This will make driver complex. Driver should be as simple as possible.

You are free to provide helpers. Of course drivers will get more
complex with pm, but that's unavoidable.

								Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22  4:42   ` Len Brown
  2007-03-22 11:56     ` Jim Gettys
@ 2007-03-22 13:20     ` Pavel Machek
  2007-03-22 13:44       ` Oliver Neukum
  2007-03-22 19:41     ` David Brownell
  2 siblings, 1 reply; 42+ messages in thread
From: Pavel Machek @ 2007-03-22 13:20 UTC (permalink / raw)
  To: Len Brown; +Cc: linux-pm, linux-pm

Hi!

> > > Runtime device power management or dynamic device power management
> > > (dpm).
> > > 
> > > Why dpm: 
> > >      1. put an idle device into low power state to save power 
> > >      2. speed up S3/S4. In resume time, we could resume devices only as
> > >         the devices are used. In suspend time, we could skip suspended
> > >         devices. (suspend/resume a device equals to change device state)
> 
> Today on system suspend we suspend all devices.
> Today on system resume, we resume all devices.

That's not how it works.

On system suspend, we _tell_ all devices to suspend

If device driver auto-suspended, it will of course not do anything. I
believe we want to keep it designed like that.

> Instead I think we should focus on exporting the appropriate APIs
> so that a management application with platform specific knowledge can
> efficiently get the kernel/drivers to implement its policies.

Please... pick one driver for whatever hardware you like... MMC card
reader in x60? And add runtime suspend/resume to that.

You'll probably find out that no new APIs are needed.

> > > My proposal: 
> > >      1. device’s power parameters. If a device’s power state depends on
> > >         several parameters, we can map different parameters combining
> > >          to a single index, which looks like ACPI Dx state. In this way,
> > >         dpm framework and policy have a generic interface to get/set
> > >         device’s state. Each state exports some info, including this
> > >         state’s power consumption/latency. Device driver can export
> > >         extra info to policy, dpm framework doesn’t handle the extra
> > >         info, but policy can. 
> 
> I don't think it is realistic for devices to export power numbers to user-space.
> Sure, it would be great, I just don't think it is realistic.
> 
> Latencies?  maybe.

Not sure about latencies. So open() on soundcard takes few miliseconds
more... userspace will not even notice.

> In general, no API has a chance until somebody actually tries it out
> and programs to it.

Yes... please.

> > >      3. detect if a device is idle. The idea is each device has a busy
> > >         timestamp. Every time the driver wants to handle the device,
> > >         driver will update the timestamp. Policy can poll the timestamp
> > >         to determine if the device is idle. 
> > 
> > That's not how the USB implementation works.  Although a timestamp like 
> > the one you describe is going to be added.
> 
> I sort of like this idea -- it seems that it is low overhead.
> Of course it requires every device driver to be changed.
> Instead we could maybe hook the generic driver entry points
> and do this in the framework -- dunno if that is viable.

No, you can't get around changing all the drivers.

Generic entry points are for _system_ suspend, and if you try to abuse
them for runtime PM, you'll have to audit/change all the drivers.

> > (This is cutting-edge stuff, not all present even in the development
> > trees.  But we're getting there.)
> > 
> > The API design is documented, so far as it exists, by the kerneldoc in 
> > drivers/usb/core/driver.c.
> 
> This is the "intelligent device driver" model -- the driver actually has a clue
> and can do the work internally.  Probably we need some combination of this
> plus the simple timeout/user-policy-manager for dumber drivers if we are to
> cover the whole system.

You simply turn dumber drivers to more inteligent ones for devices you
care about. As I explained above, you have to touch the drivers
anyway.

Maybe some helpers to make that job easier are possible...
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 13:20     ` Pavel Machek
@ 2007-03-22 13:44       ` Oliver Neukum
  2007-03-22 13:56         ` Pavel Machek
  0 siblings, 1 reply; 42+ messages in thread
From: Oliver Neukum @ 2007-03-22 13:44 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-pm, Pavel Machek

Am Donnerstag, 22. März 2007 14:20 schrieb Pavel Machek:
> > > That's not how the USB implementation works.  Although a timestamp like 
> > > the one you describe is going to be added.
> > 
> > I sort of like this idea -- it seems that it is low overhead.
> > Of course it requires every device driver to be changed.
> > Instead we could maybe hook the generic driver entry points
> > and do this in the framework -- dunno if that is viable.
> 
> No, you can't get around changing all the drivers.
> 
> Generic entry points are for _system_ suspend, and if you try to abuse
> them for runtime PM, you'll have to audit/change all the drivers.

Is this your position regarding USB autosuspend, too? Should we use
other methods than suspend/resume?

	Regards
		Oliver

PS: Do we have _two_ pm lists?

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 13:44       ` Oliver Neukum
@ 2007-03-22 13:56         ` Pavel Machek
  2007-03-22 14:18           ` Oliver Neukum
  0 siblings, 1 reply; 42+ messages in thread
From: Pavel Machek @ 2007-03-22 13:56 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: linux-pm, linux-pm

Hi!

> > > > That's not how the USB implementation works.  Although a timestamp like 
> > > > the one you describe is going to be added.
> > > 
> > > I sort of like this idea -- it seems that it is low overhead.
> > > Of course it requires every device driver to be changed.
> > > Instead we could maybe hook the generic driver entry points
> > > and do this in the framework -- dunno if that is viable.
> > 
> > No, you can't get around changing all the drivers.
> > 
> > Generic entry points are for _system_ suspend, and if you try to abuse
> > them for runtime PM, you'll have to audit/change all the drivers.
> 
> Is this your position regarding USB autosuspend, too? Should we use
> other methods than suspend/resume?

Well, you should have audited USB drivers when enabling autosuspend...
But I believe you did that so you are pretty much okay.

(With autosuspend, you can get situation when request from userland
comes in even when device is suspended; some devices will need
fixing).

								Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 13:56         ` Pavel Machek
@ 2007-03-22 14:18           ` Oliver Neukum
  2007-03-22 14:22             ` Pavel Machek
  0 siblings, 1 reply; 42+ messages in thread
From: Oliver Neukum @ 2007-03-22 14:18 UTC (permalink / raw)
  To: Pavel Machek, Alan Stern; +Cc: linux-pm, linux-pm

Am Donnerstag, 22. März 2007 14:56 schrieb Pavel Machek:
> > > Generic entry points are for _system_ suspend, and if you try to abuse
> > > them for runtime PM, you'll have to audit/change all the drivers.
> > 
> > Is this your position regarding USB autosuspend, too? Should we use
> > other methods than suspend/resume?
> 
> Well, you should have audited USB drivers when enabling autosuspend...
> But I believe you did that so you are pretty much okay.

We audited them. Respectively, are auditing them.

> (With autosuspend, you can get situation when request from userland
> comes in even when device is suspended; some devices will need
> fixing).

Currently, such requests are ignored. Is there any problem with that?

	Regards
		Oliver

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 14:18           ` Oliver Neukum
@ 2007-03-22 14:22             ` Pavel Machek
  2007-03-22 14:26               ` Oliver Neukum
  0 siblings, 1 reply; 42+ messages in thread
From: Pavel Machek @ 2007-03-22 14:22 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: linux-pm, linux-pm

On Thu 2007-03-22 15:18:34, Oliver Neukum wrote:
> Am Donnerstag, 22. März 2007 14:56 schrieb Pavel Machek:
> > > > Generic entry points are for _system_ suspend, and if you try to abuse
> > > > them for runtime PM, you'll have to audit/change all the drivers.
> > > 
> > > Is this your position regarding USB autosuspend, too? Should we use
> > > other methods than suspend/resume?
> > 
> > Well, you should have audited USB drivers when enabling autosuspend...
> > But I believe you did that so you are pretty much okay.
> 
> We audited them. Respectively, are auditing them.

Ok. (It would be nice to document 'USB suspend/resume routines are
called during runtime, too' somewhere.

> > (With autosuspend, you can get situation when request from userland
> > comes in even when device is suspended; some devices will need
> > fixing).
> 
> Currently, such requests are ignored. Is there any problem with that?

You should probably autowake such device, no?

So USB stick sits unused for 10minutes and autosuspend. I want to read
the USB stick. Stick needs to autowakeup, me thinks.
								Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 14:22             ` Pavel Machek
@ 2007-03-22 14:26               ` Oliver Neukum
  2007-03-22 14:35                 ` Pavel Machek
  0 siblings, 1 reply; 42+ messages in thread
From: Oliver Neukum @ 2007-03-22 14:26 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-pm, linux-pm

Am Donnerstag, 22. März 2007 15:22 schrieb Pavel Machek:
> On Thu 2007-03-22 15:18:34, Oliver Neukum wrote:
> > Am Donnerstag, 22. März 2007 14:56 schrieb Pavel Machek:

> > > Well, you should have audited USB drivers when enabling autosuspend...
> > > But I believe you did that so you are pretty much okay.
> > 
> > We audited them. Respectively, are auditing them.
> 
> Ok. (It would be nice to document 'USB suspend/resume routines are
> called during runtime, too' somewhere.

OK.

> > > (With autosuspend, you can get situation when request from userland
> > > comes in even when device is suspended; some devices will need
> > > fixing).
> > 
> > Currently, such requests are ignored. Is there any problem with that?
> 
> You should probably autowake such device, no?

Sorry, I misunderstood. IO requests wake an autosuspended device.
A system wide suspend is ignored, if the device is already suspended.

	Regards
		Oliver

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 14:26               ` Oliver Neukum
@ 2007-03-22 14:35                 ` Pavel Machek
  0 siblings, 0 replies; 42+ messages in thread
From: Pavel Machek @ 2007-03-22 14:35 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: linux-pm, linux-pm

Hi!

> > > > (With autosuspend, you can get situation when request from userland
> > > > comes in even when device is suspended; some devices will need
> > > > fixing).
> > > 
> > > Currently, such requests are ignored. Is there any problem with that?
> > 
> > You should probably autowake such device, no?
> 
> Sorry, I misunderstood. IO requests wake an autosuspended device.
> A system wide suspend is ignored, if the device is already suspended.

Yes, that's okay. (ISTR problems when IO request oopsed an
autosuspended device).
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-21 21:39     ` Pavel Machek
  2007-03-22  3:09       ` Shaohua Li
@ 2007-03-22 19:20       ` David Brownell
  2007-03-22 20:32         ` Alan Stern
  1 sibling, 1 reply; 42+ messages in thread
From: David Brownell @ 2007-03-22 19:20 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-pm, Pavel Machek

On Wednesday 21 March 2007 2:39 pm, Pavel Machek wrote:

> > > USB gets the dependencies right, just copy that.
> > Does USB include all kinds of dependence, eg non parent-children
> > dependence?
> 
> No, probably not, as USB was designed properly.

It was designed to work with as few wires as possible:  "minimalist"
design.  That's not the same as "proper"; not everything works with
the same design constraints.


> How common are those cross dependencies?

Common.  SOC audio setups are relatively simple examples, which
I know have been making trouble on Linux for some time.  One hopes
that the new ALSA SOC stuff helps sort this out:

  - SOC serial controller (I2S, AC97, McBSP, SII, etc) manages
    encoded data bitsteams (e.g. N channels, PCM or uLaw, etc)
    for input, output, or both.

  - External codec interprets those bitstreams.

  - That codec is controlled using I2C, SPI, or some other bus
    for control, e.g. "set volume", "enter stereo mode".

  - The codec and serial controllers have separate power controls.

Think of this as separate control, data, and power channels;
which are not multiplexed like USB.

At the hardware level it probably looks like two different driver
model devices (I2S/etc, and codec) that could have semi-generic
drivers (I think this is what the ALSA SOC stuff is aiming for),
plus board-specific "power codec on/off" interfaces.  Then there
are the /dev interfaces ALSA creates for each functionality.


> Do we really want to solve them generically? 

What we need to be generic is:  PM not preventing good solutions.
I'm not sure we're there yet.

- Dave

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 11:56     ` Jim Gettys
@ 2007-03-22 19:28       ` David Brownell
  0 siblings, 0 replies; 42+ messages in thread
From: David Brownell @ 2007-03-22 19:28 UTC (permalink / raw)
  To: linux-pm, jg

On Thursday 22 March 2007 4:56 am, Jim Gettys wrote:

> On system suspend, we may not want to suspend all devices; we may need
> to leave certain devices alone, and only power down the host interface
> to them.
> 
> Upon system resume, therefore, devices may also *not* need to be
> resumed; only the host interface to them powered up again.
> 
> We have two devices in the OLPC machine in this class: our screen, and
> our wireless, both of which will often/usually be left on while the rest
> of the sysetm is suspended.

I'm suspecting this is an area where Linux doesn't yet do what you
need to be done.  Right?

Of course, one model here is that this "suspend" is not the same as
an "echo something > /sys/power/state" ... that you'd be using runtime
power management, and just opportunistically notice that the system is
going to be idle for a while so that with CONFIG_NO_HZ your system idle
loop could shut down various things (CPU, maybe more).

- Dave

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22  4:42   ` Len Brown
  2007-03-22 11:56     ` Jim Gettys
  2007-03-22 13:20     ` Pavel Machek
@ 2007-03-22 19:41     ` David Brownell
  2 siblings, 0 replies; 42+ messages in thread
From: David Brownell @ 2007-03-22 19:41 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-pm

On Wednesday 21 March 2007 9:42 pm, Len Brown wrote:

> > >      2. The device dependence varies from different systems especially
> > >         for embedded system. The idea is dpm framework handles device
> > >         dependence (like, resume a device’s parent before resume the
> > >         device itself),

The driver model PM framework **ALREADY DOES THAT** so nothing new
is required ...


> I'm skeptical about an additional framework in the kernel to track
> dependencies,

The clock framework and driver model tree already handle a big chunk
of those dependencies.  Of course, they're also not an "additional"
framework (except maybe from the x86 perspective, where the clock
framework isn't available).


> as I don't think we should even try to track embedded system 
> dependencies in the kernel.

That approach seems unlikely to work, unless one wants to make it
even harder to use Linux on embedded systems.  On the other hand,
I'd hate to see a "dependency tracking API" rather than something
focussed on solving specific problems.  (Solve first, then maybe
generalize later.)


> This is the "intelligent device driver" model -- the driver actually has a clue
> and can do the work internally.  Probably we need some combination of this
> plus the simple timeout/user-policy-manager for dumber drivers if we are to
> cover the whole system.

Yes, those two approaches should cover large chunks of the driver space.

- Dave

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-19 15:44 ` Alan Stern
  2007-03-20  1:06   ` Shaohua Li
  2007-03-22  4:42   ` Len Brown
@ 2007-03-22 19:58   ` David Brownell
  2 siblings, 0 replies; 42+ messages in thread
From: David Brownell @ 2007-03-22 19:58 UTC (permalink / raw)
  To: linux-pm

On Monday 19 March 2007 8:44 am, Alan Stern wrote:
> On Mon, 19 Mar 2007, Shaohua Li wrote:
> 
> > ...
> > Basically we need device driver support, a kernel framework and a policy
> > (determine when to change a device’s power state).
> 
> A lot of development along these lines has already been going on in the 
> USB subsystem.  It isn't complete yet, but a lot of the ideas you raise 
> have already been implemented.

ISTR pointing out a few years ago that USB makes a good testbed for
such things, in technical terms ... it's got the "complete problem"
wrapped up in one more-or-less modern subsystem.  So making it do
PM well has been an object lesson in how the Linux PM infrastructure
works -- or, too often, doesn't.

The most troublesome spot being that ACPI interferes on PCs, so we
can't yet do stuff like put EHCI/OHCI/UHCI controllers into PCI_D2 at
runtime and rely on remote wakeup.   But embedded Linux systems make
it easy to work with saner frameworks; on those systems you can see
even more of the pieces working well together.  :)

- Dave

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-19  9:08 [RFC] dynamic device power management proposal Shaohua Li
  2007-03-19 15:44 ` Alan Stern
  2007-03-20 18:30 ` Pavel Machek
@ 2007-03-22 20:02 ` David Brownell
  2007-03-22 22:10   ` Greg KH
  2 siblings, 1 reply; 42+ messages in thread
From: David Brownell @ 2007-03-22 20:02 UTC (permalink / raw)
  To: linux-pm

On Monday 19 March 2007 2:08 am, Shaohua Li wrote:
> This is my preliminary design, and I’d like to listen to your opinions.

Best forwarded as a patch, not a tarfile...

And also, best expressed as improvements to the standard driver model
PM framework, rather than something new.  For example, pick one issue
that the driver model doesn't handle well enough to suit you, and
work on patches to solve that.

- Dave

_______________________________________________
linux-pm mailing list
linux-pm@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 19:20       ` David Brownell
@ 2007-03-22 20:32         ` Alan Stern
  0 siblings, 0 replies; 42+ messages in thread
From: Alan Stern @ 2007-03-22 20:32 UTC (permalink / raw)
  To: David Brownell; +Cc: linux-pm, linux-pm, Pavel Machek

On Thu, 22 Mar 2007, David Brownell wrote:

> On Wednesday 21 March 2007 2:39 pm, Pavel Machek wrote:
> 
> > > > USB gets the dependencies right, just copy that.
> > > Does USB include all kinds of dependence, eg non parent-children
> > > dependence?
> > 
> > No, probably not, as USB was designed properly.
> 
> It was designed to work with as few wires as possible:  "minimalist"
> design.  That's not the same as "proper"; not everything works with
> the same design constraints.

Sort of an off-topic side issue:  One of the aspects of USB that I have
found surprisingly "improper" is the way it handles remote wakeup.  
According to the USB spec, when a device sends a remote wakeup request to
its parent hub, the hub _has_ to resume the device -- or if the hub is
also suspended, it has to pass the wakeup request on up to its own parent,
all the way back to the host computer if necessary.

The point is, the wakeup request must be honored (and fairly quickly,
too); the spec doesn't allow the parent to keep the device suspended.  
Although presumably nothing terribly bad would happen if it did.

Alan Stern

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 20:02 ` David Brownell
@ 2007-03-22 22:10   ` Greg KH
  0 siblings, 0 replies; 42+ messages in thread
From: Greg KH @ 2007-03-22 22:10 UTC (permalink / raw)
  To: linux-pm

On Thu, Mar 22, 2007 at 01:02:38PM -0700, David Brownell wrote:
> On Monday 19 March 2007 2:08 am, Shaohua Li wrote:
> > This is my preliminary design, and I???d like to listen to your opinions.
> 
> Best forwarded as a patch, not a tarfile...

Especially as some of us don't even look at the tarfile...

> And also, best expressed as improvements to the standard driver model
> PM framework, rather than something new.  For example, pick one issue
> that the driver model doesn't handle well enough to suit you, and
> work on patches to solve that.

Exactly.  Remember, one tiny step at a time please.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-27 12:05 ` Pavel Machek
@ 2007-03-27 12:19   ` Oliver Neukum
  0 siblings, 0 replies; 42+ messages in thread
From: Oliver Neukum @ 2007-03-27 12:19 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-pm, Pavel Machek

Am Dienstag, 27. März 2007 14:05 schrieb Pavel Machek:
> High-latency devices indeed may be served better by separating the
> semantics. Fortunately the high-latency (we are talking >50msec here,

USB takes a minimum of 30ms to resume a device.

	Regards
		Oliver
-- 
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg)
This signature is a legal requirement

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 19:05 Scott E. Preece
@ 2007-03-27 12:05 ` Pavel Machek
  2007-03-27 12:19   ` Oliver Neukum
  0 siblings, 1 reply; 42+ messages in thread
From: Pavel Machek @ 2007-03-27 12:05 UTC (permalink / raw)
  To: Scott E. Preece; +Cc: linux-pm

Hi!

> | > And latency may be ignorable in a laptop environment, but it absolutely
> | > isn't in embedded devices, which users expect to operate immediately, as
> | > though they were gear-driven rather than computer-driven.
> | 
> | What latency are you talking about? Powering up piece of hw takes one
> | milisecond or something. If your /dev/dsp takes 3 seconds to power up,
> | you probably need userspace policy daemon. But that is not the case,
> | hw takes few miliseconds to wake up.
> 
> Sure, but *some* devices take substantially longer to power up or
> down.  If you insist that the driver should make the power down
> decision, then you lump high-latency and low-latency devices together,
> even though high-latency devices might be better served by separating
> the semantics.

High-latency devices indeed may be served better by separating the
semantics. Fortunately the high-latency (we are talking >50msec here,
right?) are rare enough... Like "none" in most embedded
systems... Actually only common high-latency device is harddrive
(spinup/spindown), and that's already handled specially with userspace
hooks.

									Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-21 20:19 Scott E. Preece
  2007-03-21 21:45 ` Pavel Machek
@ 2007-03-26 13:53 ` Amit Kucheria
  1 sibling, 0 replies; 42+ messages in thread
From: Amit Kucheria @ 2007-03-26 13:53 UTC (permalink / raw)
  To: Scott E. Preece; +Cc: linux-pm, pavel

On 3/21/07, Scott E. Preece <preece@motorola.com> wrote:
>
> | From: "Amit Kucheria"<kucheria.amit@gmail.com>
> |
> | On 3/21/07, Shaohua Li <shaohua.li@intel.com> wrote:
> | > On Wed, 2007-03-21 at 02:30 +0800, Pavel Machek wrote:
> |
> | > > No, that's not how it works; look at hda_audio, it already has
> | > > powersave. Just power down audio card 5 seconds after its control file
> | > > is closed.
> | > It's another case of doing policy in a driver.
> | >
> |
> | IMHO, this kind of policy is best handled inside the driver because it
> | is specific to the hardware. This will ensure that the driver will
> | just work on every distro without some userspace policy being present
> | and setup _correctly_.
> ---

I was playing devil's advocate here. Considering who I work for, we
definitely have cases where having all these settings configurable
from userspace sounds like a very good idea. But after thinking some
more, I am worried about having too many things exported to userspace
and increasing the complexity of the policy manager. Combined with
poorly chosen default values, it would mean that one could never
compile and flash a kernel that would give good battery life without
also running the vendor-shipped user-space policy manager that might
be binary only.

> On an embedded device, the knowledge of when it makes sense to keep a
> disk spinning, to avoid latency when it's needed next, versus when it
> makes sense to spin it down to save power, probably fits better in user
> space than in the kernel. In such a case there's likely to be a "master"
> application (in our case, for instance, "the phone application") that
> owns a lot of knowledge about whole-system state and user interactions.
> Not, of course, that we have a disk to spin down.
>
> On the other hand, we also have devices that do their own power saving,
> largely in cases where they don't have latency issues large enough to
> worry about.

I believe we do need something along the lines of what USB has as
pointed out by Alan - an 'idle time' value and a 'allowed target
state' entry.

Regards,
Amit
--
Amit Kucheria, NOKIA

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
@ 2007-03-22 19:18 Scott E. Preece
  0 siblings, 0 replies; 42+ messages in thread
From: Scott E. Preece @ 2007-03-22 19:18 UTC (permalink / raw)
  To: stern; +Cc: linux-pm, pavel


| From: Alan Stern<stern@rowland.harvard.edu>
| 
| On Thu, 22 Mar 2007, Scott E. Preece wrote:
| 
| > I would normally call designs that expect important functions (like
| > power on/power off) to happen as side effects of other operations (like
| > opening and closing files) broken to begin with. It's still a bad idea
| > to hide policy inside the driver.
| 
| Even though other people have already answered this, I'd like to add my 
| own comments.
| 
| Firstly, doing power on/power off as side effects of other operations is 
| _not_ a policy choice.  It is a design principle:
| 
| 	When device D has been idle for more than N ms, it should be
| 	put in a low-power state (unless such state changes have been
| 	disabled for D by userspace).
| 
| Of course N will vary for different D's, and the exact choice of N _is_
| policy.  Thus N should be exposed and configurable by userspace.  So
| should the ability to disable the state changes.  But the principle
| above isn't a policy, it is part of the design.
| 
| Secondly, this principle _requires_ that power on/power off occur as side 
| effects of other operations, since those other operations affect whether 
| or not the device is idle.
| 
| If anybody wants to argue against the principle itself, then go ahead and
| say so.  I, for one, don't see anything objectionable about it.
---

I have absolutely no problem with the principle, as long as things are
as you describe - the timing is exposed and configurable and there is
the ability to disable the transitions.

I also have no problem with operations interacting with power on/off
when they clearly have to (sure, if the device is off and the user
writes to it, you probably want to turn it on), but open and close are
different in that respect from read and write - they simply delimit the
time over which operations may be requested and don't inherently imply
anything about the power-state of the device. There is no reason
whatever that a device has to be powered on all the time its driver has
it recorded as open and there's no reason to assume it's OK to power it
off when it's closed.

I disagree with you about whether it's policy (it seems to me that
deciding when to apply a mechanism is exactly what policy is), but it's
not worth arguing about.

scott
-- 
scott preece
motorola mobile devices, il67, 1800 s. oak st., champaign, il  61820  
e-mail:	preece@motorola.com	fax:	+1-217-384-8550
phone:	+1-217-384-8589	cell: +1-217-433-6114	pager: 2174336114@vtext.com

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
@ 2007-03-22 19:05 Scott E. Preece
  2007-03-27 12:05 ` Pavel Machek
  0 siblings, 1 reply; 42+ messages in thread
From: Scott E. Preece @ 2007-03-22 19:05 UTC (permalink / raw)
  To: pavel; +Cc: linux-pm


| From: Pavel Machek<pavel@ucw.cz>
| 
| Hi!
| 
| > | > Yes, we may just not close a sound device file, but phone
| > | > applications I've seen, do close the file.
| > | 
| > | Fix the app, then.
| > ---
| > 
| > I would normally call designs that expect important functions (like
| > power on/power off) to happen as side effects of other operations (like
| > opening and closing files) broken to begin with. It's still a bad idea
| > to hide policy inside the driver.
| 
| Then you are welcome to go design your own operating system.
| 
| I certinaly do not want open() on powered down /dev/dsp to succeed
| with /dev/dsp powered down.
---

I don't, either. I just don't want it to power down unless I've said
it's OK. I would be fine with an API that cleanly tells the device not
to power down on its own. 

You said "let's not break our designs for corner cases"; I simply
expressed the opinion that that aspect of the design seemed broken, by
normal software design criteria - don't let important things happen as
side effects.

---
| 
| > There's nothing contrived or corner-case-ish about cyclic operations in
| > a world where media players, animations, etc., are utterly
| > commonplace.
| 
| Yep? And you close your sound device between those?
---

We close it between some kinds of cyclic operations. We'd like to be
able to be finer grained in the future.

---
| > And latency may be ignorable in a laptop environment, but it absolutely
| > isn't in embedded devices, which users expect to operate immediately, as
| > though they were gear-driven rather than computer-driven.
| 
| What latency are you talking about? Powering up piece of hw takes one
| milisecond or something. If your /dev/dsp takes 3 seconds to power up,
| you probably need userspace policy daemon. But that is not the case,
| hw takes few miliseconds to wake up.
---

Sure, but *some* devices take substantially longer to power up or
down.  If you insist that the driver should make the power down
decision, then you lump high-latency and low-latency devices together,
even though high-latency devices might be better served by separating
the semantics.

scott

-- 
scott preece
motorola mobile devices, il67, 1800 s. oak st., champaign, il  61820  
e-mail:	preece@motorola.com	fax:	+1-217-384-8550
phone:	+1-217-384-8589	cell: +1-217-433-6114	pager: 2174336114@vtext.com

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 14:45 ` Alan Stern
@ 2007-03-22 18:53   ` David Brownell
  0 siblings, 0 replies; 42+ messages in thread
From: David Brownell @ 2007-03-22 18:53 UTC (permalink / raw)
  To: linux-pm; +Cc: pavel

On Thursday 22 March 2007 7:45 am, Alan Stern wrote:
> On Thu, 22 Mar 2007, Scott E. Preece wrote:
> 
> > I would normally call designs that expect important functions (like
> > power on/power off) to happen as side effects of other operations (like
> > opening and closing files) broken to begin with. It's still a bad idea
> > to hide policy inside the driver.
> 
> Even though other people have already answered this, I'd like to add my 
> own comments.
> 
> Firstly, doing power on/power off as side effects of other operations is 
> _not_ a policy choice.  It is a design principle:

Yes ... and one that's widely used in other contexts:  deallocate
resources when they're not in active use.


> 	When device D has been idle for more than N ms, it should be
> 	put in a low-power state (unless such state changes have been
> 	disabled for D by userspace).

THAT is however something I would call a heuristic.  It's a widely
used one -- disk spindown uses one value for N, displays enter their
lowpower states using other values for N, etc -- but it's still not
as definitive as for example "if the device isn't opened, it can't
possibly be in use".

Not that I see a way around having such a heuristic for things like mice,
or anything wrong with that one ... I just want to call a spade a spade
here, and not confuse (a) the design principle, with (b) a heuristic that's
used to implement that principle in certain cases.

 
> Of course N will vary for different D's, and the exact choice of N _is_
> policy.  Thus N should be exposed and configurable by userspace.  So
> should the ability to disable the state changes.  But the principle
> above isn't a policy, it is part of the design.
> 
> Secondly, this principle _requires_ that power on/power off occur as side 
> effects of other operations, since those other operations affect whether 
> or not the device is idle.
> 
> If anybody wants to argue against the principle itself, then go ahead and
> say so.  I, for one, don't see anything objectionable about it.

Me either -- for either principle or, in general, that heuristic.

Of course, choosing to apply that heuristic to a given device is
a different kettle of fish.  That's why it's got an "off" switch.  :)

- Dave

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 13:39 Scott E. Preece
  2007-03-22 13:48 ` Oliver Neukum
  2007-03-22 14:01 ` Pavel Machek
@ 2007-03-22 14:45 ` Alan Stern
  2007-03-22 18:53   ` David Brownell
  2 siblings, 1 reply; 42+ messages in thread
From: Alan Stern @ 2007-03-22 14:45 UTC (permalink / raw)
  To: Scott E. Preece; +Cc: linux-pm, pavel

On Thu, 22 Mar 2007, Scott E. Preece wrote:

> I would normally call designs that expect important functions (like
> power on/power off) to happen as side effects of other operations (like
> opening and closing files) broken to begin with. It's still a bad idea
> to hide policy inside the driver.

Even though other people have already answered this, I'd like to add my 
own comments.

Firstly, doing power on/power off as side effects of other operations is 
_not_ a policy choice.  It is a design principle:

	When device D has been idle for more than N ms, it should be
	put in a low-power state (unless such state changes have been
	disabled for D by userspace).

Of course N will vary for different D's, and the exact choice of N _is_
policy.  Thus N should be exposed and configurable by userspace.  So
should the ability to disable the state changes.  But the principle
above isn't a policy, it is part of the design.

Secondly, this principle _requires_ that power on/power off occur as side 
effects of other operations, since those other operations affect whether 
or not the device is idle.

If anybody wants to argue against the principle itself, then go ahead and
say so.  I, for one, don't see anything objectionable about it.

Alan Stern

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 13:39 Scott E. Preece
  2007-03-22 13:48 ` Oliver Neukum
@ 2007-03-22 14:01 ` Pavel Machek
  2007-03-22 14:45 ` Alan Stern
  2 siblings, 0 replies; 42+ messages in thread
From: Pavel Machek @ 2007-03-22 14:01 UTC (permalink / raw)
  To: Scott E. Preece; +Cc: linux-pm

Hi!

> | > Yes, we may just not close a sound device file, but phone
> | > applications I've seen, do close the file.
> | 
> | Fix the app, then.
> ---
> 
> I would normally call designs that expect important functions (like
> power on/power off) to happen as side effects of other operations (like
> opening and closing files) broken to begin with. It's still a bad idea
> to hide policy inside the driver.

Then you are welcome to go design your own operating system.

I certinaly do not want open() on powered down /dev/dsp to succeed
with /dev/dsp powered down.

> There's nothing contrived or corner-case-ish about cyclic operations in
> a world where media players, animations, etc., are utterly
> commonplace.

Yep? And you close your sound device between those?

> And latency may be ignorable in a laptop environment, but it absolutely
> isn't in embedded devices, which users expect to operate immediately, as
> though they were gear-driven rather than computer-driven.

What latency are you talking about? Powering up piece of hw takes one
milisecond or something. If your /dev/dsp takes 3 seconds to power up,
you probably need userspace policy daemon. But that is not the case,
hw takes few miliseconds to wake up.
								Pavel
				thinking about "don't feed the Trolls" label
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-22 13:39 Scott E. Preece
@ 2007-03-22 13:48 ` Oliver Neukum
  2007-03-22 14:01 ` Pavel Machek
  2007-03-22 14:45 ` Alan Stern
  2 siblings, 0 replies; 42+ messages in thread
From: Oliver Neukum @ 2007-03-22 13:48 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-pm, pavel

Am Donnerstag, 22. März 2007 14:39 schrieb Scott E. Preece:
> There's nothing contrived or corner-case-ish about cyclic operations in
> a world where media players, animations, etc., are utterly commonplace.
> And latency may be ignorable in a laptop environment, but it absolutely
> isn't in embedded devices, which users expect to operate immediately, as
> though they were gear-driven rather than computer-driven.

USB currently uses a delay and a switch in sysfs. Devices that have
several power saving levels would also need an attribute to specify that.
Is that acceptable?

	Regards
		Oliver

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
@ 2007-03-22 13:39 Scott E. Preece
  2007-03-22 13:48 ` Oliver Neukum
                   ` (2 more replies)
  0 siblings, 3 replies; 42+ messages in thread
From: Scott E. Preece @ 2007-03-22 13:39 UTC (permalink / raw)
  To: pavel; +Cc: linux-pm


| From: Pavel Machek<pavel@ucw.cz>
| 
| On Thu 2007-03-22 00:49:51, Dmitry Krivoschekov wrote:
| > Amit Kucheria wrote:
| > > On 3/21/07, Shaohua Li <shaohua.li@intel.com> wrote:
| > >> On Wed, 2007-03-21 at 02:30 +0800, Pavel Machek wrote:
| > >
| > >>> No, that's not how it works; look at hda_audio, it already has
| > >>> powersave. Just power down audio card 5 seconds after its control file
| > >>> is closed.
| > >> It's another case of doing policy in a driver.
| > >>
| > >
| > > IMHO, this kind of policy is best handled inside the driver because it
| > > is specific to the hardware. This will ensure that the driver will
| > > just work on every distro without some userspace policy being present
| > > and setup _correctly_.
| > 
| > It some circumstances this policy may increase power consumption
| > but not decrease it. Consider the case of repeatable operation,
| 
| And what... that happens. Lets not break our design because you can
| think of very contrieved corner case.
| 
| > something like periodic sound beep, with period of 5s.
| > In this case, a driver implementing the policy will periodically
| > suspend/resume a number of devices - audio controller, codec, ADC,
| > but the operation  itself (suspending/resuming) will consume
| > more power than power consumed by these devices in case they
| > left running for a 5s. In such a case you may want to change
| > the predefined  value or  just  disable the policy.
| 
| > Yes, we may just not close a sound device file, but phone
| > applications I've seen, do close the file.
| 
| Fix the app, then.
---

I would normally call designs that expect important functions (like
power on/power off) to happen as side effects of other operations (like
opening and closing files) broken to begin with. It's still a bad idea
to hide policy inside the driver.

There's nothing contrived or corner-case-ish about cyclic operations in
a world where media players, animations, etc., are utterly commonplace.
And latency may be ignorable in a laptop environment, but it absolutely
isn't in embedded devices, which users expect to operate immediately, as
though they were gear-driven rather than computer-driven.

scott
-- 
scott preece
motorola mobile devices, il67, 1800 s. oak st., champaign, il  61820  
e-mail:	preece@motorola.com	fax:	+1-217-384-8550
phone:	+1-217-384-8589	cell: +1-217-433-6114	pager: 2174336114@vtext.com

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
  2007-03-21 20:19 Scott E. Preece
@ 2007-03-21 21:45 ` Pavel Machek
  2007-03-26 13:53 ` Amit Kucheria
  1 sibling, 0 replies; 42+ messages in thread
From: Pavel Machek @ 2007-03-21 21:45 UTC (permalink / raw)
  To: Scott E. Preece; +Cc: linux-pm

Hi!

> | > > No, that's not how it works; look at hda_audio, it already has
> | > > powersave. Just power down audio card 5 seconds after its control file
> | > > is closed.
> | > It's another case of doing policy in a driver.
> | >
> | 
> | IMHO, this kind of policy is best handled inside the driver because it
> | is specific to the hardware. This will ensure that the driver will
> | just work on every distro without some userspace policy being present
> | and setup _correctly_.
> ---
> 
> On an embedded device, the knowledge of when it makes sense to keep a
> disk spinning, to avoid latency when it's needed next, versus when it
> makes sense to spin it down to save power, probably fits better in user
> space than in the kernel. In such a case there's likely to be a "master"
> application (in our case, for instance, "the phone application") that
> owns a lot of knowledge about whole-system state and user interactions.
> Not, of course, that we have a disk to spin down.

Agreed. Please use existing interfaces. Patch to spin disk down and
keep it down is available... but hdparm -y is enough for you.

> On the other hand, we also have devices that do their own power saving,
> largely in cases where they don't have latency issues large enough to
> worry about.

Yep. 

And we do not need great new handwavy framework for
this... please. Just add support for platform you care about.
								Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] dynamic device power management proposal
@ 2007-03-21 20:19 Scott E. Preece
  2007-03-21 21:45 ` Pavel Machek
  2007-03-26 13:53 ` Amit Kucheria
  0 siblings, 2 replies; 42+ messages in thread
From: Scott E. Preece @ 2007-03-21 20:19 UTC (permalink / raw)
  To: kucheria.amit; +Cc: linux-pm, pavel


| From: "Amit Kucheria"<kucheria.amit@gmail.com>
| 
| On 3/21/07, Shaohua Li <shaohua.li@intel.com> wrote:
| > On Wed, 2007-03-21 at 02:30 +0800, Pavel Machek wrote:
| 
| > > No, that's not how it works; look at hda_audio, it already has
| > > powersave. Just power down audio card 5 seconds after its control file
| > > is closed.
| > It's another case of doing policy in a driver.
| >
| 
| IMHO, this kind of policy is best handled inside the driver because it
| is specific to the hardware. This will ensure that the driver will
| just work on every distro without some userspace policy being present
| and setup _correctly_.
---

On an embedded device, the knowledge of when it makes sense to keep a
disk spinning, to avoid latency when it's needed next, versus when it
makes sense to spin it down to save power, probably fits better in user
space than in the kernel. In such a case there's likely to be a "master"
application (in our case, for instance, "the phone application") that
owns a lot of knowledge about whole-system state and user interactions.
Not, of course, that we have a disk to spin down.

On the other hand, we also have devices that do their own power saving,
largely in cases where they don't have latency issues large enough to
worry about.

scott
-- 
scott preece
motorola mobile devices, il67, 1800 s. oak st., champaign, il  61820  
e-mail:	preece@motorola.com	fax:	+1-217-384-8550
phone:	+1-217-384-8589	cell: +1-217-433-6114	pager: 2174336114@vtext.com

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2007-03-27 12:19 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-19  9:08 [RFC] dynamic device power management proposal Shaohua Li
2007-03-19 15:44 ` Alan Stern
2007-03-20  1:06   ` Shaohua Li
2007-03-20 14:58     ` Alan Stern
2007-03-21  1:43       ` Shaohua Li
2007-03-21 14:44         ` Alan Stern
2007-03-22  4:42   ` Len Brown
2007-03-22 11:56     ` Jim Gettys
2007-03-22 19:28       ` David Brownell
2007-03-22 13:20     ` Pavel Machek
2007-03-22 13:44       ` Oliver Neukum
2007-03-22 13:56         ` Pavel Machek
2007-03-22 14:18           ` Oliver Neukum
2007-03-22 14:22             ` Pavel Machek
2007-03-22 14:26               ` Oliver Neukum
2007-03-22 14:35                 ` Pavel Machek
2007-03-22 19:41     ` David Brownell
2007-03-22 19:58   ` David Brownell
2007-03-20 18:30 ` Pavel Machek
2007-03-21  1:34   ` Shaohua Li
2007-03-21 15:21     ` Amit Kucheria
2007-03-21 21:49       ` Dmitry Krivoschekov
2007-03-21 22:54         ` Pavel Machek
2007-03-21 21:39     ` Pavel Machek
2007-03-22  3:09       ` Shaohua Li
2007-03-22 13:13         ` Pavel Machek
2007-03-22 19:20       ` David Brownell
2007-03-22 20:32         ` Alan Stern
2007-03-22 20:02 ` David Brownell
2007-03-22 22:10   ` Greg KH
2007-03-21 20:19 Scott E. Preece
2007-03-21 21:45 ` Pavel Machek
2007-03-26 13:53 ` Amit Kucheria
2007-03-22 13:39 Scott E. Preece
2007-03-22 13:48 ` Oliver Neukum
2007-03-22 14:01 ` Pavel Machek
2007-03-22 14:45 ` Alan Stern
2007-03-22 18:53   ` David Brownell
2007-03-22 19:05 Scott E. Preece
2007-03-27 12:05 ` Pavel Machek
2007-03-27 12:19   ` Oliver Neukum
2007-03-22 19:18 Scott E. Preece

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.