On 02/25/2013 03:31 PM, Peter Krempa wrote:
Qemu's implementation of virtio RNG supports rate limiting of
the
entropy used. This patch exposes the option to tune this fucntionality.
s/fucntionality/functionality/
This patch is based on qemu commit 904d6f588063fb5ad2b61998acdf1e73fb4
The rate limiting is exported in the XML as:
<devices>
...
<rng model='virtio'>
<rate period='1234'>4321</rate>
<backend model='random'/>
</rng>
...
---
Notes:
This series would benefit from the per-driver XML parsing checks to verify
that rate > 8bits, otherwise it will be rounded down to 0 bytes. I will
follow up with that change as soon as the per-driver callbacks get in.
Version 3:
- State the time unit in docs
Version 2:
- Qemu uses bytes/period, adapt the value according to that
docs/formatdomain.html.in | 10 ++++++++++
docs/schemas/domaincommon.rng | 18 +++++++++++++++++-
src/conf/domain_conf.c | 17 +++++++++++++++++
src/conf/domain_conf.h | 2 ++
src/qemu/qemu_command.c | 9 +++++++++
.../qemuxml2argv-virtio-rng-random.args | 2 +-
.../qemuxml2argv-virtio-rng-random.xml | 1 +
7 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 2a60f61..220884c 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4294,6 +4294,7 @@ qemu-kvm -net nic,model=? /dev/null
...
<devices>
<rng model='virtio'>
+ <rate period="2000">1234</rate>
<backend model='random'>/dev/random</backend>
<!-- OR -->
<backend model='egd' type='udp'>
@@ -4316,6 +4317,15 @@ qemu-kvm -net nic,model=? /dev/null
<li>'virtio' — supported by qemu and virtio-rng kernel
module</li>
</ul>
</dd>
+ <dt><code>rate</code></dt>
+ <dd>
+ <p>
+ The rate element allows to limit the rate that the entropy can be
grammar doesn't quite flow here; see below
+ read from the source. The value is in bits that the device
is allowed
+ to read in the selected period. The period is represented in miliseconds.
s/miliseconds/milliseconds/
+ The default period is 1000ms or 1 second.
I'm still not sure we accurately covered things. Maybe:
The optional <code>rate</code> element allows limiting the rate at which
entropy can be consumed from the source. An optional
<code>period</code> attribute specifies the duration of a period in
milliseconds; if omitted, the period is taken as 1000 milliseconds (1
second). The element contents specify how many bits are permitted per
period. Drivers may enforce a minimum rate, and may round the rate down
to a minimum granularity.
+++ b/src/conf/domain_conf.h
@@ -1736,6 +1736,8 @@ enum virDomainRNGBackend {
struct _virDomainRNGDef {
int model;
int backend;
+ unsigned int rate;
+ unsigned int period;
Comments here would help:
unsigned int rate; /* bits per period */
unsigned int period; /* milliseconds */
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args
@@ -1 +1 @@
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214
-smp 1 -nographic -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot
c -usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 -object
rng-random,id=rng0,filename=/test/phile -device
virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x4
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214
-smp 1 -nographic -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot
c -usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 -object
rng-random,id=rng0,filename=/test/phile -device
virtio-rng-pci,rng=rng0,max-bytes=100,period=1234,bus=pci.0,addr=0x4
This is a long line; please split it with a backslash-newline to fit in
80 columns.
diff --git
a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml
b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml
index ab1f38c..26ddd38 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml
@@ -17,6 +17,7 @@
<controller type='usb' index='0'/>
<memballoon model='virtio'/>
<rng model='virtio'>
+ <rate period='1234'>800</rate>
<backend model='random'>/test/phile</backend>
</rng>
</devices>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org