Deleted Added
full compact
kern_shutdown.c (243515) kern_shutdown.c (243980)
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 243515 2012-11-25 14:22:08Z avg $");
38__FBSDID("$FreeBSD: head/sys/kern/kern_shutdown.c 243980 2012-12-07 08:25:08Z alfred $");
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>
47#include <sys/systm.h>
48#include <sys/bio.h>
49#include <sys/buf.h>
50#include <sys/conf.h>
51#include <sys/cons.h>
52#include <sys/eventhandler.h>
53#include <sys/jail.h>
54#include <sys/kdb.h>
55#include <sys/kernel.h>
56#include <sys/kerneldump.h>
57#include <sys/kthread.h>
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>
47#include <sys/systm.h>
48#include <sys/bio.h>
49#include <sys/buf.h>
50#include <sys/conf.h>
51#include <sys/cons.h>
52#include <sys/eventhandler.h>
53#include <sys/jail.h>
54#include <sys/kdb.h>
55#include <sys/kernel.h>
56#include <sys/kerneldump.h>
57#include <sys/kthread.h>
58#include <sys/ktr.h>
58#include <sys/malloc.h>
59#include <sys/mount.h>
60#include <sys/priv.h>
61#include <sys/proc.h>
62#include <sys/reboot.h>
63#include <sys/resourcevar.h>
64#include <sys/sched.h>
65#include <sys/smp.h>

--- 79 unchanged lines hidden (view full) ---

145/* Context information for dump-debuggers. */
146static struct pcb dumppcb; /* Registers. */
147lwpid_t dumptid; /* Thread ID. */
148
149static void poweroff_wait(void *, int);
150static void shutdown_halt(void *junk, int howto);
151static void shutdown_panic(void *junk, int howto);
152static void shutdown_reset(void *junk, int howto);
59#include <sys/malloc.h>
60#include <sys/mount.h>
61#include <sys/priv.h>
62#include <sys/proc.h>
63#include <sys/reboot.h>
64#include <sys/resourcevar.h>
65#include <sys/sched.h>
66#include <sys/smp.h>

--- 79 unchanged lines hidden (view full) ---

146/* Context information for dump-debuggers. */
147static struct pcb dumppcb; /* Registers. */
148lwpid_t dumptid; /* Thread ID. */
149
150static void poweroff_wait(void *, int);
151static void shutdown_halt(void *junk, int howto);
152static void shutdown_panic(void *junk, int howto);
153static void shutdown_reset(void *junk, int howto);
154static void vpanic(const char *fmt, va_list ap) __dead2;
153
154/* register various local shutdown events */
155static void
156shutdown_conf(void *unused)
157{
158
159 EVENTHANDLER_REGISTER(shutdown_final, poweroff_wait, NULL,
160 SHUTDOWN_PRI_FIRST);

--- 372 unchanged lines hidden (view full) ---

533 spinlock_enter();
534#endif
535
536 /* cpu_boot(howto); */ /* doesn't do anything at the moment */
537 cpu_reset();
538 /* NOTREACHED */ /* assuming reset worked */
539}
540
155
156/* register various local shutdown events */
157static void
158shutdown_conf(void *unused)
159{
160
161 EVENTHANDLER_REGISTER(shutdown_final, poweroff_wait, NULL,
162 SHUTDOWN_PRI_FIRST);

--- 372 unchanged lines hidden (view full) ---

535 spinlock_enter();
536#endif
537
538 /* cpu_boot(howto); */ /* doesn't do anything at the moment */
539 cpu_reset();
540 /* NOTREACHED */ /* assuming reset worked */
541}
542
543#ifdef INVARIANTS
544static int kassert_warn_only = 0;
545#ifdef KTR
546static int kassert_do_ktr = 0;
547#endif
548static int kassert_do_log = 1;
549static int kassert_log_pps_limit = 4;
550static int kassert_log_mute_at = 0;
551static int kassert_log_panic_at = 0;
552static int kassert_warnings = 0;
553
554SYSCTL_NODE(_debug, OID_AUTO, kassert, CTLFLAG_RW, NULL, "kassert options");
555
556SYSCTL_INT(_debug_kassert, OID_AUTO, warn_only, CTLFLAG_RW | CTLFLAG_TUN,
557 &kassert_warn_only, 0,
558 "KASSERT triggers a panic (1) or just a warning (0)");
559TUNABLE_INT("debug.kassert.warn_only", &kassert_warn_only);
560
561#ifdef KTR
562SYSCTL_UINT(_debug_kassert, OID_AUTO, do_ktr, CTLFLAG_RW | CTLFLAG_TUN,
563 &kassert_do_ktr, 0,
564 "KASSERT does a KTR, set this to the KTRMASK you want");
565TUNABLE_INT("debug.kassert.do_ktr", &kassert_do_ktr);
566#endif
567
568SYSCTL_INT(_debug_kassert, OID_AUTO, do_log, CTLFLAG_RW | CTLFLAG_TUN,
569 &kassert_do_log, 0, "KASSERT triggers a panic (1) or just a warning (0)");
570TUNABLE_INT("debug.kassert.do_log", &kassert_do_log);
571
572SYSCTL_INT(_debug_kassert, OID_AUTO, warnings, CTLFLAG_RW | CTLFLAG_TUN,
573 &kassert_warnings, 0, "number of KASSERTs that have been triggered");
574TUNABLE_INT("debug.kassert.warnings", &kassert_warnings);
575
576SYSCTL_INT(_debug_kassert, OID_AUTO, log_panic_at, CTLFLAG_RW | CTLFLAG_TUN,
577 &kassert_log_panic_at, 0, "max number of KASSERTS before we will panic");
578TUNABLE_INT("debug.kassert.log_panic_at", &kassert_log_panic_at);
579
580SYSCTL_INT(_debug_kassert, OID_AUTO, log_pps_limit, CTLFLAG_RW | CTLFLAG_TUN,
581 &kassert_log_pps_limit, 0, "limit number of log messages per second");
582TUNABLE_INT("debug.kassert.log_pps_limit", &kassert_log_pps_limit);
583
584SYSCTL_INT(_debug_kassert, OID_AUTO, log_mute_at, CTLFLAG_RW | CTLFLAG_TUN,
585 &kassert_log_mute_at, 0, "max number of KASSERTS to log");
586TUNABLE_INT("debug.kassert.log_mute_at", &kassert_log_mute_at);
587
588static int kassert_sysctl_kassert(SYSCTL_HANDLER_ARGS);
589
590SYSCTL_PROC(_debug_kassert, OID_AUTO, kassert,
591 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE, NULL, 0,
592 kassert_sysctl_kassert, "I", "set to trigger a test kassert");
593
594static int
595kassert_sysctl_kassert(SYSCTL_HANDLER_ARGS)
596{
597 int error, i;
598
599 error = sysctl_wire_old_buffer(req, sizeof(int));
600 if (error == 0) {
601 i = 0;
602 error = sysctl_handle_int(oidp, &i, 0, req);
603 }
604 if (error != 0 || req->newptr == NULL)
605 return (error);
606 KASSERT(0, ("kassert_sysctl_kassert triggered kassert %d", i));
607 return (0);
608}
609
541/*
610/*
611 * Called by KASSERT, this decides if we will panic
612 * or if we will log via printf and/or ktr.
613 */
614void
615kassert_panic(const char *fmt, ...)
616{
617 static char buf[256];
618 va_list ap;
619
620 va_start(ap, fmt);
621 (void)vsnprintf(buf, sizeof(buf), fmt, ap);
622 va_end(ap);
623
624 /*
625 * panic if we're not just warning, or if we've exceeded
626 * kassert_log_panic_at warnings.
627 */
628 if (!kassert_warn_only ||
629 (kassert_log_panic_at > 0 &&
630 kassert_warnings >= kassert_log_panic_at)) {
631 va_start(ap, fmt);
632 vpanic(fmt, ap);
633 /* NORETURN */
634 }
635#ifdef KTR
636 if (kassert_do_ktr)
637 CTR0(ktr_mask, buf);
638#endif /* KTR */
639 /*
640 * log if we've not yet met the mute limit.
641 */
642 if (kassert_do_log &&
643 (kassert_log_mute_at == 0 ||
644 kassert_warnings < kassert_log_mute_at)) {
645 static struct timeval lasterr;
646 static int curerr;
647
648 if (ppsratecheck(&lasterr, &curerr, kassert_log_pps_limit)) {
649 printf("KASSERT failed: %s\n", buf);
650 kdb_backtrace();
651 }
652 }
653 atomic_add_int(&kassert_warnings, 1);
654}
655#endif
656
657/*
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{
658 * Panic is called on unresolvable fatal errors. It prints "panic: mesg",
659 * and then reboots. If we are called twice, then we avoid trying to sync
660 * the disks as this often leads to recursive panics.
661 */
662void
663panic(const char *fmt, ...)
664{
665 va_list ap;
666
667 va_start(ap, fmt);
668 vpanic(fmt, ap);
669}
670
671static void
672vpanic(const char *fmt, va_list ap)
673{
549#ifdef SMP
550 cpuset_t other_cpus;
551#endif
552 struct thread *td = curthread;
553 int bootopt, newpanic;
674#ifdef SMP
675 cpuset_t other_cpus;
676#endif
677 struct thread *td = curthread;
678 int bootopt, newpanic;
554 va_list ap;
555 static char buf[256];
556
557 spinlock_enter();
558
559#ifdef SMP
560 /*
561 * stop_cpus_hard(other_cpus) should prevent multiple CPUs from
562 * concurrently entering panic. Only the winner will proceed

--- 19 unchanged lines hidden (view full) ---

582 if (panicstr)
583 bootopt |= RB_NOSYNC;
584 else {
585 bootopt |= RB_DUMP;
586 panicstr = fmt;
587 newpanic = 1;
588 }
589
679 static char buf[256];
680
681 spinlock_enter();
682
683#ifdef SMP
684 /*
685 * stop_cpus_hard(other_cpus) should prevent multiple CPUs from
686 * concurrently entering panic. Only the winner will proceed

--- 19 unchanged lines hidden (view full) ---

706 if (panicstr)
707 bootopt |= RB_NOSYNC;
708 else {
709 bootopt |= RB_DUMP;
710 panicstr = fmt;
711 newpanic = 1;
712 }
713
590 va_start(ap, fmt);
591 if (newpanic) {
592 (void)vsnprintf(buf, sizeof(buf), fmt, ap);
593 panicstr = buf;
594 cngrab();
595 printf("panic: %s\n", buf);
596 } else {
597 printf("panic: ");
598 vprintf(fmt, ap);
599 printf("\n");
600 }
714 if (newpanic) {
715 (void)vsnprintf(buf, sizeof(buf), fmt, ap);
716 panicstr = buf;
717 cngrab();
718 printf("panic: %s\n", buf);
719 } else {
720 printf("panic: ");
721 vprintf(fmt, ap);
722 printf("\n");
723 }
601 va_end(ap);
602#ifdef SMP
603 printf("cpuid = %d\n", PCPU_GET(cpuid));
604#endif
605
606#ifdef KDB
607 if (newpanic && trace_on_panic)
608 kdb_backtrace();
609 if (debugger_on_panic)

--- 147 unchanged lines hidden ---
724#ifdef SMP
725 printf("cpuid = %d\n", PCPU_GET(cpuid));
726#endif
727
728#ifdef KDB
729 if (newpanic && trace_on_panic)
730 kdb_backtrace();
731 if (debugger_on_panic)

--- 147 unchanged lines hidden ---