【发布时间】:2014-12-03 13:07:22
【问题描述】:
我最近发现了 sched_setaffinity 方法的这个原型:
extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
我正在尝试使用它来设置任务的关联性,但它似乎不起作用。这是我的实现:
#define _GNU_SOURCE
#include <linux/sched.h>
#include <linux/cpumask.h>
int set_aff (pid_t pid, int core)
{
static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS);
struct cpumask *const task_cpumask = to_cpumask(cpu_possible_bits);
cpumask_set_cpu(core, task_cpumask);
sched_setaffinity(pid, task_cpumask);
return 0;
}
我的代码编译没有任何错误,但是当我尝试调用此方法时,它会中断。有谁知道为什么?
有没有更好的方法从内核方法中执行此操作?
【问题讨论】:
-
可以查看taskset实用程序源码gitorious.org/util-linux-ng/util-linux-ng/source/…
-
你想知道什么?为什么你的代码会中断或如何编写功能?
-
我想知道如何对功能进行编码,因为我是否以错误的方式实例化了某些东西。我在上面从内核调度程序函数设置亲和力的实现导致我的设备的启动序列在某个点后停止并不断重启。
-
这能回答你的问题吗? Using "sched_setaffinity()" in Linux Kernel
标签: linux-kernel kernel task