2.5: syscalls for setting task affinity
PATCH 1/1 2.5: syscalls for setting task affinity
The attached patch implements a syscall interface for setting and retrieving a task's CPU affinity (task->cpus_allowed):
int sched_set_affinity(pid_t pid, unsigned long *new_mask_ptr); int sched_get_affinity(pid_t pid)
sched_set_affinity uses the set_cpus_allowed function in Ingo's new scheduler to do all the hard work. Additionally, this patch is based off Ingo's previous syscall affinity patch and my proc-based affinity patch. Much credit to Ingo for this past work and his current scheduler.
Security is enforced: calling user must match task's uid or euid or possess CAP_SYS_NICE.
I think exporting cpus_allowed as a bit mask is the proper user interface for CPU affinity. Certainly more complicated solutions exist, but this should get the job done. I have also updated my proc-based solution although Ingo and others have flamed^Wconvinced me a syscall-based interface is ideal. I agree, mostly on the basis that /proc may not be mounted but I will post an updated proc-based solution anyhow for proper discussion.
Patch is against 2.5.6-pre1. Enjoy,
Robert Love
arch/i386/kernel/entry.S +2 -0
@@ -716,6 +716,8 @@ .long SYMBOL_NAME(sys_lremovexattr) .long SYMBOL_NAME(sys_fremovexattr) .long SYMBOL_NAME(sys_tkill) + .long SYMBOL_NAME(sys_sched_set_affinity) + .long SYMBOL_NAME(sys_sched_get_affinity) /* 240 */ .rept NR_syscalls-(.-sys_call_table)/4 .long SYMBOL_NAME(sys_ni_syscall)
include/asm-i386/unistd.h +2 -0
@@ -243,6 +243,8 @@#define __NR_lremovexattr 236#define __NR_fremovexattr 237#define __NR_tkill 238 +#define __NR_sched_set_affinity 239 +#define __NR_sched_get_affinity 240/* user-visible error numbers are in the range -1 - -124: see <asm-i386/errno.h> */
kernel/sched.c +66 -0
72 lines not on this page · raw message