]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/sys/param.h
Standard Libraries for EDK II.
[mirror_edk2.git] / StdLib / Include / sys / param.h
1 /* $NetBSD: param.h,v 1.244.2.9.2.2 2008/10/05 08:44:03 bouyer Exp $ */
2
3 /*-
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)param.h 8.3 (Berkeley) 4/4/95
37 */
38
39 #ifndef _SYS_PARAM_H_
40 #define _SYS_PARAM_H_
41
42 /*
43 * Historic BSD #defines -- probably will remain untouched for all time.
44 */
45 #define BSD 199506 /* System version (year & month). */
46 #define BSD4_3 1
47 #define BSD4_4 1
48
49 /*
50 * #define __NetBSD_Version__ MMmmrrpp00
51 *
52 * M = major version
53 * m = minor version; a minor number of 99 indicates current.
54 * r = 0 (*)
55 * p = patchlevel
56 *
57 * When new releases are made, src/gnu/usr.bin/groff/tmac/mdoc.local
58 * needs to be updated and the changes sent back to the groff maintainers.
59 *
60 * (*) Up to 2.0I "release" used to be "",A-Z,Z[A-Z] but numeric
61 * e.g. NetBSD-1.2D = 102040000 ('D' == 4)
62 * NetBSD-2.0H (200080000) was changed on 20041001 to:
63 * 2.99.9 (299000900)
64 */
65
66 #define __NetBSD_Version__ 400000003 /* NetBSD 4.0.1 */
67
68 #define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
69 (m) * 1000000) + (p) * 100) <= __NetBSD_Version__)
70
71 /*
72 * Historical NetBSD #define
73 *
74 * NetBSD 1.4 was the last release for which this value was incremented.
75 * The value is now permanently fixed at 199905. It will never be
76 * changed again.
77 *
78 * New code must use __NetBSD_Version__ instead, and should not even
79 * count on NetBSD being defined.
80 *
81 */
82
83 #define NetBSD 199905 /* NetBSD version (year & month). */
84
85 #ifndef _LOCORE
86 //#include <sys/inttypes.h>
87 #include <sys/types.h>
88 #endif
89
90 /*
91 * Machine-independent constants (some used in following include files).
92 * Redefined constants are from POSIX 1003.1 limits file.
93 *
94 * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>)
95 * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)
96 */
97 #include <sys/syslimits.h>
98
99 #define MAXCOMLEN 16 /* max command name remembered */
100 #define MAXINTERP PATH_MAX /* max interpreter file name length */
101 /* DEPRECATED: use LOGIN_NAME_MAX instead. */
102 #define MAXLOGNAME (LOGIN_NAME_MAX - 1) /* max login name length */
103 #define NCARGS ARG_MAX /* max bytes for an exec function */
104 #define NGROUPS NGROUPS_MAX /* max number groups */
105 #define NOGROUP 65535 /* marker for empty group set member */
106 #define MAXHOSTNAMELEN 256 /* max hostname size */
107
108 #ifndef NOFILE
109 #define NOFILE OPEN_MAX /* max open files per process */
110 #endif
111 #ifndef MAXUPRC /* max simultaneous processes */
112 #define MAXUPRC CHILD_MAX /* POSIX 1003.1-compliant default */
113 #else
114 #if (MAXUPRC - 0) < CHILD_MAX
115 #error MAXUPRC less than CHILD_MAX. See options(4) for details.
116 #endif /* (MAXUPRC - 0) < CHILD_MAX */
117 #endif /* !defined(MAXUPRC) */
118
119 /* Signals. */
120 #include <sys/signal.h>
121
122 /* Machine type dependent parameters. */
123 #include <machine/param.h>
124 #include <machine/limits.h>
125
126 /* pages ("clicks") to disk blocks */
127 #define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT))
128 #define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT))
129
130 /* bytes to pages */
131 #define ctob(x) ((x) << PGSHIFT)
132 #define btoc(x) (((x) + PGOFSET) >> PGSHIFT)
133
134 /* bytes to disk blocks */
135 #define dbtob(x) ((x) << DEV_BSHIFT)
136 #define btodb(x) ((x) >> DEV_BSHIFT)
137
138 /*
139 * Stack macros. On most architectures, the stack grows down,
140 * towards lower addresses; it is the rare architecture where
141 * it grows up, towards higher addresses.
142 *
143 * STACK_GROW and STACK_SHRINK adjust a stack pointer by some
144 * size, no questions asked. STACK_ALIGN aligns a stack pointer.
145 *
146 * STACK_ALLOC returns a pointer to allocated stack space of
147 * some size; given such a pointer and a size, STACK_MAX gives
148 * the maximum (in the "maxsaddr" sense) stack address of the
149 * allocated memory.
150 */
151 #if defined(_KERNEL) || defined(__EXPOSE_STACK)
152 #ifdef __MACHINE_STACK_GROWS_UP
153 #define STACK_GROW(sp, _size) (((caddr_t)(sp)) + (_size))
154 #define STACK_SHRINK(sp, _size) (((caddr_t)(sp)) - (_size))
155 #define STACK_ALIGN(sp, bytes) \
156 ((caddr_t)((((unsigned long)(sp)) + (bytes)) & ~(bytes)))
157 #define STACK_ALLOC(sp, _size) ((caddr_t)(sp))
158 #define STACK_MAX(p, _size) (((caddr_t)(p)) + (_size))
159 #else
160 #define STACK_GROW(sp, _size) (((caddr_t)(sp)) - (_size))
161 #define STACK_SHRINK(sp, _size) (((caddr_t)(sp)) + (_size))
162 #define STACK_ALIGN(sp, bytes) \
163 ((caddr_t)(((unsigned long)(sp)) & ~(bytes)))
164 #define STACK_ALLOC(sp, _size) (((caddr_t)(sp)) - (_size))
165 #define STACK_MAX(p, _size) ((caddr_t)(p))
166 #endif
167 #endif /* defined(_KERNEL) || defined(__EXPOSE_STACK) */
168
169 /*
170 * Priorities. Note that with 32 run queues, differences less than 4 are
171 * insignificant.
172 */
173 #define PSWP 0
174 #define PVM 4
175 #define PINOD 8
176 #define PRIBIO 16
177 #define PVFS 20
178 #define PZERO 22 /* No longer magic, shouldn't be here. XXX */
179 #define PSOCK 24
180 #define PWAIT 32
181 #define PLOCK 36
182 #define PPAUSE 40
183 #define PUSER 50
184 #define MAXPRI 127 /* Priorities range from 0 through MAXPRI. */
185
186 #define PRIMASK 0x0ff
187 #define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
188 #define PNORELOCK 0x200 /* OR'd with pri for cond_wait() to not relock
189 the interlock */
190 #define PNOEXITERR 0x400 /* OR'd with pri for tsleep to not exit
191 with an error code when LWPs are exiting */
192 #define NBPW sizeof(int) /* number of bytes per word (integer) */
193
194 #define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */
195 #define NODEV (dev_t)(-1) /* non-existent device */
196
197 #define CBLOCK 64 /* Clist block size, must be a power of 2. */
198 #define CBQSIZE (CBLOCK/NBBY) /* Quote bytes/cblock - can do better. */
199 /* Data chars/clist. */
200 #define CBSIZE (CBLOCK - (int)sizeof(struct cblock *) - CBQSIZE)
201 #define CROUND (CBLOCK - 1) /* Clist rounding. */
202
203 /*
204 * File system parameters and macros.
205 *
206 * The file system is made out of blocks of at most MAXBSIZE units, with
207 * smaller units (fragments) only in the last direct block. MAXBSIZE
208 * primarily determines the size of buffers in the buffer pool. It may be
209 * made larger without any effect on existing file systems; however making
210 * it smaller may make some file systems unmountable.
211 */
212 #ifndef MAXBSIZE /* XXX */
213 #define MAXBSIZE MAXPHYS
214 #endif
215 #define MAXFRAG 8
216
217 /*
218 * MAXPATHLEN defines the longest permissible path length after expanding
219 * symbolic links. It is used to allocate a temporary buffer from the buffer
220 * pool in which to do the name expansion, hence should be a power of two,
221 * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the
222 * maximum number of symbolic links that may be expanded in a path name.
223 * It should be set high enough to allow all legitimate uses, but halt
224 * infinite loops reasonably quickly.
225 */
226 #define MAXPATHLEN PATH_MAX
227 #define MAXSYMLINKS 32
228
229 /* Bit map related macros. */
230 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
231 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
232 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
233 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
234
235 /* Macros for counting and rounding. */
236 #ifndef howmany
237 #define howmany(x, y) (((x)+((y)-1))/(y))
238 #endif
239 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
240 #define rounddown(x,y) (((x)/(y))*(y))
241 #define powerof2(x) ((((x)-1)&(x))==0)
242
243 ///* Macros for min/max. */
244 //#define MIN(a,b) (((a)<(b))?(a):(b))
245 //#define MAX(a,b) (((a)>(b))?(a):(b))
246
247 /*
248 * Constants for setting the parameters of the kernel memory allocator.
249 *
250 * 2 ** MINBUCKET is the smallest unit of memory that will be
251 * allocated. It must be at least large enough to hold a pointer.
252 *
253 * Units of memory less or equal to MAXALLOCSAVE will permanently
254 * allocate physical memory; requests for these size pieces of
255 * memory are quite fast. Allocations greater than MAXALLOCSAVE must
256 * always allocate and free physical memory; requests for these
257 * size allocations should be done infrequently as they will be slow.
258 *
259 * Constraints: NBPG <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and
260 * MAXALLOCSAVE must be a power of two.
261 */
262 #ifdef _LP64
263 #define MINBUCKET 5 /* 5 => min allocation of 32 bytes */
264 #else
265 #define MINBUCKET 4 /* 4 => min allocation of 16 bytes */
266 #endif
267 #define MAXALLOCSAVE (2 * NBPG)
268
269 /*
270 * Scale factor for scaled integers used to count %cpu time and load avgs.
271 *
272 * The number of CPU `tick's that map to a unique `%age' can be expressed
273 * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that
274 * can be calculated (assuming 32 bits) can be closely approximated using
275 * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).
276 *
277 * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
278 * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.
279 */
280 #define FSHIFT 11 /* bits to right of fixed binary point */
281 #define FSCALE (1<<FSHIFT)
282
283 /*
284 * The time for a process to be blocked before being very swappable.
285 * This is a number of seconds which the system takes as being a non-trivial
286 * amount of real time. You probably shouldn't change this;
287 * it is used in subtle ways (fractions and multiples of it are, that is, like
288 * half of a ``long time'', almost a long time, etc.)
289 * It is related to human patience and other factors which don't really
290 * change over time.
291 */
292 #define MAXSLP 20
293
294 /*
295 * Defaults for Unified Buffer Cache parameters.
296 * These may be overridden in <machine/param.h>.
297 */
298
299 #ifndef UBC_WINSHIFT
300 #define UBC_WINSHIFT 13
301 #endif
302 #ifndef UBC_NWINS
303 #define UBC_NWINS 1024
304 #endif
305
306 #ifdef _KERNEL
307 /*
308 * macro to convert from milliseconds to hz without integer overflow
309 * Default version using only 32bits arithmetics.
310 * 64bit port can define 64bit version in their <machine/param.h>
311 * 0x20000 is safe for hz < 20000
312 */
313 #ifndef mstohz
314 #define mstohz(ms) \
315 (__predict_false((ms) >= 0x20000) ? \
316 ((ms +0u) / 1000u) * hz : \
317 ((ms +0u) * hz) / 1000u)
318 #endif
319 #endif /* _KERNEL */
320
321 #endif /* !_SYS_PARAM_H_ */