Subject: ktr from freebsd
To: None <tech-kern@netbsd.org>
From: Andrey Petrov <petrov@netbsd.org>
List: tech-kern
Date: 04/22/2004 01:36:06
--PNTmBPCT7hxwcZjr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Folks,
I needed low-level memory buffer tracing and I took freebsd's kern_ktr.c
for that. I stripped 'bells and whistls' like sysctl control and saving in
file, because I don't think they are really needed and it would take more
time for porting. Main reason was replace sparc64 traptrace with something
more generic and flexible, uvm_history seems closest by functionality but too tied to
uvm and somewhat too heavy for .S codes. So I ended up with freebsd's
kern_ktr and that's light-weight, simple and convinient interface.
It has mi and md parts, buffer itself, ktr_traptrace and db_show_ktr in mi (and
for mi, and C code) and CATR assembler macro for md.
Now, I use it in sparc64 and did support only for sparc64, and put those
traces only in sparc64. I'd like to go on with it further and commit it
eventually (sooner better). The problem is that it's not likely that I will
add support for other platforms or put traces in common parts in short time frame
but the feature is optionable so it wouldn't hurt to have it in sys and kern
directories. It's possible to put everything in sparc64 directory as an
alternative approach but no,
I'm attaching main pieces of kern_ktr here for your review. I'd like to
commit after some clean-up. Opinions? objections?
Andrey
--PNTmBPCT7hxwcZjr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="ktr.patch"
Index: conf/files
===================================================================
RCS file: /cvsroot/src/sys/conf/files,v
retrieving revision 1.665
diff -u -p -r1.665 files
--- conf/files 9 Apr 2004 19:01:38 -0000 1.665
+++ conf/files 22 Apr 2004 08:13:43 -0000
@@ -19,6 +19,8 @@ defflag KMEMSTATS
defflag KCONT
defflag KTRACE
defflag SYSTRACE
+defflag KTR
+defparam opt_ktr.h KTR_COMPILE
defparam MAXUPRC
defparam RTC_OFFSET
defparam DEFCORENAME
@@ -1145,6 +1147,7 @@ file kern/kern_fork.c
file kern/kern_kcont.c kcont
file kern/kern_kthread.c
file kern/kern_ktrace.c
+file kern/kern_ktr.c ktr
file kern/kern_ksyms.c ksyms | ddb | lkm needs-flag
file kern/kern_lkm.c lkm
file kern/kern_lock.c
--- /dev/null 2004-04-22 01:15:28.000000000 -0700
+++ sys/ktr.h 2004-04-18 12:49:57.000000000 -0700
@@ -0,0 +1,157 @@
+/* $NetBSD:$ */
+/*-
+ * Copyright (c) 1996 Berkeley Software Design, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Berkeley Software Design Inc's name may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from BSDI $Id: ktr.h,v 1.10.2.7 2000/03/16 21:44:42 cp Exp $
+ * $FreeBSD: src/sys/sys/ktr.h,v 1.21 2003/03/11 20:07:22 jhb Exp $
+ */
+
+/*
+ * Wraparound kernel trace buffer support.
+ */
+
+#ifndef _SYS_KTR_H_
+#define _SYS_KTR_H_
+
+/*
+ * Hack around due to egcs-1.1.2 not knowing what __func__ is.
+ */
+#ifdef __GNUC__
+#if __GNUC__ == 2 && __GNUC_MINOR__ == 91 /* egcs 1.1.2 */
+#define __func__ __FUNCTION__
+#endif
+#endif
+
+/*
+ * Trace classes
+ */
+#define KTR_GEN 0x00000001 /* General (TR) */
+#define KTR_NET 0x00000002 /* Network */
+#define KTR_DEV 0x00000004 /* Device driver */
+#define KTR_LOCK 0x00000008 /* MP locking */
+#define KTR_SMP 0x00000010 /* MP general */
+#define KTR_FS 0x00000020 /* Filesystem */
+#define KTR_PMAP 0x00000040 /* Pmap tracing */
+#define KTR_MALLOC 0x00000080 /* Malloc tracing */
+#define KTR_TRAP 0x00000100 /* Trap processing */
+#define KTR_INTR 0x00000200 /* Interrupt tracing */
+#define KTR_SIG 0x00000400 /* Signal processing */
+#define KTR_CLK 0x00000800 /* hardclock verbose */
+#define KTR_PROC 0x00001000 /* Process scheduling */
+#define KTR_SYSC 0x00002000 /* System call */
+#define KTR_INIT 0x00004000 /* System initialization */
+#define KTR_KGDB 0x00008000 /* Trace kgdb internals */
+#define KTR_IO 0x00010000 /* Upper I/O */
+#define KTR_EVH 0x00020000 /* Eventhandler */
+#define KTR_NFS 0x00040000 /* The obvious */
+#define KTR_VOP 0x00080000 /* The obvious */
+#define KTR_VM 0x00100000 /* The virtual memory system */
+#define KTR_WITNESS 0x00200000
+#define KTR_RUNQ 0x00400000 /* Run queue */
+#define KTR_CONTENTION 0x00800000 /* Lock contention */
+#define KTR_ALL 0x00ffffff
+
+/*
+ * Trace classes which can be assigned to particular use at compile time
+ * These must remain in high 22 as some assembly code counts on it
+ */
+#define KTR_CT1 0x01000000
+#define KTR_CT2 0x02000000
+#define KTR_CT3 0x04000000
+#define KTR_CT4 0x08000000
+#define KTR_CT5 0x10000000
+#define KTR_CT6 0x20000000
+#define KTR_CT7 0x40000000
+#define KTR_CT8 0x80000000
+
+/* Trace classes to compile in */
+#ifndef KTR_COMPILE
+#define KTR_COMPILE (KTR_GEN)
+#endif
+
+/* Number of ktr_entry */
+#define KTR_ENTRIES 2048
+
+/*
+ * Version number for ktr_entry struct. Increment this when you break binary
+ * compatibility.
+ */
+#define KTR_VERSION 1
+
+#define KTR_PARMS 6
+
+#ifndef _LOCORE
+
+struct ktr_entry {
+ u_int64_t ktr_timestamp;
+ int ktr_cpu;
+ int ktr_line;
+ const char *ktr_file;
+ const char *ktr_desc;
+ u_long ktr_parms[KTR_PARMS];
+};
+
+extern int ktr_cpumask;
+extern int ktr_mask;
+extern int ktr_entries;
+extern int ktr_verbose;
+
+extern volatile int ktr_idx;
+extern struct ktr_entry ktr_buf[];
+
+#endif /* !_LOCORE */
+#ifdef KTR
+
+void ktr_tracepoint(u_int mask, const char *file, int line,
+ const char *format, u_long arg1, u_long arg2, u_long arg3,
+ u_long arg4, u_long arg5, u_long arg6);
+
+#define CTR6(m, format, p1, p2, p3, p4, p5, p6) do { \
+ if (KTR_COMPILE & (m)) \
+ ktr_tracepoint((m), __FILE__, __LINE__, format, \
+ (u_long)(p1), (u_long)(p2), (u_long)(p3), \
+ (u_long)(p4), (u_long)(p5), (u_long)(p6)); \
+ } while(0)
+#define CTR0(m, format) CTR6(m, format, 0, 0, 0, 0, 0, 0)
+#define CTR1(m, format, p1) CTR6(m, format, p1, 0, 0, 0, 0, 0)
+#define CTR2(m, format, p1, p2) CTR6(m, format, p1, p2, 0, 0, 0, 0)
+#define CTR3(m, format, p1, p2, p3) CTR6(m, format, p1, p2, p3, 0, 0, 0)
+#define CTR4(m, format, p1, p2, p3, p4) CTR6(m, format, p1, p2, p3, p4, 0, 0)
+#define CTR5(m, format, p1, p2, p3, p4, p5) CTR6(m, format, p1, p2, p3, p4, p5, 0)
+#else /* KTR */
+#undef KTR_COMPILE
+#define KTR_COMPILE 0
+#define CTR0(m, d)
+#define CTR1(m, d, p1)
+#define CTR2(m, d, p1, p2)
+#define CTR3(m, d, p1, p2, p3)
+#define CTR4(m, d, p1, p2, p3, p4)
+#define CTR5(m, d, p1, p2, p3, p4, p5)
+#define CTR6(m, d, p1, p2, p3, p4, p5, p6)
+#endif /* KTR */
+
+#endif /* !_SYS_KTR_H_ */
--- /dev/null 2004-04-22 01:15:28.000000000 -0700
+++ kern/kern_ktr.c 2004-04-20 14:54:08.000000000 -0700
@@ -0,0 +1,216 @@
+/* $NetBSD:$ */
+/*-
+ * Copyright (c) 2000 John Baldwin <jhb@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * This module holds the global variables used by KTR and the ktr_tracepoint()
+ * function that does the actual tracing.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD:$");
+
+#include "opt_ddb.h"
+#include "opt_ktr.h"
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/ktr.h>
+#include <sys/proc.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
+#include <sys/time.h>
+
+#include <machine/cpu.h>
+#ifdef __sparc64__
+#include <machine/ktr.h>
+#endif
+
+#ifdef DDB
+#include <machine/db_machdep.h>
+#include <ddb/db_interface.h>
+#include <ddb/db_command.h>
+#include <ddb/db_output.h>
+#endif
+
+#ifndef KTR_ENTRIES
+#define KTR_ENTRIES 1024
+#endif
+
+#ifndef KTR_MASK
+#define KTR_MASK (KTR_GEN)
+#endif
+
+#ifndef KTR_CPUMASK
+#define KTR_CPUMASK (~0)
+#endif
+
+#ifndef KTR_TIME
+#define KTR_TIME 0 /* XXX get_cyclecount() */
+#endif
+
+#ifndef KTR_CPU
+#define KTR_CPU PCPU_GET(cpuid)
+#endif
+
+int ktr_cpumask = KTR_CPUMASK;
+int ktr_mask = KTR_MASK;
+int ktr_entries = KTR_ENTRIES;
+int ktr_version = KTR_VERSION;
+
+volatile int ktr_idx = 0;
+struct ktr_entry ktr_buf[KTR_ENTRIES];
+
+#ifdef KTR_VERBOSE
+int ktr_verbose = KTR_VERBOSE;
+#endif
+
+void
+ktr_tracepoint(u_int mask, const char *file, int line, const char *format,
+ u_long arg1, u_long arg2, u_long arg3, u_long arg4, u_long arg5,
+ u_long arg6)
+{
+ struct ktr_entry *entry;
+ int newindex, saveindex;
+ int cpu;
+
+ if (panicstr)
+ return;
+
+ if ((ktr_mask & mask) == 0)
+ return;
+ cpu = KTR_CPU;
+ if (((1 << cpu) & ktr_cpumask) == 0)
+ return;
+
+ do {
+ saveindex = ktr_idx;
+ newindex = (saveindex + 1) & (KTR_ENTRIES - 1);
+ ktr_idx = newindex;
+ } while ( 0 /* atomic_cmpset_rel_int(&ktr_idx, saveindex, newindex) == 0*/);
+
+ entry = &ktr_buf[saveindex];
+
+ entry->ktr_timestamp = KTR_TIME;
+ entry->ktr_cpu = cpu;
+ if (file != NULL)
+ while (strncmp(file, "../", 3) == 0)
+ file += 3;
+ entry->ktr_file = file;
+ entry->ktr_line = line;
+#ifdef KTR_VERBOSE
+ if (ktr_verbose) {
+#ifdef MULTIPROCESSOR
+ printf("cpu%d ", cpu);
+#endif
+ if (ktr_verbose > 1) {
+ printf("%s.%d\t", entry->ktr_file,
+ entry->ktr_line);
+ }
+ printf(format, arg1, arg2, arg3, arg4, arg5, arg6);
+ printf("\n");
+ }
+#endif
+ entry->ktr_desc = format;
+ entry->ktr_parms[0] = arg1;
+ entry->ktr_parms[1] = arg2;
+ entry->ktr_parms[2] = arg3;
+ entry->ktr_parms[3] = arg4;
+ entry->ktr_parms[4] = arg5;
+ entry->ktr_parms[5] = arg6;
+}
+
+#ifdef DDB
+
+struct tstate {
+ int cur;
+ int first;
+};
+static struct tstate tstate;
+static int db_ktr_verbose;
+static int db_mach_vtrace(void);
+
+
+void
+db_show_ktr(addr, have_addr, count, modif)
+ db_expr_t addr;
+ int have_addr;
+ db_expr_t count;
+ char *modif;
+{
+
+ tstate.cur = (ktr_idx - 1) & (KTR_ENTRIES - 1);
+ tstate.first = -1;
+ if (strcmp(modif, "v") == 0)
+ db_ktr_verbose = 1;
+ else
+ db_ktr_verbose = 0;
+
+ while (db_mach_vtrace() != 0);
+}
+
+static int
+db_mach_vtrace(void)
+{
+ struct ktr_entry *kp;
+
+ if (tstate.cur == tstate.first) {
+ db_printf("--- End of trace buffer ---\n");
+ return (0);
+ }
+ kp = &ktr_buf[tstate.cur];
+
+ /* Skip over unused entries. */
+ if (kp->ktr_desc == NULL) {
+ db_printf("--- End of trace buffer ---\n");
+ return (0);
+ }
+ db_printf("%d: ", tstate.cur);
+#ifdef MULTIPROCESSOR
+ db_printf("cpu%d ", kp->ktr_cpu);
+#endif
+ if (db_ktr_verbose) {
+ db_printf("%10.10lld %s.%d\t", (long long)kp->ktr_timestamp,
+ kp->ktr_file, kp->ktr_line);
+ }
+ db_printf(kp->ktr_desc, kp->ktr_parms[0], kp->ktr_parms[1],
+ kp->ktr_parms[2], kp->ktr_parms[3], kp->ktr_parms[4],
+ kp->ktr_parms[5]);
+ db_printf("\n");
+
+ if (tstate.first == -1)
+ tstate.first = tstate.cur;
+
+ if (--tstate.cur < 0)
+ tstate.cur = KTR_ENTRIES - 1;
+
+ return (1);
+}
+
+#endif /* DDB */
--- /dev/null 2004-04-22 01:15:28.000000000 -0700
+++ arch/sparc64/include/upa.h 2004-04-17 19:41:26.000000000 -0700
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/sparc64/include/upa.h,v 1.4 2002/04/02 17:38:52 tmm Exp $
+ */
+
+#ifndef _MACHINE_UPA_H_
+#define _MACHINE_UPA_H_
+
+#define UPA_MEMSTART 0x1c000000000UL
+#define UPA_MEMEND 0x1ffffffffffUL
+
+#define UPA_CR_MID_SHIFT (17)
+#define UPA_CR_MID_SIZE (5)
+#define UPA_CR_MID_MASK \
+ (((1 << UPA_CR_MID_SIZE) - 1) << UPA_CR_MID_SHIFT)
+
+#define UPA_CR_GET_MID(cr) ((cr & UPA_CR_MID_MASK) >> UPA_CR_MID_SHIFT)
+
+#ifdef _LOCORE
+
+#define UPA_GET_MID(r1) \
+ ldxa [%g0] ASI_MID_REG, r1 ; \
+ srlx r1, UPA_CR_MID_SHIFT, r1 ; \
+ and r1, (1 << UPA_CR_MID_SIZE) - 1, r1
+
+#endif
+
+#endif /* _MACHINE_UPA_H_ */
--- /dev/null 2004-04-22 01:15:28.000000000 -0700
+++ arch/sparc64/include/ktr.h 2004-04-17 20:04:24.000000000 -0700
@@ -0,0 +1,98 @@
+/* $NetBSD:$ */
+/*-
+ * Copyright (c) 1996 Berkeley Software Design, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Berkeley Software Design Inc's name may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from BSDI $Id: ktr.h,v 1.10.2.7 2000/03/16 21:44:42 cp Exp $
+ * $FreeBSD: src/sys/sparc64/include/ktr.h,v 1.5 2003/04/26 17:00:10 obrien Exp $
+ */
+
+#ifndef _MACHINE_KTR_H_
+#define _MACHINE_KTR_H_
+
+#include <machine/upa.h>
+#include <machine/ctlreg.h>
+
+#ifndef _LOCORE
+
+#define KTR_CPU UPA_CR_GET_MID(ldxa(0, ASI_MID_REG))
+
+#else
+
+#define SET(name, r1, r2) \
+ set name, r2
+
+#define AND(var, mask, r1, r2) \
+ SET(var, r2, r1) ; \
+ lduw [r1], r2 ; \
+ and r2, mask, r1
+
+#define TEST(var, mask, r1, r2, l1) \
+ AND(var, mask, r1, r2) ; \
+ brz r1, l1/* ## */f ; \
+ nop
+
+/*
+ * XXX could really use another register...
+ */
+#define ATR(desc, r1, r2, r3, l1, l2) \
+ .sect .rodata ; \
+l1 : .asciz desc ; \
+ .text ; \
+ SET(ktr_idx, r2, r1) ; \
+ lduw [r1], r2 ; \
+l2 : add r2, 1, r3 ; \
+ set KTR_ENTRIES - 1, r1 ; \
+ and r3, r1, r3 ; \
+ set ktr_idx, r1 ; \
+ casa [r1] ASI_NUCLEUS, r2, r3 ; \
+ cmp r2, r3 ; \
+ bne %icc, l2/* ## */b ; \
+ mov r3, r2 ; \
+ SET(ktr_buf, r3, r1) ; \
+ mulx r2, KTR_SIZEOF, r2 ; \
+ add r1, r2, r1 ; \
+ rd %tick, r2 ; \
+ stx r2, [r1 + KTR_TIMESTAMP] ; \
+ UPA_GET_MID(r2) ; \
+ stw r2, [r1 + KTR_CPU] ; \
+ stw %g0, [r1 + KTR_LINE] ; \
+ stx %g0, [r1 + KTR_FILE] ; \
+ SET(l1/* ## */b, r3, r2) ; \
+ stx r2, [r1 + KTR_DESC]
+
+#define CATR(mask, desc, r1, r2, r3, l1, l2, l3) \
+ set mask, r1 ; \
+ TEST(ktr_mask, r1, r2, r2, l3) ; \
+ UPA_GET_MID(r1) ; \
+ mov 1, r2 ; \
+ sllx r2, r1, r1 ; \
+ TEST(ktr_cpumask, r1, r2, r3, l3) ; \
+ ATR(desc, r1, r2, r3, l1, l2)
+
+#endif /* _LOCORE */
+
+#endif /* !_MACHINE_KTR_H_ */
Index: ddb/db_command.c
===================================================================
RCS file: /cvsroot/src/sys/ddb/db_command.c,v
retrieving revision 1.75
diff -u -p -r1.75 db_command.c
--- ddb/db_command.c 24 Mar 2004 15:34:52 -0000 1.75
+++ ddb/db_command.c 22 Apr 2004 08:23:45 -0000
@@ -36,6 +36,7 @@ __KERNEL_RCSID(0, "$NetBSD: db_command.c
#include "opt_ddb.h"
#include "opt_kgdb.h"
#include "opt_inet.h"
+#include "opt_ktr.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -150,6 +151,9 @@ static const struct db_command db_show_c
{ "uvmexp", db_uvmexp_print_cmd, 0, NULL },
{ "vnode", db_vnode_print_cmd, 0, NULL },
{ "watches", db_listwatch_cmd, 0, NULL },
+#if defined(KTR)
+ { "ktr", db_show_ktr, 0, NULL },
+#endif
{ NULL, NULL, 0, NULL }
};
Index: ddb/db_interface.h
===================================================================
RCS file: /cvsroot/src/sys/ddb/db_interface.h,v
retrieving revision 1.12
diff -u -p -r1.12 db_interface.h
--- ddb/db_interface.h 20 Sep 2003 03:02:03 -0000 1.12
+++ ddb/db_interface.h 22 Apr 2004 08:23:45 -0000
@@ -69,6 +69,9 @@ void db_dmesg(db_expr_t, int, db_expr_t
/* netinet/if_arp.c */
void db_show_arptab(db_expr_t, int, db_expr_t, char *);
+/* kern/kern_ktr.c */
+void db_show_ktr(db_expr_t, int, db_expr_t, char *);
+
/*
* This is used in several places to determine which printf format
* string is appropriate for displaying a variable of type db_expr_t.
--PNTmBPCT7hxwcZjr--