From 3b0f093fdcee4798c10c948450193dd2e57c8207 Mon Sep 17 00:00:00 2001 From: dg Date: Sun, 2 Oct 1994 04:48:21 +0000 Subject: "idle priority" support. Based on code from Henrik Vestergaard Draboel, but substantially rewritten by me. --- usr.sbin/rtprio/Makefile | 6 +- usr.sbin/rtprio/rtprio.1 | 92 +++++++++++++++++--------- usr.sbin/rtprio/rtprio.2 | 106 +++++++++++++++++++++++++++++ usr.sbin/rtprio/rtprio.c | 169 ++++++++++++++++++++++++----------------------- 4 files changed, 258 insertions(+), 115 deletions(-) create mode 100644 usr.sbin/rtprio/rtprio.2 (limited to 'usr.sbin') diff --git a/usr.sbin/rtprio/Makefile b/usr.sbin/rtprio/Makefile index 2ca8da9..af159bf 100644 --- a/usr.sbin/rtprio/Makefile +++ b/usr.sbin/rtprio/Makefile @@ -1,7 +1,11 @@ # from: @(#)Makefile 5.5 (Berkeley) 5/11/90 -# $Id: Makefile,v 1.2 1993/11/23 00:02:21 jtc Exp $ +# $Id: Makefile,v 1.1 1994/09/01 12:05:12 davidg Exp $ BINDIR=/usr/sbin PROG= rtprio +LINKS= ${BINDIR}/rtprio ${BINDIR}/idprio +MLINKS= rtprio.1 idprio.1 +MAN1= rtprio.1 +MAN2= rtprio.2 .include diff --git a/usr.sbin/rtprio/rtprio.1 b/usr.sbin/rtprio/rtprio.1 index a2cc7dc..5542f12 100644 --- a/usr.sbin/rtprio/rtprio.1 +++ b/usr.sbin/rtprio/rtprio.1 @@ -34,35 +34,50 @@ .Dt RTPRIO 1 .Os .Sh NAME -.Nm rtprio -.Nd execute, examine or modify a process's realtime scheduling priority +.Nm rtprio , +.Nm idprio +.Nd execute, examine or modify a utilitys or process realtime +or idletime scheduling priority .Sh SYNOPSIS -.Nm rtprio -.Nm rtprio +.Nm [id|rt]prio +.Nm [id|rt]prio .Ar pid -.Nm rtprio +.Nm [id|rt]prio .Ar priority .Ar command .Op args -.Nm rtprio +.Nm [id|rt]prio .Ar priority .Ar -pid -.Nm rtprio +.Nm [id|rt]prio .Ar -t .Ar command .Op args -.Nm rtprio +.Nm [id|rt]prio .Ar -t .Ar -pid .Sh DESCRIPTION .Nm Rtprio -is used for controlling realtime process scheduling. A process with a -realtime priority is not subject to priority degradation, and will only -be preempted by another process of equal or higher realtime priority. +is used for controlling realtime process scheduling. -.Nm Rtprio -called without arguments, will return the realtime priority +.Nm Idprio +is used for controlling idletime process scheduling, and can be called +with the same options as +.Nm Rtprio . + +A process with a realtime priority is not subject to priority +degradation, and will only be preempted by another process of equal or +higher realtime priority. + +A process with an idle priority will run only when no other +process is runnable and then only if it's idle priority is equal or +greater than all other runnable idle priority processes. + +.Nm Rtprio +or +.Nm Idprio +when called without arguments will return the realtime priority of the current process. If @@ -81,23 +96,27 @@ process. If .Ar -pid -is specified, the process with that pid will be modified, else -if +is specified, the process with the process identifier "pid" will be +modified, else if .Ar command is specified, that program is run with its arguments. .Ar Priority -is an integer between 0 (RTPRIO_MIN) and 31 (RTPRIO_MAX). 0 is the +is an integer between 0 and RTP_PRIO_MAX (usually 31). 0 is the highest priority .Ar Pid of 0 means "the current process". -Only root is allowed to set realtime priorities. +Only root is allowed to set realtime priorities. Non-root processes may +set idle priority levels for the current process only. .Sh RETURN VALUE +If .Nm rtprio -returns the (new) realtime priority of the process (see rtprio(2)), or --1 for all usage errors. +execute a command, the exit value is that of the command executed. +In all other cases, +.Nm +exits with 0 for success and 1 for all other errors. .Sh EXAMPLES .\LP @@ -131,16 +150,17 @@ To run \fItcpdump\fP without realtime priority: .Ed .\.LP -To change the realtime priority of process \fI1423\fP to RTRIO_RTOFF -(no realtime): +To change the realtime priority of process \fI1423\fP to RTP_PRIO_NORMAL +(non-realtime/"normal" priority): .Bd -literal -offset indent -compact \fBrtprio -t -1423\fP .Ed -.Sh DIAGNOSTICS -The -.Nm rtprio -utility shall exit with value of the (new) realtime priority of the -program. + +.\.LP +To make depend while not disturbing other machine usage: +.Bd -literal -offset indent -compact +\fBidprio 31 make depend\fP +.Ed .Sh SEE ALSO .Xr rtprio 2 , .Xr nice 1 , @@ -153,13 +173,25 @@ The utility appeared in FreeBSD 2.0, but is similar to the HP-UX version. +.Sh CAVEATS +You can lock yourself out of the system by placing a cpu-heavy +process in a realtime priority. .Sh BUGS -You can lock yourself out of the system by placing a cpu-intensive -process into realtime priority. - There is no way to set/view the realtime priority of process 0 (swapper) (see ps(1)). +There is in +FreeBSD +no way to ensure that a process page is present in memory therefore +the process may be stopped for pagein. (See mprotect(2), madvise(2)). + +Under +FreeBSD +system calls are currently never preempted, therefore non-realtime +processes can starve realtime procesess, or idletime processes can +starve normal priority processes. + Others ... .Sh AUTHOR -Henrik Vestergaard Draboel - hvd@terry.ping.dk +Henrik Vestergaard Draboel - hvd@terry.ping.dk is the original author. This +implementation in FreeBSD was substantially rewritten by David Greenman. diff --git a/usr.sbin/rtprio/rtprio.2 b/usr.sbin/rtprio/rtprio.2 new file mode 100644 index 0000000..2c1b4c7 --- /dev/null +++ b/usr.sbin/rtprio/rtprio.2 @@ -0,0 +1,106 @@ +.\" Copyright (c) 1994, Henrik Vestergaard Draboel +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Henrik Vestergaard Draboel. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" 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. +.\" +.\" $Id: rtprio.2,v 1.2 1994/09/01 12:09:17 davidg Exp $ +.\" +.Dd July 23, 1994 +.Dt RTPRIO 2 +.Sh NAME +.Nm rtprio +.Nd examine or modify a process realtime or idle priority +.Sh SYNOPSIS +.Fd #include +.Fd #include +.Ft int +.Fn rtprio "function" "pid_t pid" "struct rtprio *rtp" +.Sh DESCRIPTION +.Fn rtprio +is used to lookup or change the realtime or idle priority of a process. + +.Fa function +specifies the operation to be performed. RTP_LOOKUP to lookup the current priority, +and RTP_SET to set the priority. +.Fa pid +specifies the process to be used, 0 for the current process. + +.Fa *rtp +is a pointer to a struct rtprio which is used to specify the priority and priority type. +This structure has the following form: +.Bd -literal +struct rtprio { + u_short type; + u_short prio; +}; +.Ed +.Pp +The value of the +.Nm type +field may be RTP_PRIO_REALTIME for realtime priorities, +RTP_PRIO_NORMAL for normal priorities, and RTP_PRIO_IDLE for idle priorities. +The priority specified by the +.Nm prio +field ranges between 0 and +.Dv RTP_PRIO_MAX (usually 31) . +0 is the highest possible priority. + +Realtime and idle priority is inherited through fork() and exec(). + +A realtime process can only be preempted by a process of equal or +higher priority, or by an interrupt; idle priority processes will run only +when no other real/normal priority process is runnable. Higher real/idle priority processes +preempt lower real/idle priority processes. Processes of equal real/idle priority are run round-robin. +.Sh RETURN VALUES +.Fn rtprio +will return 0 for success and -1 for all errors. The global variable +.Va errno +will be set to indicate the error. +.Sh ERRORS +.Fn rtprio +will fail if +.Bl -tag -width Er +.It Bq Er EINVAL +The specified +.Fa prio +was out of range. +.It Bq Er EPERM +The calling process is not allowed to set the realtime priority. Only +root is allowed to change the realtime priority of any process, and non-root +may only change the idle priority of the current process. +.It Bq Er ESRCH +The specified process was not found. +.Sh AUTHOR +The original author was Henrik Vestergaard Draboel - hvd@terry.ping.dk. This +implementation in FreeBSD was substantially rewritten by David Greenman. +.Sh SEE ALSO +.Xr rtprio 1 , +.Xr nice 1 , +.Xr ps 1 , +.Xr nice 2 , +.Xr renice 8 + diff --git a/usr.sbin/rtprio/rtprio.c b/usr.sbin/rtprio/rtprio.c index cc66fd4..ab4d085 100644 --- a/usr.sbin/rtprio/rtprio.c +++ b/usr.sbin/rtprio/rtprio.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 1994 The Regents of the University of California. + * Copyright (c) 1994 David Greenman + * Copyright (c) 1994 Henrik Vestergaard Draboel (hvd@terry.ping.dk) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -12,16 +13,16 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * This product includes software developed by Henrik Vestergaard Draboel. + * This product includes software developed by David Greenman. + * 4. Neither the names of the authors nor the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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) @@ -29,28 +30,15 @@ * 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. + * + * $Id$ */ -/* Copyright (c) 1994 Henrik Vestergaard Drabøl (hvd@terry.pping.dk) */ - -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1989 The Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)rtprio.c 5.4 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$Id: rtprio.c,v 1.2 1993/11/23 00:02:23 jtc Exp $"; -#endif /* not lint */ - -#include -#include +#include #include -#include -#include -#include +#include +#include #include #include #include @@ -60,82 +48,95 @@ static void usage(); int main(argc, argv) - int argc; - char **argv; + int argc; + char **argv; { - int nrtprio = RTPRIO_RTOFF; - int proc=0; + char *p; + int proc = 0; + struct rtprio rtp; + + /* find basename */ + if ((p = rindex(argv[0], '/')) == NULL) + p = argv[0]; + else + ++p; - setlocale(LC_ALL, ""); - errno = 0; + if (!strcmp(p, "rtprio")) + rtp.type = RTP_PRIO_REALTIME; + else if (!strcmp(p, "idprio")) + rtp.type = RTP_PRIO_IDLE; switch (argc) { - case 2: - proc = abs(atoi(argv[1])); + case 2: + proc = abs(atoi(argv[1])); /* Should check if numeric + * arg! */ /* FALLTHROUGH */ - case 1: - nrtprio = rtprio(proc,RTPRIO_NOCHG); - fprintf(stderr,"rtprio: %d %s\n", - nrtprio, - nrtprio==RTPRIO_RTOFF?"(RTOFF)":""); - exit(nrtprio); - /* NOTREACHED */ - - default: { - switch (argv[1][0]) { - case '-': - if (strcmp(argv[1],"-t")==0) - nrtprio = RTPRIO_RTOFF; - else - usage(); - break; - - case '0':case '1':case '2':case '3':case '4': - case '5':case '6':case '7':case '8':case '9': - nrtprio = atoi (argv[1]); - - if (errno== ERANGE) usage(); - break; - + if (rtprio(RTP_LOOKUP, proc, &rtp) != 0) { + perror(argv[0]); + exit (1); + } + printf("%s: ", p); + switch (rtp.type) { + case RTP_PRIO_REALTIME: + printf("realtime priority %d\n", rtp.prio); + break; + case RTP_PRIO_NORMAL: + printf("normal priority\n"); + break; + case RTP_PRIO_IDLE: + printf("idle priority %d\n", rtp.prio); + break; default: - usage(); - break; + printf("invalid priority type %d\n", rtp.type); + break; } - switch (argv[2][0]) { - case '-': - proc = -atoi(argv[2]); - - break; + exit(0); + default: + if (argv[1][0] == '-' || isdigit(argv[1][0])) { + if (argv[1][0] == '-') { + if (strcmp(argv[1], "-t") == 0) { + rtp.type = RTP_PRIO_NORMAL; + rtp.prio = 0; + } else { + usage(p); + break; + } + } else { + rtp.prio = atoi(argv[1]); + } + } else { + usage(p); + break; } - - errno = 0; - nrtprio = rtprio(proc, nrtprio); + if (argv[2][0] == '-') + proc = -atoi(argv[2]); - if (errno) { - err (1, "rtprio"); - /* NOTREACHED */ - } + if (rtprio(RTP_SET, proc, &rtp) != 0) { + perror(argv[0]); + exit (1); + } - if (proc == 0) { - execvp(argv[2], &argv[2]); - err ((errno == ENOENT) ? 127 : 126, "%s", argv[2]);} - /* NOTREACHED */ - } + if (proc == 0) { + execvp(argv[2], &argv[2]); + perror(argv[0]); + exit (1); + } } -return(nrtprio); + exit (1); } static void -usage() +usage(basename) + char *basename; { - (void)fprintf(stderr, "usage: rtprio\n"); - (void)fprintf(stderr, "usage: rtprio [-] pid\n"); - (void)fprintf(stderr, "usage: rtprio priority command [ args ] \n"); - (void)fprintf(stderr, "usage: rtprio priority -pid \n"); - (void)fprintf(stderr, "usage: rtprio -t command [ args ] \n"); - (void)fprintf(stderr, "usage: rtprio -t -pid \n"); - + (void) fprintf(stderr, "usage: %s\n", basename); + (void) fprintf(stderr, "usage: %s [-]pid\n", basename); + (void) fprintf(stderr, "usage: %s priority command [ args ] \n", basename); + (void) fprintf(stderr, "usage: %s priority -pid \n", basename); + (void) fprintf(stderr, "usage: %s -t command [ args ] \n", basename); + (void) fprintf(stderr, "usage: %s -t -pid \n", basename); + exit(-1); } -- cgit v1.1