為什麼目前 CPU 頻率對於 root 來說是唯讀的?

為什麼目前 CPU 頻率對於 root 來說是唯讀的?

我有一個提供基準測試的程序,但它與作業系統無關,並且不知道如何讀取 CPU 頻率。測試程式透過腳本驅動。如果我提供 CPU 頻率,那麼程式就可以計算操作的吞吐量。

我以為我會提供當前的 CPU 頻率(為了最準確的讀數),但看起來該值對於 root 來說是唯讀的,其他人無法訪問:

$ ls -Al /sys/devices/system/cpu/cpu0/cpufreq/
total 0
-r--r--r-- 1 root root 4096 Jan 27 23:19 affected_cpus
-r-------- 1 root root 4096 Jan 27 23:19 cpuinfo_cur_freq
-r--r--r-- 1 root root 4096 Jan 27 23:19 cpuinfo_max_freq
-r--r--r-- 1 root root 4096 Jan 27 23:19 cpuinfo_min_freq
...
-rw-r--r-- 1 root root 4096 Jan 27 23:19 scaling_max_freq
-rw-r--r-- 1 root root 4096 Jan 27 23:19 scaling_min_freq
-rw-r--r-- 1 root root 4096 Jan 27 23:19 scaling_setspeed

作為ls -l表明,cpuinfo_cur_freq是具有該特定 ACL 的唯一物件。其他條目大多是04440644對於一些)。

為什麼目前CPU頻率對root來說是唯讀的,其他人無權存取?

答案1

你應該能夠閱讀

scaling_cur_freq

回答這個問題:

看來讀書

cpuinfo_cur_freq

直接與硬體或韌體(取決於實現)通信,顯然不應該允許無特權。

來源

相關內容