Date: Sun, 28 Jan 1996 14:31:40 +0200 (EET) From: Jukka Ukkonen <jau@jau.csc.fi> To: hackers@freebsd.org Subject: POSIX.4 scheduler interface for FreeBSD-2.1 Message-ID: <199601281231.OAA00704@jau.csc.fi>
next in thread | raw e-mail | index | archive | help
Hi all! I have spent a while tinkering with a POSIX.4 style scheduling interface to FreeBSD. Attached are the results. Before I added POSIX.4 style scheduling interface I had to add another realtime scheduling policy to the kernel. The new one uses FIFO logic required by POSIX.4 for realtime processes meaning that a process running under FIFO policy has no predetermined time slice, and it will not be involuntarily released from the CPU. The old realtime policy is still present, and it matches nicely the round-robin realtime policy in POSIX.4. Both even use the same scheduling queue. I have been running e.g. xntpd with realtime fifo priority for about a month now without any problems. At least one important question still remains to be considered. What is the benefit of having separate realtime policies at all, if there still is the possibility of a problem known as priority inversion? E.g. a process with relatively high (realtime) priority wishes to communicate with another process with worse priority using a pipe in which there is no free buffer space available. Now the process with higher priority would have to wait for the process with lower priority to read from the pipe to make room for the data to be written by the higher priority process. While waiting for the buffer to drain the process with higher priority could become pre-empted by a process which has its priority somewhere between the priorities of the communicating processes. And so we see the grand surprise, the higher priority process waits for the lower priority process, which in turn waits for the middle priority process. The realtime model has just been broken because the process with the best priority lost its place in the scheduling queue to a process with lower priority. To make realtime scheduling really deterministic and attractive to use, a mechanism for temporary priority inheritance would need to be added. With priority inheritance in effect the process with lower priority should temporarily inherit the priority and the scheduling policy from the highest priority process waiting for space to become available in the pipe buffer. Similar logic will naturally be needed with semaphores and message queues if they ever get added to the system. Probably also file locks would deserve priority inheritance to be applied. Anyway, adding posix.4 scheduler interface was an interesting undertaking. And as usual, if it is worth anything, you can use it or abuse it. If it breaks, you can keep all the pieces. There is the condition though that the source has to be available for anyone who wishes to have it. (This time the stuff, has also the traditional BSD style disclaimer banner.) Cheers, // jau ------ / Jukka A. Ukkonen, FUNET / Centre for Scientific Computing /__ M.Sc. (sw-eng & cs) Tel: (Home) +358-0-6215280 / Internet: ukkonen@csc.fi (Work) +358-0-4573208 / Internet: jau@funet.fi (Mobile) +358-400-606671 v X.400: c=fi, admd=fumail, org=csc, pn=jukka.a.ukkonen ------------------------------ clip clip ------------------------------ # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # sched.h # sched_getparam.c # sched_getscheduler.c # sched_get_priority_max.c # sched_get_priority_min.c # sched_setparam.c # sched_setscheduler.c # sched_yield.c # Kernel.Diffs # RTprio.diffs # echo x - sched.h sed 's/^X//' >sched.h << 'END-of-sched.h' X/* X * Copyright (c) 1995,1996 Jukka Ukkonen <jau@funet.fi> X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by Jukka Antero Ukkonen. X * 4. Neither the names of the authors nor the names of contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * 5. The source code must be available for anyone who wishes to have it. X * X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * %W% (Jukka Ukkonen) %E% X */ X X#ifndef lint Xstatic const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%"; X#endif X X X#ifndef _SCHED_H X#define _SCHED_H X X#include <sys/types.h> X#include <sys/rtprio.h> X#include <time.h> /* For struct timespec */ X X#ifndef _POSIX_PRIORITY_SCHEDULING X# define _POSIX_PRIORITY_SCHEDULING X#endif X X/* X * FIFO and Round-Robin must really be separate, but maybe X * it could be possible and worthwhile to try approximate FIFO X * using RR with higher priorities. X * X * RTP_PRIO_REALTIME with round-robin among equal priority X * processes at every time-quantum (= currently HZ/10) would X * still be only a poor substitute for fifo scheduling on X * systems that don't have a real fifo policy. X * X * Otherwise FIFO and RR are equivalent in all respects, but X * RR comes with involuntary release of CPU after the time X * quantum has passed. X * FIFO knows only about voluntary release of the CPU while X * the process can run as long as it wishes. So, you really X * can hang your machine, if there is no other process with X * higher RT-priority (FIFO or RR) ready to kill a infinitely X * looping FIFO process. X */ X X#ifdef RTP_PRIO_FIFO X# define SCHED_FIFO RTP_PRIO_FIFO X#else X# define SCHED_FIFO RTP_PRIO_REALTIME X#endif X X#define SCHED_RR RTP_PRIO_REALTIME X#define SCHED_TIMESHARE RTP_PRIO_NORMAL X#define SCHED_IDLE RTP_PRIO_IDLE X#define SCHED_OTHER SCHED_TIMESHARE X X/* X * Hopefully someone is interested enough to add X * the necessary deadline logic to the kernel. X */ X X#ifdef RTP_PRIO_DEADLINE X# define SCHED_DEADLINE RTP_PRIO_DEADLINE X#endif X Xstruct sched_param { X int sched_type; /* scheduling policy */ X int sched_priority; /* nice for time-share, else true prio */ X int sched_pgprio; /* pg-nice for TS, else unused */ X int sched_userprio; /* user-nice for TS, else unused */ X struct timespec sched_deadline; /* reserved for deadline scheduling */ X struct timespec sched_timereq; /* reserved for deadline scheduling */ X}; X X#endif END-of-sched.h echo x - sched_getparam.c sed 's/^X//' >sched_getparam.c << 'END-of-sched_getparam.c' X/* X * Copyright (c) 1995,1996 Jukka Ukkonen <jau@funet.fi> X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by Jukka Antero Ukkonen. X * 4. Neither the names of the authors nor the names of contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * 5. The source code must be available for anyone who wishes to have it. X * X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * %W% (Jukka Ukkonen) %E% X */ X X#ifndef lint Xstatic const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%"; X#endif X X X#include <sys/types.h> X#include <sys/time.h> X#include <sys/resource.h> X#include <sys/rtprio.h> X#include <sched.h> X#include <errno.h> X Xint Xsched_getparam (pid, param) X pid_t pid; X struct sched_param *param; X{ X struct rtprio rtp; X X if (! param) { X errno = EINVAL; X return (-1); X } X X if (rtprio (RTP_LOOKUP, pid, &rtp) < 0) X return (-1); X X param->sched_type = rtp.type; X X if (rtp.type == RTP_PRIO_NORMAL) { X errno = 0; X X param->sched_priority = getpriority (PRIO_PROCESS, pid); X X if ((param->sched_priority == -1) && errno) X return (-1); X X param->sched_priority = -param->sched_priority; X X errno = 0; X X param->sched_pgprio = getpriority (PRIO_PGRP, pid); X X if ((param->sched_pgprio == -1) && errno) X return (-1); X X param->sched_pgprio = -param->sched_pgprio; X X errno = 0; X X param->sched_userprio = getpriority (PRIO_USER, pid); X X if ((param->sched_userprio == -1) && errno) X return (-1); X X param->sched_userprio = -param->sched_userprio; X } X else X param->sched_priority = RTP_PRIO_MAX - rtp.prio; X X return (0); X} END-of-sched_getparam.c echo x - sched_getscheduler.c sed 's/^X//' >sched_getscheduler.c << 'END-of-sched_getscheduler.c' X/* X * Copyright (c) 1995,1996 Jukka Ukkonen <jau@funet.fi> X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by Jukka Antero Ukkonen. X * 4. Neither the names of the authors nor the names of contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * 5. The source code must be available for anyone who wishes to have it. X * X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * %W% (Jukka Ukkonen) %E% X */ X X#ifndef lint Xstatic const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%"; X#endif X X X#include <sys/types.h> X#include <sys/time.h> X#include <sys/resource.h> X#include <sys/rtprio.h> X Xint Xsched_getscheduler (pid) X pid_t pid; X{ X struct rtprio rtp; X X if (rtprio (RTP_LOOKUP, pid, &rtp) < 0) X return (-1); X X return ((int) rtp.type); X} END-of-sched_getscheduler.c echo x - sched_get_priority_max.c sed 's/^X//' >sched_get_priority_max.c << 'END-of-sched_get_priority_max.c' X/* X * Copyright (c) 1995,1996 Jukka Ukkonen <jau@funet.fi> X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by Jukka Antero Ukkonen. X * 4. Neither the names of the authors nor the names of contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * 5. The source code must be available for anyone who wishes to have it. X * X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * %W% (Jukka Ukkonen) %E% X */ X X#ifndef lint Xstatic const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%"; X#endif X X X#include <sys/types.h> X#include <sys/time.h> X#include <sys/resource.h> X#include <sched.h> X#include <errno.h> X Xint Xsched_get_priority_max (policy) X int policy; X{ X switch (policy) { X X case SCHED_FIFO: X case SCHED_RR: X case SCHED_IDLE: X return (RTP_PRIO_MAX); X X case SCHED_TIMESHARE: X return (PRIO_MAX); X X default: X errno = EINVAL; /* Here is a gotcha! Always check errno! */ X return (-1); /* Whether negatives are valid is unspecified. */ X } X} X END-of-sched_get_priority_max.c echo x - sched_get_priority_min.c sed 's/^X//' >sched_get_priority_min.c << 'END-of-sched_get_priority_min.c' X/* X * Copyright (c) 1995,1996 Jukka Ukkonen <jau@funet.fi> X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by Jukka Antero Ukkonen. X * 4. Neither the names of the authors nor the names of contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * 5. The source code must be available for anyone who wishes to have it. X * X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * %W% (Jukka Ukkonen) %E% X */ X X#ifndef lint Xstatic const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%"; X#endif X X X#include <sys/types.h> X#include <sys/time.h> X#include <sys/resource.h> X#include <sched.h> X#include <errno.h> X Xint Xsched_get_priority_max (policy) X int policy; X{ X switch (policy) { X X case SCHED_FIFO: X case SCHED_RR: X case SCHED_IDLE: X return (RTP_PRIO_MIN); X X case SCHED_TIMESHARE: X return (PRIO_MIN); X X default: X errno = EINVAL; /* Here is a gotcha! Always check errno! */ X return (-1); /* Whether negatives are valid is unspecified. */ X } X} X END-of-sched_get_priority_min.c echo x - sched_setparam.c sed 's/^X//' >sched_setparam.c << 'END-of-sched_setparam.c' X/* X * Copyright (c) 1995,1996 Jukka Ukkonen <jau@funet.fi> X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by Jukka Antero Ukkonen. X * 4. Neither the names of the authors nor the names of contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * 5. The source code must be available for anyone who wishes to have it. X * X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * %W% (Jukka Ukkonen) %E% X */ X X#ifndef lint Xstatic const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%"; X#endif X X X#include <sys/types.h> X#include <sys/time.h> X#include <sys/resource.h> X#include <sys/rtprio.h> X#include <sched.h> X#include <errno.h> X Xint Xsched_setparam (pid, param) X pid_t pid; X struct sched_param *param; X{ X struct rtprio rtp; X X if (! param) { X errno = EINVAL; X return (-1); X } X X if (rtprio (RTP_LOOKUP, pid, &rtp) < 0) X return (-1); X X if (rtp.type == RTP_PRIO_NORMAL) { X if (setpriority (PRIO_PROCESS, pid, -param->sched_priority) < 0) X return (-1); X X if (setpriority (PRIO_PGRP, pid, -param->sched_pgprio) < 0) X return (-1); X X if (setpriority (PRIO_USER, pid, -param->sched_userprio) < 0) X return (-1); X X rtp.prio = 0; X } X else X rtp.prio = RTP_PRIO_MAX - param->sched_priority; X X if (rtprio (RTP_SET, pid, &rtp) < 0) X return (-1); X X return (0); X} END-of-sched_setparam.c echo x - sched_setscheduler.c sed 's/^X//' >sched_setscheduler.c << 'END-of-sched_setscheduler.c' X/* X * Copyright (c) 1995,1996 Jukka Ukkonen <jau@funet.fi> X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by Jukka Antero Ukkonen. X * 4. Neither the names of the authors nor the names of contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * 5. The source code must be available for anyone who wishes to have it. X * X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * %W% (Jukka Ukkonen) %E% X */ X X#ifndef lint Xstatic const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%"; X#endif X X X#include <sys/types.h> X#include <sys/time.h> X#include <sys/resource.h> X#include <sys/rtprio.h> X#include <sched.h> X#include <errno.h> X Xint Xsched_setscheduler (pid, policy, param) X pid_t pid; X int policy; X struct sched_param *param; X{ X struct rtprio rtp; X X if (! param) { X errno = EINVAL; X return (-1); X } X X rtp.type = policy; X X if (policy == RTP_PRIO_NORMAL) { X if (setpriority (PRIO_PROCESS, pid, -param->sched_priority) < 0) X return (-1); X X if (setpriority (PRIO_PGRP, pid, -param->sched_pgprio) < 0) X return (-1); X X if (setpriority (PRIO_USER, pid, -param->sched_userprio) < 0) X return (-1); X X rtp.prio = 0; X } X else X rtp.prio = RTP_PRIO_MAX - param->sched_priority; X X if (rtprio (RTP_SET, pid, &rtp) < 0) X return (-1); X X return (0); X} END-of-sched_setscheduler.c echo x - sched_yield.c sed 's/^X//' >sched_yield.c << 'END-of-sched_yield.c' X/* X * Copyright (c) 1995,1996 Jukka Ukkonen <jau@funet.fi> X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed by Jukka Antero Ukkonen. X * 4. Neither the names of the authors nor the names of contributors X * may be used to endorse or promote products derived from this software X * without specific prior written permission. X * 5. The source code must be available for anyone who wishes to have it. X * X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X * X * %W% (Jukka Ukkonen) %E% X */ X X#ifndef lint Xstatic const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%"; X#endif X X X#include <sys/time.h> X#include <sched.h> X#include <errno.h> X Xint Xsched_yield () X{ X struct timeval timeout; X X timeout.tv_sec = timeout.tv_usec = 0; X X /* X * Select a system call that will never hang waiting for X * something really happen to force an entry to the kernel. X * X * The entry to kernel code with zero timeout should cause X * a new scheduling decission to be made. X */ X X if ((select (0, NULL, NULL, NULL, &timeout) < 0) && (errno != EINTR)) X return (-1); X X return (0); X} X END-of-sched_yield.c echo x - Kernel.Diffs sed 's/^X//' >Kernel.Diffs << 'END-of-Kernel.Diffs' X--- /sys/kern/kern_resource.c.orig Tue May 30 11:05:39 1995 X+++ /sys/kern/kern_resource.c Mon Dec 25 20:52:30 1995 X@@ -247,8 +247,11 @@ X /* can't set realtime priority */ X if (rtp.type == RTP_PRIO_REALTIME) X return (EPERM); X+ if (rtp.type == RTP_PRIO_FIFO) X+ return (EPERM); X } X switch (rtp.type) { X+ case RTP_PRIO_FIFO: X case RTP_PRIO_REALTIME: X case RTP_PRIO_NORMAL: X case RTP_PRIO_IDLE: X--- /sys/kern/kern_synch.c.orig Tue May 30 11:05:44 1995 X+++ /sys/kern/kern_synch.c Tue Dec 26 16:23:20 1995 X@@ -67,8 +67,10 @@ X roundrobin(arg) X void *arg; X { X+ if (! curproc || curproc->p_rtprio.type != RTP_PRIO_FIFO) { X+ need_resched(); X+ } X X- need_resched(); X timeout(roundrobin, NULL, hz / 10); X } X X@@ -670,7 +672,11 @@ X p->p_usrpri = newpriority; X if (newpriority < curpriority) X need_resched(); X- } else { X+ } else if (! curproc || X+ (curproc->p_rtprio.type != RTP_PRIO_FIFO) || X+ (((p->p_rtprio.type == RTP_PRIO_FIFO) || X+ (p->p_rtprio.type == RTP_PRIO_REALTIME)) && X+ (p->p_rtprio.prio < curproc->p_rtprio.prio))) { X need_resched(); X } X } X--- /sys/sys/rtprio.h.orig Sun Oct 2 06:45:59 1994 X+++ /sys/sys/rtprio.h Mon Dec 25 20:48:18 1995 X@@ -42,7 +42,26 @@ X #define RTP_PRIO_REALTIME 0 X #define RTP_PRIO_NORMAL 1 X #define RTP_PRIO_IDLE 2 X+#define RTP_PRIO_FIFO 3 X X+/* X+ * RTP_PRIO_QUANTUM -- not implemented yet! X+ * Actually this is intended as another type X+ * of round-robin policy with the ability to X+ * allow processes request a non-default X+ * time-slice or time-quantum. X+ */ X+/* #define RTP_PRIO_QUANTUM 4 */ X+ X+/* X+ * RTP_PRIO_DEADLINE -- not implemented yet! X+ */ X+/* #define RTP_PRIO_DEADLINE 5 */ X+ X+/* X+ * Actual priority ranges should be changed X+ * to cover at least some 128 to 256 steps! X+ */ X /* priority range */ X #define RTP_PRIO_MIN 0 /* Highest priority */ X #define RTP_PRIO_MAX 31 /* Lowest priority */ X@@ -57,6 +76,10 @@ X struct rtprio { X u_short type; X u_short prio; X+#if defined(RTP_PRIO_DEADLINE) || defined(RTP_PRIO_QUANTUM) X+ struct timeval deadline; /* Fail if not ready to repeat. */ X+ struct timeval quantum; /* Min./required time slice. */ X+#endif X }; X #endif X X--- /sys/i386/i386/swtch.s.orig Tue Dec 26 14:19:25 1995 X+++ /sys/i386/i386/swtch.s Tue Dec 26 14:20:58 1995 X@@ -90,6 +90,9 @@ X X movzwl P_RTPRIO_PRIO(%eax),%edx X X+ cmpw $RTP_PRIO_FIFO,P_RTPRIO_TYPE(%eax) /* fifo rt priority? */ X+ je set_rt X+ X cmpw $RTP_PRIO_REALTIME,P_RTPRIO_TYPE(%eax) /* realtime priority? */ X jne set_id /* must be idle priority */ X X--- /sys/vm/vm_glue.c.orig Mon Oct 16 22:43:05 1995 X+++ /sys/vm/vm_glue.c Mon Dec 25 20:52:32 1995 X@@ -430,6 +430,9 @@ X /* X * do not swapout a realtime process X */ X+ if (p->p_rtprio.type == RTP_PRIO_FIFO) X+ continue; X+ X if (p->p_rtprio.type == RTP_PRIO_REALTIME) X continue; X X--- /usr/include/sys/rtprio.h.orig Sun Oct 2 06:45:59 1994 X+++ /usr/include/sys/rtprio.h Mon Dec 25 20:48:18 1995 X@@ -42,7 +42,26 @@ X #define RTP_PRIO_REALTIME 0 X #define RTP_PRIO_NORMAL 1 X #define RTP_PRIO_IDLE 2 X+#define RTP_PRIO_FIFO 3 X X+/* X+ * RTP_PRIO_QUANTUM -- not implemented yet! X+ * Actually this is intended as another type X+ * of round-robin policy with the ability to X+ * allow processes request a non-default X+ * time-slice or time-quantum. X+ */ X+/* #define RTP_PRIO_QUANTUM 4 */ X+ X+/* X+ * RTP_PRIO_DEADLINE -- not implemented yet! X+ */ X+/* #define RTP_PRIO_DEADLINE 5 */ X+ X+/* X+ * Actual priority ranges should be changed X+ * to cover at least some 128 to 256 steps! X+ */ X /* priority range */ X #define RTP_PRIO_MIN 0 /* Highest priority */ X #define RTP_PRIO_MAX 31 /* Lowest priority */ X@@ -57,6 +76,10 @@ X struct rtprio { X u_short type; X u_short prio; X+#if defined(RTP_PRIO_DEADLINE) || defined(RTP_PRIO_QUANTUM) X+ struct timeval deadline; /* Fail if not ready to repeat. */ X+ struct timeval quantum; /* Min./required time slice. */ X+#endif X }; X #endif X END-of-Kernel.Diffs echo x - RTprio.diffs sed 's/^X//' >RTprio.diffs << 'END-of-RTprio.diffs' X--- /usr/src/usr.sbin/rtprio/rtprio.c.orig Sun Oct 2 06:48:21 1994 X+++ /usr/src/usr.sbin/rtprio/rtprio.c Tue Dec 26 11:18:20 1995 X@@ -63,6 +63,10 @@ X X if (!strcmp(p, "rtprio")) X rtp.type = RTP_PRIO_REALTIME; X+#ifdef RTP_PRIO_FIFO X+ else if (!strcmp(p, "rtfifoprio")) X+ rtp.type = RTP_PRIO_FIFO; X+#endif X else if (!strcmp(p, "idprio")) X rtp.type = RTP_PRIO_IDLE; X X@@ -76,8 +80,13 @@ X perror(argv[0]); X exit (1); X } X+ X printf("%s: ", p); X+ X switch (rtp.type) { X+ case RTP_PRIO_FIFO: X+ printf("hard realtime fifo priority %d\n", rtp.prio); X+ break; X case RTP_PRIO_REALTIME: X printf("realtime priority %d\n", rtp.prio); X break; END-of-RTprio.diffs exit
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199601281231.OAA00704>