[PATCH] Optimize ppc32 clone with newer kernels, add missng include in linux/utimes.c

Franz Sirl Franz.Sirl-kernel@lauterbach.com
Mon Jul 14 20:48:00 GMT 2003


Hi,

starting with 2.4.21 a long standing bug in the kernel was fixed, allowing us 
to optimize powerpc32/clone.S in this case.

Also included is a missing #include in linux/utimes.c which prevented compile 
cause INLINE_SYSCALL wasn't defined.

Franz.


	* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_FIXED_CLONE_SYSCALL):
	New macro.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S: Use it.

	* sysdeps/unix/sysv/linux/utimes.c: Include sysdep.h.

-------------- next part --------------
Index: sysdeps/unix/sysv/linux/kernel-features.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/kernel-features.h,v
retrieving revision 1.62
diff -u -p -r1.62 kernel-features.h
--- sysdeps/unix/sysv/linux/kernel-features.h	12 Jul 2003 18:46:53 -0000	1.62
+++ sysdeps/unix/sysv/linux/kernel-features.h	14 Jul 2003 09:49:01 -0000
@@ -234,6 +234,12 @@
 # define __ASSUME_NEW_PRCTL_SYSCALL		1
 #endif
 
+/* Starting with 2.4.21 the PowerPC32 clone syscall works as expected.  */
+#if __LINUX_KERNEL_VERSION >= (132096+21) && defined __powerpc__ \
+    && !defined __powerpc64__
+# define __ASSUME_FIXED_CLONE_SYSCALL		1
+#endif
+
 /* Starting with 2.4.21 PowerPC64 implements the new rt_sigreturn syscall.
    The new rt_sigreturn takes an ucontext pointer allowing rt_sigreturn
    to be used in the set/swapcontext implementation.  */
Index: sysdeps/unix/sysv/linux/utimes.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/utimes.c,v
retrieving revision 1.1
diff -u -p -r1.1 utimes.c
--- sysdeps/unix/sysv/linux/utimes.c	12 Jul 2003 18:43:55 -0000	1.1
+++ sysdeps/unix/sysv/linux/utimes.c	14 Jul 2003 09:49:01 -0000
@@ -20,6 +20,7 @@
 #include <stddef.h>
 #include <utime.h>
 #include <sys/time.h>
+#include <sysdep.h>
 #include "kernel-features.h"
 
 
Index: sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S,v
retrieving revision 1.2
diff -u -p -r1.2 clone.S
--- sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S	10 Mar 2003 08:52:31 -0000	1.2
+++ sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S	14 Jul 2003 09:49:01 -0000
@@ -20,6 +20,7 @@
 #include <sysdep.h>
 #define _ERRNO_H	1
 #include <bits/errno.h>
+#include <kernel-features.h>
 #include <bp-sym.h>
 #include <bp-asm.h>
 
@@ -44,7 +45,11 @@ ENTRY (BP_SYM (__clone))
 
 	/* Set up stack frame for parent.  */
 	stwu	r1,-32(r1)
+#ifndef __ASSUME_FIXED_CLONE_SYSCALL
 	stmw	r29,16(r1)
+#else
+	stmw	r30,16(r1)
+#endif
 
 	/* Set up stack frame for child.  */
 	clrrwi	r4,r4,4
@@ -52,8 +57,10 @@ ENTRY (BP_SYM (__clone))
 	stwu	r0,-16(r4)
 
 	/* Save fn, args, stack across syscall.  */
-	mr	r29,r3			/* Function in r29.  */
-	mr	r30,r4			/* Stack pointer in r30.  */
+	mr	r30,r3			/* Function in r30.  */
+#ifndef __ASSUME_FIXED_CLONE_SYSCALL
+	mr	r29,r4			/* Stack pointer in r29.  */
+#endif
 	mr	r31,r6			/* Argument in r31.  */
 
 	/* 'flags' argument is first parameter to clone syscall. (The other
@@ -73,13 +80,16 @@ ENTRY (BP_SYM (__clone))
 	crandc	cr1*4+eq,cr1*4+eq,cr0*4+so
 	bne-	cr1,L(parent)		/* The '-' is to minimise the race.  */
 
+#ifndef __ASSUME_FIXED_CLONE_SYSCALL
 	/* On at least mklinux DR3a5, clone() doesn't actually change
 	   the stack pointer.  I'm pretty sure this is a bug, because
 	   it adds a race condition if a signal is sent to a thread
 	   just after it is created (in the previous three instructions).  */
-	mr	r1,r30
+	mr	r1,r29
+#endif
+
 	/* Call procedure.  */
-	mtctr	r29
+	mtctr	r30
 	mr	r3,r31
 	bctrl
 	/* Call _exit with result from procedure.  */
@@ -87,7 +97,11 @@ ENTRY (BP_SYM (__clone))
 
 L(parent):
 	/* Parent.  Restore registers & return.  */
+#ifndef __ASSUME_FIXED_CLONE_SYSCALL
 	lmw	r29,16(r1)
+#else
+	lmw	r30,16(r1)
+#endif
 	addi	r1,r1,32
 	bnslr+
 	b	JUMPTARGET(__syscall_error)


More information about the Libc-alpha mailing list