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