kern_shutdown.c (242489) | kern_shutdown.c (243515) |
---|---|
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 242489 2012-11-02 18:57:38Z alfred $"); | 38__FBSDID("$FreeBSD: head/sys/kern/kern_shutdown.c 243515 2012-11-25 14:22:08Z 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 = 1; 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 | |
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 --- 410 unchanged lines hidden (view full) --- 547 * Panic is called on unresolvable fatal errors. It prints "panic: mesg", 548 * and then reboots. If we are called twice, then we avoid trying to sync 549 * the disks as this often leads to recursive panics. 550 */ 551void 552panic(const char *fmt, ...) 553{ 554#ifdef SMP | 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 --- 410 unchanged lines hidden (view full) --- 542 * Panic is called on unresolvable fatal errors. It prints "panic: mesg", 543 * and then reboots. If we are called twice, then we avoid trying to sync 544 * the disks as this often leads to recursive panics. 545 */ 546void 547panic(const char *fmt, ...) 548{ 549#ifdef SMP |
555 static volatile u_int panic_cpu = NOCPU; | |
556 cpuset_t other_cpus; 557#endif 558 struct thread *td = curthread; 559 int bootopt, newpanic; 560 va_list ap; 561 static char buf[256]; 562 | 550 cpuset_t other_cpus; 551#endif 552 struct thread *td = curthread; 553 int bootopt, newpanic; 554 va_list ap; 555 static char buf[256]; 556 |
563 if (stop_scheduler_on_panic) 564 spinlock_enter(); 565 else 566 critical_enter(); | 557 spinlock_enter(); |
567 568#ifdef SMP 569 /* | 558 559#ifdef SMP 560 /* |
570 * We don't want multiple CPU's to panic at the same time, so we 571 * use panic_cpu as a simple spinlock. We have to keep checking 572 * panic_cpu if we are spinning in case the panic on the first 573 * CPU is canceled. | 561 * stop_cpus_hard(other_cpus) should prevent multiple CPUs from 562 * concurrently entering panic. Only the winner will proceed 563 * further. |
574 */ | 564 */ |
575 if (panic_cpu != PCPU_GET(cpuid)) 576 while (atomic_cmpset_int(&panic_cpu, NOCPU, 577 PCPU_GET(cpuid)) == 0) 578 while (panic_cpu != NOCPU) 579 ; /* nothing */ 580 581 if (stop_scheduler_on_panic) { 582 if (panicstr == NULL && !kdb_active) { 583 other_cpus = all_cpus; 584 CPU_CLR(PCPU_GET(cpuid), &other_cpus); 585 stop_cpus_hard(other_cpus); 586 } 587 588 /* 589 * We set stop_scheduler here and not in the block above, 590 * because we want to ensure that if panic has been called and 591 * stop_scheduler_on_panic is true, then stop_scheduler will 592 * always be set. Even if panic has been entered from kdb. 593 */ 594 td->td_stopsched = 1; | 565 if (panicstr == NULL && !kdb_active) { 566 other_cpus = all_cpus; 567 CPU_CLR(PCPU_GET(cpuid), &other_cpus); 568 stop_cpus_hard(other_cpus); |
595 } | 569 } |
570 571 /* 572 * We set stop_scheduler here and not in the block above, 573 * because we want to ensure that if panic has been called and 574 * stop_scheduler_on_panic is true, then stop_scheduler will 575 * always be set. Even if panic has been entered from kdb. 576 */ 577 td->td_stopsched = 1; |
|
596#endif 597 598 bootopt = RB_AUTOBOOT; 599 newpanic = 0; 600 if (panicstr) 601 bootopt |= RB_NOSYNC; 602 else { 603 bootopt |= RB_DUMP; --- 23 unchanged lines hidden (view full) --- 627 if (debugger_on_panic) 628 kdb_enter(KDB_WHY_PANIC, "panic"); 629#endif 630 /*thread_lock(td); */ 631 td->td_flags |= TDF_INPANIC; 632 /* thread_unlock(td); */ 633 if (!sync_on_panic) 634 bootopt |= RB_NOSYNC; | 578#endif 579 580 bootopt = RB_AUTOBOOT; 581 newpanic = 0; 582 if (panicstr) 583 bootopt |= RB_NOSYNC; 584 else { 585 bootopt |= RB_DUMP; --- 23 unchanged lines hidden (view full) --- 609 if (debugger_on_panic) 610 kdb_enter(KDB_WHY_PANIC, "panic"); 611#endif 612 /*thread_lock(td); */ 613 td->td_flags |= TDF_INPANIC; 614 /* thread_unlock(td); */ 615 if (!sync_on_panic) 616 bootopt |= RB_NOSYNC; |
635 if (!stop_scheduler_on_panic) 636 critical_exit(); | |
637 kern_reboot(bootopt); 638} 639 640/* 641 * Support for poweroff delay. 642 * 643 * Please note that setting this delay too short might power off your machine 644 * before the write cache on your hard disk has been flushed, leading to --- 132 unchanged lines hidden --- | 617 kern_reboot(bootopt); 618} 619 620/* 621 * Support for poweroff delay. 622 * 623 * Please note that setting this delay too short might power off your machine 624 * before the write cache on your hard disk has been flushed, leading to --- 132 unchanged lines hidden --- |