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