[prev in list] [next in list] [prev in thread] [next in thread] 

List:       glibc-alpha
Subject:    Re: [PATCH] NPTL cancellation optimization - please review
From:       Matt Turner <mattst88 () gmail ! com>
Date:       2010-12-24 4:23:23
Message-ID: AANLkTint7Ug311qxX0=_UPQ_JMkU=_-HtGUTPdipXOps () mail ! gmail ! com
[Download RAW message or body]

2010/3/9 Alexander Fyodorov <alexvf@bk.ru>:
> Hi
> 
> This patch improves performance of functions changing thread cancellation state and \
> type by removing atomic operations from them. Their speed roughly doubled on my \
> Core Quad. 
> Main idea is simple: since state and type are changed only by the thread itself, \
> they should not require such rigorous synchronization. The 'cancelhandling' word \
> takes 4 bytes, so we can put type and state in different bytes within the word and \
> access them directly. Specific position of a given flag will then depend on \
> endiannes. 
> Checking whether the thread was canceled must be done after it enables cancellation \
> or set it to asynchronous mode. To enforce this order, I put a barrier between the \
> respective store and load. Since the read is data-dependent on the corresponding \
> write and many architectures do not reorder such accesses, putting \
> atomic_full_barrier() there would be an overkill. So I added a new type of barrier \
> which defaults to a full barrier. 
> On my computer 'make check' fails some tests even without the patch, so I am not \
> sure about me being able to test it. At least it broke nothing that was working \
> before. 
> 
> 
> 2010-03-09 šFyodorov V. Alexander š<alexvf@bk.ru>
> 
> š š š š* nptl/descr.h: Change bits position in the 'cancelhandling' field.
> š š š š* include/atomic.h: Define atomic_full_barrier to
> š š š što __sync_synchronize. Add default
> š š š šatomic_read_after_write_dependent_barrier definition.
> š š š š* sysdeps/ia64/bits/atomic.h: Remove atomic_full_barrier
> š š š šdefinition.
> š š š š* nptl/cancellation.c: Replace atomic operation with a barrier.
> š š š š* nptl/cleanup_defer_compat.c: Likewise.
> š š š š* nptl/pthread_setcancelstate.c: Likewise.
> š š š š* nptl/pthread_setcanceltype.c: Likewise.
> š š š š* nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S: Delete.
> š š š š* nptl/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S: Delete.
> š š š š* nptl/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S: Delete.
> š š š š* sysdeps/i386/i486/bits/atomic.h: Define
> š š š šatomic_read_after_write_dependent_barrier.
> š š š š* sysdeps/x86_64/bits/atomic.h: Likewise.
> š š š š* sysdeps/sparc/sparc32/bits/atomic.h: Likewise.
> š š š š* sysdeps/sparc/sparc64/bits/atomic.h: Likewise.
> 
> 
> diff --git a/include/atomic.h b/include/atomic.h
> index 37d0111..2f708f1 100644
> --- a/include/atomic.h
> +++ b/include/atomic.h
> @@ -510,7 +510,7 @@
> š#endif
> 
> š#ifndef atomic_full_barrier
> -# define atomic_full_barrier() __asm ("" ::: "memory")
> +# define atomic_full_barrier() __sync_synchronize ()
> š#endif
> 
> 
> @@ -534,4 +534,9 @@
> š# define atomic_delay() do { /* nothing */ } while (0)
> š#endif
> 
> +
> +#ifndef atomic_read_after_write_dependent_barrier()
> +# define atomic_read_after_write_dependent_barrier() atomic_full_barrier ()
> +#endif
> +
> š#endif /* atomic.h */
> diff --git a/nptl/cancellation.c b/nptl/cancellation.c
> index eac7973..b6ed39a 100644
> --- a/nptl/cancellation.c
> +++ b/nptl/cancellation.c
> @@ -32,29 +32,13 @@ __pthread_enable_asynccancel (void)
> š struct pthread *self = THREAD_SELF;
> š int oldval = THREAD_GETMEM (self, cancelhandling);
> 
> - šwhile (1)
> - š š{
> - š š šint newval = oldval | CANCELTYPE_BITMASK;
> -
> - š š šif (newval == oldval)
> - break;
> -
> - š š šint curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
> - š š šoldval);
> - š š šif (__builtin_expect (curval == oldval, 1))
> - {
> - šif (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
> - š š{
> - š š šTHREAD_SETMEM (self, result, PTHREAD_CANCELED);
> - š š š__do_cancel ();
> - š š}
> -
> - šbreak;
> - }
> -
> - š š š/* Prepare the next round. š*/
> - š š šoldval = curval;
> - š š}
> + š/* Set the new value. */
> + šTHREAD_SETMEM (self, cancel.type, (char) PTHREAD_CANCEL_ASYNCHRONOUS);
> +
> + š/* See comment in pthread_setcancelstate (). */
> + šatomic_read_after_write_dependent_barrier();
> +
> + šCANCELLATION_P (self);
> 
> š return oldval;
> š}
> @@ -70,22 +54,14 @@ __pthread_disable_asynccancel (int oldtype)
> š š return;
> 
> š struct pthread *self = THREAD_SELF;
> - šint newval;
> 
> - šint oldval = THREAD_GETMEM (self, cancelhandling);
> -
> - šwhile (1)
> - š š{
> - š š šnewval = oldval & ~CANCELTYPE_BITMASK;
> + š/* Set the new value. */
> + šTHREAD_SETMEM (self, cancel.type, (char) PTHREAD_CANCEL_DEFERRED);
> 
> - š š šint curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
> - š š šoldval);
> - š š šif (__builtin_expect (curval == oldval, 1))
> - break;
> + š/* See comment in pthread_setcancelstate (). */
> + šatomic_read_after_write_dependent_barrier();
> 
> - š š š/* Prepare the next round. š*/
> - š š šoldval = curval;
> - š š}
> + šint newval = THREAD_GETMEM (self, cancelhandling);
> 
> š /* We cannot return when we are being canceled. šUpon return the
> š š šthread might be things which would have to be undone. šThe
> diff --git a/nptl/cleanup_defer_compat.c b/nptl/cleanup_defer_compat.c
> index a0ed6da..51078d8 100644
> --- a/nptl/cleanup_defer_compat.c
> +++ b/nptl/cleanup_defer_compat.c
> @@ -35,20 +35,7 @@ _pthread_cleanup_push_defer (buffer, routine, arg)
> š int cancelhandling = THREAD_GETMEM (self, cancelhandling);
> 
> š /* Disable asynchronous cancellation for now. š*/
> - šif (__builtin_expect (cancelhandling & CANCELTYPE_BITMASK, 0))
> - š šwhile (1)
> - š š š{
> - int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
> - cancelhandling
> - & ~CANCELTYPE_BITMASK,
> - cancelhandling);
> - if (__builtin_expect (curval == cancelhandling, 1))
> - š/* Successfully replaced the value. š*/
> - šbreak;
> -
> - /* Prepare for the next round. š*/
> - cancelhandling = curval;
> - š š š}
> + šTHREAD_SETMEM (self, cancel.type, (char) PTHREAD_CANCEL_DEFERRED);
> 
> š buffer->__canceltype = (cancelhandling & CANCELTYPE_BITMASK
> š š š? PTHREAD_CANCEL_ASYNCHRONOUS
> @@ -68,24 +55,12 @@ _pthread_cleanup_pop_restore (buffer, execute)
> 
> š THREAD_SETMEM (self, cleanup, buffer->__prev);
> 
> - šint cancelhandling;
> - šif (__builtin_expect (buffer->__canceltype != PTHREAD_CANCEL_DEFERRED, 0)
> - š š š&& ((cancelhandling = THREAD_GETMEM (self, cancelhandling))
> - š& CANCELTYPE_BITMASK) == 0)
> + šTHREAD_SETMEM (self, cancel.type, (char) buffer->__canceltype);
> +
> + šif (buffer->__canceltype == PTHREAD_CANCEL_ASYNCHRONOUS)
> š š {
> - š š šwhile (1)
> - {
> - šint curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
> - šcancelhandling
> - š| CANCELTYPE_BITMASK,
> - šcancelhandling);
> - šif (__builtin_expect (curval == cancelhandling, 1))
> - š š/* Successfully replaced the value. š*/
> - š šbreak;
> -
> - š/* Prepare for the next round. š*/
> - šcancelhandling = curval;
> - }
> + š š š/* See comment in pthread_setcancelstate (). */
> + š š šatomic_read_after_write_dependent_barrier();
> 
> š š š CANCELLATION_P (self);
> š š }
> diff --git a/nptl/descr.h b/nptl/descr.h
> index 9c366e7..dfb350f 100644
> --- a/nptl/descr.h
> +++ b/nptl/descr.h
> @@ -20,6 +20,7 @@
> š#ifndef _DESCR_H
> š#define _DESCR_H 1
> 
> +#include <endian.h>
> š#include <limits.h>
> š#include <sched.h>
> š#include <setjmp.h>
> @@ -240,30 +241,62 @@ struct pthread
> š#define HAVE_CLEANUP_JMP_BUF
> 
> š /* Flags determining processing of cancellation. š*/
> - šint cancelhandling;
> + šunion {
> + š šint cancelhandling;
> + š šstruct {
> + š š šchar state;
> + š š šchar type;
> + š š} cancel;
> + š};
> +#if BYTE_ORDER == LITTLE_ENDIAN
> š /* Bit set if cancellation is disabled. š*/
> š#define CANCELSTATE_BIT 0
> -#define CANCELSTATE_BITMASK (0x01 << CANCELSTATE_BIT)
> š /* Bit set if asynchronous cancellation mode is selected. š*/
> -#define CANCELTYPE_BIT 1
> -#define CANCELTYPE_BITMASK (0x01 << CANCELTYPE_BIT)
> +#define CANCELTYPE_BIT 8
> š /* Bit set if canceling has been initiated. š*/
> -#define CANCELING_BIT 2
> -#define CANCELING_BITMASK (0x01 << CANCELING_BIT)
> +#define CANCELING_BIT 16
> š /* Bit set if canceled. š*/
> -#define CANCELED_BIT 3
> -#define CANCELED_BITMASK (0x01 << CANCELED_BIT)
> +#define CANCELED_BIT 17
> š /* Bit set if thread is exiting. š*/
> -#define EXITING_BIT 4
> -#define EXITING_BITMASK (0x01 << EXITING_BIT)
> +#define EXITING_BIT 18
> š /* Bit set if thread terminated and TCB is freed. š*/
> -#define TERMINATED_BIT 5
> -#define TERMINATED_BITMASK (0x01 << TERMINATED_BIT)
> +#define TERMINATED_BIT 19
> š /* Bit set if thread is supposed to change XID. š*/
> -#define SETXID_BIT 6
> +#define SETXID_BIT 20
> +#else
> +#if BYTE_ORDER == BIG_ENDIAN
> + š/* Bit set if cancellation is disabled. š*/
> +#define CANCELSTATE_BIT 24
> + š/* Bit set if asynchronous cancellation mode is selected. š*/
> +#define CANCELTYPE_BIT 16
> +#else /* BYTE_ORDER == PDP_ENDIAN */
> + š/* Bit set if cancellation is disabled. š*/
> +#define CANCELSTATE_BIT 16
> + š/* Bit set if asynchronous cancellation mode is selected. š*/
> +#define CANCELTYPE_BIT 24
> +#endif
> + š/* Bit set if canceling has been initiated. š*/
> +#define CANCELING_BIT 0
> + š/* Bit set if canceled. š*/
> +#define CANCELED_BIT 1
> + š/* Bit set if thread is exiting. š*/
> +#define EXITING_BIT 2
> + š/* Bit set if thread terminated and TCB is freed. š*/
> +#define TERMINATED_BIT 3
> + š/* Bit set if thread is supposed to change XID. š*/
> +#define SETXID_BIT 4
> +#endif
> +#define CANCELSTATE_BITMASK (0x01 << CANCELSTATE_BIT)
> +#define CANCELTYPE_BITMASK (0x01 << CANCELTYPE_BIT)
> +#define CANCELING_BITMASK (0x01 << CANCELING_BIT)
> +#define CANCELED_BITMASK (0x01 << CANCELED_BIT)
> +#define EXITING_BITMASK (0x01 << EXITING_BIT)
> +#define TERMINATED_BITMASK (0x01 << TERMINATED_BIT)
> š#define SETXID_BITMASK (0x01 << SETXID_BIT)
> š /* Mask for the rest. šHelps the compiler to optimize. š*/
> -#define CANCEL_RESTMASK 0xffffff80
> +#define CANCEL_RESTMASK \
> + š( ~((int) (CANCELSTATE_BITMASK | CANCELTYPE_BITMASK | CANCELING_BITMASK | \
> CANCELED_BITMASK \ + š š š š š | EXITING_BITMASK | TERMINATED_BITMASK | \
> SETXID_BITMASK)) ) 
> š#define CANCEL_ENABLED_AND_CANCELED(value) \
> š (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK š š š\
> diff --git a/nptl/pthread_setcancelstate.c b/nptl/pthread_setcancelstate.c
> index a452c2e..580fd15 100644
> --- a/nptl/pthread_setcancelstate.c
> +++ b/nptl/pthread_setcancelstate.c
> @@ -34,38 +34,37 @@ __pthread_setcancelstate (state, oldstate)
> 
> š self = THREAD_SELF;
> 
> - šint oldval = THREAD_GETMEM (self, cancelhandling);
> - šwhile (1)
> + š/* Store the old value. š*/
> + šif (oldstate != NULL)
> š š {
> - š š šint newval = (state == PTHREAD_CANCEL_DISABLE
> - š š? oldval | CANCELSTATE_BITMASK
> - š š: oldval & ~CANCELSTATE_BITMASK);
> + š š šint oldval = THREAD_GETMEM (self, cancelhandling);
> 
> - š š š/* Store the old value. š*/
> - š š šif (oldstate != NULL)
> - *oldstate = ((oldval & CANCELSTATE_BITMASK)
> - š š ? PTHREAD_CANCEL_DISABLE : PTHREAD_CANCEL_ENABLE);
> + š š š*oldstate = ((oldval & CANCELSTATE_BITMASK)
> + š š š š š š š? PTHREAD_CANCEL_DISABLE : PTHREAD_CANCEL_ENABLE);
> + š š}
> 
> - š š š/* Avoid doing unnecessary work. šThe atomic operation can
> - potentially be expensive if the memory has to be locked and
> - remote cache lines have to be invalidated. š*/
> - š š šif (oldval == newval)
> - break;
> + š/* Set the new value. */
> + šTHREAD_SETMEM (self, cancel.state, (char) state);
> 
> - š š š/* Update the cancel handling word. šThis has to be done
> - atomically since other bits could be modified as well. š*/
> - š š šint curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
> - š š šoldval);
> - š š šif (__builtin_expect (curval == oldval, 1))
> - {
> - šif (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
> - š š__do_cancel ();
> + šif (state == PTHREAD_CANCEL_ENABLE)
> + š š{
> + š š š/* This (and similar) barrier makes sure that we check whether the thread
> + š š š * was canceled only _after_ we enable cancellation. Otherwise there is a \
> chance + š š š * that pthread_cancel() will not send SIGCANCEL and \
> pthread_setcancelstate() + š š š * will not notice that CANCELED_BIT was set by \
> pthread_cancel(). + š š š * Note that the read and the write accesses refer to the \
> overlapping memory + š š š * locations. Some architectures (Itanium) can reorder a \
> data-dependent read + š š š * before an older write while some (i386, Sparc) can \
> not. So it is possible to + š š š * remove this barrier in some cases. */
> + š š šatomic_read_after_write_dependent_barrier();
> 
> - šbreak;
> - }
> + š š šint newval = THREAD_GETMEM (self, cancelhandling);
> 
> - š š š/* Prepare for the next round. š*/
> - š š šoldval = curval;
> + š š šif (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS(newval))
> + š š š š{
> + š š š š šTHREAD_SETMEM (self, result, PTHREAD_CANCELED);
> + š š š š š__do_cancel ();
> + š š š š}
> š š }
> 
> š return 0;
> diff --git a/nptl/pthread_setcanceltype.c b/nptl/pthread_setcanceltype.c
> index bbe87ba..43d3dab 100644
> --- a/nptl/pthread_setcanceltype.c
> +++ b/nptl/pthread_setcanceltype.c
> @@ -34,43 +34,31 @@ __pthread_setcanceltype (type, oldtype)
> 
> š self = THREAD_SELF;
> 
> - šint oldval = THREAD_GETMEM (self, cancelhandling);
> - šwhile (1)
> + š/* Store the old value. š*/
> + šif (oldtype != NULL)
> š š {
> - š š šint newval = (type == PTHREAD_CANCEL_ASYNCHRONOUS
> - š š? oldval | CANCELTYPE_BITMASK
> - š š: oldval & ~CANCELTYPE_BITMASK);
> + š š šint oldval = THREAD_GETMEM (self, cancelhandling);
> 
> - š š š/* Store the old value. š*/
> - š š šif (oldtype != NULL)
> - *oldtype = ((oldval & CANCELTYPE_BITMASK)
> - š š? PTHREAD_CANCEL_ASYNCHRONOUS : PTHREAD_CANCEL_DEFERRED);
> + š š š*oldtype = ((oldval & CANCELTYPE_BITMASK)
> + š š š š š š š? PTHREAD_CANCEL_ASYNCHRONOUS : PTHREAD_CANCEL_DEFERRED);
> + š š}
> 
> - š š š/* Avoid doing unnecessary work. šThe atomic operation can
> - potentially be expensive if the memory has to be locked and
> - remote cache lines have to be invalidated. š*/
> - š š šif (oldval == newval)
> - break;
> + š/* Set the new value. */
> + šTHREAD_SETMEM (self, cancel.type, (char) type);
> 
> - š š š/* Update the cancel handling word. šThis has to be done
> - atomically since other bits could be modified as well. š*/
> - š š šint curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
> - š š šoldval);
> - š š šif (__builtin_expect (curval == oldval, 1))
> - {
> - šif (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
> - š š{
> - š š šTHREAD_SETMEM (self, result, PTHREAD_CANCELED);
> - š š š__do_cancel ();
> - š š}
> + šif (type == PTHREAD_CANCEL_ASYNCHRONOUS)
> + š š{
> + š š š/* See comment in pthread_setcancelstate (). */
> + š š šatomic_read_after_write_dependent_barrier();
> 
> - šbreak;
> - }
> + š š šint newval = THREAD_GETMEM (self, cancelhandling);
> 
> - š š š/* Prepare for the next round. š*/
> - š š šoldval = curval;
> + š š šif (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS(newval))
> + š š š š{
> + š š š š šTHREAD_SETMEM (self, result, PTHREAD_CANCELED);
> + š š š š š__do_cancel ();
> + š š š š}
> š š }
> -
> š return 0;
> š}
> šstrong_alias (__pthread_setcanceltype, pthread_setcanceltype)
> diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S \
> b/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S index 6806962..e69de29 100644
> --- a/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
> +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
> @@ -1,116 +0,0 @@
> -/* Copyright (C) 2009 Free Software Foundation, Inc.
> - š This file is part of the GNU C Library.
> - š Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
> -
> - š The GNU C Library is free software; you can redistribute it and/or
> - š modify it under the terms of the GNU Lesser General Public
> - š License as published by the Free Software Foundation; either
> - š version 2.1 of the License, or (at your option) any later version.
> -
> - š The GNU C Library is distributed in the hope that it will be useful,
> - š but WITHOUT ANY WARRANTY; without even the implied warranty of
> - š MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. šSee the GNU
> - š Lesser General Public License for more details.
> -
> - š You should have received a copy of the GNU Lesser General Public
> - š License along with the GNU C Library; if not, write to the Free
> - š Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> - š 02111-1307 USA. š*/
> -
> -#include <sysdep.h>
> -#include <tcb-offsets.h>
> -#include <kernel-features.h>
> -#include "lowlevellock.h"
> -
> -#ifdef IS_IN_libpthread
> -# ifdef SHARED
> -# šdefine __pthread_unwind __GI___pthread_unwind
> -# endif
> -#else
> -# ifndef SHARED
> - .weak __pthread_unwind
> -# endif
> -#endif
> -
> -
> -#ifdef __ASSUME_PRIVATE_FUTEX
> -# define LOAD_PRIVATE_FUTEX_WAIT(reg) \
> - movl $(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
> -#else
> -# if FUTEX_WAIT == 0
> -# šdefine LOAD_PRIVATE_FUTEX_WAIT(reg) \
> - movl %fs:PRIVATE_FUTEX, reg
> -# else
> -# šdefine LOAD_PRIVATE_FUTEX_WAIT(reg) \
> - movl %fs:PRIVATE_FUTEX, reg ; \
> - orl $FUTEX_WAIT, reg
> -# endif
> -#endif
> -
> -/* It is crucial that the functions in this file don't modify registers
> - š other than %rax and %r11. šThe syscall wrapper code depends on this
> - š because it doesn't explicitly save the other registers which hold
> - š relevant values. š*/
> - .text
> -
> - .hidden __pthread_enable_asynccancel
> -ENTRY(__pthread_enable_asynccancel)
> - movl %fs:CANCELHANDLING, %eax
> -2: movl %eax, %r11d
> - orl $TCB_CANCELTYPE_BITMASK, %r11d
> - cmpl %eax, %r11d
> - je 1f
> -
> - lock
> - cmpxchgl %r11d, %fs:CANCELHANDLING
> - jnz 2b
> -
> - andl $(TCB_CANCELSTATE_BITMASK|TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK|TCB_EXITING_BITMASK|TCB_CANCEL_RESTMASK|TCB_TERMINATED_BITMASK), \
>                 %r11d
> - cmpl $(TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK), %r11d
> - je 3f
> -
> -1: ret
> -
> -3: movq $TCB_PTHREAD_CANCELED, %fs:RESULT
> - lock
> - orl $TCB_EXITING_BITMASK, %fs:CANCELHANDLING
> - movq %fs:CLEANUP_JMP_BUF, %rdi
> -#ifdef SHARED
> - call __pthread_unwind@PLT
> -#else
> - call __pthread_unwind
> -#endif
> - hlt
> -END(__pthread_enable_asynccancel)
> -
> -
> - .hidden __pthread_disable_asynccancel
> -ENTRY(__pthread_disable_asynccancel)
> - testl $TCB_CANCELTYPE_BITMASK, %edi
> - jnz 1f
> -
> - movl %fs:CANCELHANDLING, %eax
> -2: movl %eax, %r11d
> - andl $~TCB_CANCELTYPE_BITMASK, %r11d
> - lock
> - cmpxchgl %r11d, %fs:CANCELHANDLING
> - jnz 2b
> -
> - movl %r11d, %eax
> -3: andl $(TCB_CANCELING_BITMASK|TCB_CANCELED_BITMASK), %eax
> - cmpl $TCB_CANCELING_BITMASK, %eax
> - je 4f
> -1: ret
> -
> - /* Performance doesn't matter in this loop. šWe will
> - š delay until the thread is canceled. šAnd we will unlikely
> - š enter the loop twice. š*/
> -4: movq %fs:0, %rdi
> - movl $__NR_futex, %eax
> - xorq %r10, %r10
> - addq $CANCELHANDLING, %rdi
> - LOAD_PRIVATE_FUTEX_WAIT (%esi)
> - syscall
> - movl %fs:CANCELHANDLING, %eax
> - jmp 3b
> -END(__pthread_disable_asynccancel)
> diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S \
> b/nptl/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S index 1100588..e69de29 \
>                 100644
> --- a/nptl/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
> +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
> @@ -1,22 +0,0 @@
> -/* Copyright (C) 2009 Free Software Foundation, Inc.
> - š This file is part of the GNU C Library.
> - š Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
> -
> - š The GNU C Library is free software; you can redistribute it and/or
> - š modify it under the terms of the GNU Lesser General Public
> - š License as published by the Free Software Foundation; either
> - š version 2.1 of the License, or (at your option) any later version.
> -
> - š The GNU C Library is distributed in the hope that it will be useful,
> - š but WITHOUT ANY WARRANTY; without even the implied warranty of
> - š MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. šSee the GNU
> - š Lesser General Public License for more details.
> -
> - š You should have received a copy of the GNU Lesser General Public
> - š License along with the GNU C Library; if not, write to the Free
> - š Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> - š 02111-1307 USA. š*/
> -
> -#define __pthread_enable_asynccancel __libc_enable_asynccancel
> -#define __pthread_disable_asynccancel __libc_disable_asynccancel
> -#include "cancellation.S"
> diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S \
> b/nptl/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S index ce4192b..e69de29 \
>                 100644
> --- a/nptl/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S
> +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S
> @@ -1,22 +0,0 @@
> -/* Copyright (C) 2009 Free Software Foundation, Inc.
> - š This file is part of the GNU C Library.
> - š Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
> -
> - š The GNU C Library is free software; you can redistribute it and/or
> - š modify it under the terms of the GNU Lesser General Public
> - š License as published by the Free Software Foundation; either
> - š version 2.1 of the License, or (at your option) any later version.
> -
> - š The GNU C Library is distributed in the hope that it will be useful,
> - š but WITHOUT ANY WARRANTY; without even the implied warranty of
> - š MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. šSee the GNU
> - š Lesser General Public License for more details.
> -
> - š You should have received a copy of the GNU Lesser General Public
> - š License along with the GNU C Library; if not, write to the Free
> - š Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> - š 02111-1307 USA. š*/
> -
> -#define __pthread_enable_asynccancel __librt_enable_asynccancel
> -#define __pthread_disable_asynccancel __librt_disable_asynccancel
> -#include "cancellation.S"
> diff --git a/sysdeps/i386/i486/bits/atomic.h b/sysdeps/i386/i486/bits/atomic.h
> index 4ee6fef..55fe2a0 100644
> --- a/sysdeps/i386/i486/bits/atomic.h
> +++ b/sysdeps/i386/i486/bits/atomic.h
> @@ -553,3 +553,5 @@ typedef uintmax_t uatomic_max_t;
> š#define atomic_or(mem, mask) __arch_or_body (LOCK_PREFIX, mem, mask)
> 
> š#define catomic_or(mem, mask) __arch_or_body (__arch_cprefix, mem, mask)
> +
> +#define atomic_read_after_write_dependent_barrier() __asm __volatile("" ::: \
>                 "memory")
> diff --git a/sysdeps/ia64/bits/atomic.h b/sysdeps/ia64/bits/atomic.h
> index 1020c2f..8b4d6bf 100644
> --- a/sysdeps/ia64/bits/atomic.h
> +++ b/sysdeps/ia64/bits/atomic.h
> @@ -115,5 +115,3 @@ typedef uintmax_t uatomic_max_t;
> š š š š} š š š\
> š š šwhile (__builtin_expect (__val != __oldval, 0)); š š š\
> š š š__oldval & __mask; })
> -
> -#define atomic_full_barrier() __sync_synchronize ()
> diff --git a/sysdeps/sparc/sparc32/bits/atomic.h \
> b/sysdeps/sparc/sparc32/bits/atomic.h index ef553f7..0143793 100644
> --- a/sysdeps/sparc/sparc32/bits/atomic.h
> +++ b/sysdeps/sparc/sparc32/bits/atomic.h
> @@ -324,4 +324,6 @@ extern uint64_t _dl_hwcap __attribute__((weak));
> 
> š#endif
> 
> +#define atomic_read_after_write_dependent_barrier() __asm __volatile("" ::: \
> "memory") +
> š#endif /* bits/atomic.h */
> diff --git a/sysdeps/sparc/sparc64/bits/atomic.h \
> b/sysdeps/sparc/sparc64/bits/atomic.h index d0a64af..859adc8 100644
> --- a/sysdeps/sparc/sparc64/bits/atomic.h
> +++ b/sysdeps/sparc/sparc64/bits/atomic.h
> @@ -107,3 +107,5 @@ typedef uintmax_t uatomic_max_t;
> š __asm __volatile ("membar #LoadLoad | #LoadStore" : : : "memory")
> š#define atomic_write_barrier() \
> š __asm __volatile ("membar #StoreLoad | #StoreStore" : : : "memory")
> +#define atomic_read_after_write_dependent_barrier() \
> + š__asm __volatile("" ::: "memory")
> diff --git a/sysdeps/x86_64/bits/atomic.h b/sysdeps/x86_64/bits/atomic.h
> index 7c138eb..9c895cd 100644
> --- a/sysdeps/x86_64/bits/atomic.h
> +++ b/sysdeps/x86_64/bits/atomic.h
> @@ -496,3 +496,5 @@ typedef uintmax_t uatomic_max_t;
> š#define atomic_or(mem, mask) __arch_or_body (LOCK_PREFIX, mem, mask)
> 
> š#define catomic_or(mem, mask) __arch_or_body (__arch_cprefix, mem, mask)
> +
> +#define atomic_read_after_write_dependent_barrier() __asm __volatile("" ::: \
> "memory")

Did anyone ever review this?


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic