[Midnightbsd-cvs] src [10637] sync

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jun 9 12:46:37 EDT 2018


Revision: 10637
          http://svnweb.midnightbsd.org/src/?rev=10637
Author:   laffer1
Date:     2018-06-09 12:46:37 -0400 (Sat, 09 Jun 2018)
Log Message:
-----------
sync

Modified Paths:
--------------
    trunk/lib/libthr/Makefile
    trunk/lib/libthr/arch/amd64/Makefile.inc
    trunk/lib/libthr/arch/amd64/amd64/_umtx_op_err.S
    trunk/lib/libthr/arch/amd64/amd64/pthread_md.c
    trunk/lib/libthr/arch/amd64/include/pthread_md.h
    trunk/lib/libthr/arch/i386/Makefile.inc
    trunk/lib/libthr/arch/i386/i386/_umtx_op_err.S
    trunk/lib/libthr/arch/i386/i386/pthread_md.c
    trunk/lib/libthr/arch/i386/include/pthread_md.h
    trunk/lib/libthr/libthr.3

Property Changed:
----------------
    trunk/lib/libthr/arch/amd64/Makefile.inc
    trunk/lib/libthr/arch/amd64/amd64/_umtx_op_err.S
    trunk/lib/libthr/arch/i386/Makefile.inc
    trunk/lib/libthr/arch/i386/i386/_umtx_op_err.S
    trunk/lib/libthr/libthr.3

Modified: trunk/lib/libthr/Makefile
===================================================================
--- trunk/lib/libthr/Makefile	2018-06-09 16:44:43 UTC (rev 10636)
+++ trunk/lib/libthr/Makefile	2018-06-09 16:46:37 UTC (rev 10637)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/lib/libthr/Makefile 313602 2017-02-11 06:35:29Z ngie $
 #
 # All library objects contain FreeBSD revision strings by default; they may be
 # excluded as a space-saving measure.  To produce a library that does
@@ -15,15 +16,15 @@
 
 LIB=thr
 SHLIB_MAJOR= 3
-WARNS?=	0
+WARNS?=	3
 CFLAGS+=-DPTHREAD_KERNEL
-CFLAGS+=-I${.CURDIR}/../libc/include -I${.CURDIR}/thread \
-	-I${.CURDIR}/../../include
+CFLAGS+=-I${SRCTOP}/lib/libc/include -I${.CURDIR}/thread \
+	-I${SRCTOP}/include
 CFLAGS+=-I${.CURDIR}/arch/${MACHINE_CPUARCH}/include
 CFLAGS+=-I${.CURDIR}/sys
-CFLAGS+=-I${.CURDIR}/../../libexec/rtld-elf
-CFLAGS+=-I${.CURDIR}/../../libexec/rtld-elf/${MACHINE_CPUARCH}
-CFLAGS+=-I${.CURDIR}/../libthread_db
+CFLAGS+=-I${SRCTOP}/libexec/rtld-elf
+CFLAGS+=-I${SRCTOP}/libexec/rtld-elf/${MACHINE_CPUARCH}
+CFLAGS+=-I${SRCTOP}/lib/libthread_db
 CFLAGS+=-Winline
 
 .ifndef NO_THREAD_UNWIND_STACK
@@ -33,14 +34,13 @@
 
 LDFLAGS+=-Wl,-znodelete
 
-VERSION_DEF=${.CURDIR}/../libc/Versions.def
+VERSION_DEF=${SRCTOP}/lib/libc/Versions.def
 SYMBOL_MAPS=${.CURDIR}/pthread.map
 
 MAN=	libthr.3
 
-# enable extra internal consistancy checks
+# enable extra internal consistency checks
 CFLAGS+=-D_PTHREADS_INVARIANTS
-#CFLAGS+=-g
 
 PRECIOUSLIB=
 
@@ -64,4 +64,8 @@
 CFLAGS+=-DSYSCALL_COMPAT
 .endif
 
+.if ${MK_TESTS} != "no"
+SUBDIR+=	tests
+.endif
+
 .include <bsd.lib.mk>

Modified: trunk/lib/libthr/arch/amd64/Makefile.inc
===================================================================
--- trunk/lib/libthr/arch/amd64/Makefile.inc	2018-06-09 16:44:43 UTC (rev 10636)
+++ trunk/lib/libthr/arch/amd64/Makefile.inc	2018-06-09 16:46:37 UTC (rev 10637)
@@ -1,3 +1,10 @@
-#$FreeBSD$
+# $MidnightBSD$
+#$FreeBSD: stable/10/lib/libthr/arch/amd64/Makefile.inc 290014 2015-10-26 16:21:56Z vangyzen $
 
 SRCS+=	pthread_md.c _umtx_op_err.S
+
+# With the current compiler and libthr code, using SSE in libthr
+# does not provide enough performance improvement to outweigh
+# the extra context switch cost.  This can measurably impact
+# performance when the application also does not use enough SSE.
+CFLAGS+=${CFLAGS_NO_SIMD}


Property changes on: trunk/lib/libthr/arch/amd64/Makefile.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libthr/arch/amd64/amd64/_umtx_op_err.S
===================================================================
--- trunk/lib/libthr/arch/amd64/amd64/_umtx_op_err.S	2018-06-09 16:44:43 UTC (rev 10636)
+++ trunk/lib/libthr/arch/amd64/amd64/_umtx_op_err.S	2018-06-09 16:46:37 UTC (rev 10637)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 2008 David Xu <davidxu at freebsd.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libthr/arch/amd64/amd64/_umtx_op_err.S 217107 2011-01-07 16:09:33Z kib $
  */
 
 #include <sys/syscall.h>


Property changes on: trunk/lib/libthr/arch/amd64/amd64/_umtx_op_err.S
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libthr/arch/amd64/amd64/pthread_md.c
===================================================================
--- trunk/lib/libthr/arch/amd64/amd64/pthread_md.c	2018-06-09 16:44:43 UTC (rev 10636)
+++ trunk/lib/libthr/arch/amd64/amd64/pthread_md.c	2018-06-09 16:46:37 UTC (rev 10637)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 2003 Daniel Eischen <deischen at freebsd.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * (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$
+ * $FreeBSD: stable/10/lib/libthr/arch/amd64/amd64/pthread_md.c 157461 2006-04-04 03:26:06Z davidxu $
  */
 
 #include <sys/types.h>

Modified: trunk/lib/libthr/arch/amd64/include/pthread_md.h
===================================================================
--- trunk/lib/libthr/arch/amd64/include/pthread_md.h	2018-06-09 16:44:43 UTC (rev 10636)
+++ trunk/lib/libthr/arch/amd64/include/pthread_md.h	2018-06-09 16:46:37 UTC (rev 10637)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 2003 David Xu <davidxu at freebsd.org>
  * Copyright (c) 2001 Daniel Eischen <deischen at freebsd.org>
@@ -24,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libthr/arch/amd64/include/pthread_md.h 228536 2011-12-15 19:42:25Z dim $
  */
 
 /*

Modified: trunk/lib/libthr/arch/i386/Makefile.inc
===================================================================
--- trunk/lib/libthr/arch/i386/Makefile.inc	2018-06-09 16:44:43 UTC (rev 10636)
+++ trunk/lib/libthr/arch/i386/Makefile.inc	2018-06-09 16:46:37 UTC (rev 10637)
@@ -1,3 +1,10 @@
-# $FreeBSD$
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libthr/arch/i386/Makefile.inc 290014 2015-10-26 16:21:56Z vangyzen $
 
 SRCS+=	pthread_md.c _umtx_op_err.S
+
+# With the current compiler and libthr code, using SSE in libthr
+# does not provide enough performance improvement to outweigh
+# the extra context switch cost.  This can measurably impact
+# performance when the application also does not use enough SSE.
+CFLAGS+=${CFLAGS_NO_SIMD}


Property changes on: trunk/lib/libthr/arch/i386/Makefile.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libthr/arch/i386/i386/_umtx_op_err.S
===================================================================
--- trunk/lib/libthr/arch/i386/i386/_umtx_op_err.S	2018-06-09 16:44:43 UTC (rev 10636)
+++ trunk/lib/libthr/arch/i386/i386/_umtx_op_err.S	2018-06-09 16:46:37 UTC (rev 10637)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 2008 David Xu <davidxu at freebsd.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libthr/arch/i386/i386/_umtx_op_err.S 217107 2011-01-07 16:09:33Z kib $
  */
 
 #include <machine/asm.h>


Property changes on: trunk/lib/libthr/arch/i386/i386/_umtx_op_err.S
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libthr/arch/i386/i386/pthread_md.c
===================================================================
--- trunk/lib/libthr/arch/i386/i386/pthread_md.c	2018-06-09 16:44:43 UTC (rev 10636)
+++ trunk/lib/libthr/arch/i386/i386/pthread_md.c	2018-06-09 16:46:37 UTC (rev 10637)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 2003 David Xu <davidxu at freebsd.org>
  * Copyright (c) 2001,2003 Daniel Eischen <deischen at freebsd.org>
@@ -24,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libthr/arch/i386/i386/pthread_md.c 157461 2006-04-04 03:26:06Z davidxu $
  */
 
 #include <sys/types.h>

Modified: trunk/lib/libthr/arch/i386/include/pthread_md.h
===================================================================
--- trunk/lib/libthr/arch/i386/include/pthread_md.h	2018-06-09 16:44:43 UTC (rev 10636)
+++ trunk/lib/libthr/arch/i386/include/pthread_md.h	2018-06-09 16:46:37 UTC (rev 10637)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2002 Daniel Eischen <deischen at freebsd.org>.
  * Copyright (c) 2005 David Xu <davidxu at freebsd.org>.
@@ -24,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/lib/libthr/arch/i386/include/pthread_md.h 228536 2011-12-15 19:42:25Z dim $
  */
 
 /*

Modified: trunk/lib/libthr/libthr.3
===================================================================
--- trunk/lib/libthr/libthr.3	2018-06-09 16:44:43 UTC (rev 10636)
+++ trunk/lib/libthr/libthr.3	2018-06-09 16:46:37 UTC (rev 10637)
@@ -1,6 +1,12 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 2005 Robert N. M. Watson
+.\" Copyright (c) 2014,2015 The FreeBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
+.\" Part of this documentation was written by
+.\" Konstantin Belousov <kib at FreeBSD.org> under sponsorship
+.\" from the FreeBSD Foundation.
+.\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
 .\" are met:
@@ -22,9 +28,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libthr/libthr.3 302010 2016-06-18 13:42:33Z jilles $
 .\"
-.Dd October 19, 2007
+.Dd February 12, 2015
 .Dt LIBTHR 3
 .Os
 .Sh NAME
@@ -42,11 +48,203 @@
 library interfaces for application threading.
 It
 has been optimized for use by applications expecting system scope thread
-semantics, and can provide significant performance improvements
-compared to
-.Lb libkse .
+semantics.
+.Pp
+The library is tightly integrated with the run-time link editor
+.Xr ld-elf.so.1 1
+and
+.Lb libc ;
+all three components must be built from the same source tree.
+Mixing
+.Li libc
+and
+.Nm
+libraries from different versions of
+.Fx
+is not supported.
+The run-time linker
+.Xr ld-elf.so.1 1
+has some code to ensure backward-compatibility with older versions of
+.Nm .
+.Pp
+The man page documents the quirks and tunables of the
+.Nm .
+When linking with
+.Li -lpthread ,
+the run-time dependency
+.Li libthr.so.3
+is recorded in the produced object.
+.Sh MUTEX ACQUISITION
+A locked mutex (see
+.Xr pthread_mutex_lock 3 )
+is represented by a volatile variable of type
+.Dv lwpid_t ,
+which records the global system identifier of the thread
+owning the lock.
+.Nm
+performs a contested mutex acquisition in three stages, each of which
+is more resource-consuming than the previous.
+The first two stages are only applied for a mutex of
+.Dv PTHREAD_MUTEX_ADAPTIVE_NP
+type and
+.Dv PTHREAD_PRIO_NONE
+protocol (see
+.Xr pthread_mutexattr 3 ) .
+.Pp
+First, on SMP systems, a spin loop
+is performed, where the library attempts to acquire the lock by
+.Xr atomic 9
+operations.
+The loop count is controlled by the
+.Ev LIBPTHREAD_SPINLOOPS
+environment variable, with a default value of 2000.
+.Pp
+If the spin loop
+was unable to acquire the mutex, a yield loop
+is executed, performing the same
+.Xr atomic 9
+acquisition attempts as the spin loop,
+but each attempt is followed by a yield of the CPU time
+of the thread using the
+.Xr sched_yield 2
+syscall.
+By default, the yield loop
+is not executed.
+This is controlled by the
+.Ev LIBPTHREAD_YIELDLOOPS
+environment variable.
+.Pp
+If both the spin and yield loops
+failed to acquire the lock, the thread is taken off the CPU and
+put to sleep in the kernel with the
+.Xr umtx 2
+syscall.
+The kernel wakes up a thread and hands the ownership of the lock to
+the woken thread when the lock becomes available.
+.Sh THREAD STACKS
+Each thread is provided with a private user-mode stack area
+used by the C runtime.
+The size of the main (initial) thread stack is set by the kernel, and is
+controlled by the
+.Dv RLIMIT_STACK
+process resource limit (see
+.Xr getrlimit 2 ) .
+.Pp
+By default, the main thread's stack size is equal to the value of
+.Dv RLIMIT_STACK
+for the process.
+If the
+.Ev LIBPTHREAD_SPLITSTACK_MAIN
+environment variable is present in the process environment
+(its value does not matter),
+the main thread's stack is reduced to 4MB on 64bit architectures, and to
+2MB on 32bit architectures, when the threading library is initialized.
+The rest of the address space area which has been reserved by the
+kernel for the initial process stack is used for non-initial thread stacks
+in this case.
+The presence of the
+.Ev LIBPTHREAD_BIGSTACK_MAIN
+environment variable overrides
+.Ev LIBPTHREAD_SPLITSTACK_MAIN ;
+it is kept for backward-compatibility.
+.Pp
+The size of stacks for threads created by the process at run-time
+with the
+.Xr pthread_create 3
+call is controlled by thread attributes: see
+.Xr pthread_attr 3 ,
+in particular, the
+.Xr pthread_attr_setstacksize 3 ,
+.Xr pthread_attr_setguardsize 3
+and
+.Xr pthread_attr_setstackaddr 3
+functions.
+If no attributes for the thread stack size are specified, the default
+non-initial thread stack size is 2MB for 64bit architectures, and 1MB
+for 32bit architectures.
+.Sh RUN-TIME SETTINGS
+The following environment variables are recognized by
+.Nm
+and adjust the operation of the library at run-time:
+.Bl -tag -width LIBPTHREAD_SPLITSTACK_MAIN
+.It Ev LIBPTHREAD_BIGSTACK_MAIN
+Disables the reduction of the initial thread stack enabled by
+.Ev LIBPTHREAD_SPLITSTACK_MAIN .
+.It Ev LIBPTHREAD_SPLITSTACK_MAIN
+Causes a reduction of the initial thread stack, as described in the
+section
+.Sx THREAD STACKS .
+This was the default behaviour of
+.Nm
+before
+.Fx 11.0 .
+.It Ev LIBPTHREAD_SPINLOOPS
+The integer value of the variable overrides the default count of
+iterations in the
+.Li spin loop
+of the mutex acquisition.
+The default count is 2000, set by the
+.Dv MUTEX_ADAPTIVE_SPINS
+constant in the
+.Nm
+sources.
+.It Ev LIBPTHREAD_YIELDLOOPS
+A non-zero integer value enables the yield loop
+in the process of the mutex acquisition.
+The value is the count of loop operations.
+.It Ev LIBPTHREAD_QUEUE_FIFO
+The integer value of the variable specifies how often blocked
+threads are inserted at the head of the sleep queue, instead of its tail.
+Bigger values reduce the frequency of the FIFO discipline.
+The value must be between 0 and 255.
+.El
+.Sh INTERACTION WITH RUN-TIME LINKER
+On load,
+.Nm
+installs interposing handlers into the hooks exported by
+.Li libc .
+The interposers provide real locking implementation instead of the
+stubs for single-threaded processes in
+.Li ,
+cancellation support and some modifications to the signal operations.
+.Pp
+.Nm
+cannot be unloaded; the
+.Xr dlclose 3
+function does not perform any action when called with a handle for
+.Nm .
+One of the reasons is that the internal interposing of
+.Li libc
+functions cannot be undone.
+.Sh SIGNALS
+The implementation interposes the user-installed
+.Xr signal 3
+handlers.
+This interposing is done to postpone signal delivery to threads which
+entered (libthr-internal) critical sections, where the calling
+of the user-provided signal handler is unsafe.
+An example of such a situation is owning the internal library lock.
+When a signal is delivered while the signal handler cannot be safely
+called, the call is postponed and performed until after the exit from
+the critical section.
+This should be taken into account when interpreting
+.Xr ktrace 1
+logs.
 .Sh SEE ALSO
-.Xr pthread 3
+.Xr ktrace 1 ,
+.Xr ld-elf.so.1 1 ,
+.Xr getrlimit 2 ,
+.Xr umtx 2 ,
+.Xr dlclose 3 ,
+.Xr dlopen 3 ,
+.Xr errno 3 ,
+.Xr getenv 3 ,
+.Xr libc 3 ,
+.Xr pthread_attr 3 ,
+.Xr pthread_attr_setstacksize 3 ,
+.Xr pthread_create 3 ,
+.Xr signal 3 ,
+.Xr atomic 9
 .Sh AUTHORS
 .An -nosplit
 The


Property changes on: trunk/lib/libthr/libthr.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property


More information about the Midnightbsd-cvs mailing list