From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1792) id 6BB023858D33; Sat, 23 Mar 2024 22:16:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BB023858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1711232208; bh=eGTu/vmGD1bEt7jnJJWSBgz1vvO//kKGXiEtEju19s0=; h=From:To:Subject:Date:From; b=fpz2AX8P0YRByP5oKs8R3Jhf7wq8jixW4odKWxjA+O1MzeuBdPx0DAOmdF5bNkyQb icMgxL2AvF3pDo3sYaxmOgRlQmPm2KZCnXeCdcJ9fWdeygdGpJUhhoZHKFi+25zmag YQOljzIAmq/u2IajRYMWiBTpdiDvFBsLiYGuxmRs= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Samuel Thibault To: glibc-cvs@sourceware.org Subject: [glibc] htl: Implement some support for TLS_DTV_AT_TP X-Act-Checkin: glibc X-Git-Author: Sergey Bugaev X-Git-Refname: refs/heads/master X-Git-Oldrev: a4273efa219480a7f2c9c8fa7bc8bb71c48c3604 X-Git-Newrev: dc1a77269c971652a8a5167ec366792eae052e65 Message-Id: <20240323221648.6BB023858D33@sourceware.org> Date: Sat, 23 Mar 2024 22:16:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dc1a77269c971652a8a5167ec366792eae052e65 commit dc1a77269c971652a8a5167ec366792eae052e65 Author: Sergey Bugaev Date: Sat Mar 23 20:32:59 2024 +0300 htl: Implement some support for TLS_DTV_AT_TP Signed-off-by: Sergey Bugaev Message-ID: <20240323173301.151066-19-bugaevc@gmail.com> Diff: --- htl/pt-create.c | 2 ++ sysdeps/htl/dl-thread_gscope_wait.c | 16 ++++++++++++++-- sysdeps/mach/hurd/htl/pt-sysdep.c | 9 +++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/htl/pt-create.c b/htl/pt-create.c index fac61f1b22..8a735d99cb 100644 --- a/htl/pt-create.c +++ b/htl/pt-create.c @@ -177,7 +177,9 @@ __pthread_create_internal (struct __pthread **thread, err = ENOMEM; goto failed_thread_tls_alloc; } +#if TLS_TCB_AT_TP pthread->tcb->tcb = pthread->tcb; +#endif /* And initialize the rest of the machine context. This may include additional machine- and system-specific initializations that diff --git a/sysdeps/htl/dl-thread_gscope_wait.c b/sysdeps/htl/dl-thread_gscope_wait.c index 90a9a79850..ee0a316527 100644 --- a/sysdeps/htl/dl-thread_gscope_wait.c +++ b/sysdeps/htl/dl-thread_gscope_wait.c @@ -20,6 +20,18 @@ #include #include +static inline int * +thread_gscope_flag (struct __pthread *t) +{ +#if TLS_TCB_AT_TP + return &t->tcb->gscope_flag; +#elif TLS_DTV_AT_TP + return &((tcbprehead_t *) t->tcb - 1)->gscope_flag; +#else +# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined" +#endif +} + void __thread_gscope_wait (void) { @@ -33,10 +45,10 @@ __thread_gscope_wait (void) for (i = 0; i < GL (dl_pthread_num_threads); ++i) { t = GL (dl_pthread_threads[i]); - if (t == NULL || t->tcb->gscope_flag == THREAD_GSCOPE_FLAG_UNUSED) + if (t == NULL || *thread_gscope_flag (t) == THREAD_GSCOPE_FLAG_UNUSED) continue; - gscope_flagp = &t->tcb->gscope_flag; + gscope_flagp = thread_gscope_flag (t); /* We have to wait until this thread is done with the global scope. First tell the thread that we are waiting and diff --git a/sysdeps/mach/hurd/htl/pt-sysdep.c b/sysdeps/mach/hurd/htl/pt-sysdep.c index 270e77531e..5372cbf77f 100644 --- a/sysdeps/mach/hurd/htl/pt-sysdep.c +++ b/sysdeps/mach/hurd/htl/pt-sysdep.c @@ -100,7 +100,16 @@ _init_routine (void *stack) to the new stack. Pretend it wasn't allocated so that it remains valid if the main thread terminates. */ thread->stack = 0; +#if TLS_TCB_AT_TP thread->tcb = THREAD_SELF; +#elif TLS_DTV_AT_TP + /* Assuming THREAD_SELF is implemented as subtracting TLS_PRE_TCB_SIZE + from the value of a thread pointer regsiter, this should optimize + down to simply reading that register. */ + thread->tcb = (tcbhead_t *) (((char *) THREAD_SELF) + TLS_PRE_TCB_SIZE); +#else +# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined" +#endif #ifndef PAGESIZE __pthread_default_attr.__guardsize = __vm_page_size;