我们的嵌入式Linux能够设置CPU亲和性,但是,ucLibc不支持sched_ {set / get}亲和功能。
因此我们尝试使用syscall接口调用内核。我们写了:
#include <sys/syscall.h>
_syscall3 (int, sched_setaffinity, pid_t, pid, unsigned int, len, unsigned long *, user_mask_ptr)
_syscall3 (int, sched_getaffinity, pid_t, pid, unsigned int, len, unsigned long *, user_mask_ptr)
使用普通的gcc(x86,Fedora Linux,gcc 4.1.2 Redhat)进行编译,我们得到:
bind.c:114: error: expected declaration specifiers or â...â before âsched_setaffinityâ
bind.c:114: error: expected declaration specifiers or â...â before âpid_tâ
bind.c:114: error: expected declaration specifiers or â...â before âpidâ
bind.c:114: error: expected declaration specifiers or â...â before âlenâ
bind.c:114: error: expected declaration specifiers or â...â before âuser_mask_ptrâ
如何正确使用_syscall3
才能使其正常运行?
感谢。
答案 0 :(得分:3)
您应该使用系统调用包装器:
syscall(__NR_sched_setaffinity, pid, len, user_mask_ptr);