Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Dec 1996 15:21:24 +0200 (EET)
From:      jau@iki.fi
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   kern/2273: POSIX.4 / POSIX.1a style sched_*() API and RTFIFO-scheduler patches
Message-ID:  <199612241321.PAA00743@jau.thunderbolt.fi>
Resent-Message-ID: <199612241330.FAA21376@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         2273
>Category:       kern
>Synopsis:       support for POSIX.4 / POSIX.1a RT-scheduler API
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 24 05:30:01 PST 1996
>Last-Modified:
>Originator:     Jukka Ukkonen
>Organization:
Private person
>Release:        FreeBSD 2.1-STABLE i386
>Environment:
	The attached patches were done against FreeBSD 2.1-STABLE
	As far as I can see, it shouldn't be hard to import to 2.2
	line though.

>Description:
	FreeBSD has been missing support for POSIX.4/POSIX.1a style
	scheduler API and the RT-fifo scheduling policy required by
	POSIX.
	The attached patch is an example how this functionality could
	be added relatively quickly.

>How-To-Repeat:
	Fail to compile anything using POSIX sched_*() functions.

>Fix:
	Check the attached patch and add it (with modifications to
	your taste) to FreeBSD distribution, if you consider it to
	be even close to what is needed. I have been playing with
	for some time now with no ill effects at all.


>Audit-Trail:
>Unformatted:
>End:


# 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/sched.h
#	sched/sched_getparam.c
#	sched/sched_getscheduler.c
#	sched/sched_get_priority_max.c
#	sched/sched_get_priority_min.c
#	sched/sched_setparam.c
#	sched/sched_setscheduler.c
#	sched/Kernel-Sched.Diffs
#	sched/sched_yield.Diffs
#	sched/RTprio.diffs
#	sched/Makefile
#
echo x - sched/sched.h
sed 's/^X//' >sched/sched.h << 'END-of-sched/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
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/sched.h
echo x - sched/sched_getparam.c
sed 's/^X//' >sched/sched_getparam.c << 'END-of-sched/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/sched_getparam.c
echo x - sched/sched_getscheduler.c
sed 's/^X//' >sched/sched_getscheduler.c << 'END-of-sched/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/sched_getscheduler.c
echo x - sched/sched_get_priority_max.c
sed 's/^X//' >sched/sched_get_priority_max.c << 'END-of-sched/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    errno = 0;
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/sched_get_priority_max.c
echo x - sched/sched_get_priority_min.c
sed 's/^X//' >sched/sched_get_priority_min.c << 'END-of-sched/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    errno = 0;
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/sched_get_priority_min.c
echo x - sched/sched_setparam.c
sed 's/^X//' >sched/sched_setparam.c << 'END-of-sched/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/sched_setparam.c
echo x - sched/sched_setscheduler.c
sed 's/^X//' >sched/sched_setscheduler.c << 'END-of-sched/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/sched_setscheduler.c
echo x - sched/Kernel-Sched.Diffs
sed 's/^X//' >sched/Kernel-Sched.Diffs << 'END-of-sched/Kernel-Sched.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-sched/Kernel-Sched.Diffs
echo x - sched/sched_yield.Diffs
sed 's/^X//' >sched/sched_yield.Diffs << 'END-of-sched/sched_yield.Diffs'
X--- /sys/kern/init_sysent.c.no_sched_yield	Wed Dec  4 23:41:55 1996
X+++ /sys/kern/init_sysent.c	Wed Dec  4 23:49:14 1996
X@@ -179,6 +179,7 @@
X int	mlock();
X int	munlock();
X int	getsid();
X+int	sched_yield();
X int	lkmnosys();
X 
X #ifdef COMPAT_43
X@@ -489,7 +490,8 @@
X 	{ 2, munlock },			/* 204 = munlock */
X 	/* { 0, nosys },		205 = nosys */
X 	{ 1, getsid },			/* 205 = getsid */
X-	{ 0, nosys },			/* 206 = nosys */
X+	/* { 0, nosys },		206 = nosys */
X+	{ 0, sched_yield },			/* 206 = sched_yield */
X 	{ 0, nosys },			/* 207 = nosys */
X 	{ 0, nosys },			/* 208 = nosys */
X 	{ 0, nosys },			/* 209 = nosys */
X--- /sys/kern/syscalls.c.no_sched_yield	Wed Dec  4 23:42:24 1996
X+++ /sys/kern/syscalls.c	Wed Dec  4 23:46:07 1996
X@@ -249,7 +249,8 @@
X 	"munlock",			/* 204 = munlock */
X 	/* "#205",			205 = nosys */
X 	"getsid",			/* 205 = getsid */
X-	"#206",			/* 206 = nosys */
X+	/* "#206",			206 = nosys */
X+	"sched_yield",			/* 206 = sched_yield */
X 	"#207",			/* 207 = nosys */
X 	"#208",			/* 208 = nosys */
X 	"#209",			/* 209 = nosys */
X--- /sys/kern/syscalls.master.no_sched_yield	Wed Dec  4 23:42:43 1996
X+++ /sys/kern/syscalls.master	Wed Dec  4 23:44:28 1996
X@@ -280,7 +280,8 @@
X 204	STD	2 BSD	munlock
X ; 205	UNIMPL	0 NOHIDE nosys
X 205	STD	1 BSD	getsid
X-206	UNIMPL	0 NOHIDE nosys
X+; 206	UNIMPL	0 NOHIDE nosys
X+206	STD	0 POSIX	sched_yield
X 207	UNIMPL	0 NOHIDE nosys
X 208	UNIMPL	0 NOHIDE nosys
X 209	UNIMPL	0 NOHIDE nosys
X--- /sys/kern/kern_synch.c.no_sched_yield	Tue Dec 24 13:12:02 1996
X+++ /sys/kern/kern_synch.c	Tue Dec 24 11:25:33 1996
X@@ -681,3 +681,20 @@
X 	}
X }
X 
X+struct sched_yield_args {
X+	void	*arg;
X+};
X+/* ARGSUSED */
X+int
X+sched_yield (p, uap, retval)
X+    struct proc		    *p;
X+    struct sched_yield_args *uap;
X+    int			    *retval;
X+{
X+    need_resched ();	/* Wild, isn't it? */
X+
X+    *retval = 0;
X+
X+    return (0);
X+}
X+
X--- /usr/include/sys/syscall.h.no_sched_yield	Tue Dec 24 13:19:56 1996
X+++ /usr/include/sys/syscall.h	Tue Dec 24 12:23:18 1996
X@@ -193,3 +193,4 @@
X #define	SYS_mlock	203
X #define	SYS_munlock	204
X #define	SYS_getsid	205
X+#define	SYS_sched_yield	206
X--- /usr/include/unistd.h.no_sched_yield	Tue Dec 24 13:18:59 1996
X+++ /usr/include/unistd.h	Tue Dec 24 12:39:59 1996
X@@ -174,6 +174,7 @@
X int	 vhangup __P((void));
X void	*valloc __P((size_t));			/* obsoleted by malloc() */
X pid_t	 vfork __P((void));
X+int	 sched_yield __P((void));
X #endif /* !_POSIX_SOURCE */
X __END_DECLS
X 
X--- /sys/sys/syscall.h.no_sched_yield	Tue Dec 24 13:22:52 1996
X+++ /sys/sys/syscall.h	Tue Dec 24 12:23:56 1996
X@@ -193,3 +193,4 @@
X #define	SYS_mlock	203
X #define	SYS_munlock	204
X #define	SYS_getsid	205
X+#define	SYS_sched_yield	206
END-of-sched/sched_yield.Diffs
echo x - sched/RTprio.diffs
sed 's/^X//' >sched/RTprio.diffs << 'END-of-sched/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-sched/RTprio.diffs
echo x - sched/Makefile
sed 's/^X//' >sched/Makefile << 'END-of-sched/Makefile'
X
XCC	= gcc
X
X.c.o:
X	$(CC) $(CFLAGS) -c $<
X	ld -r -x $@
X	mv a.out $@
X	chmod a-x $@
X
XCINCL	= -I../include -I../ctype
X
XCFLAGS	= -O4 -fexpensive-optimizations -fpcc-struct-return -funsigned-char \
X	-D_NO_POSIX_OPAQUE_TYPES $(CDEBUG) $(CINCL)
X#CFLAGS	= $(CDEBUG) $(CINCL)
X
XSRCS 	= \
X	sched_get_priority_max.c	sched_setparam.c \
X	sched_get_priority_min.c	sched_setscheduler.c \
X	sched_getparam.c		sched_getscheduler.c
X	
XOBJS 	= \
X	sched_get_priority_max.o	sched_setparam.o \
X	sched_get_priority_min.o	sched_setscheduler.o \
X	sched_getparam.o		sched_getscheduler.o
X
Xlibsched.a: $(OBJS)
X	rm -f $@
X	ar rv $@ $(OBJS)
X	ranlib $@
X
END-of-sched/Makefile
exit





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612241321.PAA00743>