Source-Changes-HG archive

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

[src/trunk]: src Realtime signal support from GSoC 2016, Charles Cui.



details:   https://anonhg.NetBSD.org/src/rev/aaf2bd556b02
branches:  trunk
changeset: 346812:aaf2bd556b02
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Aug 04 06:43:43 2016 +0000

description:
Realtime signal support from GSoC 2016, Charles Cui.

diffstat:

 include/limits.h                |    4 +-
 lib/libc/gen/sysconf.c          |    8 ++-
 sys/kern/kern_sig.c             |   76 +++++++++++++++++----------
 sys/kern/sys_sig.c              |    6 +-
 sys/sys/signal.h                |    8 +-
 sys/sys/signalvar.h             |    4 +-
 sys/sys/unistd.h                |    4 +-
 tests/lib/libc/sys/t_sigqueue.c |  108 +++++++++++++++++++++++++++++++++++++++-
 8 files changed, 174 insertions(+), 44 deletions(-)

diffs (truncated from 488 to 300 lines):

diff -r 07f0407c3256 -r aaf2bd556b02 include/limits.h
--- a/include/limits.h  Thu Aug 04 06:13:15 2016 +0000
+++ b/include/limits.h  Thu Aug 04 06:43:43 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: limits.h,v 1.39 2016/07/21 16:01:58 njoly Exp $        */
+/*     $NetBSD: limits.h,v 1.40 2016/08/04 06:43:43 christos Exp $     */
 
 /*
  * Copyright (c) 1988, 1993
@@ -94,6 +94,8 @@
 
 #define        _POSIX_TIMER_MAX        32
 #define        _POSIX_SEM_NSEMS_MAX    256
+#define        _POSIX_SIGQUEUE_MAX     32
+#define        _POSIX_REALTIME_SIGNALS 200112L
 #define        _POSIX_DELAYTIMER_MAX   32
 #define        _POSIX_TTY_NAME_MAX     9
 #define        _POSIX_TZNAME_MAX       6
diff -r 07f0407c3256 -r aaf2bd556b02 lib/libc/gen/sysconf.c
--- a/lib/libc/gen/sysconf.c    Thu Aug 04 06:13:15 2016 +0000
+++ b/lib/libc/gen/sysconf.c    Thu Aug 04 06:43:43 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysconf.c,v 1.40 2016/07/03 14:24:58 christos Exp $    */
+/*     $NetBSD: sysconf.c,v 1.41 2016/08/04 06:43:43 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.40 2016/07/03 14:24:58 christos Exp $");
+__RCSID("$NetBSD: sysconf.c,v 1.41 2016/08/04 06:43:43 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -429,6 +429,10 @@
                return _POSIX_THREAD_CPUTIME;
        case _SC_DELAYTIMER_MAX:
                return _POSIX_DELAYTIMER_MAX;
+       case _SC_SIGQUEUE_MAX:
+               return _POSIX_SIGQUEUE_MAX;
+       case _SC_REALTIME_SIGNALS:
+               return 200112L;
        default:
                errno = EINVAL;
                return (-1);
diff -r 07f0407c3256 -r aaf2bd556b02 sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Thu Aug 04 06:13:15 2016 +0000
+++ b/sys/kern/kern_sig.c       Thu Aug 04 06:43:43 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.327 2016/04/28 00:37:39 christos Exp $  */
+/*     $NetBSD: kern_sig.c,v 1.328 2016/08/04 06:43:43 christos Exp $  */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.327 2016/04/28 00:37:39 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.328 2016/08/04 06:43:43 christos Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -106,6 +106,7 @@
 
 #include <uvm/uvm_extern.h>
 
+#define        SIGQUEUE_MAX    32
 static pool_cache_t    sigacts_cache   __read_mostly;
 static pool_cache_t    ksiginfo_cache  __read_mostly;
 static callout_t       proc_stop_ch    __cacheline_aligned;
@@ -118,7 +119,7 @@
 static void    proc_stop_callout(void *);
 static int     sigchecktrace(void);
 static int     sigpost(struct lwp *, sig_t, int, int);
-static void    sigput(sigpend_t *, struct proc *, ksiginfo_t *);
+static int     sigput(sigpend_t *, struct proc *, ksiginfo_t *);
 static int     sigunwait(struct proc *, const ksiginfo_t *);
 static void    sigswitch(bool, int, int);
 
@@ -523,7 +524,7 @@
        }
 }
 
-static bool
+static int
 siggetinfo(sigpend_t *sp, ksiginfo_t *out, int signo)
 {
        ksiginfo_t *ksi;
@@ -532,9 +533,12 @@
                goto out;
 
        /* Find siginfo and copy it out. */
+       int count = 0;
        TAILQ_FOREACH(ksi, &sp->sp_info, ksi_list) {
                if (ksi->ksi_signo != signo)
                        continue;
+               if (count++ > 0) /* Only remove the first, count all of them */
+                       continue; 
                TAILQ_REMOVE(&sp->sp_info, ksi, ksi_list);
                KASSERT((ksi->ksi_flags & KSI_FROMPOOL) != 0);
                KASSERT((ksi->ksi_flags & KSI_QUEUED) != 0);
@@ -543,9 +547,10 @@
                        memcpy(out, ksi, sizeof(*out));
                        out->ksi_flags &= ~(KSI_FROMPOOL | KSI_QUEUED);
                }
-               ksiginfo_free(ksi);     /* XXXSMP */
-               return true;
+               ksiginfo_free(ksi);
        }
+       if (count)
+               return count;
 
 out:
        /* If there is no siginfo, then manufacture it. */
@@ -554,7 +559,7 @@
                out->ksi_info._signo = signo;
                out->ksi_info._code = SI_NOINFO;
        }
-       return false;
+       return 0;
 }
 
 /*
@@ -568,6 +573,7 @@
 sigget(sigpend_t *sp, ksiginfo_t *out, int signo, const sigset_t *mask)
 {
        sigset_t tset;
+       int count;
 
        /* If there's no pending set, the signal is from the debugger. */
        if (sp == NULL)
@@ -590,7 +596,9 @@
 
        sigdelset(&sp->sp_set, signo);
 out:
-       (void)siggetinfo(sp, out, signo);
+       count = siggetinfo(sp, out, signo);
+       if (count > 1)
+               sigaddset(&sp->sp_set, signo);
        return signo;
 }
 
@@ -599,7 +607,7 @@
  *
  *     Append a new ksiginfo element to the list of pending ksiginfo's.
  */
-static void
+static int
 sigput(sigpend_t *sp, struct proc *p, ksiginfo_t *ksi)
 {
        ksiginfo_t *kp;
@@ -613,25 +621,33 @@
         * If there is no siginfo, we are done.
         */
        if (KSI_EMPTY_P(ksi))
-               return;
+               return 0;
 
        KASSERT((ksi->ksi_flags & KSI_FROMPOOL) != 0);
 
-#ifdef notyet  /* XXX: QUEUING */
-       if (ksi->ksi_signo < SIGRTMIN)
-#endif
-       {
-               TAILQ_FOREACH(kp, &sp->sp_info, ksi_list) {
-                       if (kp->ksi_signo == ksi->ksi_signo) {
-                               KSI_COPY(ksi, kp);
-                               kp->ksi_flags |= KSI_QUEUED;
-                               return;
-                       }
+       size_t count = 0;
+       TAILQ_FOREACH(kp, &sp->sp_info, ksi_list) {
+               count++;
+               if (ksi->ksi_signo >= SIGRTMIN && ksi->ksi_signo <= SIGRTMAX)
+                       continue;
+               if (kp->ksi_signo == ksi->ksi_signo) {
+                       KSI_COPY(ksi, kp);
+                       kp->ksi_flags |= KSI_QUEUED;
+                       return 0;
                }
        }
-
+       
+       if (count >= SIGQUEUE_MAX) {
+#ifdef DIAGNOSTIC
+               printf("%s(%d): Signal queue is full signal=%d\n",
+                   p->p_comm, p->p_pid, ksi->ksi_signo);
+#endif
+               return EAGAIN;
+       }
        ksi->ksi_flags |= KSI_QUEUED;
        TAILQ_INSERT_TAIL(&sp->sp_info, ksi, ksi_list);
+       
+       return 0;
 }
 
 /*
@@ -1195,7 +1211,7 @@
  *
  * Other ignored signals are discarded immediately.
  */
-void
+int
 kpsignal2(struct proc *p, ksiginfo_t *ksi)
 {
        int prop, signo = ksi->ksi_signo;
@@ -1205,6 +1221,7 @@
        lwpid_t lid;
        sig_t action;
        bool toall;
+       int error = 0;
 
        KASSERT(!cpu_intr_p());
        KASSERT(mutex_owned(proc_lock));
@@ -1217,7 +1234,7 @@
         * exiting, then just drop the signal here and bail out.
         */
        if (p->p_stat != SACTIVE && p->p_stat != SSTOP)
-               return;
+               return 0;
 
        /*
         * Notify any interested parties of the signal.
@@ -1245,7 +1262,8 @@
                         */
                        if ((kp = ksiginfo_alloc(p, ksi, PR_NOWAIT)) == NULL)
                                goto discard;
-                       sigput(&p->p_sigpend, p, kp);
+                       if ((error = sigput(&p->p_sigpend, p, kp)) != 0)
+                               goto out;
                }
        } else {
                /*
@@ -1329,7 +1347,8 @@
        if (lid != 0) {
                l = lwp_find(p, lid);
                if (l != NULL) {
-                       sigput(&l->l_sigpend, p, kp);
+                       if ((error = sigput(&l->l_sigpend, p, kp)) != 0)
+                               goto out;
                        membar_producer();
                        (void)sigpost(l, action, prop, kp->ksi_signo);
                }
@@ -1401,8 +1420,8 @@
         * Make signal pending.
         */
        KASSERT((p->p_slflag & PSL_TRACED) == 0);
-       sigput(&p->p_sigpend, p, kp);
-
+       if ((error = sigput(&p->p_sigpend, p, kp)) != 0)
+               goto out;
 deliver:
        /*
         * Before we set LW_PENDSIG on any LWP, ensure that the signal is
@@ -1426,9 +1445,10 @@
         */
        ksiginfo_free(kp);
        if (signo == -1)
-               return;
+               return error;
 discard:
        SDT_PROBE(proc, kernel, , signal__discard, l, p, signo, 0, 0);
+       return error;
 }
 
 void
diff -r 07f0407c3256 -r aaf2bd556b02 sys/kern/sys_sig.c
--- a/sys/kern/sys_sig.c        Thu Aug 04 06:13:15 2016 +0000
+++ b/sys/kern/sys_sig.c        Thu Aug 04 06:43:43 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_sig.c,v 1.45 2015/10/02 16:54:15 christos Exp $    */
+/*     $NetBSD: sys_sig.c,v 1.46 2016/08/04 06:43:43 christos Exp $    */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.45 2015/10/02 16:54:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.46 2016/08/04 06:43:43 christos Exp $");
 
 #include "opt_dtrace.h"
 
@@ -258,7 +258,7 @@
                    KAUTH_PROCESS_SIGNAL, p, KAUTH_ARG(ksi->ksi_signo),
                    NULL, NULL);
                if (!error && ksi->ksi_signo) {
-                       kpsignal2(p, ksi);
+                       error = kpsignal2(p, ksi);
                }
                mutex_exit(p->p_lock);
                mutex_exit(proc_lock);
diff -r 07f0407c3256 -r aaf2bd556b02 sys/sys/signal.h
--- a/sys/sys/signal.h  Thu Aug 04 06:13:15 2016 +0000
+++ b/sys/sys/signal.h  Thu Aug 04 06:43:43 2016 +0000
@@ -1,4 +1,4 @@



Home | Main Index | Thread Index | Old Index