1 /* $NetBSD: param.h,v 1.381 2011/02/01 01:40:00 matt 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__ 599004500 /* NetBSD 5.99.45 */ 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_VA_MAXPCT 153 #define VNODE_VA_MAXPCT 20 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 #ifdef __MACHINE_STACK_GROWS_UP 208 #define STACK_GROW(sp, _size) (((char *)(void *)(sp)) + (_size)) 209 #define STACK_SHRINK(sp, _size) (((char *)(void *)(sp)) - (_size)) 210 #define STACK_ALIGN(sp, bytes) \ 211 ((char *)((((unsigned long)(sp)) + (bytes)) & ~(bytes))) 212 #define STACK_ALLOC(sp, _size) ((char *)(void *)(sp)) 213 #define STACK_MAX(p, _size) (((char *)(void *)(p)) + (_size)) 214 #else 215 #define STACK_GROW(sp, _size) (((char *)(void *)(sp)) - (_size)) 216 #define STACK_SHRINK(sp, _size) (((char *)(void *)(sp)) + (_size)) 217 #define STACK_ALIGN(sp, bytes) \ 218 ((char *)(((unsigned long)(sp)) & ~(bytes))) 219 #define STACK_ALLOC(sp, _size) (((char *)(void *)(sp)) - (_size)) 220 #define STACK_MAX(p, _size) ((char *)(void *)(p)) 221 #endif 222 #endif /* defined(_KERNEL) || defined(__EXPOSE_STACK) */ 223 224 /* 225 * Historic priority levels. These are meaningless and remain only 226 * for source compatibility. Do not use in new code. 227 */ 228 #define PSWP 0 229 #define PVM 4 230 #define PINOD 8 231 #define PRIBIO 16 232 #define PVFS 20 233 #define PZERO 22 234 #define PSOCK 24 235 #define PWAIT 32 236 #define PLOCK 36 237 #define PPAUSE 40 238 #define PUSER 50 239 #define MAXPRI 127 240 241 #define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */ 242 #define PNORELOCK 0x200 /* OR'd with pri for tsleep to not relock */ 243 244 /* 245 * New priority levels. 246 */ 247 #define PRI_COUNT 224 248 #define PRI_NONE (-1) 249 250 #define PRI_KERNEL_RT 192 251 #define NPRI_KERNEL_RT 32 252 #define MAXPRI_KERNEL_RT (PRI_KERNEL_RT + NPRI_KERNEL_RT - 1) 253 254 #define PRI_USER_RT 128 255 #define NPRI_USER_RT 64 256 #define MAXPRI_USER_RT (PRI_USER_RT + NPRI_USER_RT - 1) 257 258 #define PRI_KTHREAD 96 259 #define NPRI_KTHREAD 32 260 #define MAXPRI_KTHREAD (PRI_KTHREAD + NPRI_KTHREAD - 1) 261 262 #define PRI_KERNEL 64 263 #define NPRI_KERNEL 32 264 #define MAXPRI_KERNEL (PRI_KERNEL + NPRI_KERNEL - 1) 265 266 #define PRI_USER 0 267 #define NPRI_USER 64 268 #define MAXPRI_USER (PRI_USER + NPRI_USER - 1) 269 270 /* Priority range used by POSIX real-time features */ 271 #define SCHED_PRI_MIN 0 272 #define SCHED_PRI_MAX 63 273 274 /* 275 * Kernel thread priorities. 276 */ 277 #define PRI_SOFTSERIAL MAXPRI_KERNEL_RT 278 #define PRI_SOFTNET (MAXPRI_KERNEL_RT - schedppq * 1) 279 #define PRI_SOFTBIO (MAXPRI_KERNEL_RT - schedppq * 2) 280 #define PRI_SOFTCLOCK (MAXPRI_KERNEL_RT - schedppq * 3) 281 282 #define PRI_XCALL MAXPRI_KTHREAD 283 #define PRI_PGDAEMON (MAXPRI_KTHREAD - schedppq * 1) 284 #define PRI_VM (MAXPRI_KTHREAD - schedppq * 2) 285 #define PRI_IOFLUSH (MAXPRI_KTHREAD - schedppq * 3) 286 #define PRI_BIO (MAXPRI_KTHREAD - schedppq * 4) 287 288 #define PRI_IDLE PRI_USER 289 290 /* 291 * Miscellaneous. 292 */ 293 #define NBPW sizeof(int) /* number of bytes per word (integer) */ 294 295 #define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */ 296 #define NODEV (dev_t)(-1) /* non-existent device */ 297 298 #define CBLOCK 64 /* Clist block size, must be a power of 2. */ 299 #define CBQSIZE (CBLOCK/NBBY) /* Quote bytes/cblock - can do better. */ 300 /* Data chars/clist. */ 301 #define CBSIZE (CBLOCK - (int)sizeof(struct cblock *) - CBQSIZE) 302 #define CROUND (CBLOCK - 1) /* Clist rounding. */ 303 304 /* 305 * File system parameters and macros. 306 * 307 * The file system is made out of blocks of at most MAXBSIZE units, with 308 * smaller units (fragments) only in the last direct block. MAXBSIZE 309 * primarily determines the size of buffers in the buffer pool. It may be 310 * made larger without any effect on existing file systems; however making 311 * it smaller may make some file systems unmountable. 312 */ 313 #ifndef MAXBSIZE /* XXX */ 314 #define MAXBSIZE MAXPHYS 315 #endif 316 #define MAXFRAG 8 317 318 /* 319 * MAXPATHLEN defines the longest permissible path length after expanding 320 * symbolic links. It is used to allocate a temporary buffer from the buffer 321 * pool in which to do the name expansion, hence should be a power of two, 322 * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the 323 * maximum number of symbolic links that may be expanded in a path name. 324 * It should be set high enough to allow all legitimate uses, but halt 325 * infinite loops reasonably quickly. 326 * 327 * MAXSYMLINKS should be >= _POSIX_SYMLOOP_MAX (see <limits.h>) 328 */ 329 #define MAXPATHLEN PATH_MAX 330 #define MAXSYMLINKS 32 331 332 /* Bit map related macros. */ 333 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) 334 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) 335 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) 336 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) 337 338 /* Macros for counting and rounding. */ 339 #ifndef howmany 340 #define howmany(x, y) (((x)+((y)-1))/(y)) 341 #endif 342 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) 343 #define rounddown(x,y) (((x)/(y))*(y)) 344 #define roundup2(x, m) (((x) + (m) - 1) & ~((m) - 1)) 345 #define powerof2(x) ((((x)-1)&(x))==0) 346 347 /* Macros for min/max. */ 348 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b)) 349 #define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b)) 350 351 /* 352 * Constants for setting the parameters of the kernel memory allocator. 353 * 354 * 2 ** MINBUCKET is the smallest unit of memory that will be 355 * allocated. It must be at least large enough to hold a pointer. 356 * 357 * Units of memory less or equal to MAXALLOCSAVE will permanently 358 * allocate physical memory; requests for these size pieces of 359 * memory are quite fast. Allocations greater than MAXALLOCSAVE must 360 * always allocate and free physical memory; requests for these 361 * size allocations should be done infrequently as they will be slow. 362 * 363 * Constraints: NBPG <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and 364 * MAXALLOCSAVE must be a power of two. 365 */ 366 #ifdef _LP64 367 #define MINBUCKET 5 /* 5 => min allocation of 32 bytes */ 368 #else 369 #define MINBUCKET 4 /* 4 => min allocation of 16 bytes */ 370 #endif 371 #define MAXALLOCSAVE (2 * NBPG) 372 373 /* 374 * Scale factor for scaled integers used to count %cpu time and load avgs. 375 * 376 * The number of CPU `tick's that map to a unique `%age' can be expressed 377 * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that 378 * can be calculated (assuming 32 bits) can be closely approximated using 379 * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15). 380 * 381 * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age', 382 * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024. 383 */ 384 #define FSHIFT 11 /* bits to right of fixed binary point */ 385 #define FSCALE (1<<FSHIFT) 386 387 /* 388 * The time for a process to be blocked before being very swappable. 389 * This is a number of seconds which the system takes as being a non-trivial 390 * amount of real time. You probably shouldn't change this; 391 * it is used in subtle ways (fractions and multiples of it are, that is, like 392 * half of a ``long time'', almost a long time, etc.) 393 * It is related to human patience and other factors which don't really 394 * change over time. 395 */ 396 #define MAXSLP 20 397 398 /* 399 * Defaults for Unified Buffer Cache parameters. 400 * These may be overridden in <machine/param.h>. 401 */ 402 403 #ifndef UBC_WINSHIFT 404 #define UBC_WINSHIFT 13 405 #endif 406 #ifndef UBC_NWINS 407 #define UBC_NWINS 1024 408 #endif 409 410 #ifdef _KERNEL 411 /* 412 * macro to convert from milliseconds to hz without integer overflow 413 * Default version using only 32bits arithmetics. 414 * 64bit port can define 64bit version in their <machine/param.h> 415 * 0x20000 is safe for hz < 20000 416 */ 417 #ifndef mstohz 418 #define mstohz(ms) \ 419 (__predict_false((ms) >= 0x20000) ? \ 420 ((ms +0u) / 1000u) * hz : \ 421 ((ms +0u) * hz) / 1000u) 422 #endif 423 #ifndef hztoms 424 #define hztoms(t) \ 425 (__predict_false((t) >= 0x20000) ? \ 426 ((t +0u) / hz) * 1000u : \ 427 ((t +0u) * 1000u) / hz) 428 #endif 429 430 extern const int schedppq; 431 extern size_t coherency_unit; 432 433 #endif /* _KERNEL */ 434 435 /* 436 * Minimum alignment of "struct lwp" needed by the architecture. 437 * This counts when packing a lock byte into a word alongside a 438 * pointer to an LWP. 439 */ 440 #ifndef MIN_LWP_ALIGNMENT 441 #define MIN_LWP_ALIGNMENT 32 442 #endif 443 #endif /* !__ASSEMBLER__ */ 444 445 #endif /* !_SYS_PARAM_H_ */ 446