xref: /dragonfly/sys/sys/sched.h (revision 56f51086)
1 #ifndef _SCHED_H_
2 #define _SCHED_H_
3 
4 /* sched.h: POSIX 1003.1b Process Scheduling header */
5 
6 /*-
7  * Copyright (c) 1996, 1997
8  *	HD Associates, Inc.  All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by HD Associates, Inc
21  *	and Jukka Antero Ukkonen.
22  * 4. Neither the name of the author nor the names of any co-contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL HD ASSOCIATES OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  * $FreeBSD: src/sys/posix4/sched.h,v 1.4 1999/12/29 04:55:02 peter Exp $
39  * $DragonFly: src/sys/sys/sched.h,v 1.3 2003/08/27 06:30:04 rob Exp $
40  */
41 
42 #include <sys/types.h>	/* For pid_t */
43 
44 #ifndef _KERNEL
45 #include <time.h>		/* Per P1003.4 */
46 #endif
47 
48 /* Scheduling policies
49  */
50 #define SCHED_FIFO  1
51 #define SCHED_OTHER 2
52 #define SCHED_RR    3
53 
54 struct sched_param
55 {
56 	int sched_priority;
57 };
58 
59 #ifndef _KERNEL
60 #include <sys/cdefs.h>
61 
62 __BEGIN_DECLS
63 #include <machine/cpumask.h>
64 
65 typedef cpumask_t		cpu_set_t;
66 typedef cpumask_t		cpuset_t;	/* FreeBSD compat */
67 
68 #define CPU_SETSIZE		(sizeof(cpumask_t) * 8)
69 
70 #define CPU_ZERO(set)		CPUMASK_ASSZERO(*set)
71 #define CPU_SET(cpu, set)	CPUMASK_ORBIT(*set, cpu)
72 #define CPU_CLR(cpu, set)	CPUMASK_NANDBIT(*set, cpu)
73 #define CPU_ISSET(cpu, set)	CPUMASK_TESTBIT(*set, cpu)
74 
75 #define CPU_COUNT(set)				\
76 	(__builtin_popcountl((set)->ary[0]) +	\
77 	 __builtin_popcountl((set)->ary[1]) +	\
78 	 __builtin_popcountl((set)->ary[2]) +	\
79 	 __builtin_popcountl((set)->ary[3]))
80 
81 #define CPU_AND(dst, set1, set2)		\
82 do {						\
83 	if (dst == set1) {			\
84 		CPUMASK_ANDMASK(*dst, *set2);	\
85 	} else {				\
86 		*dst = *set2;			\
87 		CPUMASK_ANDMASK(*dst, *set1);	\
88 	}					\
89 } while (0)
90 
91 #define CPU_OR(dst, set1, set2)			\
92 do {						\
93 	if (dst == set1) {			\
94 		CPUMASK_ORMASK(*dst, *set2);	\
95 	} else {				\
96 		*dst = *set2;			\
97 		CPUMASK_ORMASK(*dst, *set1);	\
98 	}					\
99 } while (0)
100 
101 #define CPU_XOR(dst, set1, set2)		\
102 do {						\
103 	if (dst == set1) {			\
104 		CPUMASK_XORMASK(*dst, *set2);	\
105 	} else {				\
106 		*dst = *set2;			\
107 		CPUMASK_XORMASK(*dst, *set1);	\
108 	}					\
109 } while (0)
110 
111 #define CPU_EQUAL(set1, set2)	CPUMASK_CMPMASKEQ(*set1, *set2)
112 
113 int sched_setparam (pid_t, const struct sched_param *);
114 int sched_getparam (pid_t, struct sched_param *);
115 
116 int sched_setscheduler (pid_t, int, const struct sched_param *);
117 int sched_getscheduler (pid_t);
118 
119 int sched_setaffinity (pid_t, size_t, const cpu_set_t *);
120 int sched_getaffinity (pid_t, size_t, cpu_set_t *);
121 
122 int sched_yield (void);
123 int sched_get_priority_max (int);
124 int sched_get_priority_min (int);
125 int sched_rr_get_interval (pid_t, struct timespec *);
126 int sched_getcpu (void);
127 __END_DECLS
128 
129 #endif
130 
131 #endif /* _SCHED_H_ */
132