My goal is to implement a system call in linux kernel that enables/disables a CPU core.

First, I implemented a system call that disbales CPU3 in a 4-core system.

The system call code is as follows:

#include <linux/kernel.h>
#include <linux/slab.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
#include <linux/cpumask.h>
#include <linux/smp.h>

asmlinkage long sys_new_syscall(void)
    unsigned int cpu3 = 3;

    set_cpu_online (cpu3, false) ;          /* clears the CPU in the cpumask */
    printk ("CPU%u is offline\n", cpu3);

    return 0;

The system call was registered correctly in the kernel and I enabled 'cpu hotplug' feature during kernel configuration ( See picture ) Kernel configuration

The kernel was build . But when I check the system call using test.c :

#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>

long new_syscall(void)
    return syscall(394);

int main(int argc, char *argv[])
     long int a = new_syscall();
     printf("System call returned %ld\n", a);
     return 0;

The OS frezzes ! What am I doing wrong ?

  • You're sure that's the correct syscall number? – Jacobm001 Aug 20 '17 at 21:56
  • yes sure the syscall number is correct. – A.Chaalane Aug 21 '17 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.