Skip to contentSkip to conversation

udev: add rules for qemu guests

PATCH Superseded Gerd Hoffmann 2 participants 7 messages Jan 25, 2011 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udev: add rules for qemu guests

These patches enable usb autosuspend for the qemu emulated HID devices. This reduces the cpu load for idle guests with a hid device attached because the linux kernel will suspend the usb bus then and qemu can stop running a 1000 Hz to emulate the (active) UHCI controller.

---
 Makefile.am                      |    6 ++++++
 extras/qemu/99-qemu-usb.rules    |   12 ++++++++++++
 extras/qemu/qemu-usb-autosuspend |    7 +++++++
 3 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100644 extras/qemu/99-qemu-usb.rules
 create mode 100755 extras/qemu/qemu-usb-autosuspend
Makefile.am +6 -0
index 2e3fe39..c09b2a0 100644
@@ -317,6 +317,12 @@ extras_v4l_id_v4l_id_LDADD = libudev/libudev-private.la
 libexec_PROGRAMS += extras/v4l_id/v4l_id
 dist_udevrules_DATA += extras/v4l_id/60-persistent-v4l.rules
 
+# ------------------------------------------------------------------------------
+# qemu -- qemu/kvm guest tweaks
+# ------------------------------------------------------------------------------
+dist_udevrules_DATA += extras/qemu/99-qemu-usb.rules
+dist_libexec_SCRIPTS += extras/qemu/qemu-usb-autosuspend
+
 if ENABLE_EXTRAS
 # ------------------------------------------------------------------------------
 # conditional extras (need glib, libusb, libacl, ...)
extras/qemu/99-qemu-usb.rules new file +12 -0
new file mode 100644
index 0000000..35f33e1
@@ -0,0 +1,12 @@
+#
+# Enable autosuspend for qemu emulated usb hid devices.
+#
+# Note that there are buggy qemu versions which advertise remote
+# wakeup support but don't actually implement it correctly.  This
+# is the reason why we need a match for the serial number here.
+# The serial number "42" is used to tag the implementations where
+# remote wakeup is working.
+#
+ACTION="add", SUBSYSTEM="usb", ATTR{product}="QEMU USB Mouse", ATTR{serial}="42", RUN+="qemu-usb-autosuspend %p"
+ACTION="add", SUBSYSTEM="usb", ATTR{product}="QEMU USB Tablet", ATTR{serial}="42", RUN+="qemu-usb-autosuspend %p"
+ACTION="add", SUBSYSTEM="usb", ATTR{product}="QEMU USB Keyboard", ATTR{serial}="42", RUN+="qemu-usb-autosuspend %p"
extras/qemu/qemu-usb-autosuspend new file +7 -0
new file mode 100755
index 0000000..48761de
@@ -0,0 +1,7 @@
+#!/bin/sh
+path="$1"
+if test -f "/sys${path}/power/control"; then
+	echo "auto" > "/sys${path}/power/control"
+elif test -f "/sys${path}/power/level"; then
+	echo "auto" > "/sys${path}/power/level"
+fi
Signature · 1 line
1.7.1
#1 lore raw
Quoted 4 lines · Gerd Hoffmann

These patches enable usb autosuspend for the qemu emulated HID devices. This reduces the cpu load for idle guests with a hid device attached because the linux kernel will suspend the usb bus then and qemu can stop running a 1000 Hz to emulate the (active) UHCI controller.

I guess this should go into the qemu package, not the udev sources.

Kay

#2 lore raw
In reply to Gerd Hoffmann
Quoted 7 lines · Kay Sievers
Quoted 4 lines · Gerd Hoffmann

These patches enable usb autosuspend for the qemu emulated HID devices. This reduces the cpu load for idle guests with a hid device attached because the linux kernel will suspend the usb bus then and qemu can stop running a 1000 Hz to emulate the (active) UHCI controller.

I guess this should go into the qemu package, not the udev sources.

Well, this should be installed in a *guest*, whereas qemu itself is installed on the virtualization *host*. Placing it in the qemu package would have no effect at all ;)

cheers,
Gerd

#3 lore raw
In reply to Gerd Hoffmann
Quoted 6 lines · Gerd Hoffmann

These patches enable usb autosuspend for the qemu emulated HID devices. This reduces the cpu load for idle guests with a hid device attached because the linux kernel will suspend the usb bus then and qemu can stop running a 1000 Hz to emulate the (active) UHCI controller.

+dist_udevrules_DATA += extras/qemu/99-qemu-usb.rules

The number should be 10-90 for the default things, or is there a dependency on anything else?

Quoted 1 line

+ACTION="add", SUBSYSTEM="usb", ATTR{product}="QEMU USB Mouse", ATTR{serial}="42", RUN+="qemu-usb-autosuspend %p"

This should probably be a simple ATTR{power/control}="auto"

extras/qemu/qemu-usb-autosuspend line 1

Quoted 4 lines
extras/qemu/qemu-usb-autosuspend new file +1 -0
@@ -0,0 +1,7 @@
+#!/bin/sh

If possible, we try to avoid shell scripts.

extras/qemu/qemu-usb-autosuspend line 7

Quoted 6 lines
extras/qemu/qemu-usb-autosuspend new file +6 -0
+path="$1"
+if test -f "/sys${path}/power/control"; then
+       echo "auto" > "/sys${path}/power/control"
+elif test -f "/sys${path}/power/level"; then
+       echo "auto" > "/sys${path}/power/level"
+fi

Which one is the actual one? Is the second try only for older kernels? That could go in the compat rules, udev does not ship rules for older kernels in the default installation.

Anyway, why isn't all this done in the kernel? Can't this be made working somehow?

Carrying out configuration, and unconditionally applying it from udev rules, should be avoided if possible and if the kernel could do it itself. We ran into serious issues in the past when more recent kernels did not like the config anymore that udev applied.

Cheers,
Kay

#4 lore raw
In reply to Gerd Hoffmann
Quoted 10 lines · Kay Sievers
Quoted 6 lines · Gerd Hoffmann

These patches enable usb autosuspend for the qemu emulated HID devices. This reduces the cpu load for idle guests with a hid device attached because the linux kernel will suspend the usb bus then and qemu can stop running a 1000 Hz to emulate the (active) UHCI controller.

+dist_udevrules_DATA += extras/qemu/99-qemu-usb.rules

The number should be 10-90 for the default things, or is there a dependency on anything else?

No dependency at all. What number do you suggest then?

Quoted 3 lines
Quoted 1 line

+ACTION="add", SUBSYSTEM="usb", ATTR{product}="QEMU USB Mouse", ATTR{serial}="42", RUN+="qemu-usb-autosuspend %p"

This should probably be a simple ATTR{power/control}="auto"

That should work indeed. Didn't know you can write sysfs files that way.

Quoted 8 lines

extras/qemu/qemu-usb-autosuspend line 7

Quoted 6 lines
extras/qemu/qemu-usb-autosuspend new file +6 -0
+path="$1"
+if test -f "/sys${path}/power/control"; then
+       echo "auto">  "/sys${path}/power/control"
+elif test -f "/sys${path}/power/level"; then
+       echo "auto">  "/sys${path}/power/level"
+fi

Which one is the actual one? Is the second try only for older kernels?

Yes, it is for older kernels.

Quoted 2 lines

That could go in the compat rules, udev does not ship rules for older kernels in the default installation.

Ok. Is there some way to express "power/control doesn't exist but power/level does" as udev rule, so I can zap the shell script?

Quoted 2 lines

Anyway, why isn't all this done in the kernel? Can't this be made working somehow?

As far I know the kernel doesn't do that by default because too much broken hardware is out there which breaks when autosuspend is enabled by default. I saw mentioned somewhere the plan is to have udev enable this for known-good devices, so I'm trying that route :)

Havn't checked whenever there is a in-kernel white list for that stuff which could be used instead.

cheers,
Gerd

#5 lore raw
In reply to Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann
Quoted 4 lines · Kay Sievers
Quoted 1 line

+dist_udevrules_DATA += extras/qemu/99-qemu-usb.rules

The number should be 10-90 for the default things, or is there a dependency on anything else?

No dependency at all.  What number do you suggest then?

Doesn't really matter, we just leave 00-09 and 91-99 for other custom stuff, to get easily before and after the common things.

Quoted 5 lines
Quoted 2 lines

That could go in the compat rules, udev does not ship rules for older kernels in the default installation.

Ok.  Is there some way to express "power/control doesn't exist but power/level does" as udev rule, so I can zap the shell script?

TEST="" should do that.

Quoted 5 lines
Quoted 2 lines

Anyway, why isn't all this done in the kernel? Can't this be made working somehow?

As far I know the kernel doesn't do that by default because too much broken hardware is out there which breaks when autosuspend is enabled by default.

Yeah, there is a reason not to do that for all devices, there are too many broken ones.

Quoted 2 lines

I saw mentioned somewhere the plan is to have udev enable this for known-good devices, so I'm trying that route :)

Oh, yeah, nice idea. That's the reason there is no list at all. :)

Quoted 2 lines

Havn't checked whenever there is a in-kernel white list for that stuff which could be used instead.

Yeah, would be nice to have some generic way to enable autosuspend when the hardware (real or emulated one) hints that it supports that. Not sure how it would look like in detail though.

Kay

#6 lore raw
In reply to Gerd Hoffmann

Hi,

Quoted 4 lines
Quoted 1 line

No dependency at all. What number do you suggest then?

Doesn't really matter, we just leave 00-09 and 91-99 for other custom stuff, to get easily before and after the common things.

Fine, so I can pick '42' ;)

Quoted 4 lines
Quoted 2 lines

Ok. Is there some way to express "power/control doesn't exist but power/level does" as udev rule, so I can zap the shell script?

TEST="" should do that.

Thanks.

Quoted 5 lines
Quoted 2 lines

Havn't checked whenever there is a in-kernel white list for that stuff which could be used instead.

Yeah, would be nice to have some generic way to enable autosuspend when the hardware (real or emulated one) hints that it supports that.

Well, there is a descriptor bit for that of course, but unfortunately one can't expect that only (physical or virtual) devices without bugs actually set that ...

cheers,
Gerd