1/* 2 * Copyright (c) 2000 3 * John Baldwin <jhb@FreeBSD.org>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the author nor the names of any co-contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY JOHN BALDWIN AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL JOHN BALDWIN OR THE VOICES IN HIS HEAD 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGE. 28 *
| 1/* 2 * Copyright (c) 2000 3 * John Baldwin <jhb@FreeBSD.org>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the author nor the names of any co-contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY JOHN BALDWIN AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL JOHN BALDWIN OR THE VOICES IN HIS HEAD 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGE. 28 *
|
49#ifndef KTR_MASK 50#define KTR_MASK (KTR_GEN) 51#endif 52 53#ifndef KTR_CPUMASK 54#define KTR_CPUMASK (~0) 55#endif 56 57#ifdef SMP 58#define KTR_CPU cpuid 59#else 60#define KTR_CPU 0 61#endif 62 63#ifdef KTR_EXTEND 64/* 65 * This variable is used only by gdb to work out what fields are in 66 * ktr_entry. 67 */ 68int ktr_extend = 1; 69SYSCTL_INT(_debug, OID_AUTO, ktr_extend, CTLFLAG_RD, &ktr_extend, 1, ""); 70#else 71int ktr_extend = 0; 72SYSCTL_INT(_debug, OID_AUTO, ktr_extend, CTLFLAG_RD, &ktr_extend, 0, ""); 73#endif /* KTR_EXTEND */ 74 75int ktr_cpumask = KTR_CPUMASK; 76SYSCTL_INT(_debug, OID_AUTO, ktr_cpumask, CTLFLAG_RW, &ktr_cpumask, KTR_CPUMASK, ""); 77 78int ktr_mask = KTR_MASK; 79SYSCTL_INT(_debug, OID_AUTO, ktr_mask, CTLFLAG_RW, &ktr_mask, KTR_MASK, ""); 80 81int ktr_entries = KTR_ENTRIES; 82SYSCTL_INT(_debug, OID_AUTO, ktr_entries, CTLFLAG_RD, &ktr_entries, KTR_ENTRIES, ""); 83 84volatile int ktr_idx = 0; 85struct ktr_entry ktr_buf[KTR_ENTRIES]; 86 87#ifdef KTR_VERBOSE 88int ktr_verbose = 1; 89#else 90int ktr_verbose = 0; 91#endif 92SYSCTL_INT(_debug, OID_AUTO, ktr_verbose, CTLFLAG_RW, &ktr_verbose, 0, ""); 93 94#ifdef KTR 95#ifdef KTR_EXTEND 96void 97ktr_tracepoint(u_int mask, char *filename, u_int line, char *format, ...) 98#else 99void 100ktr_tracepoint(u_int mask, char *format, u_long arg1, u_long arg2, u_long arg3, 101 u_long arg4, u_long arg5) 102#endif 103{ 104 struct ktr_entry *entry; 105 int newindex, saveindex, saveintr; 106#ifdef KTR_EXTEND 107 va_list ap; 108#endif 109 110 if (panicstr) 111 return; 112 if ((ktr_mask & mask) == 0) 113 return; 114#ifdef KTR_EXTEND 115 if (((1 << KTR_CPU) & ktr_cpumask) == 0) 116 return; 117#endif 118 saveintr = save_intr(); 119 disable_intr(); 120 do { 121 saveindex = ktr_idx; 122 newindex = (saveindex + 1) & (KTR_ENTRIES - 1); 123 } while (atomic_cmpset_rel_int(&ktr_idx, saveindex, newindex) == 0); 124 entry = &ktr_buf[saveindex]; 125 restore_intr(saveintr); 126 getnanotime(&entry->ktr_tv); 127#ifdef KTR_EXTEND 128 strncpy(entry->ktr_filename, filename, KTRFILENAMESIZE - 1); 129 entry->ktr_filename[KTRFILENAMESIZE - 1] = '\0'; 130 entry->ktr_line = line; 131 entry->ktr_cpu = KTR_CPU; 132 va_start(ap, format); 133 vsnprintf(entry->ktr_desc, KTRDESCSIZE, format, ap); 134 va_end(ap); 135 if (ktr_verbose) { 136#ifdef SMP 137 printf("cpu%d ", entry->ktr_cpu); 138#endif 139 if (ktr_verbose > 1) 140 printf("%s.%d\t", entry->ktr_filename, entry->ktr_line); 141 va_start(ap, format); 142 vprintf(format, ap); 143 printf("\n"); 144 va_end(ap); 145 } 146#else 147 entry->ktr_desc = format; 148 entry->ktr_parm1 = arg1; 149 entry->ktr_parm2 = arg2; 150 entry->ktr_parm3 = arg3; 151 entry->ktr_parm4 = arg4; 152 entry->ktr_parm5 = arg5; 153#endif 154}
| 54#ifndef KTR_MASK 55#define KTR_MASK (KTR_GEN) 56#endif 57 58#ifndef KTR_CPUMASK 59#define KTR_CPUMASK (~0) 60#endif 61 62#ifdef SMP 63#define KTR_CPU cpuid 64#else 65#define KTR_CPU 0 66#endif 67 68#ifdef KTR_EXTEND 69/* 70 * This variable is used only by gdb to work out what fields are in 71 * ktr_entry. 72 */ 73int ktr_extend = 1; 74SYSCTL_INT(_debug, OID_AUTO, ktr_extend, CTLFLAG_RD, &ktr_extend, 1, ""); 75#else 76int ktr_extend = 0; 77SYSCTL_INT(_debug, OID_AUTO, ktr_extend, CTLFLAG_RD, &ktr_extend, 0, ""); 78#endif /* KTR_EXTEND */ 79 80int ktr_cpumask = KTR_CPUMASK; 81SYSCTL_INT(_debug, OID_AUTO, ktr_cpumask, CTLFLAG_RW, &ktr_cpumask, KTR_CPUMASK, ""); 82 83int ktr_mask = KTR_MASK; 84SYSCTL_INT(_debug, OID_AUTO, ktr_mask, CTLFLAG_RW, &ktr_mask, KTR_MASK, ""); 85 86int ktr_entries = KTR_ENTRIES; 87SYSCTL_INT(_debug, OID_AUTO, ktr_entries, CTLFLAG_RD, &ktr_entries, KTR_ENTRIES, ""); 88 89volatile int ktr_idx = 0; 90struct ktr_entry ktr_buf[KTR_ENTRIES]; 91 92#ifdef KTR_VERBOSE 93int ktr_verbose = 1; 94#else 95int ktr_verbose = 0; 96#endif 97SYSCTL_INT(_debug, OID_AUTO, ktr_verbose, CTLFLAG_RW, &ktr_verbose, 0, ""); 98 99#ifdef KTR 100#ifdef KTR_EXTEND 101void 102ktr_tracepoint(u_int mask, char *filename, u_int line, char *format, ...) 103#else 104void 105ktr_tracepoint(u_int mask, char *format, u_long arg1, u_long arg2, u_long arg3, 106 u_long arg4, u_long arg5) 107#endif 108{ 109 struct ktr_entry *entry; 110 int newindex, saveindex, saveintr; 111#ifdef KTR_EXTEND 112 va_list ap; 113#endif 114 115 if (panicstr) 116 return; 117 if ((ktr_mask & mask) == 0) 118 return; 119#ifdef KTR_EXTEND 120 if (((1 << KTR_CPU) & ktr_cpumask) == 0) 121 return; 122#endif 123 saveintr = save_intr(); 124 disable_intr(); 125 do { 126 saveindex = ktr_idx; 127 newindex = (saveindex + 1) & (KTR_ENTRIES - 1); 128 } while (atomic_cmpset_rel_int(&ktr_idx, saveindex, newindex) == 0); 129 entry = &ktr_buf[saveindex]; 130 restore_intr(saveintr); 131 getnanotime(&entry->ktr_tv); 132#ifdef KTR_EXTEND 133 strncpy(entry->ktr_filename, filename, KTRFILENAMESIZE - 1); 134 entry->ktr_filename[KTRFILENAMESIZE - 1] = '\0'; 135 entry->ktr_line = line; 136 entry->ktr_cpu = KTR_CPU; 137 va_start(ap, format); 138 vsnprintf(entry->ktr_desc, KTRDESCSIZE, format, ap); 139 va_end(ap); 140 if (ktr_verbose) { 141#ifdef SMP 142 printf("cpu%d ", entry->ktr_cpu); 143#endif 144 if (ktr_verbose > 1) 145 printf("%s.%d\t", entry->ktr_filename, entry->ktr_line); 146 va_start(ap, format); 147 vprintf(format, ap); 148 printf("\n"); 149 va_end(ap); 150 } 151#else 152 entry->ktr_desc = format; 153 entry->ktr_parm1 = arg1; 154 entry->ktr_parm2 = arg2; 155 entry->ktr_parm3 = arg3; 156 entry->ktr_parm4 = arg4; 157 entry->ktr_parm5 = arg5; 158#endif 159}
|