From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29245 invoked by alias); 24 May 2007 21:17:08 -0000 Received: (qmail 29229 invoked by uid 22791); 24 May 2007 21:17:07 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 24 May 2007 21:17:04 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l4OLIrFK007273; Thu, 24 May 2007 23:18:53 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l4OLIr5n007272; Thu, 24 May 2007 23:18:53 +0200 Date: Thu, 24 May 2007 21:17:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] global scope locking for ppc/ppc64 Message-ID: <20070524211852.GG3081@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-05/txt/msg00020.txt.bz2 Hi! On ppc* (and I vaguely remember other arches) tcbhead_t is not inside of struct pthread, so making ppc compile needs some generic changes. The following patch introduces new THREAD_GSCOPE_GET_FLAG macro, so that gscope_flag field can live outside of struct pthread. 2007-05-24 Jakub Jelinek * sysdeps/powerpc/tls.h (tcbhead_t): Add gscope_flag. (THREAD_GSCOPE_FLAG_UNUSED, THREAD_GSCOPE_FLAG_USED, THREAD_GSCOPE_FLAG_WAIT): Define. (THREAD_GSCOPE_GET_FLAG, THREAD_GSCOPE_SET_FLAG, THREAD_GSCOPE_RESET_FLAG, THREAD_GSCOPE_WAIT): Define. * sysdeps/i386/tls.h (THREAD_GSCOPE_WAIT): Don't use PTR_DEMANGLE. (THREAD_GSCOPE_GET_FLAG): Define. * sysdeps/x86_64/tls.h (THREAD_GSCOPE_GET_FLAG): Define. * allocatestack.c (__wait_lookup_done): Use THREAD_GSCOPE_GET_FLAG instead of ->header.gscope_flag directly. --- libc/nptl/sysdeps/powerpc/tls.h.jj 2006-11-28 11:25:16.000000000 +0100 +++ libc/nptl/sysdeps/powerpc/tls.h 2007-05-24 18:54:03.000000000 +0200 @@ -1,5 +1,5 @@ /* Definition for thread-local data handling. NPTL/PowerPC version. - Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -63,10 +63,11 @@ typedef union dtv # include /* The stack_guard is accessed directly by GCC -fstack-protector code, - so it is a part of public ABI. The dtv and pointer_guard fields - are private. */ + so it is a part of public ABI. The dtv, pointer_guard and gscope_flag + fields are private. */ typedef struct { + int gscope_flag; uintptr_t pointer_guard; uintptr_t stack_guard; dtv_t *dtv; @@ -180,6 +181,27 @@ register void *__thread_register __asm__ different value to mean unset l_tls_offset. */ # define NO_TLS_OFFSET -1 +/* Get and set the global scope generation counter in the TCB head. */ +#define THREAD_GSCOPE_FLAG_UNUSED 0 +#define THREAD_GSCOPE_FLAG_USED 1 +#define THREAD_GSCOPE_FLAG_WAIT 2 +#define THREAD_GSCOPE_GET_FLAG(descr) \ + (((tcbhead_t *) ((char *) (descr) \ + + TLS_PRE_TCB_SIZE))[-1].gscope_flag) +#define THREAD_GSCOPE_RESET_FLAG() \ + do \ + { int __res \ + = atomic_exchange_rel (&THREAD_GSCOPE_GET_FLAG (THREAD_SELF), \ + THREAD_GSCOPE_FLAG_UNUSED); \ + if (__res == THREAD_GSCOPE_FLAG_WAIT) \ + lll_futex_wake (&THREAD_GSCOPE_GET_FLAG (THREAD_SELF), 1); \ + } \ + while (0) +#define THREAD_GSCOPE_SET_FLAG() \ + (THREAD_GSCOPE_GET_FLAG (THREAD_SELF) = THREAD_GSCOPE_FLAG_USED) +#define THREAD_GSCOPE_WAIT() \ + GL(dl_wait_lookup_done) () + #endif /* __ASSEMBLER__ */ #endif /* tls.h */ --- libc/nptl/sysdeps/i386/tls.h.jj 2007-05-24 16:41:06.000000000 +0200 +++ libc/nptl/sysdeps/i386/tls.h 2007-05-24 17:53:37.000000000 +0200 @@ -454,16 +454,9 @@ union user_desc_init while (0) #define THREAD_GSCOPE_SET_FLAG() \ THREAD_SETMEM (THREAD_SELF, header.gscope_flag, THREAD_GSCOPE_FLAG_USED) -#ifdef PTR_DEMANGLE -# define THREAD_GSCOPE_WAIT() \ - do { void (*ptr) (void) = GL(dl_wait_lookup_done); \ - PTR_DEMANGLE (ptr); \ - ptr (); \ - } while (0) -#else -# define THREAD_GSCOPE_WAIT() \ +#define THREAD_GSCOPE_GET_FLAG(descr) (descr)->header.gscope_flag +#define THREAD_GSCOPE_WAIT() \ GL(dl_wait_lookup_done) () -#endif #endif /* __ASSEMBLER__ */ --- libc/nptl/sysdeps/x86_64/tls.h.jj 2007-05-24 16:41:08.000000000 +0200 +++ libc/nptl/sysdeps/x86_64/tls.h 2007-05-24 17:53:58.000000000 +0200 @@ -360,6 +360,7 @@ typedef struct while (0) #define THREAD_GSCOPE_SET_FLAG() \ THREAD_SETMEM (THREAD_SELF, header.gscope_flag, THREAD_GSCOPE_FLAG_USED) +#define THREAD_GSCOPE_GET_FLAG(descr) (descr)->header.gscope_flag #define THREAD_GSCOPE_WAIT() \ GL(dl_wait_lookup_done) () --- libc/nptl/allocatestack.c.jj 2007-05-24 16:41:06.000000000 +0200 +++ libc/nptl/allocatestack.c 2007-05-24 18:01:04.000000000 +0200 @@ -1023,10 +1023,10 @@ __wait_lookup_done (void) list_for_each (runp, &stack_used) { struct pthread *t = list_entry (runp, struct pthread, list); - if (t == self || t->header.gscope_flag == THREAD_GSCOPE_FLAG_UNUSED) + if (t == self || THREAD_GSCOPE_GET_FLAG (t) == THREAD_GSCOPE_FLAG_UNUSED) continue; - int *const gscope_flagp = &t->header.gscope_flag; + int *const gscope_flagp = &THREAD_GSCOPE_GET_FLAG (t); /* We have to wait until this thread is done with the global scope. First tell the thread that we are waiting and @@ -1045,10 +1045,10 @@ __wait_lookup_done (void) list_for_each (runp, &__stack_user) { struct pthread *t = list_entry (runp, struct pthread, list); - if (t == self || t->header.gscope_flag == THREAD_GSCOPE_FLAG_UNUSED) + if (t == self || THREAD_GSCOPE_GET_FLAG (t) == THREAD_GSCOPE_FLAG_UNUSED) continue; - int *const gscope_flagp = &t->header.gscope_flag; + int *const gscope_flagp = &THREAD_GSCOPE_GET_FLAG (t); /* We have to wait until this thread is done with the global scope. First tell the thread that we are waiting and Jakub