user626201
user626201

Reputation: 1682

How to use _syscall3 properly

Our embedded Linux has the ability to set the CPU affinity, however, the ucLibc does not have support for the sched_{set/get}affinity functions.

Hence we are attempting to use the syscall interface to call into the kernel. We have written:

#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)

Compiling this with normal gcc (x86, Fedora Linux, gcc 4.1.2 Redhat) we get:

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â

How do you use _syscall3 properly to get this to work?

Thanks.

Upvotes: 4

Views: 2307

Answers (1)

Foo Bah
Foo Bah

Reputation: 26251

You should use the syscall wrapper:

syscall(__NR_sched_setaffinity, pid, len, user_mask_ptr);

Upvotes: 3

Related Questions