Skip to contentSkip to conversation

2.4-ac: task CPU affinity syscalls

PATCH New Robert Love 1 participant 1 message May 15, 2002 Capabilities

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2.4-ac: task CPU affinity syscalls

The following patch, against 2.4.19-pre8-ac4, implements the task CPU affinity syscalls found in 2.5. This is not suggested for inclusion in 2.4 until the 2.5 interface is assuredly what we want. I post it now for discussion and those who are interested.

The syscalls are:

sched_getaffinity(pid_t pid, unsigned long len, unsigned long *mask) sched_setaffinity(pid_t pid, unsigned long len, unsigned long *mask)

which get and set the affinity of any given task (provided proper permission) to the given CPU bitmask.

I believe we solved the locking issue I presented before: handle it as in 2.5. Acquire tasklist_lock, translate the pid into a valid task_struct, call get_task_struct to bump the task_struct's page reference count, drop tasklist_lock, call set_cpus_allowed, then call free_task_struct which does free_pages. Since the pages usage count was bumped, it will not be freed unless the task prematurely deallocated in the middle.

Comments? Hopefully this works and - assuming the 2.5 interface stays as is - I can put this aside until it is time to merge it.

Robert Love

arch/i386/kernel/entry.S +2 -2
diff -urN linux-2.4.19-pre8-ac4/arch/i386/kernel/entry.S linux/arch/i386/kernel/entry.S
@@ -639,8 +639,8 @@
  	.long SYMBOL_NAME(sys_tkill)
 	.long SYMBOL_NAME(sys_ni_syscall)	/* reserved for sendfile64 */
 	.long SYMBOL_NAME(sys_ni_syscall)	/* 240 reserved for futex */
-	.long SYMBOL_NAME(sys_ni_syscall)	/* reserved for sched_setaffinity */
-	.long SYMBOL_NAME(sys_ni_syscall)	/* reserved for sched_getaffinity */
+	.long SYMBOL_NAME(sys_sched_setaffinity)
+	.long SYMBOL_NAME(sys_sched_getaffinity)
 
 	.rept NR_syscalls-(.-sys_call_table)/4
 		.long SYMBOL_NAME(sys_ni_syscall)
arch/ppc/kernel/misc.S +16 -0
diff -urN linux-2.4.19-pre8-ac4/arch/ppc/kernel/misc.S linux/arch/ppc/kernel/misc.S
@@ -1162,6 +1162,22 @@
 	.long sys_mincore
 	.long sys_gettid
 	.long sys_tkill
+	.long sys_ni_syscall
+	.long sys_ni_syscall	/* 210 */
+	.long sys_ni_syscall
+	.long sys_ni_syscall
+	.long sys_ni_syscall
+	.long sys_ni_syscall
+	.long sys_ni_syscall	/* 215 */
+	.long sys_ni_syscall
+	.long sys_ni_syscall
+	.long sys_ni_syscall
+	.long sys_ni_syscall
+	.long sys_ni_syscall	/* 220 */
+	.long sys_ni_syscall
+	.long sys_sched_setaffinity
+	.long sys_sched_getaffinity
+
 	.rept NR_syscalls-(.-sys_call_table)/4
 		.long sys_ni_syscall
 	.endr
include/asm-ppc/unistd.h +2 -0
diff -urN linux-2.4.19-pre8-ac4/include/asm-ppc/unistd.h linux/include/asm-ppc/unistd.h
@@ -216,6 +216,8 @@
 #define __NR_mincore		206
 #define __NR_gettid		207
 #define __NR_tkill		208
+#define __NR_sched_setaffinity	222
+#define __NR_sched_getaffinity	223
 
 #define __NR(n)	#n
 
include/linux/capability.h +1 -0
diff -urN linux-2.4.19-pre8-ac4/include/linux/capability.h linux/include/linux/capability.h
@@ -243,6 +243,7 @@
 /* Allow use of FIFO and round-robin (realtime) scheduling on own
    processes and setting the scheduling algorithm used by another
    process. */
+/* Allow setting cpu affinity on other processes */
 
 #define CAP_SYS_NICE         23
 
kernel/sched.c +92 -0

98 lines not on this page · raw message