Disallow user priority adjustments for SCHED_OTHER policy, simplify
convert_pri(). Sync schedctl(8) with the change. Closes PR/38009.
This commit is contained in:
parent
43819fe5ab
commit
d5ea013e1d
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sys_sched.c,v 1.28 2008/10/15 06:51:20 wrstuden Exp $ */
|
||||
/* $NetBSD: sys_sched.c,v 1.29 2008/10/18 03:40:18 rmind Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008, Mindaugas Rasiukevicius <rmind at NetBSD org>
|
||||
@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: sys_sched.c,v 1.28 2008/10/15 06:51:20 wrstuden Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: sys_sched.c,v 1.29 2008/10/18 03:40:18 rmind Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
@ -64,39 +64,33 @@ __KERNEL_RCSID(0, "$NetBSD: sys_sched.c,v 1.28 2008/10/15 06:51:20 wrstuden Exp
|
||||
static pri_t
|
||||
convert_pri(lwp_t *l, int policy, pri_t pri)
|
||||
{
|
||||
int delta = 0;
|
||||
|
||||
switch (policy) {
|
||||
case SCHED_OTHER:
|
||||
delta = PRI_USER;
|
||||
break;
|
||||
case SCHED_FIFO:
|
||||
case SCHED_RR:
|
||||
delta = PRI_USER_RT;
|
||||
break;
|
||||
default:
|
||||
panic("upri_to_kpri");
|
||||
}
|
||||
|
||||
/* Convert user priority to the in-kernel */
|
||||
if (pri != PRI_NONE) {
|
||||
/* Convert user priority to the in-kernel */
|
||||
/* Only for real-time threads */
|
||||
KASSERT(pri >= SCHED_PRI_MIN && pri <= SCHED_PRI_MAX);
|
||||
return pri + delta;
|
||||
KASSERT(policy != SCHED_OTHER);
|
||||
return PRI_USER_RT + pri;
|
||||
}
|
||||
|
||||
/* Neither policy, nor priority change */
|
||||
if (l->l_class == policy)
|
||||
return l->l_priority;
|
||||
|
||||
/* Change the current priority to the appropriate range */
|
||||
/* Time-sharing -> real-time */
|
||||
if (l->l_class == SCHED_OTHER) {
|
||||
KASSERT(policy == SCHED_FIFO || policy == SCHED_RR);
|
||||
return delta;
|
||||
return PRI_USER_RT;
|
||||
}
|
||||
|
||||
/* Real-time -> time-sharing */
|
||||
if (policy == SCHED_OTHER) {
|
||||
KASSERT(l->l_class == SCHED_FIFO || l->l_class == SCHED_RR);
|
||||
return l->l_priority - delta;
|
||||
return l->l_priority - PRI_USER_RT;
|
||||
}
|
||||
KASSERT(l->l_class != SCHED_OTHER && policy != SCHED_OTHER);
|
||||
return l->l_class;
|
||||
|
||||
/* Real-time -> real-time */
|
||||
return l->l_priority;
|
||||
}
|
||||
|
||||
int
|
||||
@ -154,19 +148,19 @@ do_sched_setparam(pid_t pid, lwpid_t lid, int policy,
|
||||
|
||||
if (lid && lid != t->l_lid)
|
||||
continue;
|
||||
|
||||
lcnt++;
|
||||
KASSERT(pri != PRI_NONE || policy != SCHED_NONE);
|
||||
lwp_lock(t);
|
||||
lpolicy = (policy == SCHED_NONE) ? t->l_class : policy;
|
||||
|
||||
if (policy == SCHED_NONE)
|
||||
lpolicy = t->l_class;
|
||||
else
|
||||
lpolicy = policy;
|
||||
/* Disallow setting of priority for SCHED_OTHER threads */
|
||||
if (lpolicy == SCHED_FIFO && pri != PRI_NONE) {
|
||||
lwp_unlock(t);
|
||||
error = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Note that, priority may need to be changed to get into
|
||||
* the correct priority range of the new scheduling class.
|
||||
*/
|
||||
/* Convert priority, if needed */
|
||||
kpri = convert_pri(t, lpolicy, pri);
|
||||
|
||||
/* Check the permission */
|
||||
@ -178,14 +172,9 @@ do_sched_setparam(pid_t pid, lwpid_t lid, int policy,
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set the scheduling class */
|
||||
if (policy != SCHED_NONE)
|
||||
t->l_class = policy;
|
||||
|
||||
/* Change the priority */
|
||||
if (t->l_priority != kpri)
|
||||
lwp_changepri(t, kpri);
|
||||
|
||||
/* Set the scheduling class, change the priority */
|
||||
t->l_class = lpolicy;
|
||||
lwp_changepri(t, kpri);
|
||||
lwp_unlock(t);
|
||||
}
|
||||
mutex_exit(p->p_lock);
|
||||
@ -344,7 +333,6 @@ sys__sched_setaffinity(struct lwp *l,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ci == NULL) {
|
||||
/* Empty set */
|
||||
kcpuset_unuse(cpuset, NULL);
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: schedctl.8,v 1.8 2008/06/22 14:51:45 wiz Exp $
|
||||
.\" $NetBSD: schedctl.8,v 1.9 2008/10/18 03:40:18 rmind Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
@ -27,7 +27,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd June 22, 2008
|
||||
.Dd October 18, 2008
|
||||
.Dt SCHEDCTL 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -71,13 +71,15 @@ First in, first out (FIFO) scheduling policy.
|
||||
Round-robin scheduling policy.
|
||||
.El
|
||||
.It Fl P Ar pri
|
||||
Priority which will be set for the process or thread.
|
||||
For all scheduling classes, priority might be set to any value in
|
||||
the range from
|
||||
Priority for the process or thread.
|
||||
Value should be in the range from
|
||||
.Dv SCHED_PRI_MIN
|
||||
(0) to
|
||||
.Dv SCHED_PRI_MAX
|
||||
(63).
|
||||
Setting of priority for the process or thread running at
|
||||
.Dv SCHED_OTHER
|
||||
policy is not allowed.
|
||||
.It Fl p Ar pid
|
||||
The target process which will be affected.
|
||||
If the process has more than one thread, all of them will be affected.
|
||||
@ -107,7 +109,7 @@ for thread whose ID is
|
||||
in process whose ID is
|
||||
.Dq 123 :
|
||||
.Bd -literal -offset indent
|
||||
# schedctl -p 123 -t 1 -A 0,1 -C 2 -P 63
|
||||
# schedctl -p 123 -t 1 -A 0,1 -C SCHED_RR -P 63
|
||||
.Ed
|
||||
.Pp
|
||||
Run the
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: schedctl.c,v 1.11 2008/06/16 01:41:21 rmind Exp $ */
|
||||
/* $NetBSD: schedctl.c,v 1.12 2008/10/18 03:40:18 rmind Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008, Mindaugas Rasiukevicius <rmind at NetBSD org>
|
||||
@ -13,17 +13,17 @@
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -33,7 +33,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: schedctl.c,v 1.11 2008/06/16 01:41:21 rmind Exp $");
|
||||
__RCSID("$NetBSD: schedctl.c,v 1.12 2008/10/18 03:40:18 rmind Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
Loading…
Reference in New Issue
Block a user