Source-Changes-HG archive

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

[src/trunk]: src/sys Simplify pset locking, making it easier to sync with LWP...



details:   https://anonhg.NetBSD.org/src/rev/646b7639ecf7
branches:  trunk
changeset: 461273:646b7639ecf7
user:      ad <ad%NetBSD.org@localhost>
date:      Thu Nov 21 17:54:04 2019 +0000

description:
Simplify pset locking, making it easier to sync with LWP creation, etc.

diffstat:

 sys/kern/sys_pset.c |  37 +++++++++----------------------------
 sys/sys/pset.h      |   5 +----
 2 files changed, 10 insertions(+), 32 deletions(-)

diffs (146 lines):

diff -r 60bf0fd90459 -r 646b7639ecf7 sys/kern/sys_pset.c
--- a/sys/kern/sys_pset.c       Thu Nov 21 17:50:49 2019 +0000
+++ b/sys/kern/sys_pset.c       Thu Nov 21 17:54:04 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_pset.c,v 1.21 2018/12/09 23:05:02 mlelstv Exp $    */
+/*     $NetBSD: sys_pset.c,v 1.22 2019/11/21 17:54:04 ad Exp $ */
 
 /*
  * Copyright (c) 2008, Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_pset.c,v 1.21 2018/12/09 23:05:02 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pset.c,v 1.22 2019/11/21 17:54:04 ad Exp $");
 
 #include <sys/param.h>
 
@@ -156,8 +156,6 @@
                return EINVAL;
        if (psets[psid - 1] == NULL)
                return EINVAL;
-       if (psets[psid - 1]->ps_flags & PSET_BUSY)
-               return EBUSY;
 
        return 0;
 }
@@ -204,7 +202,6 @@
 kern_pset_destroy(psetid_t psid)
 {
        struct cpu_info *ci;
-       pset_info_t *pi;
        struct lwp *l;
        CPU_INFO_ITERATOR cii;
        int error;
@@ -229,10 +226,6 @@
                        continue;
                spc->spc_psid = PS_NONE;
        }
-       /* Mark that processor-set is going to be destroyed */
-       pi = psets[psid - 1];
-       pi->ps_flags |= PSET_BUSY;
-       mutex_exit(&cpu_lock);
 
        /* Unmark the processor-set ID from each thread */
        mutex_enter(proc_lock);
@@ -245,12 +238,11 @@
        mutex_exit(proc_lock);
 
        /* Destroy the processor-set */
-       mutex_enter(&cpu_lock);
+       kmem_free(psets[psid - 1], sizeof(pset_info_t));
        psets[psid - 1] = NULL;
        psets_count--;
        mutex_exit(&cpu_lock);
 
-       kmem_free(pi, sizeof(pset_info_t));
        return 0;
 }
 
@@ -452,9 +444,6 @@
        }
        if (psid == PS_MYID)
                psid = curlwp->l_psid;
-       if (psid != PS_QUERY && psid != PS_NONE)
-               psets[psid - 1]->ps_flags |= PSET_BUSY;
-       mutex_exit(&cpu_lock);
 
        /*
         * Get PID and LID from the ID.
@@ -463,6 +452,7 @@
        id1 = SCARG(uap, first_id);
        id2 = SCARG(uap, second_id);
 
+       mutex_enter(proc_lock);
        switch (SCARG(uap, idtype)) {
        case P_PID:
                /*
@@ -493,19 +483,13 @@
        }
 
        /* Find the process */
-       mutex_enter(proc_lock);
        p = proc_find(pid);
        if (p == NULL) {
-               mutex_exit(proc_lock);
                error = ESRCH;
                goto error;
        }
-       mutex_enter(p->p_lock);
-       mutex_exit(proc_lock);
-
        /* Disallow modification of the system processes */
        if (p->p_flag & PK_SYSTEM) {
-               mutex_exit(p->p_lock);
                error = EPERM;
                goto error;
        }
@@ -513,6 +497,7 @@
        /* Find the LWP(s) */
        lcnt = 0;
        ci = NULL;
+       mutex_enter(p->p_lock);
        LIST_FOREACH(t, &p->p_lwps, l_sibling) {
                if (lid && lid != t->l_lid)
                        continue;
@@ -531,16 +516,12 @@
        mutex_exit(p->p_lock);
        if (lcnt == 0) {
                error = ESRCH;
-               goto error;
        }
-       if (SCARG(uap, opsid))
-               error = copyout(&opsid, SCARG(uap, opsid), sizeof(psetid_t));
 error:
-       if (psid != PS_QUERY && psid != PS_NONE) {
-               mutex_enter(&cpu_lock);
-               psets[psid - 1]->ps_flags &= ~PSET_BUSY;
-               mutex_exit(&cpu_lock);
-       }
+       mutex_exit(proc_lock);
+       mutex_exit(&cpu_lock);
+       if (error == 0 && SCARG(uap, opsid))
+               error = copyout(&opsid, SCARG(uap, opsid), sizeof(psetid_t));
        return error;
 }
 
diff -r 60bf0fd90459 -r 646b7639ecf7 sys/sys/pset.h
--- a/sys/sys/pset.h    Thu Nov 21 17:50:49 2019 +0000
+++ b/sys/sys/pset.h    Thu Nov 21 17:54:04 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pset.h,v 1.6 2018/05/28 21:05:02 chs Exp $     */
+/*     $NetBSD: pset.h,v 1.7 2019/11/21 17:54:04 ad Exp $      */
 
 /*
  * Copyright (c) 2008, Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -57,9 +57,6 @@
        int             ps_flags;
 } pset_info_t;
 
-/* Flags */
-#define        PSET_BUSY       0x01
-
 void   psets_init(void);
 
 #endif /* _KERNEL */



Home | Main Index | Thread Index | Old Index