1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-12 09:58:36 +00:00

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.
This commit is contained in:
Julian Elischer 2004-05-08 08:56:05 +00:00
parent ec1100fc6e
commit 60f798c1c8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=129050

View File

@ -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: