有没有办法确定是否发生了SMM中断? [英] Is there a way to determine that SMM interrupt has occured?

查看:155
本文介绍了有没有办法确定是否发生了SMM中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在一定的定义间隔内确定 SMM 条目在当前内核上发生过?

Is there a way to determine, for some progamatically defined interval, if a SMM entry has occurred on the current core?

推荐答案

从Nehalem开始,MSR寄存器0x34(称为MSR_SMI_COUNT)对自系统启动以来发生的SMI数量进行计数.它是只读的且特定于Intel.您可以使用/dev/cpu/CPUNUM/msr接口从用户模式从该寄存器(或任何其他MSR寄存器)读取可编程性.有几种使用该界面显示SMI计数的工具,包括 msr-tools ()和涡轮增压器(sudo turbostat --msr 0x34).

Starting with Nehalem, the MSR register 0x34 (called MSR_SMI_COUNT) counts the number of SMIs that occurred since the system was booted. It's read-only and Intel-specific. You can programmability read from this register (or any other MSR register) from user mode using the /dev/cpu/CPUNUM/msr interface. There are several tools that use the interface to show the SMI count including msr-tools (sudo rdmsr -a 0x34) and turbostat (sudo turbostat --msr 0x34).

我已经从turbostat源代码(/source/tools/power/x86/turbostat/turbostat.c)中提取了此代码. get_msr_fd函数返回msr文件的文件描述符. get_msr函数接受CPU编号,MSR偏移量(对于MSR_SMI_COUNT为0x34)和指向将保存MSR值的64位位置的指针(尽管MSR_SMI_COUNT是32位计数器,并且高32位保留).

I've extracted this code from the turbostat source code (/source/tools/power/x86/turbostat/turbostat.c). The get_msr_fd function returns the file descriptor of the msr file. The get_msr function accepts the CPU number, the MSR offset (0x34 for MSR_SMI_COUNT), and a pointer to a 64-bit location that will hold the value of the MSR (although MSR_SMI_COUNT is a 32-bit counter and the upper 32 bits are reserved).

int get_msr_fd(int cpu)
{
    char pathname[32];
    int fd;

    fd = fd_percpu[cpu];

    if (fd)
        return fd;

    sprintf(pathname, "/dev/cpu/%d/msr", cpu);
    fd = open(pathname, O_RDONLY);
    if (fd < 0)
        err(-1, "%s open failed, try chown or chmod +r /dev/cpu/*/msr, or run as root", pathname);

    fd_percpu[cpu] = fd;

    return fd;
}

int get_msr(int cpu, off_t offset, unsigned long long *msr)
{
    ssize_t retval;

    retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset);

    if (retval != sizeof *msr)
        err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset);

    return 0;
}

一个SMI可能每秒发生多次或长时间不出现.但是观察MSR_SMI_COUNT变化的一种方法是发出同步SMI.通常,这可以通过将一些8位值写入I/O端口0xB2或0xB3来完成.您可以参考芯片组手册来确定哪些I/O端口可以触发SMI.

An SMI may occur multiple times per second or may not occur for a long period of time. But one way to observe a change in MSR_SMI_COUNT is by issuing a synchronous SMI. Typically, this can be done by writing some 8-bit value to I/O port 0xB2 or 0xB3. You can refer to your chipset manual to determine which I/O ports may trigger an SMI.

这篇关于有没有办法确定是否发生了SMM中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆