kern_shutdown.c (227309) | kern_shutdown.c (228424) |
---|---|
1/*- 2 * Copyright (c) 1986, 1988, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 35 */ 36 37#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1986, 1988, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/sys/kern/kern_shutdown.c 227309 2011-11-07 15:43:11Z ed $"); | 38__FBSDID("$FreeBSD: head/sys/kern/kern_shutdown.c 228424 2011-12-11 21:02:01Z avg $"); |
39 40#include "opt_ddb.h" 41#include "opt_kdb.h" 42#include "opt_panic.h" 43#include "opt_sched.h" 44#include "opt_watchdog.h" 45 46#include <sys/param.h> --- 69 unchanged lines hidden (view full) --- 116TUNABLE_INT("debug.trace_on_panic", &trace_on_panic); 117#endif /* KDB */ 118 119static int sync_on_panic = 0; 120SYSCTL_INT(_kern, OID_AUTO, sync_on_panic, CTLFLAG_RW | CTLFLAG_TUN, 121 &sync_on_panic, 0, "Do a sync before rebooting from a panic"); 122TUNABLE_INT("kern.sync_on_panic", &sync_on_panic); 123 | 39 40#include "opt_ddb.h" 41#include "opt_kdb.h" 42#include "opt_panic.h" 43#include "opt_sched.h" 44#include "opt_watchdog.h" 45 46#include <sys/param.h> --- 69 unchanged lines hidden (view full) --- 116TUNABLE_INT("debug.trace_on_panic", &trace_on_panic); 117#endif /* KDB */ 118 119static int sync_on_panic = 0; 120SYSCTL_INT(_kern, OID_AUTO, sync_on_panic, CTLFLAG_RW | CTLFLAG_TUN, 121 &sync_on_panic, 0, "Do a sync before rebooting from a panic"); 122TUNABLE_INT("kern.sync_on_panic", &sync_on_panic); 123 |
124static int stop_scheduler_on_panic = 0; 125SYSCTL_INT(_kern, OID_AUTO, stop_scheduler_on_panic, CTLFLAG_RW | CTLFLAG_TUN, 126 &stop_scheduler_on_panic, 0, "stop scheduler upon entering panic"); 127TUNABLE_INT("kern.stop_scheduler_on_panic", &stop_scheduler_on_panic); 128 |
|
124static SYSCTL_NODE(_kern, OID_AUTO, shutdown, CTLFLAG_RW, 0, 125 "Shutdown environment"); 126 127#ifndef DIAGNOSTIC 128static int show_busybufs; 129#else 130static int show_busybufs = 1; 131#endif 132SYSCTL_INT(_kern_shutdown, OID_AUTO, show_busybufs, CTLFLAG_RW, 133 &show_busybufs, 0, ""); 134 135/* 136 * Variable panicstr contains argument to first call to panic; used as flag 137 * to indicate that the kernel has already called panic. 138 */ 139const char *panicstr; 140 | 129static SYSCTL_NODE(_kern, OID_AUTO, shutdown, CTLFLAG_RW, 0, 130 "Shutdown environment"); 131 132#ifndef DIAGNOSTIC 133static int show_busybufs; 134#else 135static int show_busybufs = 1; 136#endif 137SYSCTL_INT(_kern_shutdown, OID_AUTO, show_busybufs, CTLFLAG_RW, 138 &show_busybufs, 0, ""); 139 140/* 141 * Variable panicstr contains argument to first call to panic; used as flag 142 * to indicate that the kernel has already called panic. 143 */ 144const char *panicstr; 145 |
146int stop_scheduler; /* system stopped CPUs for panic */ |
|
141int dumping; /* system is dumping */ 142int rebooting; /* system is rebooting */ 143static struct dumperinfo dumper; /* our selected dumper */ 144 145/* Context information for dump-debuggers. */ 146static struct pcb dumppcb; /* Registers. */ 147static lwpid_t dumptid; /* Thread ID. */ 148 --- 140 unchanged lines hidden (view full) --- 289 static int first_buf_printf = 1; 290 291#if defined(SMP) 292 /* 293 * Bind us to CPU 0 so that all shutdown code runs there. Some 294 * systems don't shutdown properly (i.e., ACPI power off) if we 295 * run on another processor. 296 */ | 147int dumping; /* system is dumping */ 148int rebooting; /* system is rebooting */ 149static struct dumperinfo dumper; /* our selected dumper */ 150 151/* Context information for dump-debuggers. */ 152static struct pcb dumppcb; /* Registers. */ 153static lwpid_t dumptid; /* Thread ID. */ 154 --- 140 unchanged lines hidden (view full) --- 295 static int first_buf_printf = 1; 296 297#if defined(SMP) 298 /* 299 * Bind us to CPU 0 so that all shutdown code runs there. Some 300 * systems don't shutdown properly (i.e., ACPI power off) if we 301 * run on another processor. 302 */ |
297 thread_lock(curthread); 298 sched_bind(curthread, 0); 299 thread_unlock(curthread); 300 KASSERT(PCPU_GET(cpuid) == 0, ("%s: not running on cpu 0", __func__)); | 303 if (!SCHEDULER_STOPPED()) { 304 thread_lock(curthread); 305 sched_bind(curthread, 0); 306 thread_unlock(curthread); 307 KASSERT(PCPU_GET(cpuid) == 0, ("boot: not running on cpu 0")); 308 } |
301#endif 302 /* We're in the process of rebooting. */ 303 rebooting = 1; 304 305 /* collect extra flags that shutdown_nice might have set */ 306 howto |= shutdown_howto; 307 308 /* We are out of the debugger now. */ --- 233 unchanged lines hidden (view full) --- 542 * and then reboots. If we are called twice, then we avoid trying to sync 543 * the disks as this often leads to recursive panics. 544 */ 545void 546panic(const char *fmt, ...) 547{ 548#ifdef SMP 549 static volatile u_int panic_cpu = NOCPU; | 309#endif 310 /* We're in the process of rebooting. */ 311 rebooting = 1; 312 313 /* collect extra flags that shutdown_nice might have set */ 314 howto |= shutdown_howto; 315 316 /* We are out of the debugger now. */ --- 233 unchanged lines hidden (view full) --- 550 * and then reboots. If we are called twice, then we avoid trying to sync 551 * the disks as this often leads to recursive panics. 552 */ 553void 554panic(const char *fmt, ...) 555{ 556#ifdef SMP 557 static volatile u_int panic_cpu = NOCPU; |
558 cpuset_t other_cpus; |
|
550#endif 551 struct thread *td = curthread; 552 int bootopt, newpanic; 553 va_list ap; 554 static char buf[256]; 555 | 559#endif 560 struct thread *td = curthread; 561 int bootopt, newpanic; 562 va_list ap; 563 static char buf[256]; 564 |
556 critical_enter(); | 565 if (stop_scheduler_on_panic) 566 spinlock_enter(); 567 else 568 critical_enter(); 569 |
557#ifdef SMP 558 /* 559 * We don't want multiple CPU's to panic at the same time, so we 560 * use panic_cpu as a simple spinlock. We have to keep checking 561 * panic_cpu if we are spinning in case the panic on the first 562 * CPU is canceled. 563 */ 564 if (panic_cpu != PCPU_GET(cpuid)) 565 while (atomic_cmpset_int(&panic_cpu, NOCPU, 566 PCPU_GET(cpuid)) == 0) 567 while (panic_cpu != NOCPU) 568 ; /* nothing */ | 570#ifdef SMP 571 /* 572 * We don't want multiple CPU's to panic at the same time, so we 573 * use panic_cpu as a simple spinlock. We have to keep checking 574 * panic_cpu if we are spinning in case the panic on the first 575 * CPU is canceled. 576 */ 577 if (panic_cpu != PCPU_GET(cpuid)) 578 while (atomic_cmpset_int(&panic_cpu, NOCPU, 579 PCPU_GET(cpuid)) == 0) 580 while (panic_cpu != NOCPU) 581 ; /* nothing */ |
582 583 if (stop_scheduler_on_panic) { 584 if (panicstr == NULL && !kdb_active) { 585 other_cpus = all_cpus; 586 CPU_CLR(PCPU_GET(cpuid), &other_cpus); 587 stop_cpus_hard(other_cpus); 588 } 589 590 /* 591 * We set stop_scheduler here and not in the block above, 592 * because we want to ensure that if panic has been called and 593 * stop_scheduler_on_panic is true, then stop_scheduler will 594 * always be set. Even if panic has been entered from kdb. 595 */ 596 stop_scheduler = 1; 597 } |
|
569#endif 570 571 bootopt = RB_AUTOBOOT; 572 newpanic = 0; 573 if (panicstr) 574 bootopt |= RB_NOSYNC; 575 else { 576 bootopt |= RB_DUMP; --- 22 unchanged lines hidden (view full) --- 599 if (debugger_on_panic) 600 kdb_enter(KDB_WHY_PANIC, "panic"); 601#endif 602 /*thread_lock(td); */ 603 td->td_flags |= TDF_INPANIC; 604 /* thread_unlock(td); */ 605 if (!sync_on_panic) 606 bootopt |= RB_NOSYNC; | 598#endif 599 600 bootopt = RB_AUTOBOOT; 601 newpanic = 0; 602 if (panicstr) 603 bootopt |= RB_NOSYNC; 604 else { 605 bootopt |= RB_DUMP; --- 22 unchanged lines hidden (view full) --- 628 if (debugger_on_panic) 629 kdb_enter(KDB_WHY_PANIC, "panic"); 630#endif 631 /*thread_lock(td); */ 632 td->td_flags |= TDF_INPANIC; 633 /* thread_unlock(td); */ 634 if (!sync_on_panic) 635 bootopt |= RB_NOSYNC; |
607 critical_exit(); | 636 if (!stop_scheduler_on_panic) 637 critical_exit(); |
608 kern_reboot(bootopt); 609} 610 611/* 612 * Support for poweroff delay. 613 * 614 * Please note that setting this delay too short might power off your machine 615 * before the write cache on your hard disk has been flushed, leading to --- 121 unchanged lines hidden --- | 638 kern_reboot(bootopt); 639} 640 641/* 642 * Support for poweroff delay. 643 * 644 * Please note that setting this delay too short might power off your machine 645 * before the write cache on your hard disk has been flushed, leading to --- 121 unchanged lines hidden --- |