NetBSD-Bugs archive

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

Re: kern/37987: sys__sched_getparam doesn't work if LWP with lid=1 exited.



The following reply was made to PR kern/37987; it has been noted by GNATS.

From: "Mindaugas R." <rmind%NetBSD.org@localhost>
To: yamt%mwd.biglobe.ne.jp@localhost, ad%netbsd.org@localhost
Cc: gnats-bugs%NetBSD.org@localhost, netbsd-bugs%netbsd.org@localhost
Subject: Re: kern/37987: sys__sched_getparam doesn't work if LWP with lid=1
 exited.
Date: Mon, 18 Feb 2008 02:00:32 +0000

 This is a multi-part message in MIME format.
 
 --Multipart=_Mon__18_Feb_2008_02_00_32_+0000_7F9v9yJNpaoEPInz
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 
 "Mindaugas R." <rmind%NetBSD.org@localhost> wrote:
 > > >Fix:
 > >    use proc_representative_lwp?
 > 
 > Yes, it is not a good solution. But if I remember correctly, we are trying
 > to avoid proc_representative_lwp(), no? I may be confused.
 > 
 > LIST_FIRST(&p->p_lwps) was another solution I was thinking about.
 
 "Andrew Doran" <ad%netbsd.org@localhost> wrote:
 > May I suggest LIST_FIRST(&p->p_lwps)? proc_representative_lwp() is not very
 > deterministic.
 
 Are we intended to replace and remove proc_representative_lwp()?
 
 Please review the attached patch.
 
 -- 
 Best regards,
 Mindaugas
 www.NetBSD.org
 
 --Multipart=_Mon__18_Feb_2008_02_00_32_+0000_7F9v9yJNpaoEPInz
 Content-Type: text/plain;
  name="lwp_find.diff"
 Content-Disposition: attachment;
  filename="lwp_find.diff"
 Content-Transfer-Encoding: 7bit
 
 Index: sys_sched.c
 ===================================================================
 RCS file: /cvsroot/src/sys/kern/sys_sched.c,v
 retrieving revision 1.11
 diff -u -p -r1.11 sys_sched.c
 --- sys_sched.c        16 Feb 2008 16:39:34 -0000      1.11
 +++ sys_sched.c        18 Feb 2008 01:58:37 -0000
 @@ -210,35 +210,19 @@ sys__sched_getparam(struct lwp *l, const
        } */
        struct sched_param param;
        struct lwp *t;
 -      lwpid_t lid;
        int error, policy;
  
 -      /* If not specified, use the first LWP */
 -      lid = SCARG(uap, lid) == 0 ? 1 : SCARG(uap, lid);
 -
 -      if (SCARG(uap, pid) != 0) {
 -              /* Locks the LWP */
 -              t = lwp_find2(SCARG(uap, pid), lid);
 -      } else {
 -              struct proc *p = l->l_proc;
 -              /* Use the calling process */
 -              mutex_enter(&p->p_smutex);
 -              t = lwp_find(p, lid);
 -              if (t != NULL)
 -                      lwp_lock(t);
 -              mutex_exit(&p->p_smutex);
 -      }
 -      if (t == NULL) {
 -              error = ESRCH;
 -              goto error;
 -      }
 +      /* Locks the LWP */
 +      t = lwp_find2(SCARG(uap, pid), SCARG(uap, lid));
 +      if (t == NULL)
 +              return ESRCH;
  
        /* Check the permission */
        error = kauth_authorize_process(l->l_cred,
            KAUTH_PROCESS_SCHEDULER_GETPARAM, t->l_proc, NULL, NULL, NULL);
        if (error != 0) {
                lwp_unlock(t);
 -              goto error;
 +              return error;
        }
  
        param.sched_priority = t->l_priority;
 @@ -257,7 +241,6 @@ sys__sched_getparam(struct lwp *l, const
        error = copyout(&param, SCARG(uap, params), sizeof(param));
        if (error == 0 && SCARG(uap, policy) != NULL)
                error = copyout(&policy, SCARG(uap, policy), sizeof(int));
 -error:
        return error;
  }
  
 @@ -375,28 +358,14 @@ sys__sched_getaffinity(struct lwp *l,
        } */
        struct lwp *t;
        void *cpuset;
 -      lwpid_t lid;
        int error;
  
        if (SCARG(uap, size) <= 0)
                return EINVAL;
        cpuset = kmem_zalloc(sizeof(cpuset_t), KM_SLEEP);
  
 -      /* If not specified, use the first LWP */
 -      lid = SCARG(uap, lid) == 0 ? 1 : SCARG(uap, lid);
 -
 -      if (SCARG(uap, pid) != 0) {
 -              /* Locks the LWP */
 -              t = lwp_find2(SCARG(uap, pid), lid);
 -      } else {
 -              struct proc *p = l->l_proc;
 -              /* Use the calling process */
 -              mutex_enter(&p->p_smutex);
 -              t = lwp_find(p, lid);
 -              if (t != NULL)
 -                      lwp_lock(t);
 -              mutex_exit(&p->p_smutex);
 -      }
 +      /* Locks the LWP */
 +      t = lwp_find2(SCARG(uap, pid), SCARG(uap, lid));
        if (t == NULL) {
                kmem_free(cpuset, sizeof(cpuset_t));
                return ESRCH;
 Index: kern_lwp.c
 ===================================================================
 RCS file: /cvsroot/src/sys/kern/kern_lwp.c,v
 retrieving revision 1.93
 diff -u -p -r1.93 kern_lwp.c
 --- kern_lwp.c 28 Jan 2008 12:23:42 -0000      1.93
 +++ kern_lwp.c 18 Feb 2008 01:58:42 -0000
 @@ -1097,7 +1097,8 @@ lwp_migrate(lwp_t *l, struct cpu_info *c
  }
  
  /*
 - * Find the LWP in the process.
 + * Find the LWP in the process.  Arguments may be zero, in such case,
 + * the calling process and first LWP in the list will be used.
   * On success - returns LWP locked.
   */
  struct lwp *
 @@ -1107,14 +1108,17 @@ lwp_find2(pid_t pid, lwpid_t lid)
        lwp_t *l;
  
        /* Find the process */
 -      p = p_find(pid, PFIND_UNLOCK_FAIL);
 +      p = (pid == 0) ? curlwp->l_proc : p_find(pid, PFIND_UNLOCK_FAIL);
        if (p == NULL)
                return NULL;
        mutex_enter(&p->p_smutex);
 -      mutex_exit(&proclist_lock);
 +      if (pid != 0) {
 +              /* Case of p_find */
 +              mutex_exit(&proclist_lock);
 +      }
  
        /* Find the thread */
 -      l = lwp_find(p, lid);
 +      l = (lid == 0) ? LIST_FIRST(&p->p_lwps) : lwp_find(p, lid);
        if (l != NULL)
                lwp_lock(l);
        mutex_exit(&p->p_smutex);
 
 --Multipart=_Mon__18_Feb_2008_02_00_32_+0000_7F9v9yJNpaoEPInz--
 


Home | Main Index | Thread Index | Old Index