Print this page
remove whole-process swapping
Long before Unix supported paging, it used process swapping to reclaim
memory. The code is there and in theory it runs when we get *extremely* low
on memory. In practice, it never runs since the definition of low-on-memory
is antiquated. (XXX: define what antiquated means)
You can check the number of swapout/swapin events with kstats:
$ kstat -p ::vm:swapin ::vm:swapout
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/sun4/os/mlsetup.c
+++ new/usr/src/uts/sun4/os/mlsetup.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/types.h>
27 27 #include <sys/systm.h>
28 28 #include <sys/archsystm.h>
29 29 #include <sys/machsystm.h>
30 30 #include <sys/disp.h>
31 31 #include <sys/autoconf.h>
32 32 #include <sys/promif.h>
33 33 #include <sys/prom_plat.h>
34 34 #include <sys/promimpl.h>
35 35 #include <sys/platform_module.h>
36 36 #include <sys/clock.h>
37 37 #include <sys/pte.h>
38 38 #include <sys/scb.h>
39 39 #include <sys/cpu.h>
40 40 #include <sys/stack.h>
41 41 #include <sys/intreg.h>
42 42 #include <sys/ivintr.h>
43 43 #include <vm/as.h>
44 44 #include <vm/hat_sfmmu.h>
45 45 #include <sys/reboot.h>
46 46 #include <sys/sysmacros.h>
47 47 #include <sys/vtrace.h>
48 48 #include <sys/trap.h>
49 49 #include <sys/machtrap.h>
50 50 #include <sys/privregs.h>
51 51 #include <sys/machpcb.h>
52 52 #include <sys/proc.h>
53 53 #include <sys/cpupart.h>
54 54 #include <sys/pset.h>
55 55 #include <sys/cpu_module.h>
56 56 #include <sys/copyops.h>
57 57 #include <sys/panic.h>
58 58 #include <sys/bootconf.h> /* for bootops */
59 59 #include <sys/pg.h>
60 60 #include <sys/kdi.h>
61 61 #include <sys/fpras.h>
62 62
63 63 #include <sys/prom_debug.h>
64 64 #include <sys/debug.h>
65 65
66 66 #include <sys/sunddi.h>
67 67 #include <sys/lgrp.h>
68 68 #include <sys/traptrace.h>
69 69
70 70 #include <sys/kobj_impl.h>
71 71 #include <sys/kdi_machimpl.h>
72 72
73 73 /*
74 74 * External Routines:
75 75 */
76 76 extern void map_wellknown_devices(void);
77 77 extern void hsvc_setup(void);
78 78 extern void mach_descrip_startup_init(void);
79 79 extern void mach_soft_state_init(void);
80 80
81 81 int dcache_size;
82 82 int dcache_linesize;
83 83 int icache_size;
84 84 int icache_linesize;
85 85 int ecache_size;
86 86 int ecache_alignsize;
87 87 int ecache_associativity;
88 88 int ecache_setsize; /* max possible e$ setsize */
89 89 int cpu_setsize; /* max e$ setsize of configured cpus */
90 90 int dcache_line_mask; /* spitfire only */
91 91 int vac_size; /* cache size in bytes */
92 92 uint_t vac_mask; /* VAC alignment consistency mask */
93 93 int vac_shift; /* log2(vac_size) for ppmapout() */
94 94 int vac = 0; /* virtual address cache type (none == 0) */
95 95
96 96 /*
97 97 * fpRAS. An individual sun4* machine class (or perhaps subclass,
98 98 * eg sun4u/cheetah) must set fpras_implemented to indicate that it implements
99 99 * the fpRAS feature. The feature can be suppressed by setting fpras_disable
100 100 * or the mechanism can be disabled for individual copy operations with
101 101 * fpras_disableids. All these are checked in post_startup() code so
102 102 * fpras_disable and fpras_disableids can be set in /etc/system.
103 103 * If/when fpRAS is implemented on non-sun4 architectures these
104 104 * definitions will need to move up to the common level.
105 105 */
106 106 int fpras_implemented;
107 107 int fpras_disable;
108 108 int fpras_disableids;
109 109
110 110 /*
111 111 * Static Routines:
112 112 */
113 113 static void kern_splr_preprom(void);
114 114 static void kern_splx_postprom(void);
115 115
116 116 /*
117 117 * Setup routine called right before main(). Interposing this function
118 118 * before main() allows us to call it in a machine-independent fashion.
119 119 */
120 120
121 121 void
122 122 mlsetup(struct regs *rp, kfpu_t *fp)
123 123 {
124 124 struct machpcb *mpcb;
125 125
126 126 extern char t0stack[];
127 127 extern struct classfuncs sys_classfuncs;
128 128 extern disp_t cpu0_disp;
129 129 unsigned long long pa;
130 130
131 131 #ifdef TRAPTRACE
132 132 TRAP_TRACE_CTL *ctlp;
133 133 #endif /* TRAPTRACE */
134 134
135 135 /* drop into kmdb on boot -d */
136 136 if (boothowto & RB_DEBUGENTER)
137 137 kmdb_enter();
138 138
139 139 /*
140 140 * initialize cpu_self
↓ open down ↓ |
140 lines elided |
↑ open up ↑ |
141 141 */
142 142 cpu0.cpu_self = &cpu0;
143 143
144 144 /*
145 145 * initialize t0
146 146 */
147 147 t0.t_stk = (caddr_t)rp - REGOFF;
148 148 /* Can't use va_to_pa here - wait until prom_ initialized */
149 149 t0.t_stkbase = t0stack;
150 150 t0.t_pri = maxclsyspri - 3;
151 - t0.t_schedflag = TS_LOAD | TS_DONT_SWAP;
151 + t0.t_schedflag = 0;
152 152 t0.t_procp = &p0;
153 153 t0.t_plockp = &p0lock.pl_lock;
154 154 t0.t_lwp = &lwp0;
155 155 t0.t_forw = &t0;
156 156 t0.t_back = &t0;
157 157 t0.t_next = &t0;
158 158 t0.t_prev = &t0;
159 159 t0.t_cpu = &cpu0; /* loaded by _start */
160 160 t0.t_disp_queue = &cpu0_disp;
161 161 t0.t_bind_cpu = PBIND_NONE;
162 162 t0.t_bind_pset = PS_NONE;
163 163 t0.t_bindflag = (uchar_t)default_binding_mode;
164 164 t0.t_cpupart = &cp_default;
165 165 t0.t_clfuncs = &sys_classfuncs.thread;
166 166 t0.t_copyops = NULL;
167 167 THREAD_ONPROC(&t0, CPU);
168 168
169 169 lwp0.lwp_thread = &t0;
170 170 lwp0.lwp_procp = &p0;
171 171 lwp0.lwp_regs = (void *)rp;
172 172 t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1;
173 173
174 174 mpcb = lwptompcb(&lwp0);
175 175 mpcb->mpcb_fpu = fp;
176 176 mpcb->mpcb_fpu->fpu_q = mpcb->mpcb_fpu_q;
177 177 mpcb->mpcb_thread = &t0;
178 178 lwp0.lwp_fpu = (void *)mpcb->mpcb_fpu;
179 179
180 180 p0.p_exec = NULL;
181 181 p0.p_stat = SRUN;
182 182 p0.p_flag = SSYS;
183 183 p0.p_tlist = &t0;
184 184 p0.p_stksize = 2*PAGESIZE;
185 185 p0.p_stkpageszc = 0;
186 186 p0.p_as = &kas;
187 187 p0.p_lockp = &p0lock;
188 188 p0.p_utraps = NULL;
189 189 p0.p_brkpageszc = 0;
190 190 p0.p_t1_lgrpid = LGRP_NONE;
191 191 p0.p_tr_lgrpid = LGRP_NONE;
192 192 sigorset(&p0.p_ignore, &ignoredefault);
193 193
194 194 CPU->cpu_thread = &t0;
195 195 CPU->cpu_dispthread = &t0;
196 196 bzero(&cpu0_disp, sizeof (disp_t));
197 197 CPU->cpu_disp = &cpu0_disp;
198 198 CPU->cpu_disp->disp_cpu = CPU;
199 199 CPU->cpu_idle_thread = &t0;
200 200 CPU->cpu_flags = CPU_RUNNING;
201 201 CPU->cpu_id = getprocessorid();
202 202 CPU->cpu_dispatch_pri = t0.t_pri;
203 203
204 204 /*
205 205 * Initialize thread/cpu microstate accounting
206 206 */
207 207 init_mstate(&t0, LMS_SYSTEM);
208 208 init_cpu_mstate(CPU, CMS_SYSTEM);
209 209
210 210 /*
211 211 * Initialize lists of available and active CPUs.
212 212 */
213 213 cpu_list_init(CPU);
214 214
215 215 cpu_vm_data_init(CPU);
216 216
217 217 pg_cpu_bootstrap(CPU);
218 218
219 219 (void) prom_set_preprom(kern_splr_preprom);
220 220 (void) prom_set_postprom(kern_splx_postprom);
221 221 PRM_INFO("mlsetup: now ok to call prom_printf");
222 222
223 223 mpcb->mpcb_pa = va_to_pa(t0.t_stk);
224 224
225 225 /*
226 226 * Claim the physical and virtual resources used by panicbuf,
227 227 * then map panicbuf. This operation removes the phys and
228 228 * virtual addresses from the free lists.
229 229 */
230 230 if (prom_claim_virt(PANICBUFSIZE, panicbuf) != panicbuf)
231 231 prom_panic("Can't claim panicbuf virtual address");
232 232
233 233 if (prom_retain("panicbuf", PANICBUFSIZE, MMU_PAGESIZE, &pa) != 0)
234 234 prom_panic("Can't allocate retained panicbuf physical address");
235 235
236 236 if (prom_map_phys(-1, PANICBUFSIZE, panicbuf, pa) != 0)
237 237 prom_panic("Can't map panicbuf");
238 238
239 239 PRM_DEBUG(panicbuf);
240 240 PRM_DEBUG(pa);
241 241
242 242 /*
243 243 * Negotiate hypervisor services, if any
244 244 */
245 245 hsvc_setup();
246 246 mach_soft_state_init();
247 247
248 248 #ifdef TRAPTRACE
249 249 /*
250 250 * initialize the trap trace buffer for the boot cpu
251 251 * XXX todo, dynamically allocate this buffer too
252 252 */
253 253 ctlp = &trap_trace_ctl[CPU->cpu_id];
254 254 ctlp->d.vaddr_base = trap_tr0;
255 255 ctlp->d.offset = ctlp->d.last_offset = 0;
256 256 ctlp->d.limit = TRAP_TSIZE; /* XXX dynamic someday */
257 257 ctlp->d.paddr_base = va_to_pa(trap_tr0);
258 258 #endif /* TRAPTRACE */
259 259
260 260 /*
261 261 * Initialize the Machine Description kernel framework
262 262 */
263 263
264 264 mach_descrip_startup_init();
265 265
266 266 /*
267 267 * initialize HV trap trace buffer for the boot cpu
268 268 */
269 269 mach_htraptrace_setup(CPU->cpu_id);
270 270 mach_htraptrace_configure(CPU->cpu_id);
271 271
272 272 /*
273 273 * lgroup framework initialization. This must be done prior
274 274 * to devices being mapped.
275 275 */
276 276 lgrp_init(LGRP_INIT_STAGE1);
277 277
278 278 cpu_setup();
279 279
280 280 if (boothowto & RB_HALT) {
281 281 prom_printf("unix: kernel halted by -h flag\n");
282 282 prom_enter_mon();
283 283 }
284 284
285 285 setcputype();
286 286 map_wellknown_devices();
287 287 setcpudelay();
288 288 }
289 289
290 290 /*
291 291 * These routines are called immediately before and
292 292 * immediately after calling into the firmware. The
293 293 * firmware is significantly confused by preemption -
294 294 * particularly on MP machines - but also on UP's too.
295 295 */
296 296
297 297 static int saved_spl;
298 298
299 299 static void
300 300 kern_splr_preprom(void)
301 301 {
302 302 saved_spl = spl7();
303 303 }
304 304
305 305 static void
306 306 kern_splx_postprom(void)
307 307 {
308 308 splx(saved_spl);
309 309 }
310 310
311 311
312 312 /*
313 313 * WARNING
314 314 * The code fom here to the end of mlsetup.c runs before krtld has
315 315 * knitted unix and genunix together. It can call routines in unix,
316 316 * but calls into genunix will fail spectacularly. More specifically,
317 317 * calls to prom_*, bop_* and str* will work, everything else is
318 318 * caveat emptor.
319 319 *
320 320 * Also note that while #ifdef sun4u is generally a bad idea, they
321 321 * exist here to concentrate the dangerous code into a single file.
322 322 */
323 323
324 324 static char *
325 325 getcpulist(void)
326 326 {
327 327 pnode_t node;
328 328 /* big enough for OBP_NAME and for a reasonably sized OBP_COMPATIBLE. */
329 329 static char cpubuf[5 * OBP_MAXDRVNAME];
330 330 int nlen, clen, i;
331 331 #ifdef sun4u
332 332 char dname[OBP_MAXDRVNAME];
333 333 #endif
334 334
335 335 node = prom_findnode_bydevtype(prom_rootnode(), OBP_CPU);
336 336 if (node != OBP_NONODE && node != OBP_BADNODE) {
337 337 if ((nlen = prom_getproplen(node, OBP_NAME)) <= 0 ||
338 338 nlen > sizeof (cpubuf) ||
339 339 prom_getprop(node, OBP_NAME, cpubuf) <= 0)
340 340 prom_panic("no name in cpu node");
341 341
342 342 /* nlen includes the terminating null character */
343 343 #ifdef sun4v
344 344 if ((clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0) {
345 345 #else /* sun4u */
346 346 /*
347 347 * For the CMT case, need check the parent "core"
348 348 * node for the compatible property.
349 349 */
350 350 if ((clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0 ||
351 351 ((node = prom_parentnode(node)) != OBP_NONODE &&
352 352 node != OBP_BADNODE &&
353 353 (clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0 &&
354 354 prom_getprop(node, OBP_DEVICETYPE, dname) > 0 &&
355 355 strcmp(dname, "core") == 0)) {
356 356 #endif
357 357 if ((clen + nlen) > sizeof (cpubuf))
358 358 prom_panic("cpu node \"compatible\" too long");
359 359 /* read in compatible, leaving space for ':' */
360 360 if (prom_getprop(node, OBP_COMPATIBLE,
361 361 &cpubuf[nlen]) != clen)
362 362 prom_panic("cpu node \"compatible\" error");
363 363 clen += nlen; /* total length */
364 364 /* convert all null characters to ':' */
365 365 clen--; /* except the final one... */
366 366 for (i = 0; i < clen; i++)
367 367 if (cpubuf[i] == '\0')
368 368 cpubuf[i] = ':';
369 369 }
370 370 #ifdef sun4u
371 371 /*
372 372 * Some PROMs return SUNW,UltraSPARC when they actually have
373 373 * SUNW,UltraSPARC-II cpus. SInce we're now filtering out all
374 374 * SUNW,UltraSPARC systems during the boot phase, we can safely
375 375 * point the auxv CPU value at SUNW,UltraSPARC-II.
376 376 */
377 377 if (strcmp("SUNW,UltraSPARC", cpubuf) == 0)
378 378 (void) strcpy(cpubuf, "SUNW,UltraSPARC-II");
379 379 #endif
380 380 return (cpubuf);
381 381 } else
382 382 return (NULL);
383 383 }
384 384
385 385 /*
386 386 * called immediately from _start to stich the
387 387 * primary modules together
388 388 */
389 389 void
390 390 kobj_start(void *cif)
391 391 {
392 392 Ehdr *ehdr;
393 393 Phdr *phdr;
394 394 uint32_t eadr, padr;
395 395 val_t bootaux[BA_NUM];
396 396 int i;
397 397
398 398 prom_init("kernel", cif);
399 399 bop_init();
400 400 #ifdef DEBUG
401 401 if (bop_getproplen("stop-me") != -1)
402 402 prom_enter_mon();
403 403 #endif
404 404
405 405 if (bop_getprop("elfheader-address", (caddr_t)&eadr) == -1)
406 406 prom_panic("no ELF image");
407 407 ehdr = (Ehdr *)(uintptr_t)eadr;
408 408 for (i = 0; i < BA_NUM; i++)
409 409 bootaux[i].ba_val = NULL;
410 410 bootaux[BA_PHNUM].ba_val = ehdr->e_phnum;
411 411 bootaux[BA_PHENT].ba_val = ehdr->e_phentsize;
412 412 bootaux[BA_LDNAME].ba_ptr = NULL;
413 413
414 414 padr = eadr + ehdr->e_phoff;
415 415 bootaux[BA_PHDR].ba_ptr = (void *)(uintptr_t)padr;
416 416 for (i = 0; i < ehdr->e_phnum; i++) {
417 417 phdr = (Phdr *)((uintptr_t)padr + i * ehdr->e_phentsize);
418 418 if (phdr->p_type == PT_DYNAMIC) {
419 419 bootaux[BA_DYNAMIC].ba_ptr = (void *)phdr->p_vaddr;
420 420 break;
421 421 }
422 422 }
423 423
424 424 bootaux[BA_LPAGESZ].ba_val = MMU_PAGESIZE4M;
425 425 bootaux[BA_PAGESZ].ba_val = MMU_PAGESIZE;
426 426 bootaux[BA_IFLUSH].ba_val = 1;
427 427 bootaux[BA_CPU].ba_ptr = getcpulist();
428 428 bootaux[BA_MMU].ba_ptr = NULL;
429 429
430 430 kobj_init(cif, NULL, bootops, bootaux);
431 431
432 432 /* kernel stitched together; we can now test #pragma's */
433 433 if (&plat_setprop_enter != NULL) {
434 434 prom_setprop_enter = &plat_setprop_enter;
435 435 prom_setprop_exit = &plat_setprop_exit;
436 436 ASSERT(prom_setprop_exit != NULL);
437 437 }
438 438
439 439 }
440 440
441 441 /*
442 442 * Create modpath from kernel name.
443 443 * If we booted:
444 444 * /platform/`uname -i`/kernel/sparcv9/unix
445 445 * or
446 446 * /platform/`uname -m`/kernel/sparcv9/unix
447 447 *
448 448 * then make the modpath:
449 449 * /platform/`uname -i`/kernel /platform/`uname -m`/kernel
450 450 *
451 451 * otherwise, make the modpath the dir the kernel was
452 452 * loaded from, minus any sparcv9 extension
453 453 *
454 454 * note the sparcv9 dir is optional since a unix -> sparcv9/unix
455 455 * symlink is available as a shortcut.
456 456 */
457 457 void
458 458 mach_modpath(char *path, const char *fname)
459 459 {
460 460 char *p;
461 461 int len, compat;
462 462 const char prefix[] = "/platform/";
463 463 char platname[MAXPATHLEN];
464 464 #ifdef sun4u
465 465 char defname[] = "sun4u";
466 466 #else
467 467 char defname[] = "sun4v";
468 468 #endif
469 469 const char suffix[] = "/kernel";
470 470 const char isastr[] = "/sparcv9";
471 471
472 472 /*
473 473 * check for /platform
474 474 */
475 475 p = (char *)fname;
476 476 if (strncmp(p, prefix, sizeof (prefix) - 1) != 0)
477 477 goto nopath;
478 478 p += sizeof (prefix) - 1;
479 479
480 480 /*
481 481 * check for the default name or the platform name.
482 482 * also see if we used the 'compatible' name
483 483 * (platname == default)
484 484 */
485 485 (void) bop_getprop("impl-arch-name", platname);
486 486 compat = strcmp(platname, defname) == 0;
487 487 len = strlen(platname);
488 488 if (strncmp(p, platname, len) == 0)
489 489 p += len;
490 490 else if (strncmp(p, defname, sizeof (defname) - 1) == 0)
491 491 p += sizeof (defname) - 1;
492 492 else
493 493 goto nopath;
494 494
495 495 /*
496 496 * check for /kernel/sparcv9 or just /kernel
497 497 */
498 498 if (strncmp(p, suffix, sizeof (suffix) - 1) != 0)
499 499 goto nopath;
500 500 p += sizeof (suffix) - 1;
501 501 if (strncmp(p, isastr, sizeof (isastr) - 1) == 0)
502 502 p += sizeof (isastr) - 1;
503 503
504 504 /*
505 505 * check we're at the last component
506 506 */
507 507 if (p != strrchr(fname, '/'))
508 508 goto nopath;
509 509
510 510 /*
511 511 * everything is kosher; setup modpath
512 512 */
513 513 (void) strcpy(path, "/platform/");
514 514 (void) strcat(path, platname);
515 515 (void) strcat(path, "/kernel");
516 516 if (!compat) {
517 517 (void) strcat(path, " /platform/");
518 518 (void) strcat(path, defname);
519 519 (void) strcat(path, "/kernel");
520 520 }
521 521 return;
522 522
523 523 nopath:
524 524 /*
525 525 * Construct the directory path from the filename.
526 526 */
527 527 if ((p = strrchr(fname, '/')) == NULL)
528 528 return;
529 529
530 530 while (p > fname && *(p - 1) == '/')
531 531 p--; /* remove trailing '/' characters */
532 532 if (p == fname)
533 533 p++; /* so "/" -is- the modpath in this case */
534 534
535 535 /*
536 536 * Remove optional isa-dependent directory name - the module
537 537 * subsystem will put this back again (!)
538 538 */
539 539 len = p - fname;
540 540 if (len > sizeof (isastr) - 1 &&
541 541 strncmp(&fname[len - (sizeof (isastr) - 1)], isastr,
542 542 sizeof (isastr) - 1) == 0)
543 543 p -= sizeof (isastr) - 1;
544 544 (void) strncpy(path, fname, p - fname);
545 545 }
↓ open down ↓ |
384 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX