为什么当前 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

直接与硬件通信,或者 - 根据实现 - 与固件通信,显然不应允许非特权。

来源

相关内容