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