From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTGZb-00032k-Bf for qemu-devel@nongnu.org; Wed, 23 Nov 2011 12:25:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RTGZY-0008LQ-SV for qemu-devel@nongnu.org; Wed, 23 Nov 2011 12:25:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTGZY-0008L5-LW for qemu-devel@nongnu.org; Wed, 23 Nov 2011 12:25:24 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pANHPNDH012196 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 23 Nov 2011 12:25:24 -0500 From: Gerd Hoffmann Date: Wed, 23 Nov 2011 18:25:17 +0100 Message-Id: <1322069117-27150-8-git-send-email-kraxel@redhat.com> In-Reply-To: <1322069117-27150-1-git-send-email-kraxel@redhat.com> References: <1322069117-27150-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 7/7] usb-host: add usb_host_do_reset function. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Add a special function to reset the host usb device. It tracks the time needed by the USBDEVFS_RESET ioctl and prints a warning in case it needs too long. Usually it should be finished in 200 - 300 miliseconds. Warning threshold is one second. Intention is to help troubleshooting by indicating that the usb device stopped responding even to a reset request and is possibly broken. Signed-off-by: Gerd Hoffmann --- usb-linux.c | 25 ++++++++++++++++++++++--- 1 files changed, 22 insertions(+), 3 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index d4426ea..ab4c693 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -148,6 +148,25 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_file, const char *device_name); static int usb_linux_update_endp_table(USBHostDevice *s); +static int usb_host_do_reset(USBHostDevice *dev) +{ + struct timeval s, e; + uint32_t usecs; + int ret; + + gettimeofday(&s, NULL); + ret = ioctl(dev->fd, USBDEVFS_RESET); + gettimeofday(&e, NULL); + usecs = (e.tv_sec - s.tv_sec) * 1000000; + usecs += e.tv_usec - s.tv_usec; + if (usecs > 1000000) { + /* more than a second, something is fishy, broken usb device? */ + fprintf(stderr, "husb: device %d:%d reset took %d.%06d seconds\n", + dev->bus_num, dev->addr, usecs / 1000000, usecs % 1000000); + } + return ret; +} + static struct endp_data *get_endp(USBHostDevice *s, int pid, int ep) { struct endp_data *eps = pid == USB_TOKEN_IN ? s->ep_in : s->ep_out; @@ -606,7 +625,7 @@ static void usb_host_handle_reset(USBDevice *dev) trace_usb_host_reset(s->bus_num, s->addr); - ioctl(s->fd, USBDEVFS_RESET); + usb_host_do_reset(s);; usb_host_claim_interfaces(s, 0); usb_linux_update_endp_table(s); @@ -1370,7 +1389,7 @@ static int usb_host_close(USBHostDevice *dev) if (dev->dev.attached) { usb_device_detach(&dev->dev); } - ioctl(dev->fd, USBDEVFS_RESET); + usb_host_do_reset(dev); close(dev->fd); dev->fd = -1; return 0; @@ -1381,7 +1400,7 @@ static void usb_host_exit_notifier(struct Notifier *n, void *data) USBHostDevice *s = container_of(n, USBHostDevice, exit); if (s->fd != -1) { - ioctl(s->fd, USBDEVFS_RESET); + usb_host_do_reset(s);; } } -- 1.7.1