Module Name:    src
Committed By:   yamt
Date:           Fri Apr 13 15:27:14 UTC 2012

Modified Files:
        src/sys/kern: sys_sched.c

Log Message:
- do_sched_getparam: release locks earlier.
- add comments


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/kern/sys_sched.c

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_sched.c
diff -u src/sys/kern/sys_sched.c:1.40 src/sys/kern/sys_sched.c:1.41
--- src/sys/kern/sys_sched.c:1.40	Sun Feb 19 21:06:56 2012
+++ src/sys/kern/sys_sched.c	Fri Apr 13 15:27:13 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_sched.c,v 1.40 2012/02/19 21:06:56 rmind Exp $	*/
+/*	$NetBSD: sys_sched.c,v 1.41 2012/04/13 15:27:13 yamt Exp $	*/
 
 /*
  * Copyright (c) 2008, 2011 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_sched.c,v 1.40 2012/02/19 21:06:56 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_sched.c,v 1.41 2012/04/13 15:27:13 yamt Exp $");
 
 #include <sys/param.h>
 
@@ -92,6 +92,11 @@ convert_pri(lwp_t *l, int policy, pri_t 
 	/* Real-time -> time-sharing */
 	if (policy == SCHED_OTHER) {
 		KASSERT(l->l_class == SCHED_FIFO || l->l_class == SCHED_RR);
+		/*
+		 * this is a bit arbitrary because the priority is dynamic
+		 * for SCHED_OTHER threads and will likely be changed by
+		 * the scheduler soon anyway.
+		 */
 		return l->l_priority - PRI_USER_RT;
 	}
 
@@ -214,6 +219,11 @@ out:
 	return error;
 }
 
+/*
+ * do_sched_getparam:
+ *
+ * if lid=0, returns the parameter of the first LWP in the process.
+ */
 int
 do_sched_getparam(pid_t pid, lwpid_t lid, int *policy,
     struct sched_param *params)
@@ -222,8 +232,7 @@ do_sched_getparam(pid_t pid, lwpid_t lid
 	struct lwp *t;
 	int error, lpolicy;
 
-	/* Locks the LWP */
-	t = lwp_find2(pid, lid);
+	t = lwp_find2(pid, lid); /* acquire p_lock */
 	if (t == NULL)
 		return ESRCH;
 
@@ -238,7 +247,17 @@ do_sched_getparam(pid_t pid, lwpid_t lid
 	lwp_lock(t);
 	lparams.sched_priority = t->l_priority;
 	lpolicy = t->l_class;
+	lwp_unlock(t);
+	mutex_exit(t->l_proc->p_lock);
 
+	/*
+	 * convert to the user-visible priority value.
+	 * it's an inversion of convert_pri().
+	 *
+	 * the SCHED_OTHER case is a bit arbitrary given that
+	 *	- we don't allow setting the priority.
+	 *	- the priority is dynamic.
+	 */
 	switch (lpolicy) {
 	case SCHED_OTHER:
 		lparams.sched_priority -= PRI_USER;
@@ -255,8 +274,6 @@ do_sched_getparam(pid_t pid, lwpid_t lid
 	if (params != NULL)
 		*params = lparams;
 
-	lwp_unlock(t);
-	mutex_exit(t->l_proc->p_lock);
 	return error;
 }
 

Reply via email to