Running this
strace -ff -tt perl -e 'open(A,"<","/proc/cpuinfo");'
Run Code Online (Sandbox Code Playgroud)
gives this:
22:36:10.365187 openat(AT_FDCWD, "/proc/cpuinfo", O_RDONLY) = 3
22:36:10.382061 ioctl(3, TCGETS, 0x7fffb127ea50) = -1 ENOTTY (Inappropriate ioctl for device)
Run Code Online (Sandbox Code Playgroud)
/proc/cpuinfo
is an in-memory file that does not require access to a slow disk. Why is it taking 17 ms to open?
I have tested 10 times on an idle system and the timing is very consistent.
$ uname -a
Linux hk 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
从内核的 4.12 版开始,在支持APERF / MPERF MSR 的x86 CPU 上,打开时会有轻微的延迟,/proc/cpuinfo
以确保准确报告 CPU 频率(或者至少不要显示太陈旧的值)。这在cpufreq 中略有改变:x86:使 scaling_cur_freq 的行为更符合预期(4.13,延迟增加),再次在x86/CPU:始终在 /proc/cpuinfo 中显示当前 CPU 频率(4.14,延迟减少)。