[libvirt] limit cpu speed in domain xml

Hi. Does it possible to limit vm cpu speed for example to 1Ghz or 500Mhz ? I need to simulate some hardware with specific cpu speed and test my application inside this vm , i want to measure results from each test and need constant cpu speed for testing (i need to run test not only my notebook but on server too and want identical cpu speed inside vm) -- Vasiliy Tolstov, e-mail: v.tolstov@selfip.ru

On Thu, Mar 16, 2017 at 12:14:31AM +0300, Vasiliy Tolstov wrote:
Hi. Does it possible to limit vm cpu speed for example to 1Ghz or 500Mhz ? I need to simulate some hardware with specific cpu speed and test my application inside this vm , i want to measure results from each test and need constant cpu speed for testing (i need to run test not only my notebook but on server too and want identical cpu speed inside vm)
You can set how much time the VM gets (i.e. limit it), but I'm not sure to what extent will that guarantee stable speed. Unfortunately, there is no way to tell QEMU what the frequency should be in the guest either. I don't think it's possible in KVM. You could, _theoretically_, pin the domain to a specific physical CPUs, and force a specific frequency of those pCPUs using cpufreq. If you are concerned with the speeds, you should also make sure you expose exactly the same CPU model to the guest. Anyway, I would be very careful with interpreting the results in any case. Martin P.S.: I always wondered if I could somehow tell QEMU to advertise slower frequency to the guest. I would even have some use cases for that, I think. If somebody knows, tell me ;)

On Thu, Mar 16, 2017 at 12:14:31AM +0300, Vasiliy Tolstov wrote:
Hi. Does it possible to limit vm cpu speed for example to 1Ghz or 500Mhz ? I need to simulate some hardware with specific cpu speed and test my application inside this vm , i want to measure results from each test and need constant cpu speed for testing (i need to run test not only my notebook but on server too and want identical cpu speed inside vm)
There's no way to do this at a KVM or libvirt level. The host kernel will always auto-scale CPU frequency according to the load placed on them by the guest OS (and other processes). To get a fixed frequency,and predictable benchmark results you would have to first use CPUAffinity in systemd.conf (or equiv) to ensure no other OS processes run on a particular chosen CPU. Then strictly bind the guest vCPU to that host CPU. Finally you would have to use sysfs to set the scaling_max_freq/min_freq to contrl what speed your host CPUs ran at. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|

16 Мар 2017 г. 13:18 пользователь "Daniel P. Berrange" <berrange@redhat.com> написал: On Thu, Mar 16, 2017 at 12:14:31AM +0300, Vasiliy Tolstov wrote:
Hi. Does it possible to limit vm cpu speed for example to 1Ghz or 500Mhz ? I need to simulate some hardware with specific cpu speed and test my application inside this vm , i want to measure results from each test and need constant cpu speed for testing (i need to run test not only my notebook but on server too and want identical cpu speed inside vm)
There's no way to do this at a KVM or libvirt level. The host kernel will always auto-scale CPU frequency according to the load placed on them by the guest OS (and other processes). To get a fixed frequency,and predictable benchmark results you would have to first use CPUAffinity in systemd.conf (or equiv) to ensure no other OS processes run on a particular chosen CPU. Then strictly bind the guest vCPU to that host CPU. Finally you would have to use sysfs to set the scaling_max_freq/min_freq to contrl what speed your host CPUs ran at. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :| Thanks! Next question, does it possible to provide constant speed for vps in case of cloud service? For example user buy vps with 500mhz or 1ghz and pay for guaranteed resource? Weights not very useful because I can't guarantee that each vps have needed processor time...

On Thu, Mar 16, 2017 at 08:41:48PM +0300, Vasiliy Tolstov wrote:
Thanks! Next question, does it possible to provide constant speed for vps in case of cloud service? For example user buy vps with 500mhz or 1ghz and pay for guaranteed resource?
IMHO that's a pretty poor way to provide/allocate capacity. The relative processors speeds don't directly correlate to performance. If you want to restrict a user to 1/2 the CPU, then run it at full speed but give a schedular cap
Weights not very useful because I can't guarantee that each vps have needed processor time...
CPU quota + period are the settings you want to timeslice CPUs into fixed quanties. Weight is just a relative prioritization measure. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|
participants (3)
-
Daniel P. Berrange
-
Martin Kletzander
-
Vasiliy Tolstov