From: Gerd Hoffmann <kraxel@redhat.com> To: qemu-devel@nongnu.org Cc: "Thomas Huth" <thuth@redhat.com>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, "Wainer dos Santos Moschetta" <wainersm@redhat.com>, "Willian Rampazzo" <willianr@redhat.com>, "Gerd Hoffmann" <kraxel@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org> Subject: [PULL 1/7] usb-host: wire up timer for windows Date: Thu, 29 Jul 2021 14:50:38 +0200 [thread overview] Message-ID: <20210729125044.3531457-2-kraxel@redhat.com> (raw) In-Reply-To: <20210729125044.3531457-1-kraxel@redhat.com> On windows we can't wait on file descriptors. Poll libusb using a timer instead. Fixes long-standing FIXME. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/431 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Message-Id: <20210623085249.1151901-2-kraxel@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/usb/host-libusb.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index c0f314462aaf..00f6fbb29b39 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -254,6 +254,29 @@ static void usb_host_del_fd(int fd, void *user_data) qemu_set_fd_handler(fd, NULL, NULL, NULL); } +#else + +static QEMUTimer *poll_timer; +static uint32_t request_count; + +static void usb_host_timer_kick(void) +{ + int64_t delay_ns; + + delay_ns = request_count + ? (NANOSECONDS_PER_SECOND / 100) /* 10 ms interval with active req */ + : (NANOSECONDS_PER_SECOND); /* 1 sec interval otherwise */ + timer_mod(poll_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + delay_ns); +} + +static void usb_host_timer(void *opaque) +{ + struct timeval tv = { 0, 0 }; + + libusb_handle_events_timeout(ctx, &tv); + usb_host_timer_kick(); +} + #endif /* !CONFIG_WIN32 */ static int usb_host_init(void) @@ -276,7 +299,8 @@ static int usb_host_init(void) libusb_set_debug(ctx, loglevel); #endif #ifdef CONFIG_WIN32 - /* FIXME: add support for Windows. */ + poll_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, usb_host_timer, NULL); + usb_host_timer_kick(); #else libusb_set_pollfd_notifiers(ctx, usb_host_add_fd, usb_host_del_fd, @@ -364,11 +388,18 @@ static USBHostRequest *usb_host_req_alloc(USBHostDevice *s, USBPacket *p, r->buffer = g_malloc(bufsize); } QTAILQ_INSERT_TAIL(&s->requests, r, next); +#ifdef CONFIG_WIN32 + request_count++; + usb_host_timer_kick(); +#endif return r; } static void usb_host_req_free(USBHostRequest *r) { +#ifdef CONFIG_WIN32 + request_count--; +#endif QTAILQ_REMOVE(&r->host->requests, r, next); libusb_free_transfer(r->xfer); g_free(r->buffer); -- 2.31.1
next prev parent reply other threads:[~2021-07-29 12:53 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-29 12:50 [PULL 0/7] Usb 20210729 patches Gerd Hoffmann 2021-07-29 12:50 ` Gerd Hoffmann [this message] 2021-07-29 12:50 ` [PULL 2/7] ci: add libusb for windows builds Gerd Hoffmann 2021-07-29 12:50 ` [PULL 3/7] usbredir: fix free call Gerd Hoffmann 2021-07-29 12:50 ` [PULL 4/7] docs: Incorporate information in usb-storage.txt into rST manual Gerd Hoffmann 2021-07-29 12:50 ` [PULL 5/7] docs: Fold usb2.txt USB controller information into usb.rst Gerd Hoffmann 2021-07-29 12:50 ` [PULL 6/7] docs: Fold usb2.txt physical port addressing info " Gerd Hoffmann 2021-07-29 12:50 ` [PULL 7/7] docs: Fold usb2.txt passthrough information " Gerd Hoffmann 2021-07-30 8:14 ` [PULL 0/7] Usb 20210729 patches Peter Maydell
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210729125044.3531457-2-kraxel@redhat.com \ --to=kraxel@redhat.com \ --cc=alex.bennee@linaro.org \ --cc=f4bug@amsat.org \ --cc=qemu-devel@nongnu.org \ --cc=thuth@redhat.com \ --cc=wainersm@redhat.com \ --cc=willianr@redhat.com \ --subject='Re: [PULL 1/7] usb-host: wire up timer for windows' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.