libata: take advantage of cmwq and remove concurrency limitations

libata has two concurrency related limitations.

a. ata_wq which is used for polling PIO has single thread per CPU.  If
   there are multiple devices doing polling PIO on the same CPU, they
   can't be executed simultaneously.

b. ata_aux_wq which is used for SCSI probing has single thread.  In
   cases where SCSI probing is stalled for extended period of time
   which is possible for ATAPI devices, this will stall all probing.

#a is solved by increasing maximum concurrency of ata_wq.  Please note
that polling PIO might be used under allocation path and thus needs to
be served by a separate wq with a rescuer.

#b is solved by using the default wq instead and achieving exclusion
via per-port mutex.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Jeff Garzik <jgarzik@pobox.com>
This commit is contained in:
Tejun Heo 2010-07-02 10:03:52 +02:00
parent d313dd85ad
commit ad72cf9885
6 changed files with 15 additions and 30 deletions

View File

@ -98,8 +98,6 @@ static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
unsigned int ata_print_id = 1; unsigned int ata_print_id = 1;
struct workqueue_struct *ata_aux_wq;
struct ata_force_param { struct ata_force_param {
const char *name; const char *name;
unsigned int cbl; unsigned int cbl;
@ -5611,6 +5609,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN; ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN;
#endif #endif
mutex_init(&ap->scsi_scan_mutex);
INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug); INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug);
INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
INIT_LIST_HEAD(&ap->eh_done_q); INIT_LIST_HEAD(&ap->eh_done_q);
@ -6549,29 +6548,20 @@ static int __init ata_init(void)
ata_parse_force_param(); ata_parse_force_param();
ata_aux_wq = create_singlethread_workqueue("ata_aux");
if (!ata_aux_wq)
goto fail;
rc = ata_sff_init(); rc = ata_sff_init();
if (rc) if (rc) {
goto fail; kfree(ata_force_tbl);
return rc;
}
printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n"); printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n");
return 0; return 0;
fail:
kfree(ata_force_tbl);
if (ata_aux_wq)
destroy_workqueue(ata_aux_wq);
return rc;
} }
static void __exit ata_exit(void) static void __exit ata_exit(void)
{ {
ata_sff_exit(); ata_sff_exit();
kfree(ata_force_tbl); kfree(ata_force_tbl);
destroy_workqueue(ata_aux_wq);
} }
subsys_initcall(ata_init); subsys_initcall(ata_init);

View File

@ -727,7 +727,7 @@ void ata_scsi_error(struct Scsi_Host *host)
if (ap->pflags & ATA_PFLAG_LOADING) if (ap->pflags & ATA_PFLAG_LOADING)
ap->pflags &= ~ATA_PFLAG_LOADING; ap->pflags &= ~ATA_PFLAG_LOADING;
else if (ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) else if (ap->pflags & ATA_PFLAG_SCSI_HOTPLUG)
queue_delayed_work(ata_aux_wq, &ap->hotplug_task, 0); schedule_delayed_work(&ap->hotplug_task, 0);
if (ap->pflags & ATA_PFLAG_RECOVERED) if (ap->pflags & ATA_PFLAG_RECOVERED)
ata_port_printk(ap, KERN_INFO, "EH complete\n"); ata_port_printk(ap, KERN_INFO, "EH complete\n");
@ -2944,7 +2944,7 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
ehc->i.flags |= ATA_EHI_SETMODE; ehc->i.flags |= ATA_EHI_SETMODE;
/* schedule the scsi_rescan_device() here */ /* schedule the scsi_rescan_device() here */
queue_work(ata_aux_wq, &(ap->scsi_rescan_task)); schedule_work(&(ap->scsi_rescan_task));
} else if (dev->class == ATA_DEV_UNKNOWN && } else if (dev->class == ATA_DEV_UNKNOWN &&
ehc->tries[dev->devno] && ehc->tries[dev->devno] &&
ata_class_enabled(ehc->classes[dev->devno])) { ata_class_enabled(ehc->classes[dev->devno])) {

View File

@ -3435,7 +3435,7 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
" switching to async\n"); " switching to async\n");
} }
queue_delayed_work(ata_aux_wq, &ap->hotplug_task, queue_delayed_work(system_long_wq, &ap->hotplug_task,
round_jiffies_relative(HZ)); round_jiffies_relative(HZ));
} }
@ -3582,6 +3582,7 @@ void ata_scsi_hotplug(struct work_struct *work)
} }
DPRINTK("ENTER\n"); DPRINTK("ENTER\n");
mutex_lock(&ap->scsi_scan_mutex);
/* Unplug detached devices. We cannot use link iterator here /* Unplug detached devices. We cannot use link iterator here
* because PMP links have to be scanned even if PMP is * because PMP links have to be scanned even if PMP is
@ -3595,6 +3596,7 @@ void ata_scsi_hotplug(struct work_struct *work)
/* scan for new ones */ /* scan for new ones */
ata_scsi_scan_host(ap, 0); ata_scsi_scan_host(ap, 0);
mutex_unlock(&ap->scsi_scan_mutex);
DPRINTK("EXIT\n"); DPRINTK("EXIT\n");
} }
@ -3673,9 +3675,7 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
* @work: Pointer to ATA port to perform scsi_rescan_device() * @work: Pointer to ATA port to perform scsi_rescan_device()
* *
* After ATA pass thru (SAT) commands are executed successfully, * After ATA pass thru (SAT) commands are executed successfully,
* libata need to propagate the changes to SCSI layer. This * libata need to propagate the changes to SCSI layer.
* function must be executed from ata_aux_wq such that sdev
* attach/detach don't race with rescan.
* *
* LOCKING: * LOCKING:
* Kernel thread context (may sleep). * Kernel thread context (may sleep).
@ -3688,6 +3688,7 @@ void ata_scsi_dev_rescan(struct work_struct *work)
struct ata_device *dev; struct ata_device *dev;
unsigned long flags; unsigned long flags;
mutex_lock(&ap->scsi_scan_mutex);
spin_lock_irqsave(ap->lock, flags); spin_lock_irqsave(ap->lock, flags);
ata_for_each_link(link, ap, EDGE) { ata_for_each_link(link, ap, EDGE) {
@ -3707,6 +3708,7 @@ void ata_scsi_dev_rescan(struct work_struct *work)
} }
spin_unlock_irqrestore(ap->lock, flags); spin_unlock_irqrestore(ap->lock, flags);
mutex_unlock(&ap->scsi_scan_mutex);
} }
/** /**

View File

@ -3318,14 +3318,7 @@ void ata_sff_port_init(struct ata_port *ap)
int __init ata_sff_init(void) int __init ata_sff_init(void)
{ {
/* ata_sff_wq = alloc_workqueue("ata_sff", WQ_RESCUER, WQ_MAX_ACTIVE);
* FIXME: In UP case, there is only one workqueue thread and if you
* have more than one PIO device, latency is bloody awful, with
* occasional multi-second "hiccups" as one PIO device waits for
* another. It's an ugly wart that users DO occasionally complain
* about; luckily most users have at most one PIO polled device.
*/
ata_sff_wq = create_workqueue("ata_sff");
if (!ata_sff_wq) if (!ata_sff_wq)
return -ENOMEM; return -ENOMEM;

View File

@ -54,7 +54,6 @@ enum {
}; };
extern unsigned int ata_print_id; extern unsigned int ata_print_id;
extern struct workqueue_struct *ata_aux_wq;
extern int atapi_passthru16; extern int atapi_passthru16;
extern int libata_fua; extern int libata_fua;
extern int libata_noacpi; extern int libata_noacpi;

View File

@ -751,6 +751,7 @@ struct ata_port {
struct ata_host *host; struct ata_host *host;
struct device *dev; struct device *dev;
struct mutex scsi_scan_mutex;
struct delayed_work hotplug_task; struct delayed_work hotplug_task;
struct work_struct scsi_rescan_task; struct work_struct scsi_rescan_task;