Extended the POSIX scheduler APIs to accept lwpid as well, we've already
done this in ptrace syscall, when a pid is large than PID_MAX, the syscall will search a thread in current process. It permits 1:1 thread library to get and set a thread's scheduler attributes.
This commit is contained in:
parent
8004384a92
commit
65343c788c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=160257
@ -100,7 +100,7 @@ ksched_detach(struct ksched *ks)
|
||||
#define P1B_PRIO_MAX rtpprio_to_p4prio(RTP_PRIO_MIN)
|
||||
|
||||
static __inline int
|
||||
getscheduler(register_t *ret, struct ksched *ksched, struct thread *td)
|
||||
getscheduler(struct ksched *ksched, struct thread *td, int *policy)
|
||||
{
|
||||
struct rtprio rtp;
|
||||
int e = 0;
|
||||
@ -111,15 +111,15 @@ getscheduler(register_t *ret, struct ksched *ksched, struct thread *td)
|
||||
switch (rtp.type)
|
||||
{
|
||||
case RTP_PRIO_FIFO:
|
||||
*ret = SCHED_FIFO;
|
||||
*policy = SCHED_FIFO;
|
||||
break;
|
||||
|
||||
case RTP_PRIO_REALTIME:
|
||||
*ret = SCHED_RR;
|
||||
*policy = SCHED_RR;
|
||||
break;
|
||||
|
||||
default:
|
||||
*ret = SCHED_OTHER;
|
||||
*policy = SCHED_OTHER;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -127,27 +127,27 @@ getscheduler(register_t *ret, struct ksched *ksched, struct thread *td)
|
||||
}
|
||||
|
||||
int
|
||||
ksched_setparam(register_t *ret, struct ksched *ksched,
|
||||
ksched_setparam(struct ksched *ksched,
|
||||
struct thread *td, const struct sched_param *param)
|
||||
{
|
||||
register_t policy;
|
||||
int policy;
|
||||
int e;
|
||||
|
||||
e = getscheduler(&policy, ksched, td);
|
||||
e = getscheduler(ksched, td, &policy);
|
||||
|
||||
if (e == 0)
|
||||
{
|
||||
if (policy == SCHED_OTHER)
|
||||
e = EINVAL;
|
||||
else
|
||||
e = ksched_setscheduler(ret, ksched, td, policy, param);
|
||||
e = ksched_setscheduler(ksched, td, policy, param);
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
int
|
||||
ksched_getparam(register_t *ret, struct ksched *ksched,
|
||||
ksched_getparam(struct ksched *ksched,
|
||||
struct thread *td, struct sched_param *param)
|
||||
{
|
||||
struct rtprio rtp;
|
||||
@ -169,7 +169,7 @@ ksched_getparam(register_t *ret, struct ksched *ksched,
|
||||
*
|
||||
*/
|
||||
int
|
||||
ksched_setscheduler(register_t *ret, struct ksched *ksched,
|
||||
ksched_setscheduler(struct ksched *ksched,
|
||||
struct thread *td, int policy, const struct sched_param *param)
|
||||
{
|
||||
int e = 0;
|
||||
@ -243,22 +243,22 @@ ksched_setscheduler(register_t *ret, struct ksched *ksched,
|
||||
}
|
||||
|
||||
int
|
||||
ksched_getscheduler(register_t *ret, struct ksched *ksched, struct thread *td)
|
||||
ksched_getscheduler(struct ksched *ksched, struct thread *td, int *policy)
|
||||
{
|
||||
return getscheduler(ret, ksched, td);
|
||||
return getscheduler(ksched, td, policy);
|
||||
}
|
||||
|
||||
/* ksched_yield: Yield the CPU.
|
||||
*/
|
||||
int
|
||||
ksched_yield(register_t *ret, struct ksched *ksched)
|
||||
ksched_yield(struct ksched *ksched)
|
||||
{
|
||||
sched_relinquish(curthread);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ksched_get_priority_max(register_t*ret, struct ksched *ksched, int policy)
|
||||
ksched_get_priority_max(struct ksched *ksched, int policy, int *prio)
|
||||
{
|
||||
int e = 0;
|
||||
|
||||
@ -266,11 +266,11 @@ ksched_get_priority_max(register_t*ret, struct ksched *ksched, int policy)
|
||||
{
|
||||
case SCHED_FIFO:
|
||||
case SCHED_RR:
|
||||
*ret = RTP_PRIO_MAX;
|
||||
*prio = RTP_PRIO_MAX;
|
||||
break;
|
||||
|
||||
case SCHED_OTHER:
|
||||
*ret = PRIO_MAX;
|
||||
*prio = PRIO_MAX;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -281,7 +281,7 @@ ksched_get_priority_max(register_t*ret, struct ksched *ksched, int policy)
|
||||
}
|
||||
|
||||
int
|
||||
ksched_get_priority_min(register_t *ret, struct ksched *ksched, int policy)
|
||||
ksched_get_priority_min(struct ksched *ksched, int policy, int *prio)
|
||||
{
|
||||
int e = 0;
|
||||
|
||||
@ -289,11 +289,11 @@ ksched_get_priority_min(register_t *ret, struct ksched *ksched, int policy)
|
||||
{
|
||||
case SCHED_FIFO:
|
||||
case SCHED_RR:
|
||||
*ret = P1B_PRIO_MIN;
|
||||
*prio = P1B_PRIO_MIN;
|
||||
break;
|
||||
|
||||
case SCHED_OTHER:
|
||||
*ret = PRIO_MIN;
|
||||
*prio = PRIO_MIN;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -304,8 +304,8 @@ ksched_get_priority_min(register_t *ret, struct ksched *ksched, int policy)
|
||||
}
|
||||
|
||||
int
|
||||
ksched_rr_get_interval(register_t *ret, struct ksched *ksched,
|
||||
struct thread *td, struct timespec *timespec)
|
||||
ksched_rr_get_interval(struct ksched *ksched,
|
||||
struct thread *td, struct timespec *timespec)
|
||||
{
|
||||
*timespec = ksched->rr_interval;
|
||||
|
||||
|
@ -90,7 +90,6 @@ SYSCALL_NOT_PRESENT_GEN(sched_yield)
|
||||
SYSCALL_NOT_PRESENT_GEN(sched_get_priority_max)
|
||||
SYSCALL_NOT_PRESENT_GEN(sched_get_priority_min)
|
||||
SYSCALL_NOT_PRESENT_GEN(sched_rr_get_interval)
|
||||
|
||||
#else
|
||||
|
||||
/* Configured in kernel version:
|
||||
@ -127,22 +126,27 @@ sched_setparam(struct thread *td, struct sched_setparam_args *uap)
|
||||
targetp = td->td_proc;
|
||||
targettd = td;
|
||||
PROC_LOCK(targetp);
|
||||
} else {
|
||||
} else if (uap->pid <= PID_MAX) {
|
||||
targetp = pfind(uap->pid);
|
||||
if (targetp == NULL)
|
||||
return (ESRCH);
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp);
|
||||
} else {
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
targettd = thread_find(targetp, uap->pid);
|
||||
if (targetp == NULL) {
|
||||
e = ESRCH;
|
||||
goto done2;
|
||||
PROC_UNLOCK(targetp);
|
||||
return (ESRCH);
|
||||
}
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
||||
}
|
||||
|
||||
e = p_cansched(td, targetp);
|
||||
if (e == 0) {
|
||||
e = ksched_setparam(&td->td_retval[0], ksched, targettd,
|
||||
e = ksched_setparam(ksched, targettd,
|
||||
(const struct sched_param *)&sched_param);
|
||||
}
|
||||
PROC_UNLOCK(targetp);
|
||||
done2:
|
||||
return (e);
|
||||
}
|
||||
|
||||
@ -161,24 +165,29 @@ sched_getparam(struct thread *td, struct sched_getparam_args *uap)
|
||||
targetp = td->td_proc;
|
||||
targettd = td;
|
||||
PROC_LOCK(targetp);
|
||||
} else {
|
||||
} else if (uap->pid <= PID_MAX) {
|
||||
targetp = pfind(uap->pid);
|
||||
if (targetp == NULL) {
|
||||
e = ESRCH;
|
||||
goto done2;
|
||||
return (ESRCH);
|
||||
}
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
||||
} else {
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
targettd = thread_find(targetp, uap->pid);
|
||||
if (targettd == NULL) {
|
||||
PROC_UNLOCK(targetp);
|
||||
return (ESRCH);
|
||||
}
|
||||
}
|
||||
|
||||
e = p_cansee(td, targetp);
|
||||
if (e == 0) {
|
||||
e = ksched_getparam(&td->td_retval[0], ksched, targettd,
|
||||
&sched_param);
|
||||
e = ksched_getparam(ksched, targettd, &sched_param);
|
||||
}
|
||||
PROC_UNLOCK(targetp);
|
||||
if (e == 0)
|
||||
e = copyout(&sched_param, uap->param, sizeof(sched_param));
|
||||
done2:
|
||||
return (e);
|
||||
}
|
||||
|
||||
@ -205,22 +214,27 @@ sched_setscheduler(struct thread *td, struct sched_setscheduler_args *uap)
|
||||
targetp = td->td_proc;
|
||||
targettd = td;
|
||||
PROC_LOCK(targetp);
|
||||
} else {
|
||||
} else if (uap->pid <= PID_MAX) {
|
||||
targetp = pfind(uap->pid);
|
||||
if (targetp == NULL) {
|
||||
e = ESRCH;
|
||||
goto done2;
|
||||
if (targetp == NULL)
|
||||
return (ESRCH);
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp);
|
||||
} else {
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
targettd = thread_find(targetp, uap->pid);
|
||||
if (targettd == NULL) {
|
||||
PROC_UNLOCK(targetp);
|
||||
return (ESRCH);
|
||||
}
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
||||
}
|
||||
|
||||
e = p_cansched(td, targetp);
|
||||
if (e == 0) {
|
||||
e = ksched_setscheduler(&td->td_retval[0], ksched, targettd,
|
||||
e = ksched_setscheduler(ksched, targettd,
|
||||
uap->policy, (const struct sched_param *)&sched_param);
|
||||
}
|
||||
PROC_UNLOCK(targetp);
|
||||
done2:
|
||||
return (e);
|
||||
}
|
||||
|
||||
@ -230,7 +244,7 @@ sched_setscheduler(struct thread *td, struct sched_setscheduler_args *uap)
|
||||
int
|
||||
sched_getscheduler(struct thread *td, struct sched_getscheduler_args *uap)
|
||||
{
|
||||
int e;
|
||||
int e, policy;
|
||||
struct thread *targettd;
|
||||
struct proc *targetp;
|
||||
|
||||
@ -238,18 +252,29 @@ sched_getscheduler(struct thread *td, struct sched_getscheduler_args *uap)
|
||||
targetp = td->td_proc;
|
||||
targettd = td;
|
||||
PROC_LOCK(targetp);
|
||||
} else {
|
||||
} else if (uap->pid <= PID_MAX) {
|
||||
targetp = pfind(uap->pid);
|
||||
if (targetp == NULL) {
|
||||
e = ESRCH;
|
||||
goto done2;
|
||||
}
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
||||
} else {
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
targettd = thread_find(targetp, uap->pid);
|
||||
if (targettd == NULL) {
|
||||
PROC_UNLOCK(targetp);
|
||||
e = ESRCH;
|
||||
goto done2;
|
||||
}
|
||||
}
|
||||
|
||||
e = p_cansee(td, targetp);
|
||||
if (e == 0)
|
||||
e = ksched_getscheduler(&td->td_retval[0], ksched, targettd);
|
||||
if (e == 0) {
|
||||
e = ksched_getscheduler(ksched, targettd, &policy);
|
||||
td->td_retval[0] = policy;
|
||||
}
|
||||
PROC_UNLOCK(targetp);
|
||||
|
||||
done2:
|
||||
@ -262,10 +287,8 @@ sched_getscheduler(struct thread *td, struct sched_getscheduler_args *uap)
|
||||
int
|
||||
sched_yield(struct thread *td, struct sched_yield_args *uap)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = ksched_yield(&td->td_retval[0], ksched);
|
||||
return (error);
|
||||
return (ksched_yield(ksched));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -275,9 +298,10 @@ int
|
||||
sched_get_priority_max(struct thread *td,
|
||||
struct sched_get_priority_max_args *uap)
|
||||
{
|
||||
int error;
|
||||
int error, prio;
|
||||
|
||||
error = ksched_get_priority_max(&td->td_retval[0], ksched, uap->policy);
|
||||
error = ksched_get_priority_max(ksched, uap->policy, &prio);
|
||||
td->td_retval[0] = prio;
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -288,9 +312,12 @@ int
|
||||
sched_get_priority_min(struct thread *td,
|
||||
struct sched_get_priority_min_args *uap)
|
||||
{
|
||||
int error;
|
||||
int error, prio;
|
||||
|
||||
error = ksched_get_priority_min(&td->td_retval[0], ksched, uap->policy);
|
||||
error = ksched_get_priority_min(ksched, uap->policy, &prio);
|
||||
td->td_retval[0] = prio;
|
||||
printf("uap->policy=%d error=%d prio=%d\n", uap->policy, error,
|
||||
prio);
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -322,18 +349,24 @@ kern_sched_rr_get_interval(struct thread *td, pid_t pid,
|
||||
targettd = td;
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
} else {
|
||||
} else if (pid <= PID_MAX) {
|
||||
targetp = pfind(pid);
|
||||
if (targetp == NULL)
|
||||
return (ESRCH);
|
||||
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp);
|
||||
} else {
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
targettd = thread_find(targetp, pid);
|
||||
if (targettd == NULL) {
|
||||
PROC_UNLOCK(targetp);
|
||||
return (ESRCH);
|
||||
}
|
||||
}
|
||||
|
||||
e = p_cansee(td, targetp);
|
||||
if (e == 0)
|
||||
e = ksched_rr_get_interval(&td->td_retval[0], ksched, targettd,
|
||||
ts);
|
||||
e = ksched_rr_get_interval(ksched, targettd, ts);
|
||||
PROC_UNLOCK(targetp);
|
||||
return (e);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ ksched_detach(struct ksched *ks)
|
||||
#define P1B_PRIO_MAX rtpprio_to_p4prio(RTP_PRIO_MIN)
|
||||
|
||||
static __inline int
|
||||
getscheduler(register_t *ret, struct ksched *ksched, struct thread *td)
|
||||
getscheduler(struct ksched *ksched, struct thread *td, int *policy)
|
||||
{
|
||||
struct rtprio rtp;
|
||||
int e = 0;
|
||||
@ -111,15 +111,15 @@ getscheduler(register_t *ret, struct ksched *ksched, struct thread *td)
|
||||
switch (rtp.type)
|
||||
{
|
||||
case RTP_PRIO_FIFO:
|
||||
*ret = SCHED_FIFO;
|
||||
*policy = SCHED_FIFO;
|
||||
break;
|
||||
|
||||
case RTP_PRIO_REALTIME:
|
||||
*ret = SCHED_RR;
|
||||
*policy = SCHED_RR;
|
||||
break;
|
||||
|
||||
default:
|
||||
*ret = SCHED_OTHER;
|
||||
*policy = SCHED_OTHER;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -127,27 +127,27 @@ getscheduler(register_t *ret, struct ksched *ksched, struct thread *td)
|
||||
}
|
||||
|
||||
int
|
||||
ksched_setparam(register_t *ret, struct ksched *ksched,
|
||||
ksched_setparam(struct ksched *ksched,
|
||||
struct thread *td, const struct sched_param *param)
|
||||
{
|
||||
register_t policy;
|
||||
int policy;
|
||||
int e;
|
||||
|
||||
e = getscheduler(&policy, ksched, td);
|
||||
e = getscheduler(ksched, td, &policy);
|
||||
|
||||
if (e == 0)
|
||||
{
|
||||
if (policy == SCHED_OTHER)
|
||||
e = EINVAL;
|
||||
else
|
||||
e = ksched_setscheduler(ret, ksched, td, policy, param);
|
||||
e = ksched_setscheduler(ksched, td, policy, param);
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
int
|
||||
ksched_getparam(register_t *ret, struct ksched *ksched,
|
||||
ksched_getparam(struct ksched *ksched,
|
||||
struct thread *td, struct sched_param *param)
|
||||
{
|
||||
struct rtprio rtp;
|
||||
@ -169,7 +169,7 @@ ksched_getparam(register_t *ret, struct ksched *ksched,
|
||||
*
|
||||
*/
|
||||
int
|
||||
ksched_setscheduler(register_t *ret, struct ksched *ksched,
|
||||
ksched_setscheduler(struct ksched *ksched,
|
||||
struct thread *td, int policy, const struct sched_param *param)
|
||||
{
|
||||
int e = 0;
|
||||
@ -243,22 +243,22 @@ ksched_setscheduler(register_t *ret, struct ksched *ksched,
|
||||
}
|
||||
|
||||
int
|
||||
ksched_getscheduler(register_t *ret, struct ksched *ksched, struct thread *td)
|
||||
ksched_getscheduler(struct ksched *ksched, struct thread *td, int *policy)
|
||||
{
|
||||
return getscheduler(ret, ksched, td);
|
||||
return getscheduler(ksched, td, policy);
|
||||
}
|
||||
|
||||
/* ksched_yield: Yield the CPU.
|
||||
*/
|
||||
int
|
||||
ksched_yield(register_t *ret, struct ksched *ksched)
|
||||
ksched_yield(struct ksched *ksched)
|
||||
{
|
||||
sched_relinquish(curthread);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ksched_get_priority_max(register_t*ret, struct ksched *ksched, int policy)
|
||||
ksched_get_priority_max(struct ksched *ksched, int policy, int *prio)
|
||||
{
|
||||
int e = 0;
|
||||
|
||||
@ -266,11 +266,11 @@ ksched_get_priority_max(register_t*ret, struct ksched *ksched, int policy)
|
||||
{
|
||||
case SCHED_FIFO:
|
||||
case SCHED_RR:
|
||||
*ret = RTP_PRIO_MAX;
|
||||
*prio = RTP_PRIO_MAX;
|
||||
break;
|
||||
|
||||
case SCHED_OTHER:
|
||||
*ret = PRIO_MAX;
|
||||
*prio = PRIO_MAX;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -281,7 +281,7 @@ ksched_get_priority_max(register_t*ret, struct ksched *ksched, int policy)
|
||||
}
|
||||
|
||||
int
|
||||
ksched_get_priority_min(register_t *ret, struct ksched *ksched, int policy)
|
||||
ksched_get_priority_min(struct ksched *ksched, int policy, int *prio)
|
||||
{
|
||||
int e = 0;
|
||||
|
||||
@ -289,11 +289,11 @@ ksched_get_priority_min(register_t *ret, struct ksched *ksched, int policy)
|
||||
{
|
||||
case SCHED_FIFO:
|
||||
case SCHED_RR:
|
||||
*ret = P1B_PRIO_MIN;
|
||||
*prio = P1B_PRIO_MIN;
|
||||
break;
|
||||
|
||||
case SCHED_OTHER:
|
||||
*ret = PRIO_MIN;
|
||||
*prio = PRIO_MIN;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -304,8 +304,8 @@ ksched_get_priority_min(register_t *ret, struct ksched *ksched, int policy)
|
||||
}
|
||||
|
||||
int
|
||||
ksched_rr_get_interval(register_t *ret, struct ksched *ksched,
|
||||
struct thread *td, struct timespec *timespec)
|
||||
ksched_rr_get_interval(struct ksched *ksched,
|
||||
struct thread *td, struct timespec *timespec)
|
||||
{
|
||||
*timespec = ksched->rr_interval;
|
||||
|
||||
|
@ -90,7 +90,6 @@ SYSCALL_NOT_PRESENT_GEN(sched_yield)
|
||||
SYSCALL_NOT_PRESENT_GEN(sched_get_priority_max)
|
||||
SYSCALL_NOT_PRESENT_GEN(sched_get_priority_min)
|
||||
SYSCALL_NOT_PRESENT_GEN(sched_rr_get_interval)
|
||||
|
||||
#else
|
||||
|
||||
/* Configured in kernel version:
|
||||
@ -127,22 +126,27 @@ sched_setparam(struct thread *td, struct sched_setparam_args *uap)
|
||||
targetp = td->td_proc;
|
||||
targettd = td;
|
||||
PROC_LOCK(targetp);
|
||||
} else {
|
||||
} else if (uap->pid <= PID_MAX) {
|
||||
targetp = pfind(uap->pid);
|
||||
if (targetp == NULL)
|
||||
return (ESRCH);
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp);
|
||||
} else {
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
targettd = thread_find(targetp, uap->pid);
|
||||
if (targetp == NULL) {
|
||||
e = ESRCH;
|
||||
goto done2;
|
||||
PROC_UNLOCK(targetp);
|
||||
return (ESRCH);
|
||||
}
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
||||
}
|
||||
|
||||
e = p_cansched(td, targetp);
|
||||
if (e == 0) {
|
||||
e = ksched_setparam(&td->td_retval[0], ksched, targettd,
|
||||
e = ksched_setparam(ksched, targettd,
|
||||
(const struct sched_param *)&sched_param);
|
||||
}
|
||||
PROC_UNLOCK(targetp);
|
||||
done2:
|
||||
return (e);
|
||||
}
|
||||
|
||||
@ -161,24 +165,29 @@ sched_getparam(struct thread *td, struct sched_getparam_args *uap)
|
||||
targetp = td->td_proc;
|
||||
targettd = td;
|
||||
PROC_LOCK(targetp);
|
||||
} else {
|
||||
} else if (uap->pid <= PID_MAX) {
|
||||
targetp = pfind(uap->pid);
|
||||
if (targetp == NULL) {
|
||||
e = ESRCH;
|
||||
goto done2;
|
||||
return (ESRCH);
|
||||
}
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
||||
} else {
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
targettd = thread_find(targetp, uap->pid);
|
||||
if (targettd == NULL) {
|
||||
PROC_UNLOCK(targetp);
|
||||
return (ESRCH);
|
||||
}
|
||||
}
|
||||
|
||||
e = p_cansee(td, targetp);
|
||||
if (e == 0) {
|
||||
e = ksched_getparam(&td->td_retval[0], ksched, targettd,
|
||||
&sched_param);
|
||||
e = ksched_getparam(ksched, targettd, &sched_param);
|
||||
}
|
||||
PROC_UNLOCK(targetp);
|
||||
if (e == 0)
|
||||
e = copyout(&sched_param, uap->param, sizeof(sched_param));
|
||||
done2:
|
||||
return (e);
|
||||
}
|
||||
|
||||
@ -205,22 +214,27 @@ sched_setscheduler(struct thread *td, struct sched_setscheduler_args *uap)
|
||||
targetp = td->td_proc;
|
||||
targettd = td;
|
||||
PROC_LOCK(targetp);
|
||||
} else {
|
||||
} else if (uap->pid <= PID_MAX) {
|
||||
targetp = pfind(uap->pid);
|
||||
if (targetp == NULL) {
|
||||
e = ESRCH;
|
||||
goto done2;
|
||||
if (targetp == NULL)
|
||||
return (ESRCH);
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp);
|
||||
} else {
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
targettd = thread_find(targetp, uap->pid);
|
||||
if (targettd == NULL) {
|
||||
PROC_UNLOCK(targetp);
|
||||
return (ESRCH);
|
||||
}
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
||||
}
|
||||
|
||||
e = p_cansched(td, targetp);
|
||||
if (e == 0) {
|
||||
e = ksched_setscheduler(&td->td_retval[0], ksched, targettd,
|
||||
e = ksched_setscheduler(ksched, targettd,
|
||||
uap->policy, (const struct sched_param *)&sched_param);
|
||||
}
|
||||
PROC_UNLOCK(targetp);
|
||||
done2:
|
||||
return (e);
|
||||
}
|
||||
|
||||
@ -230,7 +244,7 @@ sched_setscheduler(struct thread *td, struct sched_setscheduler_args *uap)
|
||||
int
|
||||
sched_getscheduler(struct thread *td, struct sched_getscheduler_args *uap)
|
||||
{
|
||||
int e;
|
||||
int e, policy;
|
||||
struct thread *targettd;
|
||||
struct proc *targetp;
|
||||
|
||||
@ -238,18 +252,29 @@ sched_getscheduler(struct thread *td, struct sched_getscheduler_args *uap)
|
||||
targetp = td->td_proc;
|
||||
targettd = td;
|
||||
PROC_LOCK(targetp);
|
||||
} else {
|
||||
} else if (uap->pid <= PID_MAX) {
|
||||
targetp = pfind(uap->pid);
|
||||
if (targetp == NULL) {
|
||||
e = ESRCH;
|
||||
goto done2;
|
||||
}
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
||||
} else {
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
targettd = thread_find(targetp, uap->pid);
|
||||
if (targettd == NULL) {
|
||||
PROC_UNLOCK(targetp);
|
||||
e = ESRCH;
|
||||
goto done2;
|
||||
}
|
||||
}
|
||||
|
||||
e = p_cansee(td, targetp);
|
||||
if (e == 0)
|
||||
e = ksched_getscheduler(&td->td_retval[0], ksched, targettd);
|
||||
if (e == 0) {
|
||||
e = ksched_getscheduler(ksched, targettd, &policy);
|
||||
td->td_retval[0] = policy;
|
||||
}
|
||||
PROC_UNLOCK(targetp);
|
||||
|
||||
done2:
|
||||
@ -262,10 +287,8 @@ sched_getscheduler(struct thread *td, struct sched_getscheduler_args *uap)
|
||||
int
|
||||
sched_yield(struct thread *td, struct sched_yield_args *uap)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = ksched_yield(&td->td_retval[0], ksched);
|
||||
return (error);
|
||||
return (ksched_yield(ksched));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -275,9 +298,10 @@ int
|
||||
sched_get_priority_max(struct thread *td,
|
||||
struct sched_get_priority_max_args *uap)
|
||||
{
|
||||
int error;
|
||||
int error, prio;
|
||||
|
||||
error = ksched_get_priority_max(&td->td_retval[0], ksched, uap->policy);
|
||||
error = ksched_get_priority_max(ksched, uap->policy, &prio);
|
||||
td->td_retval[0] = prio;
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -288,9 +312,12 @@ int
|
||||
sched_get_priority_min(struct thread *td,
|
||||
struct sched_get_priority_min_args *uap)
|
||||
{
|
||||
int error;
|
||||
int error, prio;
|
||||
|
||||
error = ksched_get_priority_min(&td->td_retval[0], ksched, uap->policy);
|
||||
error = ksched_get_priority_min(ksched, uap->policy, &prio);
|
||||
td->td_retval[0] = prio;
|
||||
printf("uap->policy=%d error=%d prio=%d\n", uap->policy, error,
|
||||
prio);
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -322,18 +349,24 @@ kern_sched_rr_get_interval(struct thread *td, pid_t pid,
|
||||
targettd = td;
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
} else {
|
||||
} else if (pid <= PID_MAX) {
|
||||
targetp = pfind(pid);
|
||||
if (targetp == NULL)
|
||||
return (ESRCH);
|
||||
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp); /* XXXKSE */
|
||||
targettd = FIRST_THREAD_IN_PROC(targetp);
|
||||
} else {
|
||||
targetp = td->td_proc;
|
||||
PROC_LOCK(targetp);
|
||||
targettd = thread_find(targetp, pid);
|
||||
if (targettd == NULL) {
|
||||
PROC_UNLOCK(targetp);
|
||||
return (ESRCH);
|
||||
}
|
||||
}
|
||||
|
||||
e = p_cansee(td, targetp);
|
||||
if (e == 0)
|
||||
e = ksched_rr_get_interval(&td->td_retval[0], ksched, targettd,
|
||||
ts);
|
||||
e = ksched_rr_get_interval(ksched, targettd, ts);
|
||||
PROC_UNLOCK(targetp);
|
||||
return (e);
|
||||
}
|
||||
|
@ -94,21 +94,21 @@ struct ksched;
|
||||
int ksched_attach(struct ksched **);
|
||||
int ksched_detach(struct ksched *);
|
||||
|
||||
int ksched_setparam(register_t *, struct ksched *,
|
||||
int ksched_setparam(struct ksched *,
|
||||
struct thread *, const struct sched_param *);
|
||||
int ksched_getparam(register_t *, struct ksched *,
|
||||
int ksched_getparam(struct ksched *,
|
||||
struct thread *, struct sched_param *);
|
||||
|
||||
int ksched_setscheduler(register_t *, struct ksched *,
|
||||
int ksched_setscheduler(struct ksched *,
|
||||
struct thread *, int, const struct sched_param *);
|
||||
int ksched_getscheduler(register_t *, struct ksched *, struct thread *);
|
||||
int ksched_getscheduler(struct ksched *, struct thread *, int *);
|
||||
|
||||
int ksched_yield(register_t *, struct ksched *);
|
||||
int ksched_yield(struct ksched *);
|
||||
|
||||
int ksched_get_priority_max(register_t *, struct ksched *, int);
|
||||
int ksched_get_priority_min(register_t *, struct ksched *, int);
|
||||
int ksched_get_priority_max(struct ksched *, int, int *);
|
||||
int ksched_get_priority_min(struct ksched *, int, int *);
|
||||
|
||||
int ksched_rr_get_interval(register_t *, struct ksched *,
|
||||
int ksched_rr_get_interval(struct ksched *,
|
||||
struct thread *, struct timespec *);
|
||||
|
||||
#endif /* _KPOSIX_PRIORITY_SCHEDULING */
|
||||
|
@ -94,21 +94,21 @@ struct ksched;
|
||||
int ksched_attach(struct ksched **);
|
||||
int ksched_detach(struct ksched *);
|
||||
|
||||
int ksched_setparam(register_t *, struct ksched *,
|
||||
int ksched_setparam(struct ksched *,
|
||||
struct thread *, const struct sched_param *);
|
||||
int ksched_getparam(register_t *, struct ksched *,
|
||||
int ksched_getparam(struct ksched *,
|
||||
struct thread *, struct sched_param *);
|
||||
|
||||
int ksched_setscheduler(register_t *, struct ksched *,
|
||||
int ksched_setscheduler(struct ksched *,
|
||||
struct thread *, int, const struct sched_param *);
|
||||
int ksched_getscheduler(register_t *, struct ksched *, struct thread *);
|
||||
int ksched_getscheduler(struct ksched *, struct thread *, int *);
|
||||
|
||||
int ksched_yield(register_t *, struct ksched *);
|
||||
int ksched_yield(struct ksched *);
|
||||
|
||||
int ksched_get_priority_max(register_t *, struct ksched *, int);
|
||||
int ksched_get_priority_min(register_t *, struct ksched *, int);
|
||||
int ksched_get_priority_max(struct ksched *, int, int *);
|
||||
int ksched_get_priority_min(struct ksched *, int, int *);
|
||||
|
||||
int ksched_rr_get_interval(register_t *, struct ksched *,
|
||||
int ksched_rr_get_interval(struct ksched *,
|
||||
struct thread *, struct timespec *);
|
||||
|
||||
#endif /* _KPOSIX_PRIORITY_SCHEDULING */
|
||||
|
Loading…
Reference in New Issue
Block a user