Linux でランキュー待ち時間がCPU時間にカウントされないことを確認した


run キューで待たされた時間は CPU Time にはカウントされない - ablog



$ time perl -e 'for(1..10000){for(1..10000){}}'

real    0m5.301s
user    0m3.971s
sys     0m1.280s


$ for i in {1..10}; do time perl -e 'for(1..10000){for(1..10000){}}' & done

real    0m49.218s
user    0m3.322s
sys     0m1.787s

real    0m51.067s
user    0m3.479s
sys     0m1.661s

real    0m51.072s
user    0m3.430s
sys     0m1.690s

real    0m50.958s
user    0m3.424s
sys     0m1.708s

real    0m51.016s
user    0m3.350s
sys     0m1.768s

real    0m50.831s
user    0m3.419s
sys     0m1.675s

real    0m51.152s
user    0m3.323s
sys     0m1.826s

real    0m51.186s
user    0m3.469s
sys     0m1.681s

real    0m51.164s
user    0m3.459s
sys     0m1.645s

real    0m51.163s
user    0m3.498s
sys     0m1.593s

1プロセスの場合と10プロセス並行の場合で比べると、user、sys はほとんど変わらないが real は10倍になっている。time の man には以下の通り書かれている。

The  time  command runs the specified program command with the given arguments. When command finishes, time writes a message to stan-dard error giving timing statistics about this program run. These statistics consist of (i) the elapsed real time between invocation and  termination, (ii) the user CPU time (the sum of the tms_utime and tms_cutime values in a struct tms as returned by times(2)), and (iii) the system CPU time (the sum of the tms_stime and tms_cstime values in a struct tms as returned by times(2)).


$ cat /etc/issue
Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)
Kernel \r on an \m

$ uname -a
Linux localhost.localdomain 2.6.18- #1 SMP Wed Sep 29 15:40:03 EDT 2010 i686 i686 i386 GNU/Linux
$ cat /proc/cpuinfo 
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 37
model name      : Intel(R) Core(TM) i5 CPU       M 520  @ 2.40GHz
stepping        : 5
cpu MHz         : 2396.003
cache size      : 6144 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 5
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 nx rdtscp constant_tsc up pni monitor ssse3
bogomips        : 4792.00