【发布时间】:2018-01-28 21:22:48
【问题描述】:
我的目标是在 linux 内核中实现一个系统调用来启用/禁用 CPU 内核。
首先,我实现了一个在 4 核系统中禁用 CPU3 的系统调用。
系统调用代码如下:
#include <linux/kernel.h>
#include <linux/slab.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
#include <linux/cpumask.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;
}
系统调用已在内核中正确注册,并且我在内核配置期间启用了“cpu hotplug”功能(见图)
内核配置:
内核已构建。但是当我使用 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;
}
操作系统死机! 我做错了什么?
【问题讨论】:
标签: linux linux-kernel real-time embedded-linux raspberry-pi3