Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src GSoC 2016 Charles Cui: Implement thread priority protection ...



details:   https://anonhg.NetBSD.org/src/rev/d12af934ab86
branches:  trunk
changeset: 346248:d12af934ab86
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jul 03 14:24:58 2016 +0000

description:
GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).

diffstat:

 lib/libc/gen/sysconf.3               |    4 +-
 lib/libc/gen/sysconf.c               |    7 +-
 lib/libc/sys/Makefile.inc            |    4 +-
 lib/libpthread/Makefile              |   18 ++-
 lib/libpthread/pthread.h             |   46 +++++-
 lib/libpthread/pthread_barrier.3     |   60 ++++++++-
 lib/libpthread/pthread_barrier.c     |   27 +++-
 lib/libpthread/pthread_barrierattr.3 |   42 +++++-
 lib/libpthread/pthread_cond.c        |   38 +++++-
 lib/libpthread/pthread_condattr.3    |   62 ++++++++-
 lib/libpthread/pthread_mutex.3       |   88 +++++++++++-
 lib/libpthread/pthread_mutex.c       |  197 +++++++++++++++++++++++++-
 lib/libpthread/pthread_mutexattr.3   |  171 +++++++++++++++-------
 lib/libpthread/pthread_rwlock.c      |   27 +++-
 lib/libpthread/pthread_rwlockattr.3  |   51 +++++-
 lib/libpthread/pthread_types.h       |    4 +-
 sys/kern/kern_lwp.c                  |    6 +-
 sys/kern/kern_sleepq.c               |    5 +-
 sys/kern/kern_synch.c                |    6 +-
 sys/kern/sys_sched.c                 |   66 ++++++++-
 sys/kern/syscalls.master             |    4 +-
 sys/sys/lwp.h                        |   10 +-
 sys/sys/sched.h                      |    3 +-
 sys/sys/unistd.h                     |    4 +-
 tests/lib/libpthread/t_cond.c        |   25 +++-
 tests/lib/libpthread/t_mutex.c       |  252 ++++++++++++++++++++++++++++++++++-
 26 files changed, 1097 insertions(+), 130 deletions(-)

diffs (truncated from 2075 to 300 lines):

diff -r 97c0f3ad2509 -r d12af934ab86 lib/libc/gen/sysconf.3
--- a/lib/libc/gen/sysconf.3    Sun Jul 03 12:27:04 2016 +0000
+++ b/lib/libc/gen/sysconf.3    Sun Jul 03 14:24:58 2016 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sysconf.3,v 1.48 2016/06/10 23:29:20 christos Exp $
+.\"    $NetBSD: sysconf.3,v 1.49 2016/07/03 14:24:58 christos Exp $
 .\"
 .\" Copyright (c) 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -178,6 +178,8 @@
 Threads
 option to which the system attempts to conform,
 otherwise \-1.
+.It Li _SC_THREAD_PRIO_PROTECT
+System supports the priority ceiling protocol for POSIX threads.
 .It Li _SC_TIMERS
 The version of
 .St -p1003.1
diff -r 97c0f3ad2509 -r d12af934ab86 lib/libc/gen/sysconf.c
--- a/lib/libc/gen/sysconf.c    Sun Jul 03 12:27:04 2016 +0000
+++ b/lib/libc/gen/sysconf.c    Sun Jul 03 14:24:58 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysconf.c,v 1.39 2016/06/10 23:29:20 christos Exp $    */
+/*     $NetBSD: sysconf.c,v 1.40 2016/07/03 14:24:58 christos Exp $    */
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)sysconf.c  8.2 (Berkeley) 3/20/94";
 #else
-__RCSID("$NetBSD: sysconf.c,v 1.39 2016/06/10 23:29:20 christos Exp $");
+__RCSID("$NetBSD: sysconf.c,v 1.40 2016/07/03 14:24:58 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -411,9 +411,10 @@
                return _POSIX_THREAD_ATTR_STACKSIZE;
        case _SC_THREAD_SAFE_FUNCTIONS:
                return _POSIX_THREAD_SAFE_FUNCTIONS;
+       case _SC_THREAD_PRIO_PROTECT:
+               return _POSIX_THREAD_PRIO_PROTECT;
        case _SC_THREAD_PRIORITY_SCHEDULING:
        case _SC_THREAD_PRIO_INHERIT:
-       case _SC_THREAD_PRIO_PROTECT:
        case _SC_THREAD_PROCESS_SHARED:
                return -1;
        case _SC_TTY_NAME_MAX:
diff -r 97c0f3ad2509 -r d12af934ab86 lib/libc/sys/Makefile.inc
--- a/lib/libc/sys/Makefile.inc Sun Jul 03 12:27:04 2016 +0000
+++ b/lib/libc/sys/Makefile.inc Sun Jul 03 14:24:58 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.230 2016/04/23 23:11:31 christos Exp $
+#      $NetBSD: Makefile.inc,v 1.231 2016/07/03 14:24:58 christos Exp $
 #      @(#)Makefile.inc        8.3 (Berkeley) 10/24/94
 
 # sys sources
@@ -173,7 +173,7 @@
        msgrcv.S msgsnd.S __msync13.S  __nanosleep50.S open.S poll.S \
        __pollts50.S __pselect50.S read.S readlink.S \
        readv.S _sched_setparam.S _sched_getparam.S _sched_setaffinity.S \
-       _sched_getaffinity.S sched_yield.S \
+       _sched_getaffinity.S sched_yield.S _sched_protect.S \
        __select50.S setcontext.S __sigprocmask14.S __sigsuspend14.S sysarch.S \
        __wait450.S wait6.S write.S writev.S
 
diff -r 97c0f3ad2509 -r d12af934ab86 lib/libpthread/Makefile
--- a/lib/libpthread/Makefile   Sun Jul 03 12:27:04 2016 +0000
+++ b/lib/libpthread/Makefile   Sun Jul 03 14:24:58 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.86 2016/04/23 23:12:19 christos Exp $
+#      $NetBSD: Makefile,v 1.87 2016/07/03 14:24:58 christos Exp $
 #
 
 WARNS?=        5
@@ -177,6 +177,8 @@
 
 MLINKS+=       pthread_barrierattr.3 pthread_barrierattr_init.3
 MLINKS+=       pthread_barrierattr.3 pthread_barrierattr_destroy.3
+MLINKS+=       pthread_barrierattr.3 pthread_barrierattr_getpshared.3
+MLINKS+=       pthread_barrierattr.3 pthread_barrierattr_setpshared.3
 
 MLINKS+=       pthread_cond.3 pthread_cond_init.3
 MLINKS+=       pthread_cond.3 pthread_cond_destroy.3
@@ -188,6 +190,9 @@
 MLINKS+=       pthread_condattr.3 pthread_condattr_init.3
 MLINKS+=       pthread_condattr.3 pthread_condattr_destroy.3
 MLINKS+=       pthread_condattr.3 pthread_condattr_setclock.3
+MLINKS+=       pthread_condattr.3 pthread_condattr_getclock.3
+MLINKS+=       pthread_condattr.3 pthread_condattr_getpshared.3
+MLINKS+=       pthread_condattr.3 pthread_condattr_setpshared.3
 
 MLINKS+=       pthread_getname_np.3 pthread_setname_np.3
 MLINKS+=       pthread_getspecific.3 pthread_setspecific.3
@@ -198,11 +203,20 @@
 MLINKS+=       pthread_mutex.3 pthread_mutex_lock.3
 MLINKS+=       pthread_mutex.3 pthread_mutex_trylock.3
 MLINKS+=       pthread_mutex.3 pthread_mutex_unlock.3
+MLINKS+=       pthread_mutex.3 pthread_mutex_timedlock.3
+MLINKS+=       pthread_mutex.3 pthread_mutex_getprioceiling.3
+MLINKS+=       pthread_mutex.3 pthread_mutex_setprioceiling.3 
 
 MLINKS+=       pthread_mutexattr.3 pthread_mutexattr_init.3
 MLINKS+=       pthread_mutexattr.3 pthread_mutexattr_destroy.3
+MLINKS+=       pthread_mutexattr.3 pthread_mutexattr_getpshared.3
+MLINKS+=       pthread_mutexattr.3 pthread_mutexattr_setpshared.3
 MLINKS+=       pthread_mutexattr.3 pthread_mutexattr_settype.3
 MLINKS+=       pthread_mutexattr.3 pthread_mutexattr_gettype.3
+MLINKS+=       pthread_mutexattr.3 pthread_mutexattr_getprotocol.3
+MLINKS+=       pthread_mutexattr.3 pthread_mutexattr_setprotocol.3
+MLINKS+=       pthread_mutexattr.3 pthread_mutexattr_getprioceiling.3
+MLINKS+=       pthread_mutexattr.3 pthread_mutexattr_setprioceiling.3  
 
 MLINKS+=       pthread_rwlock.3 pthread_rwlock_init.3
 MLINKS+=       pthread_rwlock.3 pthread_rwlock_destroy.3
@@ -217,6 +231,8 @@
 
 MLINKS+=       pthread_rwlockattr.3 pthread_rwlockattr_init.3
 MLINKS+=       pthread_rwlockattr.3 pthread_rwlockattr_destroy.3
+MLINKS+=       pthread_rwlockattr.3 pthread_rwlockattr_getpshared.3
+MLINKS+=       pthread_rwlockattr.3 pthread_rwlockattr_setpshared.3
 
 MLINKS+=       pthread_spin.3 pthread_spin_init.3
 MLINKS+=       pthread_spin.3 pthread_spin_destroy.3
diff -r 97c0f3ad2509 -r d12af934ab86 lib/libpthread/pthread.h
--- a/lib/libpthread/pthread.h  Sun Jul 03 12:27:04 2016 +0000
+++ b/lib/libpthread/pthread.h  Sun Jul 03 14:24:58 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread.h,v 1.36 2016/04/23 23:12:19 christos Exp $    */
+/*     $NetBSD: pthread.h,v 1.37 2016/07/03 14:24:58 christos Exp $    */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -94,12 +94,30 @@
 int    pthread_mutex_lock(pthread_mutex_t *);
 int    pthread_mutex_trylock(pthread_mutex_t *);
 int    pthread_mutex_unlock(pthread_mutex_t *);
+int    pthread_mutex_timedlock(pthread_mutex_t *,
+           const struct timespec * __restrict);
+int    pthread_mutex_getprioceiling(const pthread_mutex_t * __restrict,
+           int * __restrict);
+int    pthread_mutex_setprioceiling(pthread_mutex_t * __restrict, int,
+           int * __restrict);
 int    pthread_mutexattr_init(pthread_mutexattr_t *);
 int    pthread_mutexattr_destroy(pthread_mutexattr_t *);
+#ifdef _PTHREAD_PSHARED
+int    pthread_mutexattr_getpshared(const pthread_mutexattr_t * __restrict,
+           int * __restrict);
+int    pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
+#endif
 int    pthread_mutexattr_gettype(const pthread_mutexattr_t * __restrict,
            int * __restrict);
 int    pthread_mutexattr_settype(pthread_mutexattr_t *attr, int);
-
+int    pthread_mutexattr_getprotocol(const pthread_mutexattr_t * __restrict,
+           int * __restrict);
+int    pthread_mutexattr_setprotocol(pthread_mutexattr_t*,
+           int);
+int    pthread_mutexattr_getprioceiling(const pthread_mutexattr_t * __restrict,
+           int * __restrict);
+int    pthread_mutexattr_setprioceiling(pthread_mutexattr_t *,
+           int);
 int    pthread_cond_init(pthread_cond_t * __restrict,
            const pthread_condattr_t * __restrict);
 int    pthread_cond_destroy(pthread_cond_t *);
@@ -114,9 +132,15 @@
 int    pthread_condattr_init(pthread_condattr_t *);
 #if defined(_NETBSD_SOURCE)
 int     pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
+int    pthread_condattr_getclock(const pthread_condattr_t * __restrict,
+           clockid_t * __restrict);
 #endif
 int    pthread_condattr_destroy(pthread_condattr_t *);
-
+#ifdef _PTHREAD_PSHARED
+int    pthread_condattr_getpshared(const pthread_condattr_t * __restrict,
+           int * __restrict);
+int    pthread_condattr_setpshared(pthread_condattr_t *, int);
+#endif
 int    pthread_once(pthread_once_t *, void (*)(void));
 
 int    pthread_key_create(pthread_key_t *, void (*)(void *));
@@ -178,14 +202,22 @@
 int    pthread_rwlock_unlock(pthread_rwlock_t *);
 int    pthread_rwlockattr_init(pthread_rwlockattr_t *);
 int    pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
-
+#ifdef _PTHREAD_PSHARED
+int    pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * __restrict,
+           int * __restrict);
+int    pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
+#endif
 int    pthread_barrier_init(pthread_barrier_t * __restrict,
            const pthread_barrierattr_t * __restrict, unsigned int);
 int    pthread_barrier_wait(pthread_barrier_t *);
 int    pthread_barrier_destroy(pthread_barrier_t *);
 int    pthread_barrierattr_init(pthread_barrierattr_t *);
 int    pthread_barrierattr_destroy(pthread_barrierattr_t *);
-
+#ifdef _PTHREAD_PSHARED
+int    pthread_barrierattr_getpshared(const pthread_barrierattr_t * __restrict,
+    int * __restrict);
+int    pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
+#endif
 int    pthread_getschedparam(pthread_t, int * __restrict,
            struct sched_param * __restrict);
 int    pthread_setschedparam(pthread_t, int, const struct sched_param *);
@@ -251,6 +283,10 @@
 #define        PTHREAD_MUTEX_RECURSIVE         2
 #define        PTHREAD_MUTEX_DEFAULT           PTHREAD_MUTEX_NORMAL
 
+#define        PTHREAD_PRIO_NONE               0
+#define        PTHREAD_PRIO_INHERIT            1
+#define        PTHREAD_PRIO_PROTECT            2
+
 #define PTHREAD_COND_INITIALIZER       _PTHREAD_COND_INITIALIZER
 #define PTHREAD_MUTEX_INITIALIZER      _PTHREAD_MUTEX_INITIALIZER
 #define PTHREAD_ONCE_INIT              _PTHREAD_ONCE_INIT
diff -r 97c0f3ad2509 -r d12af934ab86 lib/libpthread/pthread_barrier.3
--- a/lib/libpthread/pthread_barrier.3  Sun Jul 03 12:27:04 2016 +0000
+++ b/lib/libpthread/pthread_barrier.3  Sun Jul 03 14:24:58 2016 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_barrier.3,v 1.4 2010/07/09 18:07:20 jruoho Exp $
+.\" $NetBSD: pthread_barrier.3,v 1.5 2016/07/03 14:24:58 christos Exp $
 .\"
 .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -25,7 +25,8 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\" ----------------------------------------------------------------------------
-.Dd July 8, 2010
+
+.Dd June 12, 2016
 .Dt PTHREAD_BARRIER 3
 .Os
 .Sh NAME
@@ -42,7 +43,14 @@
 .Fn pthread_barrier_destroy "pthread_barrier_t *barrier"
 .Ft int
 .Fn pthread_barrier_wait "pthread_barrier_t *barrier"
+.Ft int
+.Fn pthread_barrierattr_getpshared "const pthread_barrierattr_t * __restrict attr" \
+"int * __restrict pshared"
+.Ft int
+.Fn pthread_barrierattr_setpshared "pthread_barrierattr_t * attr" \
+"int pshared" 
 .\" ----------------------------------------------------------------------------
+
 .Sh DESCRIPTION
 The
 .Fn pthread_barrier_init
@@ -87,7 +95,18 @@
 all threads will wake up, return from their respective
 .Fn pthread_barrier_wait
 calls and continue execution.
+.Pp
+.\" -----
+The
+.Fn pthread_barrierattr_getpshared 
+function shall obtain the value of the process-shared attribute from the
+attributes object referenced by attr. 
+The
+.Fn pthread_barrierattr_setpshared
+function shall set the process-shared attribute in an initialized attributes
+object referenced by attr. 
 .\" ----------------------------------------------------------------------------
+
 .Sh RETURN VALUES
 If successful,
 .Fn pthread_barrier_init
@@ -113,7 +132,23 @@
 and atomicity of any updates to shared data with respect to the
 other threads participating in the barrier.
 In the case of failure, an error value will be returned.
+.Pp
+.\" -----
+If successful,
+.Fn pthread_barrierattr_getpshared
+shall return zero and store the value of the process-shared attribute of attr 
+into the object referenced by the
+.Fa pshared
+parameter.
+Otherwise, an error number shall be returned to indicate the error.
+.Pp
+.\" -----
+If successful,
+.Fn pthread_barrierattr_setpshared
+shall return zero;
+Otherwise, an error number shall be returned to indicate the error. 
 .\" ----------------------------------------------------------------------------
+
 .Sh ERRORS
 The
 .Fn pthread_barrier_init
@@ -152,6 +187,20 @@
 .Fa barrier
 is invalid.
 .El
+.Pp



Home | Main Index | Thread Index | Old Index