13

我正在尝试检测我的 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不知道为什么会重复。

4

1 回答 1

0

这可能不相关,但是我听说有些人已经成功地将他们的 Ryzen 7s 替换为 AMD,因为 p 状态导致 Unix 或类 Unix 系统中的系统稳定性问题。尽管从对此事的评论,尤其是华擎论坛上的关于驱动程序/固件问题的评论来看,我在其他地方读到 AMD 可能会对早期批次的芯片承担一些责任。根据我对 P 和 C 状态的了解,操作系统或主机虚拟化环境要求某些状态。那么补丁可以从内部完成吗?

于 2019-10-17T19:38:07.760 回答