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