FreeBSD/Linux Kernel Cross Reference
sys/sys/param.h
1 /* $NetBSD: param.h,v 1.330.4.16 2010/11/19 20:45:37 riz 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__ 501000000 /* NetBSD 5.1_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 * MAXHOSTNAMELEN should be >= (_POSIX_HOST_NAME_MAX + 1) (see <limits.h>)
98 * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)
99 */
100 #include <sys/syslimits.h>
101
102 #define MAXCOMLEN 16 /* max command name remembered */
103 #define MAXINTERP PATH_MAX /* max interpreter file name length */
104 /* DEPRECATED: use LOGIN_NAME_MAX instead. */
105 #define MAXLOGNAME (LOGIN_NAME_MAX - 1) /* max login name length */
106 #define NCARGS ARG_MAX /* max bytes for an exec function */
107 #define NGROUPS NGROUPS_MAX /* max number groups */
108 #define NOGROUP 65535 /* marker for empty group set member */
109 #define MAXHOSTNAMELEN 256 /* max hostname size */
110
111 #ifndef NOFILE
112 #define NOFILE OPEN_MAX /* max open files per process */
113 #endif
114 #ifndef MAXUPRC /* max simultaneous processes */
115 #define MAXUPRC CHILD_MAX /* POSIX 1003.1-compliant default */
116 #else
117 #if (MAXUPRC - 0) < CHILD_MAX
118 #error MAXUPRC less than CHILD_MAX. See options(4) for details.
119 #endif /* (MAXUPRC - 0) < CHILD_MAX */
120 #endif /* !defined(MAXUPRC) */
121
122 /* More types and definitions used throughout the kernel. */
123 #ifdef _KERNEL
124 #include <sys/cdefs.h>
125 #include <sys/errno.h>
126 #include <sys/time.h>
127 #include <sys/resource.h>
128 #include <sys/ucred.h>
129 #include <sys/uio.h>
130 #ifndef NPROC
131 #define NPROC (20 + 16 * MAXUSERS)
132 #endif
133 #ifndef NTEXT
134 #define NTEXT (80 + NPROC / 8) /* actually the object cache */
135 #endif
136 #ifndef NVNODE
137 #define NVNODE (NPROC + NTEXT + 100)
138 #define NVNODE_IMPLICIT
139 #endif
140 #ifndef VNODE_VA_MAXPCT
141 #define VNODE_VA_MAXPCT 20
142 #endif
143 #ifndef BUFCACHE_VA_MAXPCT
144 #define BUFCACHE_VA_MAXPCT 20
145 #endif
146 #define VNODE_COST 2048 /* assumed space in bytes */
147 #endif /* _KERNEL */
148
149 /* Signals. */
150 #include <sys/signal.h>
151
152 /* Machine type dependent parameters. */
153 #include <machine/param.h>
154 #include <machine/limits.h>
155
156 /* pages ("clicks") to disk blocks */
157 #define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT))
158 #define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT))
159
160 /* bytes to pages */
161 #define ctob(x) ((x) << PGSHIFT)
162 #define btoc(x) (((x) + PGOFSET) >> PGSHIFT)
163
164 /* bytes to disk blocks */
165 #define dbtob(x) ((x) << DEV_BSHIFT)
166 #define btodb(x) ((x) >> DEV_BSHIFT)
167
168 #ifndef COHERENCY_UNIT
169 #define COHERENCY_UNIT 64
170 #endif
171 #ifndef CACHE_LINE_SIZE
172 #define CACHE_LINE_SIZE 64
173 #endif
174 #ifndef MAXCPUS
175 #define MAXCPUS 32
176 #endif
177 #ifndef MAX_LWP_PER_PROC
178 #define MAX_LWP_PER_PROC 8000
179 #endif
180
181 /*
182 * Stack macros. On most architectures, the stack grows down,
183 * towards lower addresses; it is the rare architecture where
184 * it grows up, towards higher addresses.
185 *
186 * STACK_GROW and STACK_SHRINK adjust a stack pointer by some
187 * size, no questions asked. STACK_ALIGN aligns a stack pointer.
188 *
189 * STACK_ALLOC returns a pointer to allocated stack space of
190 * some size; given such a pointer and a size, STACK_MAX gives
191 * the maximum (in the "maxsaddr" sense) stack address of the
192 * allocated memory.
193 */
194 #if defined(_KERNEL) || defined(__EXPOSE_STACK)
195 #ifdef __MACHINE_STACK_GROWS_UP
196 #define STACK_GROW(sp, _size) (((char *)(void *)(sp)) + (_size))
197 #define STACK_SHRINK(sp, _size) (((char *)(void *)(sp)) - (_size))
198 #define STACK_ALIGN(sp, bytes) \
199 ((char *)((((unsigned long)(sp)) + (bytes)) & ~(bytes)))
200 #define STACK_ALLOC(sp, _size) ((char *)(void *)(sp))
201 #define STACK_MAX(p, _size) (((char *)(void *)(p)) + (_size))
202 #else
203 #define STACK_GROW(sp, _size) (((char *)(void *)(sp)) - (_size))
204 #define STACK_SHRINK(sp, _size) (((char *)(void *)(sp)) + (_size))
205 #define STACK_ALIGN(sp, bytes) \
206 ((char *)(((unsigned long)(sp)) & ~(bytes)))
207 #define STACK_ALLOC(sp, _size) (((char *)(void *)(sp)) - (_size))
208 #define STACK_MAX(p, _size) ((char *)(void *)(p))
209 #endif
210 #endif /* defined(_KERNEL) || defined(__EXPOSE_STACK) */
211
212 /*
213 * Historic priority levels. These are meaningless and remain only
214 * for source compatibility. Do not use in new code.
215 */
216 #define PSWP 0
217 #define PVM 4
218 #define PINOD 8
219 #define PRIBIO 16
220 #define PVFS 20
221 #define PZERO 22
222 #define PSOCK 24
223 #define PWAIT 32
224 #define PLOCK 36
225 #define PPAUSE 40
226 #define PUSER 50
227 #define MAXPRI 127
228
229 #define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
230 #define PNORELOCK 0x200 /* OR'd with pri for tsleep to not relock */
231
232 /*
233 * New priority levels.
234 */
235 #define PRI_COUNT 224
236 #define PRI_NONE (-1)
237
238 #define PRI_KERNEL_RT 192
239 #define NPRI_KERNEL_RT 32
240 #define MAXPRI_KERNEL_RT (PRI_KERNEL_RT + NPRI_KERNEL_RT - 1)
241
242 #define PRI_USER_RT 128
243 #define NPRI_USER_RT 64
244 #define MAXPRI_USER_RT (PRI_USER_RT + NPRI_USER_RT - 1)
245
246 #define PRI_KTHREAD 96
247 #define NPRI_KTHREAD 32
248 #define MAXPRI_KTHREAD (PRI_KTHREAD + NPRI_KTHREAD - 1)
249
250 #define PRI_KERNEL 64
251 #define NPRI_KERNEL 32
252 #define MAXPRI_KERNEL (PRI_KERNEL + NPRI_KERNEL - 1)
253
254 #define PRI_USER 0
255 #define NPRI_USER 64
256 #define MAXPRI_USER (PRI_USER + NPRI_USER - 1)
257
258 /* Priority range used by POSIX real-time features */
259 #define SCHED_PRI_MIN 0
260 #define SCHED_PRI_MAX 63
261
262 /*
263 * Kernel thread priorities.
264 */
265 #define PRI_SOFTSERIAL MAXPRI_KERNEL_RT
266 #define PRI_SOFTNET (MAXPRI_KERNEL_RT - schedppq * 1)
267 #define PRI_SOFTBIO (MAXPRI_KERNEL_RT - schedppq * 2)
268 #define PRI_SOFTCLOCK (MAXPRI_KERNEL_RT - schedppq * 3)
269
270 #define PRI_XCALL MAXPRI_KTHREAD
271 #define PRI_PGDAEMON (MAXPRI_KTHREAD - schedppq * 1)
272 #define PRI_VM (MAXPRI_KTHREAD - schedppq * 2)
273 #define PRI_IOFLUSH (MAXPRI_KTHREAD - schedppq * 3)
274 #define PRI_BIO (MAXPRI_KTHREAD - schedppq * 4)
275
276 #define PRI_IDLE PRI_USER
277
278 /*
279 * Miscellaneous.
280 */
281 #define NBPW sizeof(int) /* number of bytes per word (integer) */
282
283 #define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */
284 #define NODEV (dev_t)(-1) /* non-existent device */
285
286 #define CBLOCK 64 /* Clist block size, must be a power of 2. */
287 #define CBQSIZE (CBLOCK/NBBY) /* Quote bytes/cblock - can do better. */
288 /* Data chars/clist. */
289 #define CBSIZE (CBLOCK - (int)sizeof(struct cblock *) - CBQSIZE)
290 #define CROUND (CBLOCK - 1) /* Clist rounding. */
291
292 /*
293 * File system parameters and macros.
294 *
295 * The file system is made out of blocks of at most MAXBSIZE units, with
296 * smaller units (fragments) only in the last direct block. MAXBSIZE
297 * primarily determines the size of buffers in the buffer pool. It may be
298 * made larger without any effect on existing file systems; however making
299 * it smaller may make some file systems unmountable.
300 */
301 #ifndef MAXBSIZE /* XXX */
302 #define MAXBSIZE MAXPHYS
303 #endif
304 #define MAXFRAG 8
305
306 /*
307 * MAXPATHLEN defines the longest permissible path length after expanding
308 * symbolic links. It is used to allocate a temporary buffer from the buffer
309 * pool in which to do the name expansion, hence should be a power of two,
310 * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the
311 * maximum number of symbolic links that may be expanded in a path name.
312 * It should be set high enough to allow all legitimate uses, but halt
313 * infinite loops reasonably quickly.
314 *
315 * MAXSYMLINKS should be >= _POSIX_SYMLOOP_MAX (see <limits.h>)
316 */
317 #define MAXPATHLEN PATH_MAX
318 #define MAXSYMLINKS 32
319
320 /* Bit map related macros. */
321 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
322 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
323 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
324 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
325
326 /* Macros for counting and rounding. */
327 #ifndef howmany
328 #define howmany(x, y) (((x)+((y)-1))/(y))
329 #endif
330 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
331 #define rounddown(x,y) (((x)/(y))*(y))
332 #define roundup2(x, m) (((x) + m - 1) & ~(m - 1))
333 #define powerof2(x) ((((x)-1)&(x))==0)
334
335 /* Macros for min/max. */
336 #define MIN(a,b) (((a)<(b))?(a):(b))
337 #define MAX(a,b) (((a)>(b))?(a):(b))
338
339 /*
340 * Constants for setting the parameters of the kernel memory allocator.
341 *
342 * 2 ** MINBUCKET is the smallest unit of memory that will be
343 * allocated. It must be at least large enough to hold a pointer.
344 *
345 * Units of memory less or equal to MAXALLOCSAVE will permanently
346 * allocate physical memory; requests for these size pieces of
347 * memory are quite fast. Allocations greater than MAXALLOCSAVE must
348 * always allocate and free physical memory; requests for these
349 * size allocations should be done infrequently as they will be slow.
350 *
351 * Constraints: NBPG <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and
352 * MAXALLOCSAVE must be a power of two.
353 */
354 #ifdef _LP64
355 #define MINBUCKET 5 /* 5 => min allocation of 32 bytes */
356 #else
357 #define MINBUCKET 4 /* 4 => min allocation of 16 bytes */
358 #endif
359 #define MAXALLOCSAVE (2 * NBPG)
360
361 /*
362 * Scale factor for scaled integers used to count %cpu time and load avgs.
363 *
364 * The number of CPU `tick's that map to a unique `%age' can be expressed
365 * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that
366 * can be calculated (assuming 32 bits) can be closely approximated using
367 * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).
368 *
369 * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
370 * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.
371 */
372 #define FSHIFT 11 /* bits to right of fixed binary point */
373 #define FSCALE (1<<FSHIFT)
374
375 /*
376 * The time for a process to be blocked before being very swappable.
377 * This is a number of seconds which the system takes as being a non-trivial
378 * amount of real time. You probably shouldn't change this;
379 * it is used in subtle ways (fractions and multiples of it are, that is, like
380 * half of a ``long time'', almost a long time, etc.)
381 * It is related to human patience and other factors which don't really
382 * change over time.
383 */
384 #define MAXSLP 20
385
386 /*
387 * Defaults for Unified Buffer Cache parameters.
388 * These may be overridden in <machine/param.h>.
389 */
390
391 #ifndef UBC_WINSHIFT
392 #define UBC_WINSHIFT 13
393 #endif
394 #ifndef UBC_NWINS
395 #define UBC_NWINS 1024
396 #endif
397
398 #ifdef _KERNEL
399 /*
400 * macro to convert from milliseconds to hz without integer overflow
401 * Default version using only 32bits arithmetics.
402 * 64bit port can define 64bit version in their <machine/param.h>
403 * 0x20000 is safe for hz < 20000
404 */
405 #ifndef mstohz
406 #define mstohz(ms) \
407 (__predict_false((ms) >= 0x20000) ? \
408 ((ms +0u) / 1000u) * hz : \
409 ((ms +0u) * hz) / 1000u)
410 #endif
411 #ifndef hztoms
412 #define hztoms(t) \
413 (__predict_false((t) >= 0x20000) ? \
414 ((t +0u) / hz) * 1000u : \
415 ((t +0u) * 1000u) / hz)
416 #endif
417
418 extern const int schedppq;
419 extern size_t coherency_unit;
420
421 #endif /* _KERNEL */
422
423 /*
424 * Minimum alignment of "struct lwp" needed by the architecture.
425 * This counts when packing a lock byte into a word alongside a
426 * pointer to an LWP.
427 */
428 #ifndef MIN_LWP_ALIGNMENT
429 #define MIN_LWP_ALIGNMENT 32
430 #endif
431
432 #endif /* !_SYS_PARAM_H_ */
Cache object: 49988b649b1c0012c5276fc8b3f2f715
|