Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern - do_sched_getparam: release locks earlier.
details: https://anonhg.NetBSD.org/src/rev/11c512ebe8d1
branches: trunk
changeset: 778791:11c512ebe8d1
user: yamt <yamt%NetBSD.org@localhost>
date: Fri Apr 13 15:27:13 2012 +0000
description:
- do_sched_getparam: release locks earlier.
- add comments
diffstat:
sys/kern/sys_sched.c | 29 +++++++++++++++++++++++------
1 files changed, 23 insertions(+), 6 deletions(-)
diffs (79 lines):
diff -r a1ec3a7a35d4 -r 11c512ebe8d1 sys/kern/sys_sched.c
--- a/sys/kern/sys_sched.c Fri Apr 13 15:14:58 2012 +0000
+++ b/sys/kern/sys_sched.c Fri Apr 13 15:27:13 2012 +0000
@@ -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 @@
/* 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 @@
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 @@
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 @@
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 @@
if (params != NULL)
*params = lparams;
- lwp_unlock(t);
- mutex_exit(t->l_proc->p_lock);
return error;
}
Home |
Main Index |
Thread Index |
Old Index