Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to get the steal time with 2 VMs (each with 1 Vcpu) pinned to same core.

I run the same application on these 2 VMs simultaneously and see the performance difference. I am trying to read the steal time from inside the guest using top, vmstat etc.

Both, top and vmstat -s report the steal time (st) as 0. I also checked that procps is in latest version. I am using virtio-net. I suspect that the steal time is not being updated well. Is there something which I need to configure for this to work? My Linux version for guest image is:

Linux server-147 2.6.35-24-virtual #42-Ubuntu SMP Thu Dec 2 05:15:26 UTC 2010 x86_64 GNU/Linux

And /proc/cpuinfo shows:

processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 2
model name  : QEMU Virtual CPU version 0.14.0
stepping    : 3
cpu MHz     : 2992.498
cache size  : 4096 KB
fpu     : yes
fpu_exception   : yes
cpuid level : 4
wp      : yes
flags       : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pse36 clflush mmx fxsr sse sse2 syscall nx lm up rep_good pni cx16
hypervisor lahf_lm
bogomips    : 5984.99
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management:

Is there a way to programmatically get the value of steal cycles (e.g. using a C program)?

share|improve this question
Does your host kernel have support for KVM steal time reporting? – Michael Hampton Oct 9 '12 at 0:03
@MichaelHampton Thanks. How can I find that ? One thing I checked was that the option CONFIG_SCHEDSTATS is enabled in host kernel. What else should I check? – Abhishek Oct 9 '12 at 1:35


you may want to look for the /proc/stat file (systemwide) or /proc/PID-ID/stat file (per [guest-]process).

This could be an example code for looking for the whole cpu cycles. you can also strip down for guest cycles.

/* stat CPU of local system */
uint16_t system_cpu_percent_busyness(void) {
  long jiff_user_a, jiff_nice_a, jiff_system_a, jiff_idle_a, jiff_io_wait_a, jiff_irq_a, jiff_softirq_a, jiff_stolen_a, jiff_guest_a;
  long jiff_user_b, jiff_nice_b, jiff_system_b, jiff_idle_b, jiff_io_wait_b, jiff_irq_b, jiff_softirq_b, jiff_stolen_b, jiff_guest_b;
  long jiff_used_a, jiff_used_b, jiff_total_a, jiff_total_b;
  char cpu[10];
  FILE *pf;

  if((pf = fopen("/proc/stat", "r")) == NULL) {
  fscanf(pf, "%s\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld", cpu, &jiff_user_a, &jiff_nice_a, &jiff_system_a, &jiff_idle_a, &jiff_io_wait_a, &jiff_irq_a, &jiff_softirq_a, &jiff_stolen_a, &jiff_guest_a);
  usleep(100000); // sleep 0.1 sec

  if((pf = fopen("/proc/stat", "r")) == NULL) {
  fscanf(pf, "%s\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld", cpu, &jiff_user_b, &jiff_nice_b, &jiff_system_b, &jiff_idle_b, &jiff_io_wait_b, &jiff_irq_b, &jiff_softirq_b, &jiff_stolen_b, &jiff_guest_b);

  jiff_used_a = jiff_user_a + jiff_nice_a + jiff_system_a + jiff_io_wait_a + jiff_irq_a + jiff_softirq_a + jiff_stolen_a + jiff_guest_a;
  jiff_total_a = jiff_used_a + jiff_idle_a;

  jiff_used_b = jiff_user_b + jiff_nice_b + jiff_system_b + jiff_io_wait_b + jiff_irq_b + jiff_softirq_b + jiff_stolen_b + jiff_guest_b;
  jiff_total_b = jiff_used_b + jiff_idle_b;

  return((uint16_t)((100 * (jiff_used_b - jiff_used_a) / (jiff_total_b - jiff_total_a))));

Additional have a look into getrusage() function of your system.

share|improve this answer

Unless you have high load you may not have any CPU steal time. In order to accurately measure this you'll need to make sure that both instances are consuming enough CPU time to warrant stealing.

The program cpuburn is an effective utility for generating CPU load. Try running it in both instances simultaneously for an hour. Make sure each instance does not have an execution cap and both are assigned to the same core(s).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.