我正在尝试检测我的 cpu 的当前 p 状态。我注意到 p-state 状态 MSR (C001_0063) 在我的 ryzen 1700x 系统上总是返回 2,即使核心显然不在那个状态。我认为它曾经与我的主板附带的初始 BIOS (v0403) 一起工作,但不再可供下载1。
我的cpu超频2到3.8GHz。我曾经cpufreq-set
固定速度并cpufreq-info
验证:
analyzing CPU 0:
driver: acpi-cpufreq
CPUs which run at the same hardware frequency: 0
CPUs which need to have their frequency coordinated by software: 0
maximum transition latency: 4294.55 ms.
hardware limits: 2.20 GHz - 3.80 GHz
available frequency steps: 3.80 GHz, 2.20 GHz
available cpufreq governors: ondemand, conservative, performance, schedutil
current policy: frequency should be within 3.80 GHz and 3.80 GHz.
The governor "performance" may decide which speed to use
within this range.
current CPU frequency is 3.80 GHz (asserted by call to hardware).
下面是一个小测试程序,它显示了内核#0 的寄存器值,以及相对于 P0 状态的有效速度。需要root权限。对我来说,它经常pstate: 2, speed: 99%
在负载下打印。
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char** argv)
{
uint64_t aperf_old = 0;
uint64_t mperf_old = 0;
int fd;
fd = open("/dev/cpu/0/msr", O_RDONLY);
uint64_t pstate_limits;
pread(fd, &pstate_limits, sizeof(pstate_limits), 0xC0010061);
printf("pstate ranges: %d to %d\n", (int)(pstate_limits & 0x07), (int)((pstate_limits >> 4) & 0x07));
for(;;)
{
uint64_t pstate;
uint64_t pstate_req;
uint64_t aperf;
uint64_t mperf;
pread(fd, &pstate_req, sizeof(pstate_req), 0xC0010062);
pread(fd, &pstate, sizeof(pstate), 0xC0010063);
pread(fd, &aperf, sizeof(aperf), 0x000000E8);
pread(fd, &mperf, sizeof(mperf), 0x000000E7);
printf("pstate: %d, requested: %d", (int)(pstate & 0x07), (int)(pstate_req & 0x07));
if (mperf_old != 0 && mperf_old != mperf)
{
printf(", speed: %d%%", (int)(100 * (aperf - aperf_old) / (mperf - mperf_old)));
}
putchar('\n');
mperf_old = mperf;
aperf_old = aperf;
sleep(1);
}
}
在我的 FX-8350 上使用了类似的方法。我究竟做错了什么?也欢迎测试结果。
系统信息:
- Cpu: ryzen 1700x, P0 & P1 是 3.8GHz 3 , P2 是 2.2GHz
- 主板:华硕Prime X370-A,BIOS 3401
- 操作系统:debian 7.1,内核 4.9.0
更新:我已更改代码以打印请求的 pstate,并且该寄存器正在按预期更改。正如各种基准测试所证实的那样,实际的 CPU 速度也在发生变化。
1由于某种不明原因,bios备份功能被禁用,所以我无法在更新前进行复制。
2如果有机会,我会默认运行测试。
3不知道为什么会重复。