FreeBSD/Linux Kernel Cross Reference
sys/sys/param.h
1 /* $NetBSD: param.h,v 1.244.2.10 2007/12/17 12:49:10 ghen 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_STABLE */
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 #include <sys/null.h>
86
87 #ifndef _LOCORE
88 #include <sys/inttypes.h>
89 #include <sys/types.h>
90 #endif
91
92 /*
93 * Machine-independent constants (some used in following include files).
94 * Redefined constants are from POSIX 1003.1 limits file.
95 *
96 * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>)
97 * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)
98 */
99 #include <sys/syslimits.h>
100
101 #define MAXCOMLEN 16 /* max command name remembered */
102 #define MAXINTERP PATH_MAX /* max interpreter file name length */
103 /* DEPRECATED: use LOGIN_NAME_MAX instead. */
104 #define MAXLOGNAME (LOGIN_NAME_MAX - 1) /* max login name length */
105 #define NCARGS ARG_MAX /* max bytes for an exec function */
106 #define NGROUPS NGROUPS_MAX /* max number groups */
107 #define NOGROUP 65535 /* marker for empty group set member */
108 #define MAXHOSTNAMELEN 256 /* max hostname size */
109
110 #ifndef NOFILE
111 #define NOFILE OPEN_MAX /* max open files per process */
112 #endif
113 #ifndef MAXUPRC /* max simultaneous processes */
114 #define MAXUPRC CHILD_MAX /* POSIX 1003.1-compliant default */
115 #else
116 #if (MAXUPRC - 0) < CHILD_MAX
117 #error MAXUPRC less than CHILD_MAX. See options(4) for details.
118 #endif /* (MAXUPRC - 0) < CHILD_MAX */
119 #endif /* !defined(MAXUPRC) */
120
121 /* More types and definitions used throughout the kernel. */
122 #ifdef _KERNEL
123 #include <sys/cdefs.h>
124 #include <sys/errno.h>
125 #include <sys/time.h>
126 #include <sys/resource.h>
127 #include <sys/ucred.h>
128 #include <sys/uio.h>
129 #ifndef NPROC
130 #define NPROC (20 + 16 * MAXUSERS)
131 #endif
132 #ifndef NTEXT
133 #define NTEXT (80 + NPROC / 8) /* actually the object cache */
134 #endif
135 #ifndef NVNODE
136 #define NVNODE (NPROC + NTEXT + 100)
137 #define NVNODE_IMPLICIT
138 #endif
139 #endif /* _KERNEL */
140
141 /* Signals. */
142 #include <sys/signal.h>
143
144 /* Machine type dependent parameters. */
145 #include <machine/param.h>
146 #include <machine/limits.h>
147
148 /* pages ("clicks") to disk blocks */
149 #define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT))
150 #define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT))
151
152 /* bytes to pages */
153 #define ctob(x) ((x) << PGSHIFT)
154 #define btoc(x) (((x) + PGOFSET) >> PGSHIFT)
155
156 /* bytes to disk blocks */
157 #define dbtob(x) ((x) << DEV_BSHIFT)
158 #define btodb(x) ((x) >> DEV_BSHIFT)
159
160 /*
161 * Stack macros. On most architectures, the stack grows down,
162 * towards lower addresses; it is the rare architecture where
163 * it grows up, towards higher addresses.
164 *
165 * STACK_GROW and STACK_SHRINK adjust a stack pointer by some
166 * size, no questions asked. STACK_ALIGN aligns a stack pointer.
167 *
168 * STACK_ALLOC returns a pointer to allocated stack space of
169 * some size; given such a pointer and a size, STACK_MAX gives
170 * the maximum (in the "maxsaddr" sense) stack address of the
171 * allocated memory.
172 */
173 #if defined(_KERNEL) || defined(__EXPOSE_STACK)
174 #ifdef __MACHINE_STACK_GROWS_UP
175 #define STACK_GROW(sp, _size) (((caddr_t)(sp)) + (_size))
176 #define STACK_SHRINK(sp, _size) (((caddr_t)(sp)) - (_size))
177 #define STACK_ALIGN(sp, bytes) \
178 ((caddr_t)((((unsigned long)(sp)) + (bytes)) & ~(bytes)))
179 #define STACK_ALLOC(sp, _size) ((caddr_t)(sp))
180 #define STACK_MAX(p, _size) (((caddr_t)(p)) + (_size))
181 #else
182 #define STACK_GROW(sp, _size) (((caddr_t)(sp)) - (_size))
183 #define STACK_SHRINK(sp, _size) (((caddr_t)(sp)) + (_size))
184 #define STACK_ALIGN(sp, bytes) \
185 ((caddr_t)(((unsigned long)(sp)) & ~(bytes)))
186 #define STACK_ALLOC(sp, _size) (((caddr_t)(sp)) - (_size))
187 #define STACK_MAX(p, _size) ((caddr_t)(p))
188 #endif
189 #endif /* defined(_KERNEL) || defined(__EXPOSE_STACK) */
190
191 /*
192 * Priorities. Note that with 32 run queues, differences less than 4 are
193 * insignificant.
194 */
195 #define PSWP 0
196 #define PVM 4
197 #define PINOD 8
198 #define PRIBIO 16
199 #define PVFS 20
200 #define PZERO 22 /* No longer magic, shouldn't be here. XXX */
201 #define PSOCK 24
202 #define PWAIT 32
203 #define PLOCK 36
204 #define PPAUSE 40
205 #define PUSER 50
206 #define MAXPRI 127 /* Priorities range from 0 through MAXPRI. */
207
208 #define PRIMASK 0x0ff
209 #define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
210 #define PNORELOCK 0x200 /* OR'd with pri for cond_wait() to not relock
211 the interlock */
212 #define PNOEXITERR 0x400 /* OR'd with pri for tsleep to not exit
213 with an error code when LWPs are exiting */
214 #define NBPW sizeof(int) /* number of bytes per word (integer) */
215
216 #define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */
217 #define NODEV (dev_t)(-1) /* non-existent device */
218
219 #define CBLOCK 64 /* Clist block size, must be a power of 2. */
220 #define CBQSIZE (CBLOCK/NBBY) /* Quote bytes/cblock - can do better. */
221 /* Data chars/clist. */
222 #define CBSIZE (CBLOCK - (int)sizeof(struct cblock *) - CBQSIZE)
223 #define CROUND (CBLOCK - 1) /* Clist rounding. */
224
225 /*
226 * File system parameters and macros.
227 *
228 * The file system is made out of blocks of at most MAXBSIZE units, with
229 * smaller units (fragments) only in the last direct block. MAXBSIZE
230 * primarily determines the size of buffers in the buffer pool. It may be
231 * made larger without any effect on existing file systems; however making
232 * it smaller may make some file systems unmountable.
233 */
234 #ifndef MAXBSIZE /* XXX */
235 #define MAXBSIZE MAXPHYS
236 #endif
237 #define MAXFRAG 8
238
239 /*
240 * MAXPATHLEN defines the longest permissible path length after expanding
241 * symbolic links. It is used to allocate a temporary buffer from the buffer
242 * pool in which to do the name expansion, hence should be a power of two,
243 * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the
244 * maximum number of symbolic links that may be expanded in a path name.
245 * It should be set high enough to allow all legitimate uses, but halt
246 * infinite loops reasonably quickly.
247 */
248 #define MAXPATHLEN PATH_MAX
249 #define MAXSYMLINKS 32
250
251 /* Bit map related macros. */
252 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
253 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
254 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
255 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
256
257 /* Macros for counting and rounding. */
258 #ifndef howmany
259 #define howmany(x, y) (((x)+((y)-1))/(y))
260 #endif
261 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
262 #define rounddown(x,y) (((x)/(y))*(y))
263 #define powerof2(x) ((((x)-1)&(x))==0)
264
265 /* Macros for min/max. */
266 #define MIN(a,b) (((a)<(b))?(a):(b))
267 #define MAX(a,b) (((a)>(b))?(a):(b))
268
269 /*
270 * Constants for setting the parameters of the kernel memory allocator.
271 *
272 * 2 ** MINBUCKET is the smallest unit of memory that will be
273 * allocated. It must be at least large enough to hold a pointer.
274 *
275 * Units of memory less or equal to MAXALLOCSAVE will permanently
276 * allocate physical memory; requests for these size pieces of
277 * memory are quite fast. Allocations greater than MAXALLOCSAVE must
278 * always allocate and free physical memory; requests for these
279 * size allocations should be done infrequently as they will be slow.
280 *
281 * Constraints: NBPG <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and
282 * MAXALLOCSAVE must be a power of two.
283 */
284 #ifdef _LP64
285 #define MINBUCKET 5 /* 5 => min allocation of 32 bytes */
286 #else
287 #define MINBUCKET 4 /* 4 => min allocation of 16 bytes */
288 #endif
289 #define MAXALLOCSAVE (2 * NBPG)
290
291 /*
292 * Scale factor for scaled integers used to count %cpu time and load avgs.
293 *
294 * The number of CPU `tick's that map to a unique `%age' can be expressed
295 * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that
296 * can be calculated (assuming 32 bits) can be closely approximated using
297 * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).
298 *
299 * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
300 * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.
301 */
302 #define FSHIFT 11 /* bits to right of fixed binary point */
303 #define FSCALE (1<<FSHIFT)
304
305 /*
306 * The time for a process to be blocked before being very swappable.
307 * This is a number of seconds which the system takes as being a non-trivial
308 * amount of real time. You probably shouldn't change this;
309 * it is used in subtle ways (fractions and multiples of it are, that is, like
310 * half of a ``long time'', almost a long time, etc.)
311 * It is related to human patience and other factors which don't really
312 * change over time.
313 */
314 #define MAXSLP 20
315
316 /*
317 * Defaults for Unified Buffer Cache parameters.
318 * These may be overridden in <machine/param.h>.
319 */
320
321 #ifndef UBC_WINSHIFT
322 #define UBC_WINSHIFT 13
323 #endif
324 #ifndef UBC_NWINS
325 #define UBC_NWINS 1024
326 #endif
327
328 #ifdef _KERNEL
329 /*
330 * macro to convert from milliseconds to hz without integer overflow
331 * Default version using only 32bits arithmetics.
332 * 64bit port can define 64bit version in their <machine/param.h>
333 * 0x20000 is safe for hz < 20000
334 */
335 #ifndef mstohz
336 #define mstohz(ms) \
337 (__predict_false((ms) >= 0x20000) ? \
338 ((ms +0u) / 1000u) * hz : \
339 ((ms +0u) * hz) / 1000u)
340 #endif
341 #endif /* _KERNEL */
342
343 #endif /* !_SYS_PARAM_H_ */
Cache object: 8d9a88f0f8190cc13c57977e330bd3bd
|