USB: create new workqueue thread for USB autosuspend
This patch (as787) creates a new workqueue thread to handle delayed USB autosuspend requests. Previously the code used keventd. However it turns out that the hub driver's suspend routine calls flush_scheduled_work(), making it a poor candidate for running in keventd (the call immediately deadlocks). The solution is to use a new thread instead of keventd. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
6a9fb06039
commit
bd859281c0
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/usb.h>
|
#include <linux/usb.h>
|
||||||
|
#include <linux/workqueue.h>
|
||||||
#include "hcd.h"
|
#include "hcd.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|
||||||
@@ -1131,7 +1132,7 @@ void usb_autosuspend_device(struct usb_device *udev, int dec_usage_cnt)
|
|||||||
mutex_lock_nested(&udev->pm_mutex, udev->level);
|
mutex_lock_nested(&udev->pm_mutex, udev->level);
|
||||||
udev->pm_usage_cnt -= dec_usage_cnt;
|
udev->pm_usage_cnt -= dec_usage_cnt;
|
||||||
if (udev->pm_usage_cnt <= 0)
|
if (udev->pm_usage_cnt <= 0)
|
||||||
schedule_delayed_work(&udev->autosuspend,
|
queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
|
||||||
USB_AUTOSUSPEND_DELAY);
|
USB_AUTOSUSPEND_DELAY);
|
||||||
mutex_unlock(&udev->pm_mutex);
|
mutex_unlock(&udev->pm_mutex);
|
||||||
// dev_dbg(&udev->dev, "%s: cnt %d\n",
|
// dev_dbg(&udev->dev, "%s: cnt %d\n",
|
||||||
@@ -1215,10 +1216,10 @@ void usb_autopm_put_interface(struct usb_interface *intf)
|
|||||||
struct usb_device *udev = interface_to_usbdev(intf);
|
struct usb_device *udev = interface_to_usbdev(intf);
|
||||||
|
|
||||||
mutex_lock_nested(&udev->pm_mutex, udev->level);
|
mutex_lock_nested(&udev->pm_mutex, udev->level);
|
||||||
if (intf->condition != USB_INTERFACE_UNBOUND) {
|
if (intf->condition != USB_INTERFACE_UNBOUND &&
|
||||||
if (--intf->pm_usage_cnt <= 0)
|
--intf->pm_usage_cnt <= 0) {
|
||||||
schedule_delayed_work(&udev->autosuspend,
|
queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
|
||||||
USB_AUTOSUSPEND_DELAY);
|
USB_AUTOSUSPEND_DELAY);
|
||||||
}
|
}
|
||||||
mutex_unlock(&udev->pm_mutex);
|
mutex_unlock(&udev->pm_mutex);
|
||||||
// dev_dbg(&intf->dev, "%s: cnt %d\n",
|
// dev_dbg(&intf->dev, "%s: cnt %d\n",
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include <linux/smp_lock.h>
|
#include <linux/smp_lock.h>
|
||||||
#include <linux/usb.h>
|
#include <linux/usb.h>
|
||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
|
#include <linux/workqueue.h>
|
||||||
|
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
#include <asm/scatterlist.h>
|
#include <asm/scatterlist.h>
|
||||||
@@ -47,6 +48,8 @@ const char *usbcore_name = "usbcore";
|
|||||||
|
|
||||||
static int nousb; /* Disable USB when built into kernel image */
|
static int nousb; /* Disable USB when built into kernel image */
|
||||||
|
|
||||||
|
struct workqueue_struct *ksuspend_usb_wq; /* For autosuspend */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* usb_ifnum_to_if - get the interface object with a given interface number
|
* usb_ifnum_to_if - get the interface object with a given interface number
|
||||||
@@ -170,9 +173,9 @@ static void usb_release_dev(struct device *dev)
|
|||||||
|
|
||||||
udev = to_usb_device(dev);
|
udev = to_usb_device(dev);
|
||||||
|
|
||||||
#ifdef CONFIG_PM
|
#ifdef CONFIG_USB_SUSPEND
|
||||||
cancel_delayed_work(&udev->autosuspend);
|
cancel_delayed_work(&udev->autosuspend);
|
||||||
flush_scheduled_work();
|
flush_workqueue(ksuspend_usb_wq);
|
||||||
#endif
|
#endif
|
||||||
usb_destroy_configuration(udev);
|
usb_destroy_configuration(udev);
|
||||||
usb_put_hcd(bus_to_hcd(udev->bus));
|
usb_put_hcd(bus_to_hcd(udev->bus));
|
||||||
@@ -184,6 +187,28 @@ static void usb_release_dev(struct device *dev)
|
|||||||
|
|
||||||
#ifdef CONFIG_PM
|
#ifdef CONFIG_PM
|
||||||
|
|
||||||
|
static int ksuspend_usb_init(void)
|
||||||
|
{
|
||||||
|
ksuspend_usb_wq = create_singlethread_workqueue("ksuspend_usbd");
|
||||||
|
if (!ksuspend_usb_wq)
|
||||||
|
return -ENOMEM;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ksuspend_usb_cleanup(void)
|
||||||
|
{
|
||||||
|
destroy_workqueue(ksuspend_usb_wq);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define ksuspend_usb_init() 0
|
||||||
|
#define ksuspend_usb_cleanup() do {} while (0)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_USB_SUSPEND
|
||||||
|
|
||||||
/* usb_autosuspend_work - callback routine to autosuspend a USB device */
|
/* usb_autosuspend_work - callback routine to autosuspend a USB device */
|
||||||
static void usb_autosuspend_work(void *_udev)
|
static void usb_autosuspend_work(void *_udev)
|
||||||
{
|
{
|
||||||
@@ -195,6 +220,11 @@ static void usb_autosuspend_work(void *_udev)
|
|||||||
mutex_unlock(&udev->pm_mutex);
|
mutex_unlock(&udev->pm_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static void usb_autosuspend_work(void *_udev)
|
||||||
|
{}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -976,9 +1006,12 @@ static int __init usb_init(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retval = ksuspend_usb_init();
|
||||||
|
if (retval)
|
||||||
|
goto out;
|
||||||
retval = bus_register(&usb_bus_type);
|
retval = bus_register(&usb_bus_type);
|
||||||
if (retval)
|
if (retval)
|
||||||
goto out;
|
goto bus_register_failed;
|
||||||
retval = usb_host_init();
|
retval = usb_host_init();
|
||||||
if (retval)
|
if (retval)
|
||||||
goto host_init_failed;
|
goto host_init_failed;
|
||||||
@@ -1014,6 +1047,8 @@ major_init_failed:
|
|||||||
usb_host_cleanup();
|
usb_host_cleanup();
|
||||||
host_init_failed:
|
host_init_failed:
|
||||||
bus_unregister(&usb_bus_type);
|
bus_unregister(&usb_bus_type);
|
||||||
|
bus_register_failed:
|
||||||
|
ksuspend_usb_cleanup();
|
||||||
out:
|
out:
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -1035,6 +1070,7 @@ static void __exit usb_exit(void)
|
|||||||
usb_hub_cleanup();
|
usb_hub_cleanup();
|
||||||
usb_host_cleanup();
|
usb_host_cleanup();
|
||||||
bus_unregister(&usb_bus_type);
|
bus_unregister(&usb_bus_type);
|
||||||
|
ksuspend_usb_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
subsys_initcall(usb_init);
|
subsys_initcall(usb_init);
|
||||||
|
@@ -62,6 +62,7 @@ extern int usb_autoresume_device(struct usb_device *udev, int inc_busy_cnt);
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern struct workqueue_struct *ksuspend_usb_wq;
|
||||||
extern struct bus_type usb_bus_type;
|
extern struct bus_type usb_bus_type;
|
||||||
extern struct usb_device_driver usb_generic_driver;
|
extern struct usb_device_driver usb_generic_driver;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user