ata port runtime power management support
cover ata port runtime power management support
Hi, all
These 3 patches add ata port runtime pm support, which is done through scsi layer. scsi host runtime pm mechanism is already there(scsi_pm.c).
These patches add hooks for ata port.
Lin Ming (3):
scsi: fix potential dead lock for host runtime pm
scsi: add hooks for host runtime power management
ata: implement ata port runtime pm hooks
drivers/ata/libata-core.c | 96 +++++++++++++++++++++++++++++--------------- drivers/scsi/scsi_error.c | 4 +- drivers/scsi/scsi_pm.c | 45 +++++++++++++++++++- drivers/scsi/scsi_priv.h | 2 + include/linux/libata.h | 7 +++ include/scsi/scsi_host.h | 8 ++++ 6 files changed, 125 insertions(+), 37 deletions(-)
Thanks for any comment.
Lin Ming
PATCH 1/3 scsi: fix potential dead lock for host runtime pm
In later patch hooks will be added to do ata port runtime pm through scsi layer. libata schedules scsi EH to handle suspend, then dead lock happens because scsi EH in turn waits for the ongoing suspend, as below.
<scsi host runtime suspend>
scsi_autopm_put_host
pm_runtime_put_sync
<scsi_host runtime pm status updated to RPM_SUSPENDING>
......
<call libata hook to do suspend>
<wake up scsi EH to handle suspend>
<wait for scsi EH ...>
<scsi EH wake up>
scsi_error_handler
<resume scsi host>
scsi_autopm_get_host
pm_runtime_get_sync
.....
<sleep to wait for the ongoing scsi host suspend>
This patch fixes the dead lock by checking if there is ongoing runtime PM request. If there is ongoing runtime PM request, scsi_autopm_get_host_noresume is called to increase the usage count, but don't resume the host.
--- drivers/scsi/scsi_error.c | 4 +++- drivers/scsi/scsi_pm.c | 11 +++++++++++ drivers/scsi/scsi_priv.h | 2 ++ 3 files changed, 16 insertions(+), 1 deletions(-)
drivers/scsi/scsi_error.c +3 -1
@@ -1804,7 +1804,9 @@ int scsi_error_handler(void *data)* what we need to do to get it up and online again (if we can). * If we fail, we end up taking the thing offline. */ -if (scsi_autopm_get_host (shost) !=0 ) { +if (scsi_autopm_host_busy (shost)) +scsi_autopm_get_host_noresume (shost); +else if (scsi_autopm_get_host (shost) !=0 ) { SCSI_LOG_ERROR_RECOVERY(1, printk(KERN_ERR "Error handler scsi_eh_%d " "unable to autoresume\n",
drivers/scsi/scsi_pm.c +11 -0
@@ -185,6 +185,17 @@ void scsi_autopm_put_host(struct Scsi_Host *shost) pm_runtime_put_sync(&shost->shost_gendev); } +bool scsi_autopm_host_busy (struct Scsi_Host *shost) +{ +return (shost->shost_gendev.power.runtime_status ==RPM_RESUMING + || shost->shost_gendev.power.runtime_status ==RPM_SUSPENDING ); +} + +void scsi_autopm_get_host_noresume (struct Scsi_Host *shost) +{ +pm_runtime_get_noresume (&shost->shost_gendev); +} +#else #define scsi_runtime_suspend NULL
drivers/scsi/scsi_priv.h +2 -0
@@ -156,6 +156,8 @@ extern void scsi_autopm_get_target(struct scsi_target *);extern void scsi_autopm_put_target (struct scsi_target *);extern int scsi_autopm_get_host (struct Scsi_Host *);extern void scsi_autopm_put_host (struct Scsi_Host *); +extern bool scsi_autopm_host_busy (struct Scsi_Host *shost); +extern void scsi_autopm_get_host_noresume (struct Scsi_Host *);#else static inline void scsi_autopm_get_target (struct scsi_target *t) {}static inline void scsi_autopm_put_target (struct scsi_target *t) {}
Signature · 1 line
1.7.2.5
PATCH 2/3 scsi: add hooks for host runtime power management
In reply to Lin MingAdds ->suspend and ->resume callbacks in struct scsi_host_template to do host runtime power management.
--- drivers/scsi/scsi_pm.c | 34 +++++++++++++++++++++++++++++++--- include/scsi/scsi_host.h | 8 ++++++++ 2 files changed, 39 insertions(+), 3 deletions(-)
drivers/scsi/scsi_pm.c +31 -3
@@ -42,6 +42,28 @@ static int scsi_dev_type_resume(struct device *dev)return err; } +static int scsi_host_suspend (struct device *dev) +{ +struct Scsi_Host *shost =dev_to_shost (dev); +int err =0 ; + +if (shost->hostt->suspend) + err = shost->hostt->suspend (shost); + +return err; +} + +static int scsi_host_resume (struct device *dev) +{ +struct Scsi_Host *shost =dev_to_shost (dev); +int err =0 ; + +if (shost->hostt->resume) + err = shost->hostt->resume (shost); + +return err; +} +#ifdef CONFIG_PM_SLEEP static int scsi_bus_suspend_common (struct device *dev,pm_message_t msg)
@@ -106,7 +128,10 @@ static int scsi_runtime_suspend(struct device *dev) round_jiffies_up_relative(HZ/10))); } -/* Insert hooks here for targets, hosts, and transport classes */ +/* Insert hooks here for targets and transport classes */ + +if (scsi_is_host_device (dev)) + err =scsi_host_suspend (dev);return err; }
@@ -119,7 +144,10 @@ static int scsi_runtime_resume(struct device *dev)if (scsi_is_sdev_device (dev)) err =scsi_dev_type_resume (dev); -/* Insert hooks here for targets, hosts, and transport classes */ +/* Insert hooks here for targets and transport classes */ + +if (scsi_is_host_device (dev)) + err =scsi_host_resume (dev);return err; }
@@ -132,7 +160,7 @@ static int scsi_runtime_idle(struct device *dev)/* Insert hooks here for targets, hosts, and transport classes */ -if (scsi_is_sdev_device (dev)) +if (scsi_is_sdev_device (dev) ||scsi_is_host_device (dev)) err =pm_schedule_suspend (dev,100 );else err =pm_runtime_suspend (dev);
include/scsi/scsi_host.h +8 -0
@@ -356,6 +356,14 @@ struct scsi_host_template {enum blk_eh_timer_return (*eh_timed_out)(struct scsi_cmnd *);/* +* Optional routine for scsi host runtime pm. +* +* Status: OPTIONAL +*/ +int (*suspend)(struct Scsi_Host *); +int (*resume)(struct Scsi_Host *); + +/* * Name of proc directory */ const char *proc_name;
Signature · 1 line
1.7.2.5
PATCH 3/3 ata: implement ata port runtime pm hooks
In reply to Lin MingSplit a new function ata_port_request_pm from ata_host_request_pm. Implement runtime suspend and resume hooks for scsi layer.
--- drivers/ata/libata-core.c | 96 +++++++++++++++++++++++++++++--------------- include/linux/libata.h | 7 +++ 2 files changed, 70 insertions(+), 33 deletions(-)
drivers/ata/libata-core.c +63 -33
@@ -66,6 +66,7 @@#include <asm/byteorder.h> #include <linux/cdrom.h> #include <linux/ratelimit.h> +#include <linux/pm_runtime.h> #include "libata.h" #include "libata-transport.h"
@@ -5234,51 +5235,62 @@ bool ata_link_offline(struct ata_link *link) }#ifdef CONFIG_PM -static int ata_host_request_pm (struct ata_host *host,pm_message_t mesg, +static int ata_port_request_pm (struct ata_port *ap,pm_message_t mesg,unsigned int action,unsigned int ehi_flags,int wait) { +struct ata_link *link;unsigned long flags; -int i, rc; +int rc; -for (i =0 ; i < host->n_ports; i++) { -struct ata_port *ap = host->ports[i]; -struct ata_link *link; +/* Previous resume operation might still be in +* progress. Wait for PM_PENDING to clear. +*/ +if (ap->pflags &ATA_PFLAG_PM_PENDING ) { +ata_port_wait_eh (ap); +WARN_ON (ap->pflags &ATA_PFLAG_PM_PENDING ); + } -/* Previous resume operation might still be in -* progress. Wait for PM_PENDING to clear. -*/ -if (ap->pflags &ATA_PFLAG_PM_PENDING ) { -ata_port_wait_eh (ap); -WARN_ON (ap->pflags &ATA_PFLAG_PM_PENDING ); - } +/* request PM ops to EH */ +spin_lock_irqsave (ap->lock, flags); -/* request PM ops to EH */ -spin_lock_irqsave (ap->lock, flags); + ap->pm_mesg = mesg; +if (wait) { + rc =0 ; + ap->pm_result = &rc; + } - ap->pm_mesg = mesg; -if (wait) { - rc =0 ; - ap->pm_result = &rc; - } + ap->pflags |=ATA_PFLAG_PM_PENDING ; +ata_for_each_link (link, ap,HOST_FIRST ) { + link->eh_info.action |= action; + link->eh_info.flags |= ehi_flags; + } - ap->pflags |=ATA_PFLAG_PM_PENDING ; -ata_for_each_link (link, ap,HOST_FIRST ) { - link->eh_info.action |= action; - link->eh_info.flags |= ehi_flags; - } +ata_port_schedule_eh (ap); -ata_port_schedule_eh (ap); +spin_unlock_irqrestore (ap->lock, flags); -spin_unlock_irqrestore (ap->lock, flags); +/* wait and check result */ +if (wait) { +ata_port_wait_eh (ap); +WARN_ON (ap->pflags &ATA_PFLAG_PM_PENDING ); + } -/* wait and check result */ -if (wait) { -ata_port_wait_eh (ap); -WARN_ON (ap->pflags &ATA_PFLAG_PM_PENDING ); -if (rc) -return rc; - } +return rc; +} + +static int ata_host_request_pm (struct ata_host *host,pm_message_t mesg, +unsigned int action,unsigned int ehi_flags, +int wait) +{ +int i, rc; + +for (i =0 ; i < host->n_ports; i++) { +struct ata_port *ap = host->ports[i]; + + rc =ata_port_request_pm (ap, mesg, action, ehi_flags, wait); +if (rc) +return rc; }return 0 ;
@@ -5338,6 +5350,24 @@ void ata_host_resume(struct ata_host *host) ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0); host->dev->power.power_state = PMSG_ON; } + +#define to_ata_port (shost) (*(struct ata_port **)&shost->hostdata[0]) + +int ata_scsi_host_suspend (struct Scsi_Host *shost) +{ +struct ata_port *ap =to_ata_port (shost); + +return ata_port_request_pm (ap,PMSG_SUSPEND ,0 ,ATA_EHI_QUIET ,1 ); +} + +int ata_scsi_host_resume (struct Scsi_Host *shost) +{ +struct ata_port *ap =to_ata_port (shost); + +return ata_port_request_pm (ap,PMSG_ON ,ATA_EH_RESET , +ATA_EHI_NO_AUTOPSY |ATA_EHI_QUIET ,1 ); +} +#endif /**
include/linux/libata.h +7 -0
@@ -1010,6 +1010,11 @@ extern bool ata_link_offline(struct ata_link *link);#ifdef CONFIG_PM extern int ata_host_suspend (struct ata_host *host,pm_message_t mesg);extern void ata_host_resume (struct ata_host *host); +extern int ata_scsi_host_suspend (struct Scsi_Host *shost); +extern int ata_scsi_host_resume (struct Scsi_Host *shost); +#else +static inline int ata_scsi_host_suspend (struct Scsi_Host *shost) {return 0 ; } +static inline int ata_scsi_host_resume (struct Scsi_Host *shost) {return 0 ; };#endif extern int ata_ratelimit (void );extern void ata_msleep (struct ata_port *ap,unsigned int msecs);
@@ -1193,6 +1198,8 @@ extern struct device_attribute *ata_common_sdev_attrs[]; .name = drv_name, \ .ioctl = ata_scsi_ioctl, \ .queuecommand = ata_scsi_queuecmd, \ + .suspend = ata_scsi_host_suspend, \ + .resume = ata_scsi_host_resume, \ .can_queue = ATA_DEF_QUEUE, \ .this_id = ATA_SHT_THIS_ID, \ .cmd_per_lun = ATA_SHT_CMD_PER_LUN, \
Signature · 1 line
1.7.2.5
Re: [PATCH 1/3] scsi: fix potential dead lock for host runtime pm
In reply to Lin MingQuoted 37 lines · Lin Ming
In later patch hooks will be added to do ata port runtime pm through scsi layer. libata schedules scsi EH to handle suspend, then dead lock happens because scsi EH in turn waits for the ongoing suspend, as below.
<scsi host runtime suspend>
scsi_autopm_put_host
pm_runtime_put_sync
<scsi_hostruntime pm status updated toRPM_SUSPENDING>
......
<call libata hook to do suspend>
<wake up scsi EH to handle suspend>
<wait for scsi EH ...><scsi EH wake up>
scsi_error_handler
<resume scsi host>
scsi_autopm_get_host
pm_runtime_get_sync
.....
<sleep to wait for the ongoing scsi host suspend>This patch fixes the dead lock by checking if there is ongoing runtime PM request. If there is ongoing runtime PM request,
scsi_autopm_get_host_noresumeis called to increase the usage count, but don't resume the host.Signed-off-by Lin Ming <[email protected]>--- drivers/scsi/scsi_error.c | 4 +++- drivers/scsi/scsi_pm.c | 11 +++++++++++ drivers/scsi/scsi_priv.h | 2 ++ 3 files changed, 16 insertions(+), 1 deletions(-)drivers/scsi/scsi_error.c +0
-0
drivers/scsi/scsi_error.c int scsi_error_handler(void *data) · line 1812
Quoted 10 lines
drivers/scsi/scsi_error.c +3
-1@@ -1804,7 +1804,9 @@ int scsi_error_handler(void *data)* what we need to do to get it up and online again (if we can). * If we fail, we end up taking the thing offline. */ -if (scsi_autopm_get_host (shost) !=0 ) { +if (scsi_autopm_host_busy (shost)) +scsi_autopm_get_host_noresume (shost); +else if (scsi_autopm_get_host (shost) !=0 ) { SCSI_LOG_ERROR_RECOVERY(1, printk(KERN_ERR "Error handler scsi_eh_%d " "unable to autoresume\n",
Here's what I'm worried about: Suppose during normal operation, an error occurs. When the command is completed, runtime PM might start to suspend the host. But then the error-handler thread starts up, and of course it needs the host to be powered-up in order to recover from the error. The code you're adding could prevent this from working.
What we really need is a way to prevent host from going into runtime suspend while the error-handler is pending or running. Do you have any ideas on how to do this?
Quoted 27 lines
drivers/scsi/scsi_pm.c +11
-0@@ -185,6 +185,17 @@ void scsi_autopm_put_host(struct Scsi_Host *shost) pm_runtime_put_sync(&shost->shost_gendev); } +bool scsi_autopm_host_busy (struct Scsi_Host *shost) +{ +return (shost->shost_gendev.power.runtime_status ==RPM_RESUMING + || shost->shost_gendev.power.runtime_status ==RPM_SUSPENDING ); +} + +void scsi_autopm_get_host_noresume (struct Scsi_Host *shost) +{ +pm_runtime_get_noresume (&shost->shost_gendev); +} +#else #define scsi_runtime_suspend NULLdrivers/scsi/scsi_priv.h +0
-0
drivers/scsi/scsi_priv.h extern void scsi_autopm_get_target(struct scsi_target *); · line 163
Quoted 8 lines
drivers/scsi/scsi_priv.h +2
-0@@ -156,6 +156,8 @@ extern void scsi_autopm_get_target(struct scsi_target *);extern void scsi_autopm_put_target (struct scsi_target *);extern int scsi_autopm_get_host (struct Scsi_Host *);extern void scsi_autopm_put_host (struct Scsi_Host *); +extern bool scsi_autopm_host_busy (struct Scsi_Host *shost); +extern void scsi_autopm_get_host_noresume (struct Scsi_Host *);#else static inline void scsi_autopm_get_target (struct scsi_target *t) {}static inline void scsi_autopm_put_target (struct scsi_target *t) {}
I bet you didn't try compiling this with CONFIG_PM_RUNTIME turned off.
Alan Stern
Re: [PATCH 2/3] scsi: add hooks for host runtime power management
In reply to Lin MingQuoted 28 lines · Lin Ming
Adds ->suspend and ->resume callbacks in struct
scsi_host_templateto do host runtime power management.Signed-off-by Lin Ming <[email protected]>--- drivers/scsi/scsi_pm.c | 34 +++++++++++++++++++++++++++++++--- include/scsi/scsi_host.h | 8 ++++++++ 2 files changed, 39 insertions(+), 3 deletions(-)drivers/scsi/scsi_pm.c +11
-0@@ -42,6 +42,28 @@ static int scsi_dev_type_resume(struct device *dev)return err; } +static int scsi_host_suspend (struct device *dev) +{ +struct Scsi_Host *shost =dev_to_shost (dev); +int err =0 ; + +if (shost->hostt->suspend) + err = shost->hostt->suspend (shost); + +return err; +} +
drivers/scsi/scsi_pm.c static int scsi_dev_type_resume(struct device *dev) · line 65
Quoted 10 lines
drivers/scsi/scsi_pm.c +10
-0+static int scsi_host_resume (struct device *dev) +{ +struct Scsi_Host *shost =dev_to_shost (dev); +int err =0 ; + +if (shost->hostt->resume) + err = shost->hostt->resume (shost); + +return err; +}
These don't need to be independent routines. You can put them inline in scsi_runtime_suspend() and scsi_runtime_resume() below; that's how the device code is written.
drivers/scsi/scsi_pm.c static int scsi_runtime_idle(struct device *dev) · line 164
Quoted 7 lines
drivers/scsi/scsi_pm.c +1
-1@@ -132,7 +160,7 @@ static int scsi_runtime_idle(struct device *dev)/* Insert hooks here for targets, hosts, and transport classes */ -if (scsi_is_sdev_device (dev)) +if (scsi_is_sdev_device (dev) ||scsi_is_host_device (dev)) err =pm_schedule_suspend (dev,100 );
This is wrong. The 100-ms delay is meant for devices only. There's no reason to delay suspending a host once everything beneath it is suspended. Just leave the code the way it is now.
Quoted 7 lines
drivers/scsi/scsi_pm.c +0
-0else err =pm_runtime_suspend (dev);include/scsi/scsi_host.h +0
-0
include/scsi/scsi_host.h struct scsi_host_template { · line 364
Quoted 9 lines
include/scsi/scsi_host.h +6
-0@@ -356,6 +356,14 @@ struct scsi_host_template {enum blk_eh_timer_return (*eh_timed_out)(struct scsi_cmnd *);/* +* Optional routine for scsi host runtime pm. +* +* Status: OPTIONAL +*/ +int (*suspend)(struct Scsi_Host *); +int (*resume)(struct Scsi_Host *);
The comment should explain what drivers are supposed to do when these hooks are called. In particular, the suspend callback should _not_ power-down the entire host adapter; it should power-down only the circuitry that controls the interface to the SCSI bus. The upstream interface to the CPU should remain at full power.
If there's no way to power-down just that part of the host adapter then there's no need to have these callbacks at all. The low-level driver can simply use the runtime PM API on its own struct device.
Alan Stern
Hello,
Quoted 8 lines · Lin Ming
These 3 patches add ata port runtime pm support, which is done through scsi layer. scsi host runtime pm mechanism is already
there(scsi_pm.c).
These patches add hooks for ata port.Lin Ming (3):
scsi: fix potential dead lock for host runtime pm
scsi: add hooks for host runtime power management
ata: implement ata port runtime pm hooks
Hmmm.... Some questions.
* How much does this add on top of hardware timed auto spindown and dynamic link power management?
* Do the added benefits justify yet another runtime powersaving mechanism?
* Any way we can tie the other stuff with overall runtime PM?
Thanks.
Signature · 1 line
tejun
Re: [PATCH 2/3] scsi: add hooks for host runtime power management
In reply to Alan SternQuoted 36 lines · Alan Stern
Quoted 34 lines · Lin Ming
Adds ->suspend and ->resume callbacks in struct
scsi_host_templateto do host runtime power management.Signed-off-by Lin Ming <[email protected]>--- drivers/scsi/scsi_pm.c | 34 +++++++++++++++++++++++++++++++--- include/scsi/scsi_host.h | 8 ++++++++ 2 files changed, 39 insertions(+), 3 deletions(-)drivers/scsi/scsi_pm.c +17
-0@@ -42,6 +42,28 @@ static int scsi_dev_type_resume(struct device *dev)return err; } +static int scsi_host_suspend (struct device *dev) +{ +struct Scsi_Host *shost =dev_to_shost (dev); +int err =0 ; + +if (shost->hostt->suspend) + err = shost->hostt->suspend (shost); + +return err; +} + +static int scsi_host_resume (struct device *dev) +{ +struct Scsi_Host *shost =dev_to_shost (dev); +int err =0 ; + +if (shost->hostt->resume)
Quoted 8 lines
drivers/scsi/scsi_pm.c static int scsi_dev_type_resume(struct device *dev) · line 65
Quoted 4 lines
drivers/scsi/scsi_pm.c +4
-0+ err = shost->hostt->resume (shost); + +return err; +}These don't need to be independent routines. You can put them inline in
scsi_runtime_suspend()andscsi_runtime_resume()below; that's how the device code is written.
OK.
Quoted 5 lines
Quoted 5 lines
drivers/scsi/scsi_pm.c +0
-0@@ -132,7 +160,7 @@ static int scsi_runtime_idle(struct device *dev)/* Insert hooks here for targets, hosts, and transport classes */
Quoted 7 lines
drivers/scsi/scsi_pm.c static int scsi_runtime_idle(struct device *dev) · line 164
Quoted 3 lines
drivers/scsi/scsi_pm.c +1
-1-if (scsi_is_sdev_device (dev)) +if (scsi_is_sdev_device (dev) ||scsi_is_host_device (dev)) err =pm_schedule_suspend (dev,100 );This is wrong. The 100-ms delay is meant for devices only. There's no reason to delay suspending a host once everything beneath it is suspended. Just leave the code the way it is now.
OK.
Quoted 24 lines
Quoted 8 lines
drivers/scsi/scsi_pm.c +0
-0else err =pm_runtime_suspend (dev);include/scsi/scsi_host.h +0
-0include/scsi/scsi_host.h struct scsi_host_template { · line 364
Quoted 9 lines
include/scsi/scsi_host.h +6
-0@@ -356,6 +356,14 @@ struct scsi_host_template {enum blk_eh_timer_return (*eh_timed_out)(struct scsi_cmnd *);/* +* Optional routine for scsi host runtime pm. +* +* Status: OPTIONAL +*/ +int (*suspend)(struct Scsi_Host *); +int (*resume)(struct Scsi_Host *);The comment should explain what drivers are supposed to do when these hooks are called. In particular, the suspend callback should _not_ power-down the entire host adapter; it should power-down only the circuitry that controls the interface to the SCSI bus. The upstream interface to the CPU should remain at full power.
Quoted 3 lines
If there's no way to power-down just that part of the host adapter then there's no need to have these callbacks at all. The low-level driver can simply use the runtime PM API on its own struct device.
Good point.
I realize that this is not the natural way to do ata port runtime pm. Hooking it to scsi host runtime pm is not good. It does not deal with the races with system suspend/resume of host controller.
How about making ata port as the parent device of scsi host? Then, for example, the runtime suspend happens as below,
disk suspend --> scsi target suspend --> scsi host suspend --> ata port suspend.
Current device tree is:
/sys/devices/pci0000:00/0000:00:1f.2/
|-- ata1
|-- host0
After the change, the tree will become as:
/sys/devices/pci0000:00/0000:00:1f.2/ata1/
|-- host0
The tricky part is ata port(parent device) suspend need to schedule scsi EH which will resume scsi host(child device). Then the child device resume will in turn make parent device resume first. This is kind of recursive.
We can fix this by adding a flag somewhere to tell scsi EH don't resume the host in ata port pm request handling case.
What do you think?
Thanks,
Lin Ming
Quoted 12 lines · Tejun Heo
Hello,
Quoted 8 lines · Lin Ming
These 3 patches add ata port runtime pm support, which is done through scsi layer. scsi host runtime pm mechanism is already
there(scsi_pm.c).
These patches add hooks for ata port.Lin Ming (3):
scsi: fix potential dead lock for host runtime pm
scsi: add hooks for host runtime power management
ata: implement ata port runtime pm hooks
Quoted 4 lines
Hmmm.... Some questions.
* How much does this add on top of hardware timed auto spindown and dynamic link power management?
Sorry, I don't understand this question.
What do you mean?
Quoted 3 lines
* Do the added benefits justify yet another runtime powersaving mechanism?
There will be ACPI firmware which supports ata port runtime D3Cold. To enable ata port runtime PM is the first step.
Quoted 2 lines
* Any way we can tie the other stuff with overall runtime PM?
What's the other stuff?
Do you mean tie disk/link/port/controller stuff with overall runtime PM?
I'm not sure for now. Need to think about it more.
Re: [PATCH 2/3] scsi: add hooks for host runtime power management
In reply to Lin MingQuoted 10 lines · Lin Ming
I realize that this is not the natural way to do ata port runtime pm. Hooking it to scsi host runtime pm is not good. It does not deal with the races with system suspend/resume of host controller.
How about making ata port as the parent device of scsi host? Then, for example, the runtime suspend happens as below,
disk suspend --> scsi target suspend --> scsi host suspend --> ata port suspend.
Quoted 8 lines
Current device tree is:
/sys/devices/pci0000:00/0000:00:1f.2/
|-- ata1
|-- host0After the change, the tree will become as:
/sys/devices/pci0000:00/0000:00:1f.2/ata1/
|-- host0
I don't know enough about the ATA subsystem to say much, except that this looks more logical.
Quoted 9 lines
The tricky part is ata port(parent device) suspend need to schedule scsi EH which will resume scsi host(child device). Then the child device resume will in turn make parent device resume first. This is kind of recursive.
We can fix this by adding a flag somewhere to tell scsi EH don't resume the host in ata port pm request handling case.
What do you think?
Yes, it is a problem. But it looks like the underlying issue is that you're using the SCSI error handler to do something it was not intended for. Can't you suspend and resume the ATA port without using the error handler?
Alan Stern
Hello,
Quoted 5 lines · Lin Ming
Quoted 2 lines
* How much does this add on top of hardware timed auto spindown and dynamic link power management?
Sorry, I don't understand this question.
What do you mean?
I was curious about the amount of additional power saving on top of the existing PM features.
Quoted 5 lines
Quoted 2 lines
* Do the added benefits justify yet another runtime powersaving mechanism?
There will be ACPI firmware which supports ata port runtime D3Cold. To enable ata port runtime PM is the first step.
libata can already turn off unused ports although it wouldn't go as far as putting the whole controller into D3.
Quoted 4 lines
Quoted 1 line
* Any way we can tie the other stuff with overall runtime PM?
What's the other stuff?
Do you mean tie disk/link/port/controller stuff with overall runtime PM?
Hardware initiated spin-down (hdparm -S) and link power saving (look for ata_lpm_*). It would be great if there's an overall design how they interact before adding yet another PM vector.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 2/3] scsi: add hooks for host runtime power management
In reply to Alan SternQuoted 32 lines · Alan Stern
Quoted 10 lines · Lin Ming
I realize that this is not the natural way to do ata port runtime pm. Hooking it to scsi host runtime pm is not good. It does not deal with the races with system suspend/resume of host controller.
How about making ata port as the parent device of scsi host? Then, for example, the runtime suspend happens as below,
disk suspend --> scsi target suspend --> scsi host suspend --> ata port suspend.
Quoted 8 lines
Current device tree is:
/sys/devices/pci0000:00/0000:00:1f.2/
|-- ata1
|-- host0After the change, the tree will become as:
/sys/devices/pci0000:00/0000:00:1f.2/ata1/
|-- host0I don't know enough about the ATA subsystem to say much, except that this looks more logical.
Quoted 8 lines
The tricky part is ata port(parent device) suspend need to schedule scsi EH which will resume scsi host(child device). Then the child device resume will in turn make parent device resume first. This is kind of recursive.
We can fix this by adding a flag somewhere to tell scsi EH don't resume the host in ata port pm request handling case.
Quoted 6 lines
Quoted 1 line
What do you think?
Yes, it is a problem. But it looks like the underlying issue is that you're using the SCSI error handler to do something it was not intended for. Can't you suspend and resume the ATA port without using the error handler?
The system suspend and resume of the ATA port uses the error handler. I think the runtime suspend and resume should use the error handler too.
Tejun,
Could you comment more on this?
Thanks.
Quoted 3 lines
Alan Stern
Re: [PATCH 2/3] scsi: add hooks for host runtime power management
Hello,
Quoted 11 lines · Lin Ming
Quoted 4 lines
Yes, it is a problem. But it looks like the underlying issue is that you're using the SCSI error handler to do something it was not intended for. Can't you suspend and resume the ATA port without using the error handler?
The system suspend and resume of the ATA port uses the error handler. I think the runtime suspend and resume should use the error handler too.
Tejun,
Could you comment more on this?
I don't know. I haven't really thought about it but as it's currently designed, I don't think it'll be possible to avoid going through EH to put ATA ports into suspend mode.
Thanks.
Signature · 5 lines
tejun -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Tejun Heo
Hello,
Quoted 5 lines · Lin Ming
Quoted 2 lines
* How much does this add on top of hardware timed auto spindown and dynamic link power management?
Sorry, I don't understand this question.
What do you mean?I was curious about the amount of additional power saving on top of the existing PM features.
I'll measure the power saving.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
* Do the added benefits justify yet another runtime powersaving mechanism?
There will be ACPI firmware which supports ata port runtime D3Cold. To enable ata port runtime PM is the first step.
libata can already turn off unused ports although it wouldn't go as far as putting the whole controller into D3.
At runtime?
Could you point me which piece of code implement this?
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
* Any way we can tie the other stuff with overall runtime PM?
What's the other stuff?
Do you mean tie disk/link/port/controller stuff with overall runtime PM?Hardware initiated spin-down (hdparm -S) and link power saving (look for ata_lpm_*). It would be great if there's an overall design how they interact before adding yet another PM vector.
Yes. Need to think about it.
Thanks.
Hello,
Quoted 7 lines · Lin Ming
Quoted 5 lines
Quoted 2 lines
There will be ACPI firmware which supports ata port runtime D3Cold. To enable ata port runtime PM is the first step.
libata can already turn off unused ports although it wouldn't go as far as putting the whole controller into D3.
At runtime?
Nope, I meant unoccupied (no device attached). IIRC it's part of the LPM code.
Signature · 1 line
tejun
Re: [PATCH 2/3] scsi: add hooks for host runtime power management
In reply to Tejun HeoQuoted 11 lines · Tejun Heo
Hello,
Quoted 8 lines · Lin Ming
Quoted 4 lines
Yes, it is a problem. �But it looks like the underlying issue is that you're using the SCSI error handler to do something it was not intended for. �Can't you suspend and resume the ATA port without using the error handler?
The system suspend and resume of the ATA port uses the error handler. I think the runtime suspend and resume should use the error handler too.
Quoted 7 lines
Quoted 3 lines
Tejun,
Could you comment more on this?
I don't know. I haven't really thought about it but as it's currently designed, I don't think it'll be possible to avoid going through EH to put ATA ports into suspend mode.
Why not?
Alan Stern
Re: [PATCH 2/3] scsi: add hooks for host runtime power management
Hello,
Quoted 5 lines · Alan Stern
Quoted 3 lines
I don't know. I haven't really thought about it but as it's currently designed, I don't think it'll be possible to avoid going through EH to put ATA ports into suspend mode.
Why not?
It's just how things are designed now. There's no reason why it's fundamentally impossible but going around that would require some amount of hackery or preferably re-design. Synchronization against command processing, interrupts and all are built around EH.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 2/3] scsi: add hooks for host runtime power management
Quoted 7 lines · Tejun Heo
Hello,
Quoted 4 lines · Alan Stern
Quoted 3 lines
I don't know. I haven't really thought about it but as it's currently designed, I don't think it'll be possible to avoid going through EH to put ATA ports into suspend mode.
Quoted 6 lines
Quoted 1 line
Why not?
It's just how things are designed now. There's no reason why it's fundamentally impossible but going around that would require some amount of hackery or preferably re-design. Synchronization against command processing, interrupts and all are built around EH.
Then it sounds like the best idea is something like what Ming proposed
earlier: Have the error handler make some sort of test to determine whether it has been invoked for suspend/resume handling, and skip the runtime-PM calls on the host if it has.
This new test, whatever it is, should apply both to system suspend and runtime suspend. By the way, what would happen if a system suspend occurred while the ATA port was already runtime-suspended?
Alan Stern