cpu hotplug-是否有系统调用禁用linux中的cpu? [英] cpu hotplug - is there a system call to disable a cpu in linux?
问题描述
Linux具有启用/禁用cpu的" cpu hotplug "功能.
Linux has 'cpu hotplug' feature of enabling/disabling a cpu .
我想从C程序禁用计算机的cpus之一,所以我的问题是-怎么做?有可能吗?
I want disable one of the computers' cpus from a C program , so my question is - how? is it possible ?
在这里,我发现了以下内容:
Here I found the following :
问:我如何在逻辑上使CPU脱机?
Q: How do i logically offline a CPU?
A:请执行以下操作: #echo 0>/sys/devices/system/cpu/cpuX/online
A: Do the following: #echo 0 > /sys/devices/system/cpu/cpuX/online
尽管Coudlnt在本文档中找到了有关系统调用的任何内容,所以希望有人能对此有所启发,谢谢!
Coudlnt find anything about system calls though in this document , so hopefully someone can shed some light about this, Thanks !
推荐答案
在linux中没有用于禁用cpu的系统调用.您所发现的文章是唯一的方法.但是您可以将shell脚本重写为以下内容:
There is no syscall for disabling a cpu in linux. What you found article is the only method. But you can rewrite the shell script to the below:
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);
}
这篇关于cpu hotplug-是否有系统调用禁用linux中的cpu?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!