diff options
author | andrew <andrew@FreeBSD.org> | 2015-01-21 16:41:05 +0000 |
---|---|---|
committer | andrew <andrew@FreeBSD.org> | 2015-01-21 16:41:05 +0000 |
commit | 4721e5b10a6394debc054efdb295af2478d19b08 (patch) | |
tree | dd5374699dfdf6f807d4665c6b7b1da3ccf9760e /lib | |
parent | ef36961ce12e25e2c86a5013a6ed33b650af51fb (diff) | |
download | FreeBSD-src-4721e5b10a6394debc054efdb295af2478d19b08.zip FreeBSD-src-4721e5b10a6394debc054efdb295af2478d19b08.tar.gz |
Merge all the copies of _tcb_ctor and _tcb_dtor.
The amd64, i386, and sparc64 versions were identical, with the one
difference where the former two used inline asm instead of _tcb_get. I
have compared the function before and after replacing the asm with _tcb_get
and found the object files to be identical.
The arm, mips, and powerpc versions were almost identical. The only
difference was the powerpc version used an alignment of 1 where arm and
mips used 16. As this is an increase in alignment is will be safe.
Along with this arm, mips, and powerpc all passed, when initial was true,
the value returned from _tcb_get as the first argument to
_rtld_allocate_tls. This would then return this pointer back to the caller.
We can remove these extra calls by checking if initial is set and setting
the thread control block directly. As this is what the sparc64 code does
we can use it directly.
As after these observations all the architectures can now have identical
code we can merge them into a common file.
Differential Revision: https://reviews.freebsd.org/D1556
Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'lib')
21 files changed, 10 insertions, 321 deletions
diff --git a/lib/libthr/Makefile b/lib/libthr/Makefile index 08d5052..1acb17f 100644 --- a/lib/libthr/Makefile +++ b/lib/libthr/Makefile @@ -45,7 +45,9 @@ PRECIOUSLIB= .PATH: ${.CURDIR}/arch/${MACHINE_CPUARCH}/${MACHINE_CPUARCH} +.if exists(${.CURDIR}/arch/${MACHINE_CPUARCH}/Makefile.inc) .include "${.CURDIR}/arch/${MACHINE_CPUARCH}/Makefile.inc" +.endif .include "${.CURDIR}/sys/Makefile.inc" .include "${.CURDIR}/thread/Makefile.inc" diff --git a/lib/libthr/arch/amd64/Makefile.inc b/lib/libthr/arch/amd64/Makefile.inc index e6d99ec..797618d 100644 --- a/lib/libthr/arch/amd64/Makefile.inc +++ b/lib/libthr/arch/amd64/Makefile.inc @@ -1,3 +1,3 @@ #$FreeBSD$ -SRCS+= pthread_md.c _umtx_op_err.S +SRCS+= _umtx_op_err.S diff --git a/lib/libthr/arch/amd64/amd64/pthread_md.c b/lib/libthr/arch/amd64/amd64/pthread_md.c deleted file mode 100644 index b661657..0000000 --- a/lib/libthr/arch/amd64/amd64/pthread_md.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Neither the name of the author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <sys/types.h> -#include <rtld_tls.h> - -#include "pthread_md.h" - -/* - * The constructors. - */ -struct tcb * -_tcb_ctor(struct pthread *thread, int initial) -{ - struct tcb *tcb; - - if (initial) - __asm __volatile("movq %%fs:0, %0" : "=r" (tcb)); - else - tcb = _rtld_allocate_tls(NULL, sizeof(struct tcb), 16); - if (tcb) - tcb->tcb_thread = thread; - return (tcb); -} - -void -_tcb_dtor(struct tcb *tcb) -{ - _rtld_free_tls(tcb, sizeof(struct tcb), 16); -} diff --git a/lib/libthr/arch/amd64/include/pthread_md.h b/lib/libthr/arch/amd64/include/pthread_md.h index 0ebea2e..e4a0dd2 100644 --- a/lib/libthr/arch/amd64/include/pthread_md.h +++ b/lib/libthr/arch/amd64/include/pthread_md.h @@ -77,9 +77,6 @@ struct tcb { __result; \ }) -struct tcb *_tcb_ctor(struct pthread *, int); -void _tcb_dtor(struct tcb *tcb); - static __inline void _tcb_set(struct tcb *tcb) { diff --git a/lib/libthr/arch/arm/Makefile.inc b/lib/libthr/arch/arm/Makefile.inc deleted file mode 100644 index 2ee2247..0000000 --- a/lib/libthr/arch/arm/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $FreeBSD$ - -SRCS+= pthread_md.c diff --git a/lib/libthr/arch/arm/arm/pthread_md.c b/lib/libthr/arch/arm/arm/pthread_md.c deleted file mode 100644 index 028f06c..0000000 --- a/lib/libthr/arch/arm/arm/pthread_md.c +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * Copyright (C) 2005 David Xu <davidxu@freebsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Neither the name of the author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <stdlib.h> -#include <sys/types.h> -#include <rtld_tls.h> - -#include "pthread_md.h" - -struct tcb * -_tcb_ctor(struct pthread *thread, int initial) -{ - struct tcb *tcb; - - tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL, - sizeof(struct tcb), 16); - if (tcb) - tcb->tcb_thread = thread; - - return (tcb); -} - -void -_tcb_dtor(struct tcb *tcb) -{ - - _rtld_free_tls(tcb, sizeof(struct tcb), 16); -} diff --git a/lib/libthr/arch/arm/include/pthread_md.h b/lib/libthr/arch/arm/include/pthread_md.h index 3c3dd6d..9a6b523 100644 --- a/lib/libthr/arch/arm/include/pthread_md.h +++ b/lib/libthr/arch/arm/include/pthread_md.h @@ -47,12 +47,6 @@ struct tcb { struct pthread *tcb_thread; /* our hook */ }; -/* - * The tcb constructors. - */ -struct tcb *_tcb_ctor(struct pthread *, int); -void _tcb_dtor(struct tcb *); - /* Called from the thread to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) diff --git a/lib/libthr/arch/i386/Makefile.inc b/lib/libthr/arch/i386/Makefile.inc index 01290d5..bdab0bc 100644 --- a/lib/libthr/arch/i386/Makefile.inc +++ b/lib/libthr/arch/i386/Makefile.inc @@ -1,3 +1,3 @@ # $FreeBSD$ -SRCS+= pthread_md.c _umtx_op_err.S +SRCS+= _umtx_op_err.S diff --git a/lib/libthr/arch/i386/i386/pthread_md.c b/lib/libthr/arch/i386/i386/pthread_md.c deleted file mode 100644 index a8b31d5..0000000 --- a/lib/libthr/arch/i386/i386/pthread_md.c +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright (C) 2003 David Xu <davidxu@freebsd.org> - * Copyright (c) 2001,2003 Daniel Eischen <deischen@freebsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Neither the name of the author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <sys/types.h> -#include <machine/segments.h> -#include <machine/sysarch.h> -#include <string.h> -#include <rtld_tls.h> - -#include "pthread_md.h" - -struct tcb * -_tcb_ctor(struct pthread *thread, int initial) -{ - struct tcb *tcb; - - if (initial) - __asm __volatile("movl %%gs:0, %0" : "=r" (tcb)); - else - tcb = _rtld_allocate_tls(NULL, sizeof(struct tcb), 16); - if (tcb) - tcb->tcb_thread = thread; - return (tcb); -} - -void -_tcb_dtor(struct tcb *tcb) -{ - - _rtld_free_tls(tcb, sizeof(struct tcb), 16); -} diff --git a/lib/libthr/arch/i386/include/pthread_md.h b/lib/libthr/arch/i386/include/pthread_md.h index c160aa4..ba7b75c 100644 --- a/lib/libthr/arch/i386/include/pthread_md.h +++ b/lib/libthr/arch/i386/include/pthread_md.h @@ -76,12 +76,6 @@ struct tcb { __result; \ }) -/* - * The constructors. - */ -struct tcb *_tcb_ctor(struct pthread *, int); -void _tcb_dtor(struct tcb *tcb); - /* Called from the thread to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) diff --git a/lib/libthr/arch/mips/Makefile.inc b/lib/libthr/arch/mips/Makefile.inc deleted file mode 100644 index 2ee2247..0000000 --- a/lib/libthr/arch/mips/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $FreeBSD$ - -SRCS+= pthread_md.c diff --git a/lib/libthr/arch/mips/include/pthread_md.h b/lib/libthr/arch/mips/include/pthread_md.h index 19c9f38..32af964 100644 --- a/lib/libthr/arch/mips/include/pthread_md.h +++ b/lib/libthr/arch/mips/include/pthread_md.h @@ -50,12 +50,6 @@ struct tcb { struct pthread *tcb_thread; }; -/* - * The tcb constructors. - */ -struct tcb *_tcb_ctor(struct pthread *, int); -void _tcb_dtor(struct tcb *); - /* Called from the thread to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) diff --git a/lib/libthr/arch/mips/mips/pthread_md.c b/lib/libthr/arch/mips/mips/pthread_md.c deleted file mode 100644 index e596edc..0000000 --- a/lib/libthr/arch/mips/mips/pthread_md.c +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * Copyright (C) 2005 David Xu <davidxu@freebsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Neither the name of the author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: src/lib/libthr/arch/arm/arm/pthread_md.c,v 1.2 2005/10/29 13:40:31 davidxu - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <stdlib.h> -#include <sys/types.h> -#include <rtld_tls.h> -#include <strings.h> - -#include <machine/sysarch.h> - -#include "pthread_md.h" - -struct tcb * -_tcb_ctor(struct pthread *thread, int initial) -{ - struct tcb *tcb; - - tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL, - sizeof(struct tcb), 16); - if (tcb) - tcb->tcb_thread = thread; - - return (tcb); -} - -void -_tcb_dtor(struct tcb *tcb) -{ - - _rtld_free_tls(tcb, sizeof(struct tcb), 16); -} diff --git a/lib/libthr/arch/powerpc/Makefile.inc b/lib/libthr/arch/powerpc/Makefile.inc deleted file mode 100644 index 2ee2247..0000000 --- a/lib/libthr/arch/powerpc/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $FreeBSD$ - -SRCS+= pthread_md.c diff --git a/lib/libthr/arch/powerpc/include/pthread_md.h b/lib/libthr/arch/powerpc/include/pthread_md.h index 3563297..544ee1c 100644 --- a/lib/libthr/arch/powerpc/include/pthread_md.h +++ b/lib/libthr/arch/powerpc/include/pthread_md.h @@ -55,9 +55,6 @@ struct tcb { struct pthread *tcb_thread; }; -struct tcb *_tcb_ctor(struct pthread *, int); -void _tcb_dtor(struct tcb *); - static __inline void _tcb_set(struct tcb *tcb) { diff --git a/lib/libthr/arch/powerpc/powerpc/pthread_md.c b/lib/libthr/arch/powerpc/powerpc/pthread_md.c deleted file mode 100644 index 66f043e..0000000 --- a/lib/libthr/arch/powerpc/powerpc/pthread_md.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Neither the name of the author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include <sys/types.h> -#include <rtld_tls.h> - -#include "pthread_md.h" - -/* - * The constructors. - */ -struct tcb * -_tcb_ctor(struct pthread *thread, int initial) -{ - struct tcb *tcb; - - tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL, - sizeof(struct tcb), 1); - if (tcb) - tcb->tcb_thread = thread; - return (tcb); - -} - -void -_tcb_dtor(struct tcb *tcb) -{ - _rtld_free_tls(tcb, sizeof(struct tcb), 1); -} diff --git a/lib/libthr/arch/sparc64/Makefile.inc b/lib/libthr/arch/sparc64/Makefile.inc index 88586b4..bdab0bc 100644 --- a/lib/libthr/arch/sparc64/Makefile.inc +++ b/lib/libthr/arch/sparc64/Makefile.inc @@ -1,3 +1,3 @@ # $FreeBSD$ -SRCS+= _umtx_op_err.S pthread_md.c +SRCS+= _umtx_op_err.S diff --git a/lib/libthr/arch/sparc64/include/pthread_md.h b/lib/libthr/arch/sparc64/include/pthread_md.h index 7ee9654..35d8405 100644 --- a/lib/libthr/arch/sparc64/include/pthread_md.h +++ b/lib/libthr/arch/sparc64/include/pthread_md.h @@ -50,12 +50,6 @@ struct tcb { void *tcb_spare[1]; }; -/* - * The tcb constructors. - */ -struct tcb *_tcb_ctor(struct pthread *, int); -void _tcb_dtor(struct tcb *); - /* Called from the thread to set its private data. */ static __inline void _tcb_set(struct tcb *tcb) diff --git a/lib/libthr/thread/Makefile.inc b/lib/libthr/thread/Makefile.inc index ddde6e9..1a7c63d 100644 --- a/lib/libthr/thread/Makefile.inc +++ b/lib/libthr/thread/Makefile.inc @@ -14,6 +14,7 @@ SRCS+= \ thr_cond.c \ thr_condattr.c \ thr_create.c \ + thr_ctrdtr.c \ thr_detach.c \ thr_equal.c \ thr_event.c \ diff --git a/lib/libthr/arch/sparc64/sparc64/pthread_md.c b/lib/libthr/thread/thr_ctrdtr.c index e1d439a..9d4301e 100644 --- a/lib/libthr/arch/sparc64/sparc64/pthread_md.c +++ b/lib/libthr/thread/thr_ctrdtr.c @@ -32,7 +32,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <rtld_tls.h> -#include "pthread_md.h" +#include "thr_private.h" struct tcb * _tcb_ctor(struct pthread *thread, int initial) diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index d62de98..50be059 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -928,6 +928,9 @@ int __thr_sigwait(const sigset_t *set, int *sig); int __thr_sigwaitinfo(const sigset_t *set, siginfo_t *info); int __thr_swapcontext(ucontext_t *oucp, const ucontext_t *ucp); +struct tcb *_tcb_ctor(struct pthread *, int); +void _tcb_dtor(struct tcb *); + __END_DECLS #endif /* !_THR_PRIVATE_H */ |