diff options
author | julian <julian@FreeBSD.org> | 2004-05-08 08:56:05 +0000 |
---|---|---|
committer | julian <julian@FreeBSD.org> | 2004-05-08 08:56:05 +0000 |
commit | 98d03d5d0690372d41c78603cbbc4dd69efb8b86 (patch) | |
tree | b5ef828284a6e81110f01e5df2422bbed5f50052 | |
parent | b0b94132387b6975d7e8d2442f078d7a5af7eab3 (diff) | |
download | FreeBSD-src-98d03d5d0690372d41c78603cbbc4dd69efb8b86.zip FreeBSD-src-98d03d5d0690372d41c78603cbbc4dd69efb8b86.tar.gz |
Fix rtprio() to do sensible things when called from threaded processes.
It's not quite correct from a posix Point Of view, but it is a lot better
than what was there before. This will be revisited later
when we decide what form our priority extensions will take. Posix doesn't
specify how a system scope thread can change its priority so you need to
add non-standard extensions to be able to do it..
For now make this slightly non standard to allow it to be done.
Submitted by: Dan Eischen originally, changed by myself.
-rw-r--r-- | sys/kern/kern_resource.c | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index b16701c..a172644 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -313,11 +313,12 @@ struct rtprio_args { int rtprio(td, uap) - struct thread *td; + struct thread *td; /* curthread */ register struct rtprio_args *uap; { struct proc *curp; - register struct proc *p; + struct proc *p; + struct ksegrp *kg; struct rtprio rtp; int cierror, error; @@ -342,7 +343,33 @@ rtprio(td, uap) if ((error = p_cansee(td, p))) break; mtx_lock_spin(&sched_lock); - pri_to_rtp(FIRST_KSEGRP_IN_PROC(p), &rtp); + /* + * Return OUR priority if no pid specified, + * or if one is, report the highest priority + * in the process. There isn't much more you can do as + * there is only room to return a single priority. + * XXXKSE Maybe need a new interface to report + * priorities of multiple system scope threads. + * Note: specifying our own pid is not the same + * as leaving it zero. + */ + if (uap->pid == 0) { + pri_to_rtp(td->td_ksegrp, &rtp); + } else { + struct rtprio rtp2; + + rtp.type = RTP_PRIO_IDLE; + rtp.prio = RTP_PRIO_MAX; + FOREACH_KSEGRP_IN_PROC(p, kg) { + pri_to_rtp(kg, &rtp2); + if ((rtp2.type < rtp.type) || + ((rtp2.type == rtp.type) && + (rtp2.prio < rtp.prio))) { + rtp.type = rtp2.type; + rtp.prio = rtp2.prio; + } + } + } mtx_unlock_spin(&sched_lock); PROC_UNLOCK(p); return (copyout(&rtp, uap->rtp, sizeof(struct rtprio))); @@ -373,7 +400,21 @@ rtprio(td, uap) } } mtx_lock_spin(&sched_lock); - error = rtp_to_pri(&rtp, FIRST_KSEGRP_IN_PROC(p)); + /* + * If we are setting our own priority, set just our + * KSEGRP but if we are doing another process, + * do all the groups on that process. If we + * specify our own pid we do the latter. + */ + if (uap->pid == 0) { + error = rtp_to_pri(&rtp, td->td_ksegrp); + } else { + FOREACH_KSEGRP_IN_PROC(p, kg) { + if ((error = rtp_to_pri(&rtp, kg)) != 0) { + break; + } + } + } mtx_unlock_spin(&sched_lock); break; default: |