Date: Wed, 25 Dec 1996 12:37:17 +0200 (EET) From: "Jukka A. Ukkonen" <jau@jau.tmt.tele.fi> To: FreeBSD-gnats@freefall.freebsd.org, freebsd-bugs@freefall.freebsd.org Subject: Re: kern/2273: POSIX.4 / POSIX.1a style sched_*() API and RTFIFO-scheduler patches Message-ID: <199612251037.MAA09646@jau.tmt.tele.fi> In-Reply-To: <199612241330.FAA21372@freefall.freebsd.org> from "FreeBSD-gnats@freefall.freebsd.org" at Dec 24, 96 05:30:01 am
next in thread | previous in thread | raw e-mail | index | archive | help
Quoting FreeBSD-gnats@freefall.freebsd.org: > > Thank you very much for your problem report. > It has the internal identification `kern/2273'. > The individual assigned to look at your > bug is: freebsd-bugs. > > >Category: kern > >Responsible: freebsd-bugs > >Synopsis: support for POSIX.4 / POSIX.1a RT-scheduler API > >Arrival-Date: Tue Dec 24 05:30:01 PST 1996 > In fact there was at least one file (sched_rr_get_interval.c) missing from the shar package I sent earlier. I attach a more complete shar package at the end of this message. I also forgot to mention that you should add the lines #define _POSIX_PRIORITY_SCHEDULING and #define _SC_POSIX_SCHEDULING 28 /* or whatever number */ in /usr/include/unistd.h (or /usr/include/sys/unistd.h or some other file included by /usr/include/unistd.h), if you decide to add POSIX.4 scheduler API to the system. Cheers, // jau ------ / Jukka A. Ukkonen, Internet and New Media / Finnish Telecom Ltd. /__ M.Sc. (sw-eng & cs) (Phone) +358-2040-4025 / Internet: Jukka.Ukkonen@tele.fi (Fax) +358-2040-2712 / Internet: jau@iki.fi (Mobile) +358-400-606671 v Internet: ukkonen@nic.funet.fi (Home&Fax) +358-9-6215280 o \ / - X ------------------------- clip clip ------------------------------ / \ O # 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?199612251037.MAA09646>