xref: /dragonfly/sys/kern/kern_ktr.c (revision 81c11cd3)
1 /*
2  * Copyright (c) 2005 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 /*
35  * The following copyright applies to the DDB command code:
36  *
37  * Copyright (c) 2000 John Baldwin <jhb@FreeBSD.org>
38  * All rights reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  * 1. Redistributions of source code must retain the above copyright
44  *    notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  *    notice, this list of conditions and the following disclaimer in the
47  *    documentation and/or other materials provided with the distribution.
48  * 3. Neither the name of the author nor the names of any co-contributors
49  *    may be used to endorse or promote products derived from this software
50  *    without specific prior written permission.
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62  * SUCH DAMAGE.
63  */
64 /*
65  * $DragonFly: src/sys/kern/kern_ktr.c,v 1.23 2008/02/12 23:33:23 corecode Exp $
66  */
67 /*
68  * Kernel tracepoint facility.
69  */
70 
71 #include "opt_ddb.h"
72 #include "opt_ktr.h"
73 
74 #include <sys/param.h>
75 #include <sys/cons.h>
76 #include <sys/kernel.h>
77 #include <sys/libkern.h>
78 #include <sys/proc.h>
79 #include <sys/sysctl.h>
80 #include <sys/ktr.h>
81 #include <sys/systm.h>
82 #include <sys/time.h>
83 #include <sys/malloc.h>
84 #include <sys/spinlock.h>
85 #include <sys/thread2.h>
86 #include <sys/spinlock2.h>
87 #include <sys/ctype.h>
88 
89 #include <machine/cpu.h>
90 #include <machine/cpufunc.h>
91 #include <machine/specialreg.h>
92 #include <machine/md_var.h>
93 
94 #include <ddb/ddb.h>
95 
96 #ifndef KTR_ENTRIES
97 #define	KTR_ENTRIES		2048
98 #endif
99 #define KTR_ENTRIES_MASK	(KTR_ENTRIES - 1)
100 
101 /*
102  * test logging support.  When ktr_testlogcnt is non-zero each synchronization
103  * interrupt will issue six back-to-back ktr logging messages on cpu 0
104  * so the user can determine KTR logging overheads.
105  */
106 #if !defined(KTR_TESTLOG)
107 #define KTR_TESTLOG	KTR_ALL
108 #endif
109 KTR_INFO_MASTER(testlog);
110 #if KTR_TESTLOG
111 KTR_INFO(KTR_TESTLOG, testlog, test1, 0, "test1", sizeof(void *) * 4);
112 KTR_INFO(KTR_TESTLOG, testlog, test2, 1, "test2", sizeof(void *) * 4);
113 KTR_INFO(KTR_TESTLOG, testlog, test3, 2, "test3", sizeof(void *) * 4);
114 KTR_INFO(KTR_TESTLOG, testlog, test4, 3, "test4", 0);
115 KTR_INFO(KTR_TESTLOG, testlog, test5, 4, "test5", 0);
116 KTR_INFO(KTR_TESTLOG, testlog, test6, 5, "test6", 0);
117 #ifdef SMP
118 KTR_INFO(KTR_TESTLOG, testlog, pingpong, 6, "pingpong", 0);
119 KTR_INFO(KTR_TESTLOG, testlog, pipeline, 7, "pipeline", 0);
120 KTR_INFO(KTR_TESTLOG, testlog, crit_beg, 8, "crit_beg", 0);
121 KTR_INFO(KTR_TESTLOG, testlog, crit_end, 9, "crit_end", 0);
122 KTR_INFO(KTR_TESTLOG, testlog, spin_beg, 10, "spin_beg", 0);
123 KTR_INFO(KTR_TESTLOG, testlog, spin_end, 11, "spin_end", 0);
124 #endif
125 #define logtest(name)	KTR_LOG(testlog_ ## name, 0, 0, 0, 0)
126 #define logtest_noargs(name)	KTR_LOG(testlog_ ## name)
127 #endif
128 
129 MALLOC_DEFINE(M_KTR, "ktr", "ktr buffers");
130 
131 SYSCTL_NODE(_debug, OID_AUTO, ktr, CTLFLAG_RW, 0, "ktr");
132 
133 int		ktr_entries = KTR_ENTRIES;
134 SYSCTL_INT(_debug_ktr, OID_AUTO, entries, CTLFLAG_RD, &ktr_entries, 0, "");
135 
136 int		ktr_version = KTR_VERSION;
137 SYSCTL_INT(_debug_ktr, OID_AUTO, version, CTLFLAG_RD, &ktr_version, 0, "");
138 
139 static int	ktr_stacktrace = 1;
140 SYSCTL_INT(_debug_ktr, OID_AUTO, stacktrace, CTLFLAG_RD, &ktr_stacktrace, 0, "");
141 
142 static int	ktr_resynchronize = 0;
143 SYSCTL_INT(_debug_ktr, OID_AUTO, resynchronize, CTLFLAG_RW, &ktr_resynchronize, 0, "");
144 
145 #if KTR_TESTLOG
146 static int	ktr_testlogcnt = 0;
147 SYSCTL_INT(_debug_ktr, OID_AUTO, testlogcnt, CTLFLAG_RW, &ktr_testlogcnt, 0, "");
148 static int	ktr_testipicnt = 0;
149 #ifdef SMP
150 static int	ktr_testipicnt_remainder;
151 #endif
152 SYSCTL_INT(_debug_ktr, OID_AUTO, testipicnt, CTLFLAG_RW, &ktr_testipicnt, 0, "");
153 static int	ktr_testcritcnt = 0;
154 SYSCTL_INT(_debug_ktr, OID_AUTO, testcritcnt, CTLFLAG_RW, &ktr_testcritcnt, 0, "");
155 static int	ktr_testspincnt = 0;
156 SYSCTL_INT(_debug_ktr, OID_AUTO, testspincnt, CTLFLAG_RW, &ktr_testspincnt, 0, "");
157 #endif
158 
159 /*
160  * Give cpu0 a static buffer so the tracepoint facility can be used during
161  * early boot (note however that we still use a critical section, XXX).
162  */
163 static struct	ktr_entry ktr_buf0[KTR_ENTRIES];
164 
165 __cachealign struct ktr_cpu ktr_cpu[MAXCPU] = {
166 	{ .core.ktr_buf = &ktr_buf0[0] }
167 };
168 
169 #ifdef SMP
170 static int	ktr_sync_state = 0;
171 static int	ktr_sync_count;
172 static int64_t	ktr_sync_tsc;
173 #endif
174 struct callout	ktr_resync_callout;
175 
176 #ifdef KTR_VERBOSE
177 int	ktr_verbose = KTR_VERBOSE;
178 TUNABLE_INT("debug.ktr.verbose", &ktr_verbose);
179 SYSCTL_INT(_debug_ktr, OID_AUTO, verbose, CTLFLAG_RW, &ktr_verbose, 0, "");
180 #endif
181 
182 static void ktr_resync_callback(void *dummy __unused);
183 
184 extern int64_t tsc_offsets[];
185 
186 static void
187 ktr_sysinit(void *dummy)
188 {
189 	struct ktr_cpu_core *kcpu;
190 	int i;
191 
192 	for(i = 1; i < ncpus; ++i) {
193 		kcpu = &ktr_cpu[i].core;
194 		kcpu->ktr_buf = kmalloc(KTR_ENTRIES * sizeof(struct ktr_entry),
195 					M_KTR, M_WAITOK | M_ZERO);
196 	}
197 	callout_init(&ktr_resync_callout);
198 	callout_reset(&ktr_resync_callout, hz / 10, ktr_resync_callback, NULL);
199 }
200 SYSINIT(ktr_sysinit, SI_BOOT2_KLD, SI_ORDER_ANY, ktr_sysinit, NULL);
201 
202 /*
203  * Try to resynchronize the TSC's for all cpus.  This is really, really nasty.
204  * We have to send an IPIQ message to all remote cpus, wait until they
205  * get into their IPIQ processing code loop, then do an even stricter hard
206  * loop to get the cpus as close to synchronized as we can to get the most
207  * accurate reading.
208  *
209  * This callback occurs on cpu0.
210  */
211 #if KTR_TESTLOG
212 #ifdef SMP
213 static void ktr_pingpong_remote(void *dummy);
214 static void ktr_pipeline_remote(void *dummy);
215 #endif
216 #endif
217 
218 #if defined(SMP) && defined(_RDTSC_SUPPORTED_)
219 
220 static void ktr_resync_remote(void *dummy);
221 extern cpumask_t smp_active_mask;
222 
223 /*
224  * We use a callout callback instead of a systimer because we cannot afford
225  * to preempt anyone to do this, or we might deadlock a spin-lock or
226  * serializer between two cpus.
227  */
228 static
229 void
230 ktr_resync_callback(void *dummy __unused)
231 {
232 	int count;
233 
234 	KKASSERT(mycpu->gd_cpuid == 0);
235 
236 #if KTR_TESTLOG
237 	/*
238 	 * Test logging
239 	 */
240 	if (ktr_testlogcnt) {
241 		--ktr_testlogcnt;
242 		cpu_disable_intr();
243 		logtest(test1);
244 		logtest(test2);
245 		logtest(test3);
246 		logtest_noargs(test4);
247 		logtest_noargs(test5);
248 		logtest_noargs(test6);
249 		cpu_enable_intr();
250 	}
251 
252 	/*
253 	 * Test IPI messaging
254 	 */
255 	if (ktr_testipicnt && ktr_testipicnt_remainder == 0 && ncpus > 1) {
256 		ktr_testipicnt_remainder = ktr_testipicnt;
257 		ktr_testipicnt = 0;
258 		lwkt_send_ipiq_bycpu(1, ktr_pingpong_remote, NULL);
259 	}
260 
261 	/*
262 	 * Test critical sections
263 	 */
264 	if (ktr_testcritcnt) {
265 		crit_enter();
266 		crit_exit();
267 		logtest_noargs(crit_beg);
268 		for (count = ktr_testcritcnt; count; --count) {
269 			crit_enter();
270 			crit_exit();
271 		}
272 		logtest_noargs(crit_end);
273 		ktr_testcritcnt = 0;
274 	}
275 
276 	/*
277 	 * Test spinlock sections
278 	 */
279 	if (ktr_testspincnt) {
280 		struct spinlock spin;
281 
282 		spin_init(&spin);
283 		spin_lock(&spin);
284 		spin_unlock(&spin);
285 		logtest_noargs(spin_beg);
286 		for (count = ktr_testspincnt; count; --count) {
287 			spin_lock(&spin);
288 			spin_unlock(&spin);
289 		}
290 		logtest_noargs(spin_end);
291 		ktr_testspincnt = 0;
292 	}
293 #endif
294 
295 	/*
296 	 * Resynchronize the TSC
297 	 */
298 	if (ktr_resynchronize == 0)
299 		goto done;
300 	if ((cpu_feature & CPUID_TSC) == 0)
301 		return;
302 
303 	/*
304 	 * Send the synchronizing IPI and wait for all cpus to get into
305 	 * their spin loop.  We must process incoming IPIs while waiting
306 	 * to avoid a deadlock.
307 	 */
308 	crit_enter();
309 	ktr_sync_count = 0;
310 	ktr_sync_state = 1;
311 	ktr_sync_tsc = rdtsc();
312 	count = lwkt_send_ipiq_mask(mycpu->gd_other_cpus & smp_active_mask,
313 				    (ipifunc1_t)ktr_resync_remote, NULL);
314 	DEBUG_PUSH_INFO("ktrsync1");
315 	while (ktr_sync_count != count)
316 		lwkt_process_ipiq();
317 	DEBUG_POP_INFO();
318 
319 	/*
320 	 * Continuously update the TSC for cpu 0 while waiting for all other
321 	 * cpus to finish stage 2.
322 	 */
323 	cpu_disable_intr();
324 	ktr_sync_tsc = rdtsc();
325 	cpu_sfence();
326 	ktr_sync_state = 2;
327 	cpu_sfence();
328 	while (ktr_sync_count != 0) {
329 		ktr_sync_tsc = rdtsc();
330 		cpu_lfence();
331 		cpu_nop();
332 	}
333 	cpu_enable_intr();
334 	crit_exit();
335 	ktr_sync_state = 0;
336 done:
337 	callout_reset(&ktr_resync_callout, hz / 10, ktr_resync_callback, NULL);
338 }
339 
340 /*
341  * The remote-end of the KTR synchronization protocol runs on all cpus except
342  * cpu 0.  Since this is an IPI function, it is entered with the current
343  * thread in a critical section.
344  */
345 static void
346 ktr_resync_remote(void *dummy __unused)
347 {
348 	volatile int64_t tsc1 = ktr_sync_tsc;
349 	volatile int64_t tsc2;
350 
351 	/*
352 	 * Inform the master that we have entered our hard loop.
353 	 */
354 	KKASSERT(ktr_sync_state == 1);
355 	atomic_add_int(&ktr_sync_count, 1);
356 	DEBUG_PUSH_INFO("ktrsync2");
357 	while (ktr_sync_state == 1) {
358 		lwkt_process_ipiq();
359 	}
360 	DEBUG_POP_INFO();
361 
362 	/*
363 	 * Now the master is in a hard loop, synchronize the TSC and
364 	 * we are done.
365 	 */
366 	cpu_disable_intr();
367 	KKASSERT(ktr_sync_state == 2);
368 	tsc2 = ktr_sync_tsc;
369 	if (tsc2 > tsc1)
370 		tsc_offsets[mycpu->gd_cpuid] = rdtsc() - tsc2;
371 	atomic_subtract_int(&ktr_sync_count, 1);
372 	cpu_enable_intr();
373 }
374 
375 #if KTR_TESTLOG
376 
377 static
378 void
379 ktr_pingpong_remote(void *dummy __unused)
380 {
381 	int other_cpu;
382 
383 	logtest_noargs(pingpong);
384 	other_cpu = 1 - mycpu->gd_cpuid;
385 	if (ktr_testipicnt_remainder) {
386 		--ktr_testipicnt_remainder;
387 		lwkt_send_ipiq_bycpu(other_cpu, ktr_pingpong_remote, NULL);
388 	} else {
389 		lwkt_send_ipiq_bycpu(other_cpu, ktr_pipeline_remote, NULL);
390 		lwkt_send_ipiq_bycpu(other_cpu, ktr_pipeline_remote, NULL);
391 		lwkt_send_ipiq_bycpu(other_cpu, ktr_pipeline_remote, NULL);
392 		lwkt_send_ipiq_bycpu(other_cpu, ktr_pipeline_remote, NULL);
393 		lwkt_send_ipiq_bycpu(other_cpu, ktr_pipeline_remote, NULL);
394 	}
395 }
396 
397 static
398 void
399 ktr_pipeline_remote(void *dummy __unused)
400 {
401 	logtest_noargs(pipeline);
402 }
403 
404 #endif
405 
406 #else	/* !SMP */
407 
408 /*
409  * The resync callback for UP doesn't do anything other then run the test
410  * log messages.  If test logging is not enabled, don't bother resetting
411  * the callout.
412  */
413 static
414 void
415 ktr_resync_callback(void *dummy __unused)
416 {
417 #if KTR_TESTLOG
418 	/*
419 	 * Test logging
420 	 */
421 	if (ktr_testlogcnt) {
422 		--ktr_testlogcnt;
423 		cpu_disable_intr();
424 		logtest(test1);
425 		logtest(test2);
426 		logtest(test3);
427 		logtest_noargs(test4);
428 		logtest_noargs(test5);
429 		logtest_noargs(test6);
430 		cpu_enable_intr();
431 	}
432 	callout_reset(&ktr_resync_callout, hz / 10, ktr_resync_callback, NULL);
433 #endif
434 }
435 
436 #endif
437 
438 /*
439  * KTR_WRITE_ENTRY - Primary entry point for kernel trace logging
440  */
441 
442 static __inline
443 void
444 ktr_write_entry(struct ktr_info *info, const char *file, int line, __va_list va)
445 {
446 	struct ktr_cpu_core *kcpu;
447 	struct ktr_entry *entry;
448 	int cpu;
449 
450 	cpu = mycpu->gd_cpuid;
451 	kcpu = &ktr_cpu[cpu].core;
452 	if (kcpu->ktr_buf == NULL)
453 		return;
454 
455 	crit_enter();
456 	entry = kcpu->ktr_buf + (kcpu->ktr_idx & KTR_ENTRIES_MASK);
457 	++kcpu->ktr_idx;
458 #ifdef _RDTSC_SUPPORTED_
459 	if (cpu_feature & CPUID_TSC) {
460 #ifdef SMP
461 		entry->ktr_timestamp = rdtsc() - tsc_offsets[cpu];
462 #else
463 		entry->ktr_timestamp = rdtsc();
464 #endif
465 	} else
466 #endif
467 	{
468 		entry->ktr_timestamp = get_approximate_time_t();
469 	}
470 	entry->ktr_info = info;
471 	entry->ktr_file = file;
472 	entry->ktr_line = line;
473 	crit_exit();
474 	if (info->kf_data_size > KTR_BUFSIZE)
475 		bcopy(va, entry->ktr_data, KTR_BUFSIZE);
476 	else if (info->kf_data_size)
477 		bcopy(va, entry->ktr_data, info->kf_data_size);
478 	if (ktr_stacktrace)
479 		cpu_ktr_caller(entry);
480 #ifdef KTR_VERBOSE
481 	if (ktr_verbose && info->kf_format) {
482 #ifdef SMP
483 		kprintf("cpu%d ", cpu);
484 #endif
485 		if (ktr_verbose > 1) {
486 			kprintf("%s.%d\t", entry->ktr_file, entry->ktr_line);
487 		}
488 		kvprintf(info->kf_format, va);
489 		kprintf("\n");
490 	}
491 #endif
492 }
493 
494 void
495 ktr_log(struct ktr_info *info, const char *file, int line, ...)
496 {
497 	__va_list va;
498 
499 	if (panicstr == NULL) {
500 		__va_start(va, line);
501 		ktr_write_entry(info, file, line, va);
502 		__va_end(va);
503 	}
504 }
505 
506 #ifdef DDB
507 
508 #define	NUM_LINES_PER_PAGE	19
509 
510 struct tstate {
511 	int	cur;
512 	int	first;
513 };
514 
515 static	int db_ktr_verbose;
516 static	int db_mach_vtrace(int cpu, struct ktr_entry *kp, int idx);
517 
518 DB_SHOW_COMMAND(ktr, db_ktr_all)
519 {
520 	struct ktr_cpu_core *kcpu;
521 	int a_flag = 0;
522 	int c;
523 	int nl = 0;
524 	int i;
525 	struct tstate tstate[MAXCPU];
526 	int printcpu = -1;
527 
528 	for(i = 0; i < ncpus; i++) {
529 		kcpu = &ktr_cpu[i].core;
530 		tstate[i].first = -1;
531 		tstate[i].cur = (kcpu->ktr_idx - 1) & KTR_ENTRIES_MASK;
532 	}
533 	db_ktr_verbose = 0;
534 	while ((c = *(modif++)) != '\0') {
535 		if (c == 'v') {
536 			db_ktr_verbose = 1;
537 		}
538 		else if (c == 'a') {
539 			a_flag = 1;
540 		}
541 		else if (c == 'c') {
542 			printcpu = 0;
543 			while ((c = *(modif++)) != '\0') {
544 				if (isdigit(c)) {
545 					printcpu *= 10;
546 					printcpu += c - '0';
547 				}
548 				else {
549 					modif++;
550 					break;
551 				}
552 			}
553 			modif--;
554 		}
555 	}
556 	if (printcpu > ncpus - 1) {
557 		db_printf("Invalid cpu number\n");
558 		return;
559 	}
560 	/*
561 	 * Lopp throug all the buffers and print the content of them, sorted
562 	 * by the timestamp.
563 	 */
564 	while (1) {
565 		int counter;
566 		u_int64_t highest_ts;
567 		int highest_cpu;
568 		struct ktr_entry *kp;
569 
570 		if (a_flag == 1 && cncheckc() != -1)
571 			return;
572 		highest_ts = 0;
573 		highest_cpu = -1;
574 		/*
575 		 * Find the lowest timestamp
576 		 */
577 		for (i = 0, counter = 0; i < ncpus; i++) {
578 			kcpu = &ktr_cpu[i].core;
579 			if (kcpu->ktr_buf == NULL)
580 				continue;
581 			if (printcpu != -1 && printcpu != i)
582 				continue;
583 			if (tstate[i].cur == -1) {
584 				counter++;
585 				if (counter == ncpus) {
586 					db_printf("--- End of trace buffer ---\n");
587 					return;
588 				}
589 				continue;
590 			}
591 			if (kcpu->ktr_buf[tstate[i].cur].ktr_timestamp > highest_ts) {
592 				highest_ts = kcpu->ktr_buf[tstate[i].cur].ktr_timestamp;
593 				highest_cpu = i;
594 			}
595 		}
596 		if (highest_cpu < 0) {
597 			db_printf("no KTR data available\n");
598 			break;
599 		}
600 		i = highest_cpu;
601 		kcpu = &ktr_cpu[i].core;
602 		kp = &kcpu->ktr_buf[tstate[i].cur];
603 		if (tstate[i].first == -1)
604 			tstate[i].first = tstate[i].cur;
605 		if (--tstate[i].cur < 0)
606 			tstate[i].cur = KTR_ENTRIES - 1;
607 		if (tstate[i].first == tstate[i].cur) {
608 			db_mach_vtrace(i, kp, tstate[i].cur + 1);
609 			tstate[i].cur = -1;
610 			continue;
611 		}
612 		if (kcpu->ktr_buf[tstate[i].cur].ktr_info == NULL)
613 			tstate[i].cur = -1;
614 		if (db_more(&nl) == -1)
615 			break;
616 		if (db_mach_vtrace(i, kp, tstate[i].cur + 1) == 0)
617 			tstate[i].cur = -1;
618 	}
619 }
620 
621 static int
622 db_mach_vtrace(int cpu, struct ktr_entry *kp, int idx)
623 {
624 	if (kp->ktr_info == NULL)
625 		return(0);
626 #ifdef SMP
627 	db_printf("cpu%d ", cpu);
628 #endif
629 	db_printf("%d: ", idx);
630 	if (db_ktr_verbose) {
631 		db_printf("%10.10lld %s.%d\t", (long long)kp->ktr_timestamp,
632 		    kp->ktr_file, kp->ktr_line);
633 	}
634 	db_printf("%s\t", kp->ktr_info->kf_name);
635 	db_printf("from(%p,%p) ", kp->ktr_caller1, kp->ktr_caller2);
636 #ifdef __i386__
637 	if (kp->ktr_info->kf_format)
638 		db_vprintf(kp->ktr_info->kf_format, (__va_list)kp->ktr_data);
639 #endif
640 	db_printf("\n");
641 
642 	return(1);
643 }
644 
645 #endif	/* DDB */
646