Module Name: src Committed By: ad Date: Thu Nov 21 17:54:04 UTC 2019
Modified Files: src/sys/kern: sys_pset.c src/sys/sys: pset.h Log Message: Simplify pset locking, making it easier to sync with LWP creation, etc. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/kern/sys_pset.c cvs rdiff -u -r1.6 -r1.7 src/sys/sys/pset.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/sys_pset.c diff -u src/sys/kern/sys_pset.c:1.21 src/sys/kern/sys_pset.c:1.22 --- src/sys/kern/sys_pset.c:1.21 Sun Dec 9 23:05:02 2018 +++ src/sys/kern/sys_pset.c Thu Nov 21 17:54:04 2019 @@ -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 @@ psid_validate(psetid_t psid, bool chkps) 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 @@ static int 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 @@ kern_pset_destroy(psetid_t psid) 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 @@ kern_pset_destroy(psetid_t psid) 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 @@ sys__pset_bind(struct lwp *l, const stru } 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 @@ sys__pset_bind(struct lwp *l, const stru 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 @@ sys__pset_bind(struct lwp *l, const stru } /* 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 @@ sys__pset_bind(struct lwp *l, const stru /* 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 @@ sys__pset_bind(struct lwp *l, const stru 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; } Index: src/sys/sys/pset.h diff -u src/sys/sys/pset.h:1.6 src/sys/sys/pset.h:1.7 --- src/sys/sys/pset.h:1.6 Mon May 28 21:05:02 2018 +++ src/sys/sys/pset.h Thu Nov 21 17:54:04 2019 @@ -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 @@ typedef struct { int ps_flags; } pset_info_t; -/* Flags */ -#define PSET_BUSY 0x01 - void psets_init(void); #endif /* _KERNEL */