1/*-
2 * SPDX-License-Identifier: BSD-4-Clause
3 *
4 * Copyright (c) 1994, Henrik Vestergaard Draboel
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by Henrik Vestergaard Draboel.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef _SYS_PRIORITY_H_
35#define _SYS_PRIORITY_H_
36
37/*
38 * Process priority specifications.
39 */
40
41/*
42 * Priority classes.
43 */
44
45#define	PRI_ITHD		1	/* Interrupt thread. */
46#define	PRI_REALTIME		2	/* Real time process. */
47#define	PRI_TIMESHARE		3	/* Time sharing process. */
48#define	PRI_IDLE		4	/* Idle process. */
49
50/*
51 * PRI_FIFO is POSIX.1B SCHED_FIFO.
52 */
53
54#define	PRI_FIFO_BIT		8
55#define	PRI_FIFO		(PRI_FIFO_BIT | PRI_REALTIME)
56
57#define	PRI_BASE(P)		((P) & ~PRI_FIFO_BIT)
58#define	PRI_IS_REALTIME(P)	(PRI_BASE(P) == PRI_REALTIME)
59#define	PRI_NEED_RR(P)		((P) != PRI_FIFO)
60
61/*
62 * Priorities.  Note that with 64 run queues, differences less than 4 are
63 * insignificant.
64 */
65
66/*
67 * Priorities range from 0 to 255, but differences of less then 4 (RQ_PPQ)
68 * are insignificant.  Ranges are as follows:
69 *
70 * Interrupt threads:		0 - 15
71 * Realtime user threads:	16 - 47
72 * Top half kernel threads:	48 - 87
73 * Time sharing user threads:	88 - 223
74 * Idle user threads:		224 - 255
75 *
76 * XXX If/When the specific interrupt thread and top half thread ranges
77 * disappear, a larger range can be used for user processes.
78 */
79
80#define	PRI_MIN			(0)		/* Highest priority. */
81#define	PRI_MAX			(255)		/* Lowest priority. */
82
83#define	PRI_MIN_ITHD		(PRI_MIN)
84#define	PRI_MAX_ITHD		(PRI_MIN_REALTIME - 1)
85
86/*
87 * Most hardware interrupt threads run at the same priority, but can
88 * decay to lower priorities if they run for full time slices.
89 */
90#define	PI_REALTIME		(PRI_MIN_ITHD + 0)
91#define	PI_INTR			(PRI_MIN_ITHD + 4)
92#define	PI_AV			PI_INTR
93#define	PI_NET			PI_INTR
94#define	PI_DISK			PI_INTR
95#define	PI_TTY			PI_INTR
96#define	PI_DULL			PI_INTR
97#define	PI_SOFT			(PRI_MIN_ITHD + 8)
98#define	PI_SOFTCLOCK		PI_SOFT
99#define	PI_SWI(x)		PI_SOFT
100
101#define	PRI_MIN_REALTIME	(16)
102#define	PRI_MAX_REALTIME	(PRI_MIN_KERN - 1)
103
104#define	PRI_MIN_KERN		(48)
105#define	PRI_MAX_KERN		(PRI_MIN_TIMESHARE - 1)
106
107#define	PSWP			(PRI_MIN_KERN + 0)
108#define	PVM			(PRI_MIN_KERN + 4)
109#define	PINOD			(PRI_MIN_KERN + 8)
110#define	PRIBIO			(PRI_MIN_KERN + 12)
111#define	PVFS			(PRI_MIN_KERN + 16)
112#define	PZERO			(PRI_MIN_KERN + 20)
113#define	PSOCK			(PRI_MIN_KERN + 24)
114#define	PWAIT			(PRI_MIN_KERN + 28)
115#define	PLOCK			(PRI_MIN_KERN + 32)
116#define	PPAUSE			(PRI_MIN_KERN + 36)
117
118#define	PRI_MIN_TIMESHARE	(88)
119#define	PRI_MAX_TIMESHARE	(PRI_MIN_IDLE - 1)
120
121#define	PUSER			(PRI_MIN_TIMESHARE)
122
123#define	PRI_MIN_IDLE		(224)
124#define	PRI_MAX_IDLE		(PRI_MAX)
125
126#ifdef _KERNEL
127/* Other arguments for kern_yield(9). */
128#define	PRI_USER	-2	/* Change to current user priority. */
129#define	PRI_UNCHANGED	-1	/* Do not change priority. */
130#endif
131
132struct priority {
133	u_char	pri_class;	/* Scheduling class. */
134	u_char	pri_level;	/* Normal priority level. */
135	u_char	pri_native;	/* Priority before propagation. */
136	u_char	pri_user;	/* User priority based on p_cpu and p_nice. */
137};
138
139#endif	/* !_SYS_PRIORITY_H_ */
140