1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/types.h> 30*0Sstevel@tonic-gate #include <sys/time.h> 31*0Sstevel@tonic-gate #include <sys/param.h> 32*0Sstevel@tonic-gate #include <sys/systm.h> 33*0Sstevel@tonic-gate #include <sys/signal.h> 34*0Sstevel@tonic-gate #include <sys/sysmacros.h> 35*0Sstevel@tonic-gate #include <sys/cmn_err.h> 36*0Sstevel@tonic-gate #include <sys/user.h> 37*0Sstevel@tonic-gate #include <sys/proc.h> 38*0Sstevel@tonic-gate #include <sys/task.h> 39*0Sstevel@tonic-gate #include <sys/project.h> 40*0Sstevel@tonic-gate #include <sys/klwp.h> 41*0Sstevel@tonic-gate #include <sys/vnode.h> 42*0Sstevel@tonic-gate #include <sys/file.h> 43*0Sstevel@tonic-gate #include <sys/fcntl.h> 44*0Sstevel@tonic-gate #include <sys/flock.h> 45*0Sstevel@tonic-gate #include <sys/var.h> 46*0Sstevel@tonic-gate #include <sys/stream.h> 47*0Sstevel@tonic-gate #include <sys/strsubr.h> 48*0Sstevel@tonic-gate #include <sys/conf.h> 49*0Sstevel@tonic-gate #include <sys/class.h> 50*0Sstevel@tonic-gate #include <sys/ts.h> 51*0Sstevel@tonic-gate #include <sys/rt.h> 52*0Sstevel@tonic-gate #include <sys/exec.h> 53*0Sstevel@tonic-gate #include <sys/exechdr.h> 54*0Sstevel@tonic-gate #include <sys/buf.h> 55*0Sstevel@tonic-gate #include <sys/resource.h> 56*0Sstevel@tonic-gate #include <vm/seg.h> 57*0Sstevel@tonic-gate #include <vm/pvn.h> 58*0Sstevel@tonic-gate #include <vm/seg_kmem.h> 59*0Sstevel@tonic-gate #include <sys/vmparam.h> 60*0Sstevel@tonic-gate #include <sys/machparam.h> 61*0Sstevel@tonic-gate #include <sys/utsname.h> 62*0Sstevel@tonic-gate #include <sys/kmem.h> 63*0Sstevel@tonic-gate #include <sys/stack.h> 64*0Sstevel@tonic-gate #include <sys/modctl.h> 65*0Sstevel@tonic-gate #include <sys/fdbuffer.h> 66*0Sstevel@tonic-gate #include <sys/cyclic_impl.h> 67*0Sstevel@tonic-gate #include <sys/disp.h> 68*0Sstevel@tonic-gate #include <sys/tuneable.h> 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate #include <sys/vmem.h> 71*0Sstevel@tonic-gate #include <sys/clock.h> 72*0Sstevel@tonic-gate #include <sys/serializer.h> 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate /* 75*0Sstevel@tonic-gate * The following few lines describe generic things that must be compiled 76*0Sstevel@tonic-gate * into the booted executable (unix) rather than genunix or any other 77*0Sstevel@tonic-gate * module because they're required by crash dump readers, etc. 78*0Sstevel@tonic-gate */ 79*0Sstevel@tonic-gate struct modctl modules; /* head of linked list of modules */ 80*0Sstevel@tonic-gate char *default_path; /* default module loading path */ 81*0Sstevel@tonic-gate struct swapinfo *swapinfo; /* protected by the swapinfo_lock */ 82*0Sstevel@tonic-gate proc_t *practive; /* active process list */ 83*0Sstevel@tonic-gate uint_t nproc; /* current number of processes */ 84*0Sstevel@tonic-gate proc_t p0; /* process 0 */ 85*0Sstevel@tonic-gate struct plock p0lock; /* p0's p_lock */ 86*0Sstevel@tonic-gate klwp_t lwp0; /* t0's lwp */ 87*0Sstevel@tonic-gate task_t *task0p; /* task 0 */ 88*0Sstevel@tonic-gate kproject_t *proj0p; /* location of project 0 */ 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate /* 91*0Sstevel@tonic-gate * The following are "implementation architecture" dependent constants made 92*0Sstevel@tonic-gate * available here in the form of initialized data for use by "implementation 93*0Sstevel@tonic-gate * architecture" independent modules. See machparam.h. 94*0Sstevel@tonic-gate */ 95*0Sstevel@tonic-gate const unsigned long _pagesize = (unsigned long)PAGESIZE; 96*0Sstevel@tonic-gate const unsigned int _pageshift = (unsigned int)PAGESHIFT; 97*0Sstevel@tonic-gate const unsigned long _pageoffset = (unsigned long)PAGEOFFSET; 98*0Sstevel@tonic-gate /* 99*0Sstevel@tonic-gate * XXX - This value pagemask has to be a 64bit size because 100*0Sstevel@tonic-gate * large file support uses this mask on offsets which are 64 bit size. 101*0Sstevel@tonic-gate * using unsigned leaves the higher 32 bits value as zero thus 102*0Sstevel@tonic-gate * corrupting offset calculations in the file system and VM. 103*0Sstevel@tonic-gate */ 104*0Sstevel@tonic-gate const u_longlong_t _pagemask = (u_longlong_t)PAGEMASK; 105*0Sstevel@tonic-gate const unsigned long _mmu_pagesize = (unsigned long)MMU_PAGESIZE; 106*0Sstevel@tonic-gate const unsigned int _mmu_pageshift = (unsigned int)MMU_PAGESHIFT; 107*0Sstevel@tonic-gate const unsigned long _mmu_pageoffset = (unsigned long)MMU_PAGEOFFSET; 108*0Sstevel@tonic-gate const unsigned long _mmu_pagemask = (unsigned long)MMU_PAGEMASK; 109*0Sstevel@tonic-gate uintptr_t _kernelbase = (uintptr_t)KERNELBASE; 110*0Sstevel@tonic-gate uintptr_t _userlimit = (uintptr_t)USERLIMIT; 111*0Sstevel@tonic-gate uintptr_t _userlimit32 = (uintptr_t)USERLIMIT32; 112*0Sstevel@tonic-gate #if !defined(__ia64) 113*0Sstevel@tonic-gate const uintptr_t _argsbase = (uintptr_t)ARGSBASE; 114*0Sstevel@tonic-gate #endif 115*0Sstevel@tonic-gate const unsigned int _diskrpm = (unsigned int)DISKRPM; 116*0Sstevel@tonic-gate const unsigned long _pgthresh = (unsigned long)PGTHRESH; 117*0Sstevel@tonic-gate const unsigned int _maxslp = (unsigned int)MAXSLP; 118*0Sstevel@tonic-gate const unsigned long _maxhandspreadpages = (unsigned long)MAXHANDSPREADPAGES; 119*0Sstevel@tonic-gate const int _ncpu = (int)NCPU; 120*0Sstevel@tonic-gate const unsigned long _defaultstksz = (unsigned long)DEFAULTSTKSZ; 121*0Sstevel@tonic-gate const unsigned int _nbpg = (unsigned int)MMU_PAGESIZE; 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate /* 124*0Sstevel@tonic-gate * System parameter formulae. 125*0Sstevel@tonic-gate * 126*0Sstevel@tonic-gate * This file is copied into each directory where we compile 127*0Sstevel@tonic-gate * the kernel; it should be modified there to suit local taste 128*0Sstevel@tonic-gate * if necessary. 129*0Sstevel@tonic-gate */ 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate /* 132*0Sstevel@tonic-gate * Default hz is 100, but if we set hires_tick we get higher resolution 133*0Sstevel@tonic-gate * clock behavior (currently defined to be 1000 hz). Higher values seem 134*0Sstevel@tonic-gate * to work, but are not supported. 135*0Sstevel@tonic-gate * 136*0Sstevel@tonic-gate * If we do decide to play with higher values, remember that hz should 137*0Sstevel@tonic-gate * satisfy the following constraints to avoid integer round-off problems: 138*0Sstevel@tonic-gate * 139*0Sstevel@tonic-gate * (1) hz should be in the range 100 <= hz <= MICROSEC. If hz exceeds 140*0Sstevel@tonic-gate * MICROSEC, usec_per_tick will be zero and lots of stuff will break. 141*0Sstevel@tonic-gate * Similarly, if hz < 100 then hz / 100 == 0 and stuff will break. 142*0Sstevel@tonic-gate * 143*0Sstevel@tonic-gate * (2) If hz <= 1000, it should be both a multiple of 100 and a 144*0Sstevel@tonic-gate * divisor of 1000. 145*0Sstevel@tonic-gate * 146*0Sstevel@tonic-gate * (3) If hz > 1000, it should be both a multiple of 1000 and a 147*0Sstevel@tonic-gate * divisor of MICROSEC. 148*0Sstevel@tonic-gate * 149*0Sstevel@tonic-gate * Thus the only reasonable values of hz (i.e. the values that won't 150*0Sstevel@tonic-gate * cause roundoff error) are: 100, 200, 500, 1000, 2000, 4000, 5000, 151*0Sstevel@tonic-gate * 8000, 10000, 20000, 25000, 40000, 50000, 100000, 125000, 200000, 152*0Sstevel@tonic-gate * 250000, 500000, 1000000. As of this writing (1996) a clock rate 153*0Sstevel@tonic-gate * of more than about 10 kHz seems utterly ridiculous, although 154*0Sstevel@tonic-gate * this observation will no doubt seem quaintly amusing one day. 155*0Sstevel@tonic-gate */ 156*0Sstevel@tonic-gate int hz = 100; 157*0Sstevel@tonic-gate int hires_hz = 1000; 158*0Sstevel@tonic-gate int hires_tick = 0; 159*0Sstevel@tonic-gate int cpu_decay_factor = 10; /* this is no longer tied to clock */ 160*0Sstevel@tonic-gate int tick_per_msec; /* clock ticks per millisecond (zero if hz < 1000) */ 161*0Sstevel@tonic-gate int msec_per_tick; /* millseconds per clock tick (zero if hz > 1000) */ 162*0Sstevel@tonic-gate int usec_per_tick; /* microseconds per clock tick */ 163*0Sstevel@tonic-gate int nsec_per_tick; /* nanoseconds per clock tick */ 164*0Sstevel@tonic-gate int max_hres_adj; /* maximum adjustment of hrtime per tick */ 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate /* 167*0Sstevel@tonic-gate * Setting "snooping" to a non-zero value will cause a deadman panic if 168*0Sstevel@tonic-gate * snoop_interval microseconds elapse without lbolt increasing. The default 169*0Sstevel@tonic-gate * snoop_interval is 50 seconds. 170*0Sstevel@tonic-gate */ 171*0Sstevel@tonic-gate #define SNOOP_INTERVAL_MIN (MICROSEC) 172*0Sstevel@tonic-gate #define SNOOP_INTERVAL_DEFAULT (50 * MICROSEC) 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate int snooping = 0; 175*0Sstevel@tonic-gate uint_t snoop_interval = SNOOP_INTERVAL_DEFAULT; 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate /* 178*0Sstevel@tonic-gate * Tables of initialization functions, called from main(). 179*0Sstevel@tonic-gate */ 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate extern void system_taskq_init(void); 182*0Sstevel@tonic-gate extern void binit(void); 183*0Sstevel@tonic-gate extern void space_init(void); 184*0Sstevel@tonic-gate extern void dnlc_init(void); 185*0Sstevel@tonic-gate extern void vfsinit(void); 186*0Sstevel@tonic-gate extern void finit(void); 187*0Sstevel@tonic-gate extern void strinit(void); 188*0Sstevel@tonic-gate extern void flk_init(void); 189*0Sstevel@tonic-gate extern void ftrace_init(void); 190*0Sstevel@tonic-gate extern void softcall_init(void); 191*0Sstevel@tonic-gate extern void sadinit(void); 192*0Sstevel@tonic-gate extern void ttyinit(void); 193*0Sstevel@tonic-gate extern void schedctl_init(void); 194*0Sstevel@tonic-gate extern void deadman_init(void); 195*0Sstevel@tonic-gate extern void clock_timer_init(void); 196*0Sstevel@tonic-gate extern void clock_realtime_init(void); 197*0Sstevel@tonic-gate extern void clock_highres_init(void); 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate void (*init_tbl[])(void) = { 200*0Sstevel@tonic-gate system_taskq_init, 201*0Sstevel@tonic-gate binit, 202*0Sstevel@tonic-gate space_init, 203*0Sstevel@tonic-gate dnlc_init, 204*0Sstevel@tonic-gate vfsinit, 205*0Sstevel@tonic-gate finit, 206*0Sstevel@tonic-gate strinit, 207*0Sstevel@tonic-gate serializer_init, 208*0Sstevel@tonic-gate softcall_init, 209*0Sstevel@tonic-gate sadinit, 210*0Sstevel@tonic-gate ttyinit, 211*0Sstevel@tonic-gate as_init, 212*0Sstevel@tonic-gate pvn_init, 213*0Sstevel@tonic-gate anon_init, 214*0Sstevel@tonic-gate segvn_init, 215*0Sstevel@tonic-gate flk_init, 216*0Sstevel@tonic-gate schedctl_init, 217*0Sstevel@tonic-gate fdb_init, 218*0Sstevel@tonic-gate deadman_init, 219*0Sstevel@tonic-gate clock_timer_init, 220*0Sstevel@tonic-gate clock_realtime_init, 221*0Sstevel@tonic-gate clock_highres_init, 222*0Sstevel@tonic-gate 0 223*0Sstevel@tonic-gate }; 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate /* 227*0Sstevel@tonic-gate * Any per cpu resources should be initialized via 228*0Sstevel@tonic-gate * an entry in mp_init_tbl(). 229*0Sstevel@tonic-gate */ 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate void (*mp_init_tbl[])(void) = { 232*0Sstevel@tonic-gate ftrace_init, 233*0Sstevel@tonic-gate cyclic_mp_init, 234*0Sstevel@tonic-gate 0 235*0Sstevel@tonic-gate }; 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate int maxusers; /* kitchen-sink knob for dynamic configuration */ 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate /* 240*0Sstevel@tonic-gate * pidmax -- highest pid value assigned by the system 241*0Sstevel@tonic-gate * Settable in /etc/system 242*0Sstevel@tonic-gate */ 243*0Sstevel@tonic-gate int pidmax = DEFAULT_MAXPID; 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate /* 246*0Sstevel@tonic-gate * jump_pid - if set, this value is where pid numbers should start 247*0Sstevel@tonic-gate * after the first few system pids (0-3) are used. If 0, pids are 248*0Sstevel@tonic-gate * chosen in the usual way. This variable can be used to quickly 249*0Sstevel@tonic-gate * create large pids (by setting it to 100000, for example). pids 250*0Sstevel@tonic-gate * less than this value will never be chosen. 251*0Sstevel@tonic-gate */ 252*0Sstevel@tonic-gate pid_t jump_pid = DEFAULT_JUMPPID; 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate /* 255*0Sstevel@tonic-gate * autoup -- used in struct var for dynamic config of the age a delayed-write 256*0Sstevel@tonic-gate * buffer must be in seconds before bdflush will write it out. 257*0Sstevel@tonic-gate */ 258*0Sstevel@tonic-gate #define DEFAULT_AUTOUP 30 259*0Sstevel@tonic-gate int autoup = DEFAULT_AUTOUP; 260*0Sstevel@tonic-gate 261*0Sstevel@tonic-gate /* 262*0Sstevel@tonic-gate * bufhwm -- tuneable variable for struct var for v_bufhwm. 263*0Sstevel@tonic-gate * high water mark for buffer cache mem usage in units of K bytes. 264*0Sstevel@tonic-gate * 265*0Sstevel@tonic-gate * bufhwm_pct -- ditto, but given in % of physmem. 266*0Sstevel@tonic-gate */ 267*0Sstevel@tonic-gate int bufhwm = 0; 268*0Sstevel@tonic-gate int bufhwm_pct = 0; 269*0Sstevel@tonic-gate 270*0Sstevel@tonic-gate /* 271*0Sstevel@tonic-gate * Process table. 272*0Sstevel@tonic-gate */ 273*0Sstevel@tonic-gate int maxpid; 274*0Sstevel@tonic-gate int max_nprocs; /* set in param_init() */ 275*0Sstevel@tonic-gate int maxuprc; /* set in param_init() */ 276*0Sstevel@tonic-gate int reserved_procs; 277*0Sstevel@tonic-gate int nthread = 1; 278*0Sstevel@tonic-gate 279*0Sstevel@tonic-gate /* 280*0Sstevel@tonic-gate * UFS tunables 281*0Sstevel@tonic-gate */ 282*0Sstevel@tonic-gate int ufs_ninode; /* declared here due to backwards compatibility */ 283*0Sstevel@tonic-gate int ndquot; /* declared here due to backwards compatibility */ 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate /* 286*0Sstevel@tonic-gate * Exec switch table. This is used by the generic exec module 287*0Sstevel@tonic-gate * to switch out to the desired executable type, based on the 288*0Sstevel@tonic-gate * magic number. The currently supported types are ELF, a.out 289*0Sstevel@tonic-gate * (both NMAGIC and ZMAGIC), interpreter (#!) files, 290*0Sstevel@tonic-gate * and Java executables. 291*0Sstevel@tonic-gate */ 292*0Sstevel@tonic-gate /* 293*0Sstevel@tonic-gate * Magic numbers 294*0Sstevel@tonic-gate */ 295*0Sstevel@tonic-gate short elfmagic = 0x7f45; 296*0Sstevel@tonic-gate short intpmagic = 0x2321; 297*0Sstevel@tonic-gate short jmagic = 0x504b; 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate #if defined(__sparc) 300*0Sstevel@tonic-gate short aout_nmagic = NMAGIC; 301*0Sstevel@tonic-gate short aout_zmagic = ZMAGIC; 302*0Sstevel@tonic-gate short aout_omagic = OMAGIC; 303*0Sstevel@tonic-gate #endif 304*0Sstevel@tonic-gate short nomagic = 0; 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gate /* 307*0Sstevel@tonic-gate * Magic strings 308*0Sstevel@tonic-gate */ 309*0Sstevel@tonic-gate #define ELF32MAGIC_STRING "\x7f""ELF\x1" 310*0Sstevel@tonic-gate #define ELF64MAGIC_STRING "\x7f""ELF\x2" 311*0Sstevel@tonic-gate #define INTPMAGIC_STRING "#!" 312*0Sstevel@tonic-gate #define JAVAMAGIC_STRING "PK\003\004" 313*0Sstevel@tonic-gate #define AOUT_OMAGIC_STRING "\x1""\x07" /* 0407 */ 314*0Sstevel@tonic-gate #define AOUT_NMAGIC_STRING "\x1""\x08" /* 0410 */ 315*0Sstevel@tonic-gate #define AOUT_ZMAGIC_STRING "\x1""\x0b" /* 0413 */ 316*0Sstevel@tonic-gate #define NOMAGIC_STRING "" 317*0Sstevel@tonic-gate 318*0Sstevel@tonic-gate char elf32magicstr[] = ELF32MAGIC_STRING; 319*0Sstevel@tonic-gate char elf64magicstr[] = ELF64MAGIC_STRING; 320*0Sstevel@tonic-gate char intpmagicstr[] = INTPMAGIC_STRING; 321*0Sstevel@tonic-gate char javamagicstr[] = JAVAMAGIC_STRING; 322*0Sstevel@tonic-gate #if defined(__sparc) 323*0Sstevel@tonic-gate char aout_nmagicstr[] = AOUT_NMAGIC_STRING; 324*0Sstevel@tonic-gate char aout_zmagicstr[] = AOUT_ZMAGIC_STRING; 325*0Sstevel@tonic-gate char aout_omagicstr[] = AOUT_OMAGIC_STRING; 326*0Sstevel@tonic-gate #endif 327*0Sstevel@tonic-gate char nomagicstr[] = NOMAGIC_STRING; 328*0Sstevel@tonic-gate 329*0Sstevel@tonic-gate char *execswnames[] = { 330*0Sstevel@tonic-gate "elfexec", /* Elf32 */ 331*0Sstevel@tonic-gate #ifdef _LP64 332*0Sstevel@tonic-gate "elfexec", /* Elf64 */ 333*0Sstevel@tonic-gate #endif 334*0Sstevel@tonic-gate "intpexec", 335*0Sstevel@tonic-gate "javaexec", 336*0Sstevel@tonic-gate #if defined(__sparc) 337*0Sstevel@tonic-gate "aoutexec", 338*0Sstevel@tonic-gate "aoutexec", 339*0Sstevel@tonic-gate "aoutexec", 340*0Sstevel@tonic-gate #endif 341*0Sstevel@tonic-gate NULL, 342*0Sstevel@tonic-gate NULL, 343*0Sstevel@tonic-gate NULL 344*0Sstevel@tonic-gate }; 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate struct execsw execsw[] = { 347*0Sstevel@tonic-gate { elf32magicstr, 0, 5, NULL, NULL, NULL }, 348*0Sstevel@tonic-gate #ifdef _LP64 349*0Sstevel@tonic-gate { elf64magicstr, 0, 5, NULL, NULL, NULL }, 350*0Sstevel@tonic-gate #endif 351*0Sstevel@tonic-gate { intpmagicstr, 0, 2, NULL, NULL, NULL }, 352*0Sstevel@tonic-gate { javamagicstr, 0, 4, NULL, NULL, NULL }, 353*0Sstevel@tonic-gate #if defined(__sparc) 354*0Sstevel@tonic-gate { aout_zmagicstr, 2, 2, NULL, NULL, NULL }, 355*0Sstevel@tonic-gate { aout_nmagicstr, 2, 2, NULL, NULL, NULL }, 356*0Sstevel@tonic-gate { aout_omagicstr, 2, 2, NULL, NULL, NULL }, 357*0Sstevel@tonic-gate #endif 358*0Sstevel@tonic-gate { nomagicstr, 0, 0, NULL, NULL, NULL }, 359*0Sstevel@tonic-gate { nomagicstr, 0, 0, NULL, NULL, NULL }, 360*0Sstevel@tonic-gate { nomagicstr, 0, 0, NULL, NULL, NULL }, 361*0Sstevel@tonic-gate { nomagicstr, 0, 0, NULL, NULL, NULL } 362*0Sstevel@tonic-gate }; 363*0Sstevel@tonic-gate int nexectype = sizeof (execsw) / sizeof (execsw[0]); /* # of exec types */ 364*0Sstevel@tonic-gate kmutex_t execsw_lock; /* Used for allocation of execsw entries */ 365*0Sstevel@tonic-gate 366*0Sstevel@tonic-gate /* 367*0Sstevel@tonic-gate * symbols added to make changing max-file-descriptors 368*0Sstevel@tonic-gate * simple via /etc/system 369*0Sstevel@tonic-gate */ 370*0Sstevel@tonic-gate #define RLIM_FD_CUR 0x100 371*0Sstevel@tonic-gate #define RLIM_FD_MAX 0x10000 372*0Sstevel@tonic-gate 373*0Sstevel@tonic-gate uint_t rlim_fd_cur = RLIM_FD_CUR; 374*0Sstevel@tonic-gate uint_t rlim_fd_max = RLIM_FD_MAX; 375*0Sstevel@tonic-gate 376*0Sstevel@tonic-gate /* 377*0Sstevel@tonic-gate * (Default resource limits were formerly declared here, but are now provided by 378*0Sstevel@tonic-gate * the more general resource controls framework.) 379*0Sstevel@tonic-gate */ 380*0Sstevel@tonic-gate 381*0Sstevel@tonic-gate /* 382*0Sstevel@tonic-gate * Streams tunables 383*0Sstevel@tonic-gate */ 384*0Sstevel@tonic-gate int nstrpush = 9; 385*0Sstevel@tonic-gate int maxsepgcnt = 1; 386*0Sstevel@tonic-gate 387*0Sstevel@tonic-gate /* 388*0Sstevel@tonic-gate * strmsgsz is the size for the maximum streams message a user can create. 389*0Sstevel@tonic-gate * for Release 4.0, a value of zero will indicate no upper bound. This 390*0Sstevel@tonic-gate * parameter will disappear entirely in the next release. 391*0Sstevel@tonic-gate */ 392*0Sstevel@tonic-gate 393*0Sstevel@tonic-gate ssize_t strmsgsz = 0x10000; 394*0Sstevel@tonic-gate ssize_t strctlsz = 1024; 395*0Sstevel@tonic-gate int rstchown = 1; /* POSIX_CHOWN_RESTRICTED is enabled */ 396*0Sstevel@tonic-gate int ngroups_max = NGROUPS_MAX_DEFAULT; 397*0Sstevel@tonic-gate 398*0Sstevel@tonic-gate /* 399*0Sstevel@tonic-gate * generic scheduling stuff 400*0Sstevel@tonic-gate * 401*0Sstevel@tonic-gate * Configurable parameters for RT and TS are in the respective 402*0Sstevel@tonic-gate * scheduling class modules. 403*0Sstevel@tonic-gate */ 404*0Sstevel@tonic-gate 405*0Sstevel@tonic-gate pri_t maxclsyspri = MAXCLSYSPRI; 406*0Sstevel@tonic-gate pri_t minclsyspri = MINCLSYSPRI; 407*0Sstevel@tonic-gate char sys_name[] = "SYS"; 408*0Sstevel@tonic-gate 409*0Sstevel@tonic-gate extern pri_t sys_init(); 410*0Sstevel@tonic-gate extern classfuncs_t sys_classfuncs; 411*0Sstevel@tonic-gate 412*0Sstevel@tonic-gate sclass_t sclass[] = { 413*0Sstevel@tonic-gate { "SYS", sys_init, &sys_classfuncs, STATIC_SCHED, 0 }, 414*0Sstevel@tonic-gate { "", NULL, NULL, NULL, 0 }, 415*0Sstevel@tonic-gate { "", NULL, NULL, NULL, 0 }, 416*0Sstevel@tonic-gate { "", NULL, NULL, NULL, 0 }, 417*0Sstevel@tonic-gate { "", NULL, NULL, NULL, 0 }, 418*0Sstevel@tonic-gate { "", NULL, NULL, NULL, 0 }, 419*0Sstevel@tonic-gate { "", NULL, NULL, NULL, 0 }, 420*0Sstevel@tonic-gate { "", NULL, NULL, NULL, 0 }, 421*0Sstevel@tonic-gate { "", NULL, NULL, NULL, 0 }, 422*0Sstevel@tonic-gate { "", NULL, NULL, NULL, 0 } 423*0Sstevel@tonic-gate }; 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gate int loaded_classes = 1; /* for loaded classes */ 426*0Sstevel@tonic-gate kmutex_t class_lock; /* lock for class[] */ 427*0Sstevel@tonic-gate 428*0Sstevel@tonic-gate int nclass = sizeof (sclass) / sizeof (sclass_t); 429*0Sstevel@tonic-gate char initcls[] = "TS"; 430*0Sstevel@tonic-gate char *defaultclass = initcls; 431*0Sstevel@tonic-gate 432*0Sstevel@tonic-gate /* 433*0Sstevel@tonic-gate * Tunable system parameters. 434*0Sstevel@tonic-gate */ 435*0Sstevel@tonic-gate 436*0Sstevel@tonic-gate /* 437*0Sstevel@tonic-gate * The integers tune_* are done this way so that the tune 438*0Sstevel@tonic-gate * data structure may be "tuned" if necessary from the /etc/system 439*0Sstevel@tonic-gate * file. The tune data structure is initialized in param_init(); 440*0Sstevel@tonic-gate */ 441*0Sstevel@tonic-gate 442*0Sstevel@tonic-gate tune_t tune; 443*0Sstevel@tonic-gate 444*0Sstevel@tonic-gate /* 445*0Sstevel@tonic-gate * If freemem < t_getpgslow, then start to steal pages from processes. 446*0Sstevel@tonic-gate */ 447*0Sstevel@tonic-gate int tune_t_gpgslo = 25; 448*0Sstevel@tonic-gate 449*0Sstevel@tonic-gate /* 450*0Sstevel@tonic-gate * Rate at which fsflush is run, in seconds. 451*0Sstevel@tonic-gate */ 452*0Sstevel@tonic-gate #define DEFAULT_TUNE_T_FSFLUSHR 1 453*0Sstevel@tonic-gate int tune_t_fsflushr = DEFAULT_TUNE_T_FSFLUSHR; 454*0Sstevel@tonic-gate 455*0Sstevel@tonic-gate /* 456*0Sstevel@tonic-gate * The minimum available resident (not swappable) memory to maintain 457*0Sstevel@tonic-gate * in order to avoid deadlock. In pages. 458*0Sstevel@tonic-gate */ 459*0Sstevel@tonic-gate int tune_t_minarmem = 25; 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gate /* 462*0Sstevel@tonic-gate * The minimum available swappable memory to maintain in order to avoid 463*0Sstevel@tonic-gate * deadlock. In pages. 464*0Sstevel@tonic-gate */ 465*0Sstevel@tonic-gate int tune_t_minasmem = 25; 466*0Sstevel@tonic-gate 467*0Sstevel@tonic-gate int tune_t_flckrec = 512; /* max # of active frlocks */ 468*0Sstevel@tonic-gate 469*0Sstevel@tonic-gate /* 470*0Sstevel@tonic-gate * Number of currently available pages that cannot be 'locked' 471*0Sstevel@tonic-gate * This is set in init_pages_pp_maximum, and must be initialized 472*0Sstevel@tonic-gate * to zero here to detect an override in /etc/system 473*0Sstevel@tonic-gate */ 474*0Sstevel@tonic-gate pgcnt_t pages_pp_maximum = 0; 475*0Sstevel@tonic-gate 476*0Sstevel@tonic-gate int boothowto; /* boot flags passed to kernel */ 477*0Sstevel@tonic-gate struct var v; /* System Configuration Information */ 478*0Sstevel@tonic-gate 479*0Sstevel@tonic-gate /* 480*0Sstevel@tonic-gate * System Configuration Information 481*0Sstevel@tonic-gate */ 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate #if defined(__sparc) 484*0Sstevel@tonic-gate 485*0Sstevel@tonic-gate /* 486*0Sstevel@tonic-gate * On sparc machines, read hw_serial from the firmware at boot time 487*0Sstevel@tonic-gate * and simply assert Sun is the hardware provider. Hmm. 488*0Sstevel@tonic-gate */ 489*0Sstevel@tonic-gate char architecture[] = "sparcv9"; 490*0Sstevel@tonic-gate char architecture_32[] = "sparc"; 491*0Sstevel@tonic-gate char hw_serial[11]; 492*0Sstevel@tonic-gate char hw_provider[] = "Sun_Microsystems"; 493*0Sstevel@tonic-gate 494*0Sstevel@tonic-gate #elif defined(__i386) 495*0Sstevel@tonic-gate 496*0Sstevel@tonic-gate /* 497*0Sstevel@tonic-gate * On x86 machines, read hw_serial, hw_provider and srpc_domain from 498*0Sstevel@tonic-gate * /etc/bootrc at boot time. 499*0Sstevel@tonic-gate */ 500*0Sstevel@tonic-gate char architecture[] = "i386"; 501*0Sstevel@tonic-gate char architecture_32[] = "i386"; 502*0Sstevel@tonic-gate char hw_serial[11] = "0"; 503*0Sstevel@tonic-gate char hw_provider[SYS_NMLN] = ""; 504*0Sstevel@tonic-gate 505*0Sstevel@tonic-gate #elif defined(__ia64) 506*0Sstevel@tonic-gate 507*0Sstevel@tonic-gate /* 508*0Sstevel@tonic-gate * On ia64 machines, read hw_serial, hw_provider and srpc_domain from 509*0Sstevel@tonic-gate * /etc/bootrc at boot time. 510*0Sstevel@tonic-gate */ 511*0Sstevel@tonic-gate char architecture[] = "ia64"; 512*0Sstevel@tonic-gate char architecture_32[] = "i386"; 513*0Sstevel@tonic-gate char hw_serial[11] = "0"; 514*0Sstevel@tonic-gate char hw_provider[SYS_NMLN] = ""; 515*0Sstevel@tonic-gate 516*0Sstevel@tonic-gate #elif defined(__amd64) 517*0Sstevel@tonic-gate 518*0Sstevel@tonic-gate /* 519*0Sstevel@tonic-gate * On amd64 machines, read hw_serial, hw_provider and srpc_domain from 520*0Sstevel@tonic-gate * /etc/bootrc at boot time. 521*0Sstevel@tonic-gate */ 522*0Sstevel@tonic-gate char architecture[] = "amd64"; 523*0Sstevel@tonic-gate char architecture_32[] = "i386"; 524*0Sstevel@tonic-gate char hw_serial[11] = "0"; 525*0Sstevel@tonic-gate char hw_provider[SYS_NMLN] = ""; 526*0Sstevel@tonic-gate 527*0Sstevel@tonic-gate #else 528*0Sstevel@tonic-gate #error "unknown processor architecture" 529*0Sstevel@tonic-gate #endif 530*0Sstevel@tonic-gate 531*0Sstevel@tonic-gate char srpc_domain[SYS_NMLN] = ""; 532*0Sstevel@tonic-gate char platform[SYS_NMLN] = ""; /* read from the devinfo root node */ 533*0Sstevel@tonic-gate 534*0Sstevel@tonic-gate /* Initialize isa_list */ 535*0Sstevel@tonic-gate char *isa_list = architecture; 536*0Sstevel@tonic-gate 537*0Sstevel@tonic-gate static pgcnt_t original_physmem = 0; 538*0Sstevel@tonic-gate 539*0Sstevel@tonic-gate #define MIN_DEFAULT_MAXUSERS 8u 540*0Sstevel@tonic-gate #define MAX_DEFAULT_MAXUSERS 2048u 541*0Sstevel@tonic-gate #define MAX_MAXUSERS 4096u 542*0Sstevel@tonic-gate 543*0Sstevel@tonic-gate void 544*0Sstevel@tonic-gate param_preset(void) 545*0Sstevel@tonic-gate { 546*0Sstevel@tonic-gate original_physmem = physmem; 547*0Sstevel@tonic-gate } 548*0Sstevel@tonic-gate 549*0Sstevel@tonic-gate void 550*0Sstevel@tonic-gate param_calc(int platform_max_nprocs) 551*0Sstevel@tonic-gate { 552*0Sstevel@tonic-gate /* 553*0Sstevel@tonic-gate * Default to about one "user" per megabyte, taking into 554*0Sstevel@tonic-gate * account both physical and virtual constraints. 555*0Sstevel@tonic-gate * Note: 2^20 is a meg; shifting right by (20 - PAGESHIFT) 556*0Sstevel@tonic-gate * converts pages to megs without integer overflow. 557*0Sstevel@tonic-gate */ 558*0Sstevel@tonic-gate if (physmem > original_physmem) { 559*0Sstevel@tonic-gate physmem = original_physmem; 560*0Sstevel@tonic-gate cmn_err(CE_NOTE, "physmem limited to %ld", physmem); 561*0Sstevel@tonic-gate } 562*0Sstevel@tonic-gate if (maxusers == 0) { 563*0Sstevel@tonic-gate pgcnt_t physmegs = physmem >> (20 - PAGESHIFT); 564*0Sstevel@tonic-gate pgcnt_t virtmegs = vmem_size(heap_arena, VMEM_FREE) >> 20; 565*0Sstevel@tonic-gate maxusers = MIN(MAX(MIN(physmegs, virtmegs), 566*0Sstevel@tonic-gate MIN_DEFAULT_MAXUSERS), MAX_DEFAULT_MAXUSERS); 567*0Sstevel@tonic-gate } 568*0Sstevel@tonic-gate if (maxusers > MAX_MAXUSERS) { 569*0Sstevel@tonic-gate maxusers = MAX_MAXUSERS; 570*0Sstevel@tonic-gate cmn_err(CE_NOTE, "maxusers limited to %d", MAX_MAXUSERS); 571*0Sstevel@tonic-gate } 572*0Sstevel@tonic-gate 573*0Sstevel@tonic-gate if (ngroups_max > NGROUPS_MAX_DEFAULT) 574*0Sstevel@tonic-gate cmn_err(CE_WARN, 575*0Sstevel@tonic-gate "ngroups_max of %d > 16, NFS AUTH_SYS will not work properly", 576*0Sstevel@tonic-gate ngroups_max); 577*0Sstevel@tonic-gate 578*0Sstevel@tonic-gate #ifdef DEBUG 579*0Sstevel@tonic-gate /* 580*0Sstevel@tonic-gate * The purpose of maxusers is to prevent memory overcommit. 581*0Sstevel@tonic-gate * DEBUG kernels take more space, so reduce maxusers a bit. 582*0Sstevel@tonic-gate */ 583*0Sstevel@tonic-gate maxusers = (3 * maxusers) / 4; 584*0Sstevel@tonic-gate #endif 585*0Sstevel@tonic-gate 586*0Sstevel@tonic-gate /* 587*0Sstevel@tonic-gate * We need to dynamically change any variables now so that 588*0Sstevel@tonic-gate * the setting of maxusers and pidmax propagate to the other 589*0Sstevel@tonic-gate * variables that are dependent on them. 590*0Sstevel@tonic-gate */ 591*0Sstevel@tonic-gate if (reserved_procs == 0) 592*0Sstevel@tonic-gate reserved_procs = 5; 593*0Sstevel@tonic-gate if (pidmax < reserved_procs || pidmax > MAX_MAXPID) 594*0Sstevel@tonic-gate maxpid = MAX_MAXPID; 595*0Sstevel@tonic-gate else 596*0Sstevel@tonic-gate maxpid = pidmax; 597*0Sstevel@tonic-gate 598*0Sstevel@tonic-gate /* 599*0Sstevel@tonic-gate * This allows platform-dependent code to constrain the maximum 600*0Sstevel@tonic-gate * number of processes allowed in case there are e.g. VM limitations 601*0Sstevel@tonic-gate * with how many contexts are available. 602*0Sstevel@tonic-gate */ 603*0Sstevel@tonic-gate if (max_nprocs == 0) 604*0Sstevel@tonic-gate max_nprocs = (10 + 16 * maxusers); 605*0Sstevel@tonic-gate if (platform_max_nprocs > 0 && max_nprocs > platform_max_nprocs) 606*0Sstevel@tonic-gate max_nprocs = platform_max_nprocs; 607*0Sstevel@tonic-gate if (max_nprocs > maxpid) 608*0Sstevel@tonic-gate max_nprocs = maxpid; 609*0Sstevel@tonic-gate 610*0Sstevel@tonic-gate if (maxuprc == 0) 611*0Sstevel@tonic-gate maxuprc = (max_nprocs - reserved_procs); 612*0Sstevel@tonic-gate } 613*0Sstevel@tonic-gate 614*0Sstevel@tonic-gate void 615*0Sstevel@tonic-gate param_init(void) 616*0Sstevel@tonic-gate { 617*0Sstevel@tonic-gate /* 618*0Sstevel@tonic-gate * Set each individual element of struct var v to be the 619*0Sstevel@tonic-gate * default value. This is done this way 620*0Sstevel@tonic-gate * so that a user can set the assigned integer value in the 621*0Sstevel@tonic-gate * /etc/system file *IF* tuning is needed. 622*0Sstevel@tonic-gate */ 623*0Sstevel@tonic-gate v.v_proc = max_nprocs; /* v_proc - max # of processes system wide */ 624*0Sstevel@tonic-gate v.v_maxupttl = max_nprocs - reserved_procs; 625*0Sstevel@tonic-gate v.v_maxsyspri = (int)maxclsyspri; /* max global pri for sysclass */ 626*0Sstevel@tonic-gate v.v_maxup = MIN(maxuprc, v.v_maxupttl); /* max procs per user */ 627*0Sstevel@tonic-gate v.v_autoup = autoup; /* v_autoup - delay for delayed writes */ 628*0Sstevel@tonic-gate 629*0Sstevel@tonic-gate /* 630*0Sstevel@tonic-gate * Set each individual element of struct tune to be the 631*0Sstevel@tonic-gate * default value. Each struct element This is done this way 632*0Sstevel@tonic-gate * so that a user can set the assigned integer value in the 633*0Sstevel@tonic-gate * /etc/system file *IF* tuning is needed. 634*0Sstevel@tonic-gate */ 635*0Sstevel@tonic-gate tune.t_gpgslo = tune_t_gpgslo; 636*0Sstevel@tonic-gate tune.t_fsflushr = tune_t_fsflushr; 637*0Sstevel@tonic-gate tune.t_minarmem = tune_t_minarmem; 638*0Sstevel@tonic-gate tune.t_minasmem = tune_t_minasmem; 639*0Sstevel@tonic-gate tune.t_flckrec = tune_t_flckrec; 640*0Sstevel@tonic-gate 641*0Sstevel@tonic-gate /* 642*0Sstevel@tonic-gate * Initialization for file descriptors to correct mistaken settings in 643*0Sstevel@tonic-gate * /etc/system. Initialization of limits performed by resource control 644*0Sstevel@tonic-gate * system. 645*0Sstevel@tonic-gate */ 646*0Sstevel@tonic-gate if (rlim_fd_cur > rlim_fd_max) 647*0Sstevel@tonic-gate rlim_fd_cur = rlim_fd_max; 648*0Sstevel@tonic-gate 649*0Sstevel@tonic-gate /* 650*0Sstevel@tonic-gate * calculations needed if hz was set in /etc/system 651*0Sstevel@tonic-gate */ 652*0Sstevel@tonic-gate if (hires_tick) 653*0Sstevel@tonic-gate hz = hires_hz; 654*0Sstevel@tonic-gate 655*0Sstevel@tonic-gate tick_per_msec = hz / MILLISEC; 656*0Sstevel@tonic-gate msec_per_tick = MILLISEC / hz; 657*0Sstevel@tonic-gate usec_per_tick = MICROSEC / hz; 658*0Sstevel@tonic-gate nsec_per_tick = NANOSEC / hz; 659*0Sstevel@tonic-gate max_hres_adj = nsec_per_tick >> ADJ_SHIFT; 660*0Sstevel@tonic-gate } 661*0Sstevel@tonic-gate 662*0Sstevel@tonic-gate /* 663*0Sstevel@tonic-gate * Validate tuneable parameters following /etc/system processing, 664*0Sstevel@tonic-gate * but prior to param_init(). 665*0Sstevel@tonic-gate */ 666*0Sstevel@tonic-gate void 667*0Sstevel@tonic-gate param_check(void) 668*0Sstevel@tonic-gate { 669*0Sstevel@tonic-gate if (ngroups_max < NGROUPS_UMIN || ngroups_max > NGROUPS_UMAX) 670*0Sstevel@tonic-gate ngroups_max = NGROUPS_MAX_DEFAULT; 671*0Sstevel@tonic-gate 672*0Sstevel@tonic-gate if (autoup <= 0) { 673*0Sstevel@tonic-gate autoup = DEFAULT_AUTOUP; 674*0Sstevel@tonic-gate cmn_err(CE_WARN, "autoup <= 0; defaulting to %d", autoup); 675*0Sstevel@tonic-gate } 676*0Sstevel@tonic-gate 677*0Sstevel@tonic-gate if (tune_t_fsflushr <= 0) { 678*0Sstevel@tonic-gate tune_t_fsflushr = DEFAULT_TUNE_T_FSFLUSHR; 679*0Sstevel@tonic-gate cmn_err(CE_WARN, "tune_t_fsflushr <= 0; defaulting to %d", 680*0Sstevel@tonic-gate tune_t_fsflushr); 681*0Sstevel@tonic-gate } 682*0Sstevel@tonic-gate 683*0Sstevel@tonic-gate if (jump_pid < 0 || jump_pid >= pidmax) { 684*0Sstevel@tonic-gate jump_pid = 0; 685*0Sstevel@tonic-gate cmn_err(CE_WARN, "jump_pid < 0 or >= pidmax; ignored"); 686*0Sstevel@tonic-gate } 687*0Sstevel@tonic-gate 688*0Sstevel@tonic-gate if (snoop_interval < SNOOP_INTERVAL_MIN) { 689*0Sstevel@tonic-gate snoop_interval = SNOOP_INTERVAL_DEFAULT; 690*0Sstevel@tonic-gate cmn_err(CE_WARN, "snoop_interval < minimum (%d); defaulting" 691*0Sstevel@tonic-gate " to %d", SNOOP_INTERVAL_MIN, SNOOP_INTERVAL_DEFAULT); 692*0Sstevel@tonic-gate } 693*0Sstevel@tonic-gate } 694