cpu hotplug - 是否有系统调用来禁用 linux 中的 cpu?

cpu hotplug - is there a system call to disable a cpu in linux?

Linux 具有 enabling/disabling 和 cpu 的“cpu hotplug”功能。

我想从 C 程序禁用其中一台计算机的 cpu,所以我的问题是 - 如何?可能吗?

Here 我发现了以下内容:

Q: How do i logically offline a CPU?

A: Do the following: #echo 0 > /sys/devices/system/cpu/cpuX/online

虽然在本文档中找不到有关系统调用的任何信息,但希望有人能对此有所了解,谢谢!

linux 中没有用于禁用 cpu 的系统调用。你找到的文章是唯一的方法。但是您可以将 shell 脚本重写为以下内容:

static void set_cpu_online(int cpu, int online)
{
        int fd;
        int ret;
        char path[256];

        snprintf(path, sizeof(path) - 1,
                 "/sys/devices/system/cpu/cpu%d/online", cpu);

        fd = open(path, O_RDWR);
        assert(fd > 0);

        ret = write(fd, "0" + (online ? 1 : 0), 1);
        assert(ret == 1);
}