From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Brook Subject: Re: [Qemu-devel] High CPU use of -usbdevice tablet (was Re: KVM usability) Date: Sun, 4 Apr 2010 15:25:17 +0100 Message-ID: <201004041525.18211.paul@codesourcery.com> References: <4B87A6BF.3090301@redhat.com> <4B938F9D.7010207@redhat.com> <20100404123116.GA19866@arachsys.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: Chris Webb , Avi Kivity , kvm@vger.kernel.org, Jernej =?utf-8?q?Simon=C4=8Di=C4=8D?= To: qemu-devel@nongnu.org Return-path: Received: from mail.codesourcery.com ([38.113.113.100]:59364 "EHLO mail.codesourcery.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754329Ab0DDOZV (ORCPT ); Sun, 4 Apr 2010 10:25:21 -0400 In-Reply-To: <20100404123116.GA19866@arachsys.com> Sender: kvm-owner@vger.kernel.org List-ID: > > Looks like the tablet is set to 100 Hz polling rate. We may be able > > to get away with 30 Hz or even less (ep_bInterval, in ms, in > > hw/usb-wacom.c). > > Changing the USB tablet polling interval from 10ms to 100ms in both > hw/usb-wacom.c and hw/usb-hid.c made no difference except the an increase > in bInterval shown in lsusb -v in the guest and the hint of jerky mouse > movement I expected from setting this value so high. A similar change to > the polling interval for the keyboard and mouse also made no difference to > their performance impact. The USB HID devices implement the SET_IDLE command, so the polling interval will have no real effect on performance. My guess is that the overhead you're seeing is entirely from the USB host adapter having to wake up and check the transport descriptor lists. This will only result in the guest being woken if a device actually responds (as mentioned above it should not). >Taking the FRAME_TIMER_FREQ down to 100 in hw/usb-uhci.c does seem to reduce >the CPU load quite a bit, but at the expense of making the USB tablet (and >presumably all other USB devices) very laggy. The guest USB driver explicitly decides which devices to poll each frame. Slowing down the frame rate will effectively change the polling period by the same factor. e.g. the HID device requests a polling rate of 10ms, you slowed down frame rate by 10x, so you're efectively only polling every 100ms. If you want a quick and nasty hack then you can probably make the device wake up less often, and process multiple frames every wakeup. However this is probably going to do bad things (at best extremely poor performance) when using actual USB devices. Fixing this properly is hard because the transport descriptor lists are stores in system RAM, and polled by the host adapter. The first step is to read the whole table of descriptors, and calculate when the next event is due. However the guest will not explicitly notify the HBA when these tables are modified, so you also need some sort of MMU trap to trigger recalculation. This only gets you down to the base polling interval requested by the device. Increasing this interval causes significant user visible latency, so increasing it is not an option. The guest is also likely to distribute polling events evenly, further reducing the effective sleep interval. To fix this you need additional APIs so that a device can report when an endpoint will become unblocked, rather than just waiting to be polled and NAKing the request. Paul From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NyQlS-00083I-9F for qemu-devel@nongnu.org; Sun, 04 Apr 2010 10:25:26 -0400 Received: from [140.186.70.92] (port=41484 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NyQlQ-000839-PC for qemu-devel@nongnu.org; Sun, 04 Apr 2010 10:25:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NyQlO-0003ST-V9 for qemu-devel@nongnu.org; Sun, 04 Apr 2010 10:25:24 -0400 Received: from mx20.gnu.org ([199.232.41.8]:62788) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NyQlO-0003SP-Sg for qemu-devel@nongnu.org; Sun, 04 Apr 2010 10:25:22 -0400 Received: from mail.codesourcery.com ([38.113.113.100]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NyQlO-0003Yr-Bq for qemu-devel@nongnu.org; Sun, 04 Apr 2010 10:25:22 -0400 From: Paul Brook Subject: Re: [Qemu-devel] High CPU use of -usbdevice tablet (was Re: KVM usability) Date: Sun, 4 Apr 2010 15:25:17 +0100 References: <4B87A6BF.3090301@redhat.com> <4B938F9D.7010207@redhat.com> <20100404123116.GA19866@arachsys.com> In-Reply-To: <20100404123116.GA19866@arachsys.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201004041525.18211.paul@codesourcery.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Chris Webb , Jernej@gnu.org, Avi Kivity , kvm@vger.kernel.org, =?utf-8?q?Simon=C4=8Di=C4=8D?= > > Looks like the tablet is set to 100 Hz polling rate. We may be able > > to get away with 30 Hz or even less (ep_bInterval, in ms, in > > hw/usb-wacom.c). > > Changing the USB tablet polling interval from 10ms to 100ms in both > hw/usb-wacom.c and hw/usb-hid.c made no difference except the an increase > in bInterval shown in lsusb -v in the guest and the hint of jerky mouse > movement I expected from setting this value so high. A similar change to > the polling interval for the keyboard and mouse also made no difference to > their performance impact. The USB HID devices implement the SET_IDLE command, so the polling interval will have no real effect on performance. My guess is that the overhead you're seeing is entirely from the USB host adapter having to wake up and check the transport descriptor lists. This will only result in the guest being woken if a device actually responds (as mentioned above it should not). >Taking the FRAME_TIMER_FREQ down to 100 in hw/usb-uhci.c does seem to reduce >the CPU load quite a bit, but at the expense of making the USB tablet (and >presumably all other USB devices) very laggy. The guest USB driver explicitly decides which devices to poll each frame. Slowing down the frame rate will effectively change the polling period by the same factor. e.g. the HID device requests a polling rate of 10ms, you slowed down frame rate by 10x, so you're efectively only polling every 100ms. If you want a quick and nasty hack then you can probably make the device wake up less often, and process multiple frames every wakeup. However this is probably going to do bad things (at best extremely poor performance) when using actual USB devices. Fixing this properly is hard because the transport descriptor lists are stores in system RAM, and polled by the host adapter. The first step is to read the whole table of descriptors, and calculate when the next event is due. However the guest will not explicitly notify the HBA when these tables are modified, so you also need some sort of MMU trap to trigger recalculation. This only gets you down to the base polling interval requested by the device. Increasing this interval causes significant user visible latency, so increasing it is not an option. The guest is also likely to distribute polling events evenly, further reducing the effective sleep interval. To fix this you need additional APIs so that a device can report when an endpoint will become unblocked, rather than just waiting to be polled and NAKing the request. Paul