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. Ranges are as follows:
68 *
69 * Interrupt threads: 0 - 7
70 * Realtime user threads: 8 - 39
71 * Top half kernel threads: 40 - 55
72 * Time sharing user threads: 56 - 223
73 * Idle user threads: 224 - 255
74 *
75 * Priority levels of rtprio(2)'s RTP_PRIO_FIFO and RTP_PRIO_REALTIME and
76 * POSIX's SCHED_FIFO and SCHED_RR are directly mapped to the internal realtime
77 * range mentioned above by a simple translation. This range's length
78 * consequently cannot be changed without impacts on the scheduling priority
79 * code, and in any case must never be smaller than 32 for POSIX compliance and
80 * rtprio(2) backwards compatibility. Similarly, priority levels of rtprio(2)'s
81 * RTP_PRIO_IDLE are directly mapped to the internal idle range above (and,
82 * soon, those of the to-be-introduced SCHED_IDLE policy as well), so changing
83 * that range is subject to the same caveats and restrictions.
84 */
85
86#define PRI_MIN (0) /* Highest priority. */
87#define PRI_MAX (255) /* Lowest priority. */
88
89#define PRI_MIN_ITHD (PRI_MIN)
90#define PRI_MAX_ITHD (PRI_MIN_REALTIME - 1)
91
92/*
93 * Most hardware interrupt threads run at the same priority, but can
94 * decay to lower priorities if they run for full time slices.
95 */
96#define PI_REALTIME (PRI_MIN_ITHD + 0)
97#define PI_INTR (PRI_MIN_ITHD + 1)
98#define PI_AV PI_INTR
99#define PI_NET PI_INTR
100#define PI_DISK PI_INTR
101#define PI_TTY PI_INTR
102#define PI_DULL PI_INTR
103#define PI_SOFT (PRI_MIN_ITHD + 2)
104#define PI_SOFTCLOCK PI_SOFT
105#define PI_SWI(x) PI_SOFT
106
107#define PRI_MIN_REALTIME (8)
108#define PRI_MAX_REALTIME (PRI_MIN_KERN - 1)
109
110#define PRI_MIN_KERN (40)
111#define PRI_MAX_KERN (PRI_MIN_TIMESHARE - 1)
112
113#define PSWP (PRI_MIN_KERN + 0)
114#define PVM (PRI_MIN_KERN + 1)
115#define PINOD (PRI_MIN_KERN + 2)
116#define PRIBIO (PRI_MIN_KERN + 3)
117#define PVFS (PRI_MIN_KERN + 4)
118#define PZERO (PRI_MIN_KERN + 5)
119#define PSOCK (PRI_MIN_KERN + 6)
120#define PWAIT (PRI_MIN_KERN + 7)
121#define PLOCK (PRI_MIN_KERN + 8)
122#define PPAUSE (PRI_MIN_KERN + 9)
123
124#define PRI_MIN_TIMESHARE (56)
125#define PRI_MAX_TIMESHARE (PRI_MIN_IDLE - 1)
126
127#define PUSER (PRI_MIN_TIMESHARE)
128
129#define PRI_MIN_IDLE (224)
130#define PRI_MAX_IDLE (PRI_MAX)
131
132#ifdef _KERNEL
133/* Other arguments for kern_yield(9). */
134#define PRI_USER -2 /* Change to current user priority. */
135#define PRI_UNCHANGED -1 /* Do not change priority. */
136#endif
137
138struct priority {
139 u_char pri_class; /* Scheduling class. */
140 u_char pri_level; /* Normal priority level. */
141 u_char pri_native; /* Priority before propagation. */
142 u_char pri_user; /* User priority based on p_cpu and p_nice. */
143};
144
145#endif /* !_SYS_PRIORITY_H_ */