Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/sommerfeld_i386mp_1]: src/sys/arch/i386 Add options TRAPLOG:



details:   https://anonhg.NetBSD.org/src/rev/5603cbf84ed1
branches:  sommerfeld_i386mp_1
changeset: 482517:5603cbf84ed1
user:      sommerfeld <sommerfeld%NetBSD.org@localhost>
date:      Sat Apr 27 14:39:33 2002 +0000

description:
Add options TRAPLOG:

When enabled, each cpu gets a ring buffer; on every trap entry, we add
an entry to the trap log using the new locore "TLOG" macro.  Somewhat
like a flight recorder, this may give some post-mortem clues as to
what was going on as we were spiralling in...

XXX currently depends on various intel MSR's to record the low order
32 bits of the cycle counter as well as last-branch from and to
addresses.

diffstat:

 sys/arch/i386/i386/cpu.c          |  13 ++++++++++++-
 sys/arch/i386/i386/db_interface.c |  30 +++++++++++++++++-------------
 sys/arch/i386/i386/genassym.cf    |  20 +++++++++++++++++++-
 sys/arch/i386/i386/locore.s       |  39 +++++++++++++++++++++++++++++++++++++--
 sys/arch/i386/i386/machdep.c      |  12 ++++++++++--
 sys/arch/i386/include/cpu.h       |   4 +++-
 sys/arch/i386/include/tlog.h      |  24 ++++++++++++++++++++++++
 7 files changed, 122 insertions(+), 20 deletions(-)

diffs (truncated from 329 to 300 lines):

diff -r b11c0d20624a -r 5603cbf84ed1 sys/arch/i386/i386/cpu.c
--- a/sys/arch/i386/i386/cpu.c  Sat Apr 27 14:32:36 2002 +0000
+++ b/sys/arch/i386/i386/cpu.c  Sat Apr 27 14:39:33 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.1.2.26 2002/02/24 01:58:57 sommerfeld Exp $ */
+/* $NetBSD: cpu.c,v 1.1.2.27 2002/04/27 14:39:33 sommerfeld Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -97,6 +97,7 @@
 #include <machine/segments.h>
 #include <machine/gdt.h>
 #include <machine/mtrr.h>
+#include <machine/tlog.h>
 
 #if NLAPIC > 0
 #include <machine/apicvar.h>
@@ -125,7 +126,13 @@
  * CPU, on uniprocessors).  The CPU info list is initialized to
  * point at it.
  */
+#ifdef TRAPLOG
+struct tlog tlog_primary;
+struct cpu_info cpu_info_primary = { 0, &cpu_info_primary, &tlog_primary };
+#else  /* TRAPLOG */
 struct cpu_info cpu_info_primary = { 0, &cpu_info_primary };
+#endif /* !TRAPLOG */
+
 struct cpu_info *cpu_info_list = &cpu_info_primary;
 
 #ifdef MULTIPROCESSOR
@@ -237,6 +244,10 @@
                        panic("cpu at apic id %d already attached?", cpunum);
                cpu_info[cpunum] = ci;
 #endif
+#ifdef TRAPLOG
+               ci->ci_tlog_base = malloc(sizeof(struct tlog),
+                   M_DEVBUF, M_WAITOK);
+#endif
        } else {
                ci = &cpu_info_primary;
 #if defined(MULTIPROCESSOR)
diff -r b11c0d20624a -r 5603cbf84ed1 sys/arch/i386/i386/db_interface.c
--- a/sys/arch/i386/i386/db_interface.c Sat Apr 27 14:32:36 2002 +0000
+++ b/sys/arch/i386/i386/db_interface.c Sat Apr 27 14:39:33 2002 +0000
@@ -1,27 +1,27 @@
-/*     $NetBSD: db_interface.c,v 1.30.2.8 2001/12/29 23:30:59 sommerfeld Exp $ */
+/*     $NetBSD: db_interface.c,v 1.30.2.9 2002/04/27 14:39:34 sommerfeld Exp $ */
 
-/* 
+/*
  * Mach Operating System
  * Copyright (c) 1991,1990 Carnegie Mellon University
  * All Rights Reserved.
- * 
+ *
  * Permission to use, copy, modify and distribute this software and its
  * documentation is hereby granted, provided that both the copyright
  * notice and this permission notice appear in all copies of the
  * software, derivative works or modified versions, and any portions
  * thereof, and that both notices appear in supporting documentation.
- * 
+ *
  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- * 
+ *
  * Carnegie Mellon requests users of this software to return to
- * 
+ *
  *  Software Distribution Coordinator  or  Software.Distribution%CS.CMU.EDU@localhost
  *  School of Computer Science
  *  Carnegie Mellon University
  *  Pittsburgh PA 15213-3890
- * 
+ *
  * any improvements or extensions that they make and grant Carnegie the
  * rights to redistribute these changes.
  *
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.30.2.8 2001/12/29 23:30:59 sommerfeld Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.30.2.9 2002/04/27 14:39:34 sommerfeld Exp $");
 
 #include "opt_ddb.h"
 
@@ -112,7 +112,7 @@
 {
        int cpu_me = cpu_number();
        int win;
-       
+
        if (ddb_vec == 0)
                return 1;
 
@@ -134,7 +134,7 @@
 
        __cpu_simple_lock(&db_lock);
        ddb_cpu = NOCPU;
-       __cpu_simple_unlock(&db_lock);  
+       __cpu_simple_unlock(&db_lock);
 
        for (i=0; i<I386_MAXPROCS; i++) {
                struct cpu_info *ci = cpu_info[i];
@@ -173,7 +173,7 @@
 {
        int s;
        db_regs_t dbreg;
-       
+
        switch (type) {
        case T_BPTFLT:  /* breakpoint */
        case T_TRCTRAP: /* single_step */
@@ -211,7 +211,7 @@
        ddb_regs.tf_cs &= 0xffff;
        ddb_regs.tf_ds &= 0xffff;
        ddb_regs.tf_es &= 0xffff;
-       ddb_regs.tf_fs &= 0xffff;               
+       ddb_regs.tf_fs &= 0xffff;
        ddb_regs.tf_gs &= 0xffff;
        ddb_regs.tf_ss &= 0xffff;
        s = splhigh();
@@ -247,6 +247,10 @@
                regs->tf_ss     = ddb_regs.tf_ss;
        }
 
+#ifdef TRAPLOG
+       wrmsr(MSR_DEBUGCTLMSR, 0x1);
+#endif
+
        return (1);
 }
 
@@ -311,7 +315,7 @@
                cpu_debug_dump();
                return;
        }
-       
+
        if ((addr < 0) || (addr >= I386_MAXPROCS)) {
                db_printf("%ld: cpu out of range\n", addr);
                return;
diff -r b11c0d20624a -r 5603cbf84ed1 sys/arch/i386/i386/genassym.cf
--- a/sys/arch/i386/i386/genassym.cf    Sat Apr 27 14:32:36 2002 +0000
+++ b/sys/arch/i386/i386/genassym.cf    Sat Apr 27 14:39:33 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.17.10.14 2001/12/29 23:31:00 sommerfeld Exp $
+#      $NetBSD: genassym.cf,v 1.17.10.15 2002/04/27 14:39:34 sommerfeld Exp $
 
 #
 # Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -131,6 +131,8 @@
 include <machine/isa_machdep.h>
 endif
 
+include <machine/tlog.h>
+
 define SRUN                    SRUN
 define SONPROC                 SONPROC
 
@@ -244,10 +246,26 @@
 define CPU_INFO_FEATURES       offsetof(struct cpu_info, ci_feature_flags)
 define CPU_INFO_BRAND          offsetof(struct cpu_info, ci_brand_id)
 
+define CPU_TLOG_OFFSET         offsetof(struct cpu_info, ci_tlog_offset)
+define CPU_TLOG_BASE           offsetof(struct cpu_info, ci_tlog_base)
+
 define CPU_INFO_GDT            offsetof(struct cpu_info, ci_gdt)
 
 define SIZEOF_CPU_INFO         sizeof(struct cpu_info)
 
+define TREC_SP                 offsetof(struct trec, tr_sp)
+define TREC_HPC                offsetof(struct trec, tr_hpc)
+define TREC_IPC                offsetof(struct trec, tr_ipc)
+define TREC_TSC                offsetof(struct trec, tr_tsc)
+define TREC_LBF                offsetof(struct trec, tr_lbf)
+define TREC_LBT                offsetof(struct trec, tr_lbt)
+define TREC_IBF                offsetof(struct trec, tr_ibf)
+define TREC_IBT                offsetof(struct trec, tr_ibt)
+
+define SIZEOF_TREC             sizeof(struct trec)
+define SIZEOF_TLOG             sizeof(struct tlog)
+
+
 if defined(__HAVE_GENERIC_SOFT_INTERRUPTS)
 define __HAVE_GENERIC_SOFT_INTERRUPTS 1
 endif
diff -r b11c0d20624a -r 5603cbf84ed1 sys/arch/i386/i386/locore.s
--- a/sys/arch/i386/i386/locore.s       Sat Apr 27 14:32:36 2002 +0000
+++ b/sys/arch/i386/i386/locore.s       Sat Apr 27 14:39:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.s,v 1.215.2.29 2001/12/29 23:31:01 sommerfeld Exp $     */
+/*     $NetBSD: locore.s,v 1.215.2.30 2002/04/27 14:39:35 sommerfeld Exp $     */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -182,6 +182,40 @@
 #error BIOSEXTMEM option deprecated; use REALEXTMEM only if memory size reported by latest boot block is incorrect
 #endif
 
+#ifndef TRAPLOG
+#define TLOG           /**/
+#else
+/*
+ * Fill in trap record
+ */
+#define TLOG                                           \
+9:                                                     \
+       movl    %fs:CPU_TLOG_OFFSET, %eax;              \
+       movl    %fs:CPU_TLOG_BASE, %ebx;                \
+       addl    $SIZEOF_TREC,%eax;                      \
+       andl    $SIZEOF_TLOG-1,%eax;                    \
+       addl    %eax,%ebx;                              \
+       movl    %eax,%fs:CPU_TLOG_OFFSET;               \
+       movl    %esp,TREC_SP(%ebx);                     \
+       movl    $9b,TREC_HPC(%ebx);                     \
+       movl    TF_EIP(%esp),%eax;                      \
+       movl    %eax,TREC_IPC(%ebx);                    \
+       rdtsc                   ;                       \
+       movl    %eax,TREC_TSC(%ebx);                    \
+       movl    $MSR_LASTBRANCHFROMIP,%ecx;             \
+       rdmsr                   ;                       \
+       movl    %eax,TREC_LBF(%ebx);                    \
+       incl    %ecx            ;                       \
+       rdmsr                   ;                       \
+       movl    %eax,TREC_LBT(%ebx);                    \
+       incl    %ecx            ;                       \
+       rdmsr                   ;                       \
+       movl    %eax,TREC_IBF(%ebx);                    \
+       incl    %ecx            ;                       \
+       rdmsr                   ;                       \
+       movl    %eax,TREC_IBT(%ebx)
+#endif
+               
 /*
  * These are used on interrupt or trap entry or exit.
  */
@@ -202,7 +236,8 @@
        pushl   %gs             ; \
        movl    %eax,%gs        ; \
        movl    $GSEL(GCPU_SEL, SEL_KPL),%eax   ; \
-       movl    %eax,%fs                
+       movl    %eax,%fs        ; \
+       TLOG
 
 #define        INTRFASTEXIT \
        popl    %gs             ; \
diff -r b11c0d20624a -r 5603cbf84ed1 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Sat Apr 27 14:32:36 2002 +0000
+++ b/sys/arch/i386/i386/machdep.c      Sat Apr 27 14:39:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.376.2.33 2002/02/24 00:17:44 sommerfeld Exp $    */
+/*     $NetBSD: machdep.c,v 1.376.2.34 2002/04/27 14:39:36 sommerfeld Exp $    */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.376.2.33 2002/02/24 00:17:44 sommerfeld Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.376.2.34 2002/04/27 14:39:36 sommerfeld Exp $");
 
 #include "opt_cputype.h"
 #include "opt_ddb.h"
@@ -465,6 +465,14 @@
        }
 #endif
 #endif
+
+#ifdef TRAPLOG
+       /*
+        * Enable recording of branch from/to in MSR's
+        */
+       wrmsr(MSR_DEBUGCTLMSR, 0x1);
+#endif
+
        format_bytes(pbuf, sizeof(pbuf), ptoa(physmem));
        printf("total memory = %s\n", pbuf);
 
diff -r b11c0d20624a -r 5603cbf84ed1 sys/arch/i386/include/cpu.h
--- a/sys/arch/i386/include/cpu.h       Sat Apr 27 14:32:36 2002 +0000
+++ b/sys/arch/i386/include/cpu.h       Sat Apr 27 14:39:33 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.59.2.30 2002/02/24 00:17:46 sommerfeld Exp $ */
+/*     $NetBSD: cpu.h,v 1.59.2.31 2002/04/27 14:39:39 sommerfeld Exp $ */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -81,6 +81,8 @@
 struct cpu_info {
        struct device *ci_dev;          /* pointer to our device */
        struct cpu_info *ci_self;       /* self-pointer */
+       void    *ci_tlog_base;          /* Trap log base */
+       int32_t ci_tlog_offset;         /* Trap log current offset */
        struct schedstate_percpu ci_schedstate; /* scheduler state */
        struct cpu_info *ci_next;       /* next cpu */



Home | Main Index | Thread Index | Old Index