2

Linux has 'cpu hotplug' feature of enabling/disabling a cpu .

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 :

Q: How do i logically offline a CPU?

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

Coudlnt find anything about system calls though in this document , so hopefully someone can shed some light about this, Thanks !

Community
  • 1
  • 1
nadavgam
  • 2,014
  • 5
  • 20
  • 48

1 Answers1

1

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);
}
Youngdo Lee
  • 158
  • 6