00db10
This patch is based on the below upstream commit.
00db10
File deletions were altered to reflect file renames.
00db10
00db10
commit f50277c19df0937ea9691ab7e7c642ecd3ed3d94
00db10
Author: Torvald Riegel <triegel@redhat.com>
00db10
Date:   Sun Oct 19 21:59:26 2014 +0200
00db10
00db10
    pthread_once: Add fast path and remove x86 variants.
00db10
00db10
diff --git a/nptl/pthread_once.c b/nptl/pthread_once.c
00db10
index 595bd7e298003e00..2afb79c01fe0a61e 100644
00db10
--- a/nptl/pthread_once.c
00db10
+++ b/nptl/pthread_once.c
00db10
@@ -58,11 +58,13 @@ clear_once_control (void *arg)
00db10
    initialization is interrupted, we then fork 2^30 times (30 bits of
00db10
    once_control are used for the fork generation), and try to initialize
00db10
    again, we can deadlock because we can't distinguish the in-progress and
00db10
-   interrupted cases anymore.  */
00db10
-int
00db10
-__pthread_once (once_control, init_routine)
00db10
-     pthread_once_t *once_control;
00db10
-     void (*init_routine) (void);
00db10
+   interrupted cases anymore.
00db10
+   XXX: We split out this slow path because current compilers do not generate
00db10
+   as efficient code when the fast path in __pthread_once below is not in a
00db10
+   separate function.  */
00db10
+static int
00db10
+__attribute__ ((noinline))
00db10
+__pthread_once_slow (pthread_once_t *once_control, void (*init_routine) (void))
00db10
 {
00db10
   while (1)
00db10
     {
00db10
@@ -72,7 +74,7 @@ __pthread_once (once_control, init_routine)
00db10
          signals that initialization has finished, we need to see any
00db10
          data modifications done during initialization.  */
00db10
       val = *once_control;
00db10
-      atomic_read_barrier();
00db10
+      atomic_read_barrier ();
00db10
       do
00db10
 	{
00db10
 	  /* Check if the initialization has already been done.  */
00db10
@@ -130,5 +132,18 @@ __pthread_once (once_control, init_routine)
00db10
 
00db10
   return 0;
00db10
 }
00db10
+
00db10
+int
00db10
+__pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
00db10
+{
00db10
+  /* Fast path.  See __pthread_once_slow.  */
00db10
+  int val;
00db10
+  val = *once_control;
00db10
+  atomic_read_barrier ();
00db10
+  if (__glibc_likely ((val & __PTHREAD_ONCE_DONE) != 0))
00db10
+    return 0;
00db10
+  else
00db10
+    return __pthread_once_slow (once_control, init_routine);
00db10
+}
00db10
 weak_alias (__pthread_once, pthread_once)
00db10
 hidden_def (__pthread_once)
00db10
diff --git a/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S
00db10
deleted file mode 100644
00db10
index ca3b860a7f6f95ae..0000000000000000
00db10
--- a/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S
00db10
+++ /dev/null
00db10
@@ -1,178 +0,0 @@
00db10
-/* Copyright (C) 2002-2012 Free Software Foundation, Inc.
00db10
-   This file is part of the GNU C Library.
00db10
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
00db10
-
00db10
-   The GNU C Library is free software; you can redistribute it and/or
00db10
-   modify it under the terms of the GNU Lesser General Public
00db10
-   License as published by the Free Software Foundation; either
00db10
-   version 2.1 of the License, or (at your option) any later version.
00db10
-
00db10
-   The GNU C Library is distributed in the hope that it will be useful,
00db10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
-   Lesser General Public License for more details.
00db10
-
00db10
-   You should have received a copy of the GNU Lesser General Public
00db10
-   License along with the GNU C Library; if not, see
00db10
-   <http://www.gnu.org/licenses/>.  */
00db10
-
00db10
-#include <unwindbuf.h>
00db10
-#include <sysdep.h>
00db10
-#include <kernel-features.h>
00db10
-#include <lowlevellock.h>
00db10
-
00db10
-
00db10
-	.comm	__fork_generation, 4, 4
00db10
-
00db10
-	.text
00db10
-
00db10
-
00db10
-	.globl	__pthread_once
00db10
-	.type	__pthread_once,@function
00db10
-	.align	16
00db10
-	cfi_startproc
00db10
-__pthread_once:
00db10
-	movl	4(%esp), %ecx
00db10
-	testl	$2, (%ecx)
00db10
-	jz	1f
00db10
-	xorl	%eax, %eax
00db10
-	ret
00db10
-
00db10
-1:	pushl	%ebx
00db10
-	cfi_adjust_cfa_offset (4)
00db10
-	cfi_rel_offset (3, 0)
00db10
-	pushl	%esi
00db10
-	cfi_adjust_cfa_offset (4)
00db10
-	cfi_rel_offset (6, 0)
00db10
-	movl	%ecx, %ebx
00db10
-	xorl	%esi, %esi
00db10
-
00db10
-	/* Not yet initialized or initialization in progress.
00db10
-	   Get the fork generation counter now.  */
00db10
-6:	movl	(%ebx), %eax
00db10
-#ifdef PIC
00db10
-	LOAD_PIC_REG(cx)
00db10
-#endif
00db10
-
00db10
-5:	movl	%eax, %edx
00db10
-
00db10
-	testl	$2, %eax
00db10
-	jnz	4f
00db10
-
00db10
-	andl	$3, %edx
00db10
-#ifdef PIC
00db10
-	orl	__fork_generation@GOTOFF(%ecx), %edx
00db10
-#else
00db10
-	orl	__fork_generation, %edx
00db10
-#endif
00db10
-	orl	$1, %edx
00db10
-
00db10
-	LOCK
00db10
-	cmpxchgl %edx, (%ebx)
00db10
-	jnz	5b
00db10
-
00db10
-	/* Check whether another thread already runs the initializer.  */
00db10
-	testl	$1, %eax
00db10
-	jz	3f	/* No -> do it.  */
00db10
-
00db10
-	/* Check whether the initializer execution was interrupted
00db10
-	   by a fork.  */
00db10
-	xorl	%edx, %eax
00db10
-	testl	$0xfffffffc, %eax
00db10
-	jnz	3f	/* Different for generation -> run initializer.  */
00db10
-
00db10
-	/* Somebody else got here first.  Wait.  */
00db10
-#ifdef __ASSUME_PRIVATE_FUTEX
00db10
-	movl	$FUTEX_WAIT|FUTEX_PRIVATE_FLAG, %ecx
00db10
-#else
00db10
-# if FUTEX_WAIT == 0
00db10
-	movl	%gs:PRIVATE_FUTEX, %ecx
00db10
-# else
00db10
-	movl	$FUTEX_WAIT, %ecx
00db10
-	orl	%gs:PRIVATE_FUTEX, %ecx
00db10
-# endif
00db10
-#endif
00db10
-	movl	$SYS_futex, %eax
00db10
-	ENTER_KERNEL
00db10
-	jmp	6b
00db10
-
00db10
-3:	/* Call the initializer function after setting up the
00db10
-	   cancellation handler.  Note that it is not possible here
00db10
-	   to use the unwind-based cleanup handling.  This would require
00db10
-	   that the user-provided function and all the code it calls
00db10
-	   is compiled with exceptions.  Unfortunately this cannot be
00db10
-	   guaranteed.  */
00db10
-	subl	$UNWINDBUFSIZE+8, %esp
00db10
-	cfi_adjust_cfa_offset (UNWINDBUFSIZE+8)
00db10
-	movl	%ecx, %ebx		/* PIC register value.  */
00db10
-
00db10
-	leal	8+UWJMPBUF(%esp), %eax
00db10
-	movl	$0, 4(%esp)
00db10
-	movl	%eax, (%esp)
00db10
-	call	__sigsetjmp@PLT
00db10
-	testl	%eax, %eax
00db10
-	jne	7f
00db10
-
00db10
-	leal	8(%esp), %eax
00db10
-	call	HIDDEN_JUMPTARGET(__pthread_register_cancel)
00db10
-
00db10
-	/* Call the user-provided initialization function.  */
00db10
-	call	*24+UNWINDBUFSIZE(%esp)
00db10
-
00db10
-	/* Pop the cleanup handler.  */
00db10
-	leal	8(%esp), %eax
00db10
-	call	HIDDEN_JUMPTARGET(__pthread_unregister_cancel)
00db10
-	addl	$UNWINDBUFSIZE+8, %esp
00db10
-	cfi_adjust_cfa_offset (-UNWINDBUFSIZE-8)
00db10
-
00db10
-	/* Sucessful run of the initializer.  Signal that we are done.  */
00db10
-	movl	12(%esp), %ebx
00db10
-	LOCK
00db10
-	addl	$1, (%ebx)
00db10
-
00db10
-	/* Wake up all other threads.  */
00db10
-	movl	$0x7fffffff, %edx
00db10
-#ifdef __ASSUME_PRIVATE_FUTEX
00db10
-	movl	$FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %ecx
00db10
-#else
00db10
-	movl	$FUTEX_WAKE, %ecx
00db10
-	orl	%gs:PRIVATE_FUTEX, %ecx
00db10
-#endif
00db10
-	movl	$SYS_futex, %eax
00db10
-	ENTER_KERNEL
00db10
-
00db10
-4:	popl	%esi
00db10
-	cfi_adjust_cfa_offset (-4)
00db10
-	cfi_restore (6)
00db10
-	popl	%ebx
00db10
-	cfi_adjust_cfa_offset (-4)
00db10
-	cfi_restore (3)
00db10
-	xorl	%eax, %eax
00db10
-	ret
00db10
-
00db10
-7:	/* __sigsetjmp returned for the second time.  */
00db10
-	movl	20+UNWINDBUFSIZE(%esp), %ebx
00db10
-	cfi_adjust_cfa_offset (UNWINDBUFSIZE+16)
00db10
-	cfi_offset (3, -8)
00db10
-	cfi_offset (6, -12)
00db10
-	movl	$0, (%ebx)
00db10
-
00db10
-	movl	$0x7fffffff, %edx
00db10
-#ifdef __ASSUME_PRIVATE_FUTEX
00db10
-	movl	$FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %ecx
00db10
-#else
00db10
-	movl	$FUTEX_WAKE, %ecx
00db10
-	orl	%gs:PRIVATE_FUTEX, %ecx
00db10
-#endif
00db10
-	movl	$SYS_futex, %eax
00db10
-	ENTER_KERNEL
00db10
-
00db10
-	leal	8(%esp), %eax
00db10
-	call	HIDDEN_JUMPTARGET (__pthread_unwind_next)
00db10
-	/* NOTREACHED */
00db10
-	hlt
00db10
-	cfi_endproc
00db10
-	.size	__pthread_once,.-__pthread_once
00db10
-
00db10
-hidden_def (__pthread_once)
00db10
-strong_alias (__pthread_once, pthread_once)
00db10
diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
00db10
deleted file mode 100644
00db10
index 7f5c0810fa16b987..0000000000000000
00db10
--- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
00db10
+++ /dev/null
00db10
@@ -1,193 +0,0 @@
00db10
-/* Copyright (C) 2002-2012 Free Software Foundation, Inc.
00db10
-   This file is part of the GNU C Library.
00db10
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
00db10
-
00db10
-   The GNU C Library is free software; you can redistribute it and/or
00db10
-   modify it under the terms of the GNU Lesser General Public
00db10
-   License as published by the Free Software Foundation; either
00db10
-   version 2.1 of the License, or (at your option) any later version.
00db10
-
00db10
-   The GNU C Library is distributed in the hope that it will be useful,
00db10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
-   Lesser General Public License for more details.
00db10
-
00db10
-   You should have received a copy of the GNU Lesser General Public
00db10
-   License along with the GNU C Library; if not, see
00db10
-   <http://www.gnu.org/licenses/>.  */
00db10
-
00db10
-#include <sysdep.h>
00db10
-#include <kernel-features.h>
00db10
-#include <tcb-offsets.h>
00db10
-#include <lowlevellock.h>
00db10
-
00db10
-
00db10
-	.comm	__fork_generation, 4, 4
00db10
-
00db10
-	.text
00db10
-
00db10
-
00db10
-	.globl	__pthread_once
00db10
-	.type	__pthread_once,@function
00db10
-	.align	16
00db10
-__pthread_once:
00db10
-.LSTARTCODE:
00db10
-	cfi_startproc
00db10
-#ifdef SHARED
00db10
-	cfi_personality(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect,
00db10
-			DW.ref.__gcc_personality_v0)
00db10
-	cfi_lsda(DW_EH_PE_pcrel | DW_EH_PE_sdata4, .LexceptSTART)
00db10
-#else
00db10
-	cfi_personality(DW_EH_PE_udata4, __gcc_personality_v0)
00db10
-	cfi_lsda(DW_EH_PE_udata4, .LexceptSTART)
00db10
-#endif
00db10
-	testl	$2, (%rdi)
00db10
-	jz	1f
00db10
-	xorl	%eax, %eax
00db10
-	retq
00db10
-
00db10
-	/* Preserve the function pointer.  */
00db10
-1:	pushq	%rsi
00db10
-	cfi_adjust_cfa_offset(8)
00db10
-	xorq	%r10, %r10
00db10
-
00db10
-	/* Not yet initialized or initialization in progress.
00db10
-	   Get the fork generation counter now.  */
00db10
-6:	movl	(%rdi), %eax
00db10
-
00db10
-5:	movl	%eax, %edx
00db10
-
00db10
-	testl	$2, %eax
00db10
-	jnz	4f
00db10
-
00db10
-	andl	$3, %edx
00db10
-	orl	__fork_generation(%rip), %edx
00db10
-	orl	$1, %edx
00db10
-
00db10
-	LOCK
00db10
-	cmpxchgl %edx, (%rdi)
00db10
-	jnz	5b
00db10
-
00db10
-	/* Check whether another thread already runs the initializer.  */
00db10
-	testl	$1, %eax
00db10
-	jz	3f	/* No -> do it.  */
00db10
-
00db10
-	/* Check whether the initializer execution was interrupted
00db10
-	   by a fork.  */
00db10
-	xorl	%edx, %eax
00db10
-	testl	$0xfffffffc, %eax
00db10
-	jnz	3f	/* Different for generation -> run initializer.  */
00db10
-
00db10
-	/* Somebody else got here first.  Wait.  */
00db10
-#ifdef __ASSUME_PRIVATE_FUTEX
00db10
-	movl	$FUTEX_WAIT|FUTEX_PRIVATE_FLAG, %esi
00db10
-#else
00db10
-# if FUTEX_WAIT == 0
00db10
-	movl	%fs:PRIVATE_FUTEX, %esi
00db10
-# else
00db10
-	movl	$FUTEX_WAIT, %esi
00db10
-	orl	%fs:PRIVATE_FUTEX, %esi
00db10
-# endif
00db10
-#endif
00db10
-	movl	$SYS_futex, %eax
00db10
-	syscall
00db10
-	jmp	6b
00db10
-
00db10
-	/* Preserve the pointer to the control variable.  */
00db10
-3:	pushq	%rdi
00db10
-	cfi_adjust_cfa_offset(8)
00db10
-	pushq	%rdi
00db10
-	cfi_adjust_cfa_offset(8)
00db10
-
00db10
-.LcleanupSTART:
00db10
-	callq	*16(%rsp)
00db10
-.LcleanupEND:
00db10
-
00db10
-	/* Get the control variable address back.  */
00db10
-	popq	%rdi
00db10
-	cfi_adjust_cfa_offset(-8)
00db10
-
00db10
-	/* Sucessful run of the initializer.  Signal that we are done.  */
00db10
-	LOCK
00db10
-	incl	(%rdi)
00db10
-
00db10
-	addq	$8, %rsp
00db10
-	cfi_adjust_cfa_offset(-8)
00db10
-
00db10
-	/* Wake up all other threads.  */
00db10
-	movl	$0x7fffffff, %edx
00db10
-#ifdef __ASSUME_PRIVATE_FUTEX
00db10
-	movl	$FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %esi
00db10
-#else
00db10
-	movl	$FUTEX_WAKE, %esi
00db10
-	orl	%fs:PRIVATE_FUTEX, %esi
00db10
-#endif
00db10
-	movl	$SYS_futex, %eax
00db10
-	syscall
00db10
-
00db10
-4:	addq	$8, %rsp
00db10
-	cfi_adjust_cfa_offset(-8)
00db10
-	xorl	%eax, %eax
00db10
-	retq
00db10
-	.size	__pthread_once,.-__pthread_once
00db10
-
00db10
-
00db10
-hidden_def (__pthread_once)
00db10
-strong_alias (__pthread_once, pthread_once)
00db10
-
00db10
-
00db10
-	.type	clear_once_control,@function
00db10
-	.align	16
00db10
-clear_once_control:
00db10
-	cfi_adjust_cfa_offset(3 * 8)
00db10
-	movq	(%rsp), %rdi
00db10
-	movq	%rax, %r8
00db10
-	movl	$0, (%rdi)
00db10
-
00db10
-	movl	$0x7fffffff, %edx
00db10
-#ifdef __ASSUME_PRIVATE_FUTEX
00db10
-	movl	$FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %esi
00db10
-#else
00db10
-	movl	$FUTEX_WAKE, %esi
00db10
-	orl	%fs:PRIVATE_FUTEX, %esi
00db10
-#endif
00db10
-	movl	$SYS_futex, %eax
00db10
-	syscall
00db10
-
00db10
-	movq	%r8, %rdi
00db10
-.LcallUR:
00db10
-	call	_Unwind_Resume@PLT
00db10
-	hlt
00db10
-.LENDCODE:
00db10
-	cfi_endproc
00db10
-	.size	clear_once_control,.-clear_once_control
00db10
-
00db10
-
00db10
-	.section .gcc_except_table,"a",@progbits
00db10
-.LexceptSTART:
00db10
-	.byte	DW_EH_PE_omit			# @LPStart format
00db10
-	.byte	DW_EH_PE_omit			# @TType format
00db10
-	.byte	DW_EH_PE_uleb128		# call-site format
00db10
-	.uleb128 .Lcstend-.Lcstbegin
00db10
-.Lcstbegin:
00db10
-	.uleb128 .LcleanupSTART-.LSTARTCODE
00db10
-	.uleb128 .LcleanupEND-.LcleanupSTART
00db10
-	.uleb128 clear_once_control-.LSTARTCODE
00db10
-	.uleb128  0
00db10
-	.uleb128 .LcallUR-.LSTARTCODE
00db10
-	.uleb128 .LENDCODE-.LcallUR
00db10
-	.uleb128 0
00db10
-	.uleb128  0
00db10
-.Lcstend:
00db10
-
00db10
-
00db10
-#ifdef SHARED
00db10
-	.hidden	DW.ref.__gcc_personality_v0
00db10
-	.weak	DW.ref.__gcc_personality_v0
00db10
-	.section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
00db10
-	.align	LP_SIZE
00db10
-	.type	DW.ref.__gcc_personality_v0, @object
00db10
-	.size	DW.ref.__gcc_personality_v0, LP_SIZE
00db10
-DW.ref.__gcc_personality_v0:
00db10
-	ASM_ADDR __gcc_personality_v0
00db10
-#endif