On 06/16/2011 09:27 AM, Peter Zijlstra wrote: > Sure, I've got a couple of those things lying around: > > # perf stat -e instructions:u ./loop_1b_instructions-4x > > Performance counter stats for './loop_1b_instructions-4x': > > 4,000,085,344 instructions:u # 0.00 insns per cycle > > 0.311861278 seconds time elapsed > > --- > > #include <stdlib.h> > #include <stdio.h> > #include <time.h> > > main () > { > int i; > > fork(); > fork(); > > for (i = 0; i < 100000000; i++) { > asm("nop"); > asm("nop"); > asm("nop"); > asm("nop"); > asm("nop"); > asm("nop"); > asm("nop"); > } > wait(NULL); > wait(NULL); > wait(NULL); > wait(NULL); > } > That's the one. Guest: perf stat -e instructions:u /tmp/a.out Performance counter stats for '/tmp/a.out': 4,000,090,357 instructions:u # 0.00 insns per cycle 2.972828828 seconds time elapsed Host: perf stat -e instructions:u /tmp/a.out Performance counter stats for '/tmp/a.out': 4,000,083,592 instructions:u # 0.00 insns per cycle 0.278185315 seconds time elapsed So the counting is correct, but the time to run the command is significantly longer in the guest. That emphasizes the performance overhead of running perf-stat in the VM. Even the default counters for perf-stat are similar, showing correctness in counting: Guest: perf stat ./a.out Performance counter stats for './a.out': 2707.156752 task-clock # 0.996 CPUs utilized 337 context-switches # 0.000 M/sec 0 CPU-migrations # 0.000 M/sec 209 page-faults # 0.000 M/sec 3,103,481,148 cycles # 1.146 GHz [50.25%] <not supported> stalled-cycles-frontend <not supported> stalled-cycles-backend 3,999,894,345 instructions # 1.29 insns per cycle [50.03%] 406,716,307 branches # 150.237 M/sec [49.85%] 270,801 branch-misses # 0.07% of all branches [50.02%] 2.717859741 seconds time elapsed Host: perf stat /tmp/a.out Performance counter stats for '/tmp/a.out': 1117.694687 task-clock # 3.845 CPUs utilized 140 context-switches # 0.000 M/sec 3 CPU-migrations # 0.000 M/sec 203 page-faults # 0.000 M/sec 3,052,677,262 cycles # 2.731 GHz 1,449,951,708 stalled-cycles-frontend # 47.50% frontend cycles idle 471,788,212 stalled-cycles-backend # 15.45% backend cycles idle 4,006,074,559 instructions # 1.31 insns per cycle # 0.36 stalled cycles per insn 401,265,264 branches # 359.012 M/sec 29,376 branch-misses # 0.01% of all branches 0.290722796 seconds time elapsed David -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html