firewire: sbp2: parallelize login, reconnect, logout
authorStefan Richter <stefanr@s5r6.in-berlin.de>
Sun, 1 May 2011 18:50:31 +0000 (20:50 +0200)
committerStefan Richter <stefanr@s5r6.in-berlin.de>
Tue, 10 May 2011 20:53:46 +0000 (22:53 +0200)
The struct sbp2_logical_unit.work items can all be executed in parallel
but are not reentrant.  Furthermore, reconnect or re-login work must be
executed in a WQ_MEM_RECLAIM workqueue.

Hence replace the old single-threaded firewire-sbp2 workqueue by a
concurrency-managed but non-reentrant workqueue with rescuer.
firewire-core already maintains one, hence use this one.

In earlier versions of this change, I observed occasional failures of
parallel INQUIRY to an Initio INIC-2430 FireWire 800 to dual IDE bridge.
More testing indicates that parallel INQUIRY is not actually a problem,
but too quick successions of logout and login + INQUIRY, e.g. a quick
sequence of cable plugout and plugin, can result in failed INQUIRY.
This does not seem to be something that should or could be addressed by
serialization.

Another dual-LU device to which I currently have access to, an
OXUF924DSB FireWire 800 to dual SATA bridge with firmware from MacPower,
has been successfully tested with this too.

This change is beneficial to environments with two or more FireWire
storage devices, especially if they are located on the same bus.
Management tasks that should be performed as soon and as quickly as
possible, especially reconnect, are no longer held up by tasks on other
devices that may take a long time, especially login with INQUIRY and sd
or sr driver probe.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
drivers/firewire/core-card.c
drivers/firewire/core-cdev.c
drivers/firewire/core-device.c
drivers/firewire/core-transaction.c
drivers/firewire/core.h
drivers/firewire/sbp2.c
include/linux/firewire.h

index bb8c4d22b03e95ad53c8381a07aa9f0823a6cc96..29d2423fae6d999827c682648278366c07238a6e 100644 (file)
@@ -228,7 +228,7 @@ void fw_schedule_bus_reset(struct fw_card *card, bool delayed, bool short_reset)
 
        /* Use an arbitrary short delay to combine multiple reset requests. */
        fw_card_get(card);
-       if (!queue_delayed_work(fw_wq, &card->br_work,
+       if (!queue_delayed_work(fw_workqueue, &card->br_work,
                                delayed ? DIV_ROUND_UP(HZ, 100) : 0))
                fw_card_put(card);
 }
@@ -241,7 +241,7 @@ static void br_work(struct work_struct *work)
        /* Delay for 2s after last reset per IEEE 1394 clause 8.2.1. */
        if (card->reset_jiffies != 0 &&
            time_before64(get_jiffies_64(), card->reset_jiffies + 2 * HZ)) {
-               if (!queue_delayed_work(fw_wq, &card->br_work, 2 * HZ))
+               if (!queue_delayed_work(fw_workqueue, &card->br_work, 2 * HZ))
                        fw_card_put(card);
                return;
        }
index aa1131d26e30a850766c13ca56749c2235199d97..b1c11775839cd6543590d98a2d482dd3b9ef769c 100644 (file)
@@ -149,7 +149,7 @@ static void release_iso_resource(struct client *, struct client_resource *);
 static void schedule_iso_resource(struct iso_resource *r, unsigned long delay)
 {
        client_get(r->client);
-       if (!queue_delayed_work(fw_wq, &r->work, delay))
+       if (!queue_delayed_work(fw_workqueue, &r->work, delay))
                client_put(r->client);
 }
 
index ef900d923f1571d1e6d08ec09c6c0519767bd233..95a4714018922b52ebf484897fe7bcbd106eb318 100644 (file)
@@ -725,12 +725,13 @@ struct fw_device *fw_device_get_by_devt(dev_t devt)
        return device;
 }
 
-struct workqueue_struct *fw_wq;
+struct workqueue_struct *fw_workqueue;
+EXPORT_SYMBOL(fw_workqueue);
 
 static void fw_schedule_device_work(struct fw_device *device,
                                    unsigned long delay)
 {
-       queue_delayed_work(fw_wq, &device->work, delay);
+       queue_delayed_work(fw_workqueue, &device->work, delay);
 }
 
 /*
index d4c28a217b2ca0369609bddea8fba3f471139022..334b82a3542c18ddbc4c138deafdf1931068434d 100644 (file)
@@ -1214,21 +1214,21 @@ static int __init fw_core_init(void)
 {
        int ret;
 
-       fw_wq = alloc_workqueue(KBUILD_MODNAME,
-                               WQ_NON_REENTRANT | WQ_MEM_RECLAIM, 0);
-       if (!fw_wq)
+       fw_workqueue = alloc_workqueue("firewire",
+                                      WQ_NON_REENTRANT | WQ_MEM_RECLAIM, 0);
+       if (!fw_workqueue)
                return -ENOMEM;
 
        ret = bus_register(&fw_bus_type);
        if (ret < 0) {
-               destroy_workqueue(fw_wq);
+               destroy_workqueue(fw_workqueue);
                return ret;
        }
 
        fw_cdev_major = register_chrdev(0, "firewire", &fw_device_ops);
        if (fw_cdev_major < 0) {
                bus_unregister(&fw_bus_type);
-               destroy_workqueue(fw_wq);
+               destroy_workqueue(fw_workqueue);
                return fw_cdev_major;
        }
 
@@ -1244,7 +1244,7 @@ static void __exit fw_core_cleanup(void)
 {
        unregister_chrdev(fw_cdev_major, "firewire");
        bus_unregister(&fw_bus_type);
-       destroy_workqueue(fw_wq);
+       destroy_workqueue(fw_workqueue);
        idr_destroy(&fw_device_idr);
 }
 
index 00ea7730c6a73ea1ba3259c6cff3bf9f89ee6e47..0fe4e4e6eda72a696596c7dbcce1a7f0f6538569 100644 (file)
@@ -140,8 +140,6 @@ void fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p);
 extern struct rw_semaphore fw_device_rwsem;
 extern struct idr fw_device_idr;
 extern int fw_cdev_major;
-struct workqueue_struct;
-extern struct workqueue_struct *fw_wq;
 
 struct fw_device *fw_device_get_by_devt(dev_t devt);
 int fw_device_set_broadcast_channel(struct device *dev, void *gen);
index 2aafc614ae14e05db555dab7ada9ce0adb744411..41841a3e3f99c9acd4c4fc72c972626d8dffdcee 100644 (file)
@@ -826,8 +826,6 @@ static void sbp2_target_put(struct sbp2_target *tgt)
        kref_put(&tgt->kref, sbp2_release_target);
 }
 
-static struct workqueue_struct *sbp2_wq;
-
 /*
  * Always get the target's kref when scheduling work on one its units.
  * Each workqueue job is responsible to call sbp2_target_put() upon return.
@@ -835,7 +833,7 @@ static struct workqueue_struct *sbp2_wq;
 static void sbp2_queue_work(struct sbp2_logical_unit *lu, unsigned long delay)
 {
        sbp2_target_get(lu->tgt);
-       if (!queue_delayed_work(sbp2_wq, &lu->work, delay))
+       if (!queue_delayed_work(fw_workqueue, &lu->work, delay))
                sbp2_target_put(lu->tgt);
 }
 
@@ -1645,17 +1643,12 @@ MODULE_ALIAS("sbp2");
 
 static int __init sbp2_init(void)
 {
-       sbp2_wq = create_singlethread_workqueue(KBUILD_MODNAME);
-       if (!sbp2_wq)
-               return -ENOMEM;
-
        return driver_register(&sbp2_driver.driver);
 }
 
 static void __exit sbp2_cleanup(void)
 {
        driver_unregister(&sbp2_driver.driver);
-       destroy_workqueue(sbp2_wq);
 }
 
 module_init(sbp2_init);
index c0fb405bb4359996bdec76d78ab57be12476c236..5e6f42789afec7b20d6aeec2fc9e0d3f61a43caa 100644 (file)
@@ -449,4 +449,6 @@ void fw_iso_resource_manage(struct fw_card *card, int generation,
                            u64 channels_mask, int *channel, int *bandwidth,
                            bool allocate);
 
+extern struct workqueue_struct *fw_workqueue;
+
 #endif /* _LINUX_FIREWIRE_H */