Fix buildkernel with 'options KTR' in the config.
[dragonfly.git] / sys / kern / kern_ktr.c
CommitLineData
d3776285
MD
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 *
81540c2d
EN
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 */
6d22945a 64
81540c2d 65/*
d3776285 66 * Kernel tracepoint facility.
81540c2d
EN
67 */
68
69#include "opt_ddb.h"
70#include "opt_ktr.h"
71
72#include <sys/param.h>
73#include <sys/cons.h>
74#include <sys/kernel.h>
81540c2d
EN
75#include <sys/libkern.h>
76#include <sys/proc.h>
77#include <sys/sysctl.h>
d3776285 78#include <sys/ktr.h>
81540c2d
EN
79#include <sys/systm.h>
80#include <sys/time.h>
8e273a1d 81#include <sys/malloc.h>
c2751817 82#include <sys/spinlock.h>
8e273a1d 83#include <sys/thread2.h>
c2751817 84#include <sys/spinlock2.h>
8e273a1d 85#include <sys/ctype.h>
81540c2d
EN
86
87#include <machine/cpu.h>
88#include <machine/cpufunc.h>
89#include <machine/specialreg.h>
90#include <machine/md_var.h>
91
92#include <ddb/ddb.h>
93
94#ifndef KTR_ENTRIES
d3776285 95#define KTR_ENTRIES 2048
6d22945a
SW
96#elif (KTR_ENTRIES & KTR_ENTRIES - 1)
97#error KTR_ENTRIES must be a power of two
81540c2d 98#endif
d3776285 99#define KTR_ENTRIES_MASK (KTR_ENTRIES - 1)
81540c2d 100
96328d40
MD
101/*
102 * test logging support. When ktr_testlogcnt is non-zero each synchronization
0b698dca 103 * interrupt will issue six back-to-back ktr logging messages on cpu 0
96328d40
MD
104 * so the user can determine KTR logging overheads.
105 */
106#if !defined(KTR_TESTLOG)
107#define KTR_TESTLOG KTR_ALL
108#endif
109KTR_INFO_MASTER(testlog);
8cb417fa 110#if KTR_TESTLOG
5bf48697
AE
111KTR_INFO(KTR_TESTLOG, testlog, test1, 0, "test1 %d %d %d %d", int dummy1, int dummy2, int dummy3, int dummy4);
112KTR_INFO(KTR_TESTLOG, testlog, test2, 1, "test2 %d %d %d %d", int dummy1, int dummy2, int dummy3, int dummy4);
113KTR_INFO(KTR_TESTLOG, testlog, test3, 2, "test3 %d %d %d %d", int dummy1, int dummy2, int dummy3, int dummy4);
114KTR_INFO(KTR_TESTLOG, testlog, test4, 3, "test4");
115KTR_INFO(KTR_TESTLOG, testlog, test5, 4, "test5");
116KTR_INFO(KTR_TESTLOG, testlog, test6, 5, "test6");
5bf48697
AE
117KTR_INFO(KTR_TESTLOG, testlog, pingpong, 6, "pingpong");
118KTR_INFO(KTR_TESTLOG, testlog, pipeline, 7, "pipeline");
119KTR_INFO(KTR_TESTLOG, testlog, crit_beg, 8, "crit_beg");
120KTR_INFO(KTR_TESTLOG, testlog, crit_end, 9, "crit_end");
121KTR_INFO(KTR_TESTLOG, testlog, spin_beg, 10, "spin_beg");
122KTR_INFO(KTR_TESTLOG, testlog, spin_end, 11, "spin_end");
96328d40 123#define logtest(name) KTR_LOG(testlog_ ## name, 0, 0, 0, 0)
0b698dca 124#define logtest_noargs(name) KTR_LOG(testlog_ ## name)
8cb417fa 125#endif
96328d40 126
8e273a1d
EN
127MALLOC_DEFINE(M_KTR, "ktr", "ktr buffers");
128
d3776285 129SYSCTL_NODE(_debug, OID_AUTO, ktr, CTLFLAG_RW, 0, "ktr");
81540c2d 130
ffc26552 131int ktr_entries = KTR_ENTRIES;
f22af1e9
SW
132SYSCTL_INT(_debug_ktr, OID_AUTO, entries, CTLFLAG_RD, &ktr_entries, 0,
133 "Size of the event buffer");
81540c2d 134
ffc26552 135int ktr_version = KTR_VERSION;
81540c2d
EN
136SYSCTL_INT(_debug_ktr, OID_AUTO, version, CTLFLAG_RD, &ktr_version, 0, "");
137
af6ff89e
MD
138static int ktr_stacktrace = 1;
139SYSCTL_INT(_debug_ktr, OID_AUTO, stacktrace, CTLFLAG_RD, &ktr_stacktrace, 0, "");
140
374133e3 141static int ktr_resynchronize = 0;
f22af1e9
SW
142SYSCTL_INT(_debug_ktr, OID_AUTO, resynchronize, CTLFLAG_RW,
143 &ktr_resynchronize, 0, "Resynchronize TSC 10 times a second");
374133e3 144
96328d40
MD
145#if KTR_TESTLOG
146static int ktr_testlogcnt = 0;
147SYSCTL_INT(_debug_ktr, OID_AUTO, testlogcnt, CTLFLAG_RW, &ktr_testlogcnt, 0, "");
72d379df
MD
148static int ktr_testipicnt = 0;
149static int ktr_testipicnt_remainder;
150SYSCTL_INT(_debug_ktr, OID_AUTO, testipicnt, CTLFLAG_RW, &ktr_testipicnt, 0, "");
c2751817
MD
151static int ktr_testcritcnt = 0;
152SYSCTL_INT(_debug_ktr, OID_AUTO, testcritcnt, CTLFLAG_RW, &ktr_testcritcnt, 0, "");
153static int ktr_testspincnt = 0;
154SYSCTL_INT(_debug_ktr, OID_AUTO, testspincnt, CTLFLAG_RW, &ktr_testspincnt, 0, "");
96328d40
MD
155#endif
156
d3776285
MD
157/*
158 * Give cpu0 a static buffer so the tracepoint facility can be used during
159 * early boot (note however that we still use a critical section, XXX).
160 */
161static struct ktr_entry ktr_buf0[KTR_ENTRIES];
ddca1582 162
02289741 163struct ktr_cpu ktr_cpu[MAXCPU] = {
ddca1582
MD
164 { .core.ktr_buf = &ktr_buf0[0] }
165};
166
374133e3
MD
167static int64_t ktr_sync_tsc;
168struct callout ktr_resync_callout;
169
81540c2d
EN
170#ifdef KTR_VERBOSE
171int ktr_verbose = KTR_VERBOSE;
172TUNABLE_INT("debug.ktr.verbose", &ktr_verbose);
f22af1e9
SW
173SYSCTL_INT(_debug_ktr, OID_AUTO, verbose, CTLFLAG_RW, &ktr_verbose, 0,
174 "Log events to the console as well");
81540c2d
EN
175#endif
176
ba39e2e0
MD
177static void ktr_resync_callback(void *dummy __unused);
178
c2751817 179extern int64_t tsc_offsets[];
0b698dca 180
81540c2d
EN
181static void
182ktr_sysinit(void *dummy)
183{
ddca1582 184 struct ktr_cpu_core *kcpu;
8e273a1d
EN
185 int i;
186
d3776285 187 for(i = 1; i < ncpus; ++i) {
ddca1582
MD
188 kcpu = &ktr_cpu[i].core;
189 kcpu->ktr_buf = kmalloc(KTR_ENTRIES * sizeof(struct ktr_entry),
190 M_KTR, M_WAITOK | M_ZERO);
8e273a1d 191 }
bf0ecf68 192 callout_init_mp(&ktr_resync_callout);
ba39e2e0 193 callout_reset(&ktr_resync_callout, hz / 10, ktr_resync_callback, NULL);
81540c2d 194}
ba39e2e0 195SYSINIT(ktr_sysinit, SI_BOOT2_KLD, SI_ORDER_ANY, ktr_sysinit, NULL);
374133e3 196
374133e3
MD
197/*
198 * Try to resynchronize the TSC's for all cpus. This is really, really nasty.
199 * We have to send an IPIQ message to all remote cpus, wait until they
200 * get into their IPIQ processing code loop, then do an even stricter hard
201 * loop to get the cpus as close to synchronized as we can to get the most
202 * accurate reading.
203 *
204 * This callback occurs on cpu0.
205 */
8cb417fa 206#if KTR_TESTLOG
72d379df 207static void ktr_pingpong_remote(void *dummy);
c2751817 208static void ktr_pipeline_remote(void *dummy);
8cb417fa 209#endif
374133e3 210
1918fc5c 211#ifdef _RDTSC_SUPPORTED_
b4c3db6f
MD
212
213static void ktr_resync_remote(void *dummy);
374133e3
MD
214
215/*
216 * We use a callout callback instead of a systimer because we cannot afford
217 * to preempt anyone to do this, or we might deadlock a spin-lock or
218 * serializer between two cpus.
219 */
220static
221void
222ktr_resync_callback(void *dummy __unused)
223{
f697b97d 224 struct lwkt_cpusync cs;
ef4b87ee 225#if KTR_TESTLOG
374133e3 226 int count;
ef4b87ee 227#endif
374133e3
MD
228
229 KKASSERT(mycpu->gd_cpuid == 0);
96328d40
MD
230
231#if KTR_TESTLOG
232 /*
233 * Test logging
234 */
235 if (ktr_testlogcnt) {
236 --ktr_testlogcnt;
237 cpu_disable_intr();
238 logtest(test1);
239 logtest(test2);
240 logtest(test3);
0b698dca
MD
241 logtest_noargs(test4);
242 logtest_noargs(test5);
243 logtest_noargs(test6);
96328d40
MD
244 cpu_enable_intr();
245 }
72d379df
MD
246
247 /*
248 * Test IPI messaging
249 */
250 if (ktr_testipicnt && ktr_testipicnt_remainder == 0 && ncpus > 1) {
251 ktr_testipicnt_remainder = ktr_testipicnt;
252 ktr_testipicnt = 0;
253 lwkt_send_ipiq_bycpu(1, ktr_pingpong_remote, NULL);
254 }
c2751817
MD
255
256 /*
257 * Test critical sections
258 */
259 if (ktr_testcritcnt) {
260 crit_enter();
261 crit_exit();
262 logtest_noargs(crit_beg);
263 for (count = ktr_testcritcnt; count; --count) {
264 crit_enter();
265 crit_exit();
266 }
267 logtest_noargs(crit_end);
268 ktr_testcritcnt = 0;
269 }
270
271 /*
272 * Test spinlock sections
273 */
274 if (ktr_testspincnt) {
275 struct spinlock spin;
276
277 spin_init(&spin);
287a8577
AH
278 spin_lock(&spin);
279 spin_unlock(&spin);
c2751817
MD
280 logtest_noargs(spin_beg);
281 for (count = ktr_testspincnt; count; --count) {
287a8577
AH
282 spin_lock(&spin);
283 spin_unlock(&spin);
d666840a
MD
284 }
285 logtest_noargs(spin_end);
c2751817
MD
286 ktr_testspincnt = 0;
287 }
96328d40
MD
288#endif
289
290 /*
291 * Resynchronize the TSC
292 */
374133e3
MD
293 if (ktr_resynchronize == 0)
294 goto done;
295 if ((cpu_feature & CPUID_TSC) == 0)
296 return;
0b698dca 297
374133e3 298 crit_enter();
f697b97d
MD
299 lwkt_cpusync_init(&cs, smp_active_mask, ktr_resync_remote,
300 (void *)(intptr_t)mycpu->gd_cpuid);
301 lwkt_cpusync_interlock(&cs);
374133e3 302 ktr_sync_tsc = rdtsc();
f697b97d 303 lwkt_cpusync_deinterlock(&cs);
374133e3 304 crit_exit();
374133e3
MD
305done:
306 callout_reset(&ktr_resync_callout, hz / 10, ktr_resync_callback, NULL);
307}
308
0b698dca 309/*
f697b97d
MD
310 * The remote-end of the KTR synchronization protocol runs on all cpus.
311 * The one we run on the controlling cpu updates its tsc continuously
312 * until the others have finished syncing (theoretically), but we don't
313 * loop forever.
314 *
315 * This is a bit ad-hoc but we need to avoid livelocking inside an IPI
316 * callback. rdtsc() is a synchronizing instruction (I think).
0b698dca 317 */
374133e3 318static void
f697b97d 319ktr_resync_remote(void *arg)
374133e3 320{
f697b97d
MD
321 globaldata_t gd = mycpu;
322 int64_t delta;
323 int i;
374133e3 324
f697b97d
MD
325 if (gd->gd_cpuid == (int)(intptr_t)arg) {
326 for (i = 0; i < 2000; ++i)
327 ktr_sync_tsc = rdtsc();
328 } else {
329 delta = rdtsc() - ktr_sync_tsc;
330 if (tsc_offsets[gd->gd_cpuid] == 0)
331 tsc_offsets[gd->gd_cpuid] = delta;
332 tsc_offsets[gd->gd_cpuid] =
333 (tsc_offsets[gd->gd_cpuid] * 7 + delta) / 8;
374133e3 334 }
374133e3 335}
81540c2d 336
8cb417fa
MD
337#if KTR_TESTLOG
338
72d379df
MD
339static
340void
341ktr_pingpong_remote(void *dummy __unused)
342{
c2751817
MD
343 int other_cpu;
344
72d379df 345 logtest_noargs(pingpong);
c2751817 346 other_cpu = 1 - mycpu->gd_cpuid;
72d379df
MD
347 if (ktr_testipicnt_remainder) {
348 --ktr_testipicnt_remainder;
c2751817
MD
349 lwkt_send_ipiq_bycpu(other_cpu, ktr_pingpong_remote, NULL);
350 } else {
351 lwkt_send_ipiq_bycpu(other_cpu, ktr_pipeline_remote, NULL);
352 lwkt_send_ipiq_bycpu(other_cpu, ktr_pipeline_remote, NULL);
353 lwkt_send_ipiq_bycpu(other_cpu, ktr_pipeline_remote, NULL);
354 lwkt_send_ipiq_bycpu(other_cpu, ktr_pipeline_remote, NULL);
355 lwkt_send_ipiq_bycpu(other_cpu, ktr_pipeline_remote, NULL);
72d379df
MD
356 }
357}
358
c2751817
MD
359static
360void
361ktr_pipeline_remote(void *dummy __unused)
362{
363 logtest_noargs(pipeline);
364}
365
8cb417fa
MD
366#endif
367
1918fc5c 368#else /* !_RDTSC_SUPPORTED_ */
0b698dca
MD
369
370/*
371 * The resync callback for UP doesn't do anything other then run the test
372 * log messages. If test logging is not enabled, don't bother resetting
373 * the callout.
374 */
375static
376void
377ktr_resync_callback(void *dummy __unused)
378{
379#if KTR_TESTLOG
380 /*
381 * Test logging
382 */
383 if (ktr_testlogcnt) {
384 --ktr_testlogcnt;
385 cpu_disable_intr();
386 logtest(test1);
387 logtest(test2);
388 logtest(test3);
389 logtest_noargs(test4);
390 logtest_noargs(test5);
391 logtest_noargs(test6);
392 cpu_enable_intr();
393 }
394 callout_reset(&ktr_resync_callout, hz / 10, ktr_resync_callback, NULL);
395#endif
396}
397
374133e3 398#endif
81540c2d 399
0b698dca 400/*
5bf48697
AE
401 * Setup the next empty slot and return it to the caller to store the data
402 * directly.
0b698dca 403 */
5bf48697
AE
404struct ktr_entry *
405ktr_begin_write_entry(struct ktr_info *info, const char *file, int line)
81540c2d 406{
ddca1582 407 struct ktr_cpu_core *kcpu;
81540c2d 408 struct ktr_entry *entry;
d3776285
MD
409 int cpu;
410
411 cpu = mycpu->gd_cpuid;
ddca1582 412 kcpu = &ktr_cpu[cpu].core;
ab1b4385
MD
413 if (panicstr) /* stop logging during panic */
414 return NULL;
415 if (kcpu->ktr_buf == NULL) /* too early in boot */
5bf48697 416 return NULL;
b4cb74b5
SW
417
418 crit_enter();
ddca1582
MD
419 entry = kcpu->ktr_buf + (kcpu->ktr_idx & KTR_ENTRIES_MASK);
420 ++kcpu->ktr_idx;
527fddf7 421#ifdef _RDTSC_SUPPORTED_
b4cb74b5 422 if (cpu_feature & CPUID_TSC) {
b4cb74b5 423 entry->ktr_timestamp = rdtsc() - tsc_offsets[cpu];
527fddf7
MD
424 } else
425#endif
426 {
b4cb74b5 427 entry->ktr_timestamp = get_approximate_time_t();
8e273a1d 428 }
b4cb74b5
SW
429 entry->ktr_info = info;
430 entry->ktr_file = file;
431 entry->ktr_line = line;
432 crit_exit();
5bf48697
AE
433 return entry;
434}
435
436int
437ktr_finish_write_entry(struct ktr_info *info, struct ktr_entry *entry)
438{
b4cb74b5
SW
439 if (ktr_stacktrace)
440 cpu_ktr_caller(entry);
81540c2d 441#ifdef KTR_VERBOSE
d3776285 442 if (ktr_verbose && info->kf_format) {
5bf48697 443 kprintf("cpu%d ", mycpu->gd_cpuid);
81540c2d 444 if (ktr_verbose > 1) {
6ea70f76 445 kprintf("%s.%d\t", entry->ktr_file, entry->ktr_line);
81540c2d 446 }
5bf48697 447 return !0;
81540c2d
EN
448 }
449#endif
5bf48697 450 return 0;
d3776285
MD
451}
452
81540c2d
EN
453#ifdef DDB
454
8e273a1d 455#define NUM_LINES_PER_PAGE 19
81540c2d
EN
456
457struct tstate {
458 int cur;
459 int first;
460};
d3776285 461
81540c2d 462static int db_ktr_verbose;
d3776285 463static int db_mach_vtrace(int cpu, struct ktr_entry *kp, int idx);
81540c2d
EN
464
465DB_SHOW_COMMAND(ktr, db_ktr_all)
466{
ddca1582 467 struct ktr_cpu_core *kcpu;
8e273a1d
EN
468 int a_flag = 0;
469 int c;
81540c2d 470 int nl = 0;
8e273a1d
EN
471 int i;
472 struct tstate tstate[MAXCPU];
473 int printcpu = -1;
474
475 for(i = 0; i < ncpus; i++) {
ddca1582 476 kcpu = &ktr_cpu[i].core;
8e273a1d 477 tstate[i].first = -1;
ddca1582 478 tstate[i].cur = (kcpu->ktr_idx - 1) & KTR_ENTRIES_MASK;
8e273a1d
EN
479 }
480 db_ktr_verbose = 0;
481 while ((c = *(modif++)) != '\0') {
482 if (c == 'v') {
483 db_ktr_verbose = 1;
484 }
485 else if (c == 'a') {
486 a_flag = 1;
81540c2d 487 }
8e273a1d
EN
488 else if (c == 'c') {
489 printcpu = 0;
490 while ((c = *(modif++)) != '\0') {
491 if (isdigit(c)) {
492 printcpu *= 10;
493 printcpu += c - '0';
494 }
495 else {
496 modif++;
497 break;
498 }
499 }
500 modif--;
81540c2d
EN
501 }
502 }
8e273a1d
EN
503 if (printcpu > ncpus - 1) {
504 db_printf("Invalid cpu number\n");
505 return;
506 }
507 /*
508 * Lopp throug all the buffers and print the content of them, sorted
509 * by the timestamp.
510 */
511 while (1) {
512 int counter;
513 u_int64_t highest_ts;
514 int highest_cpu;
515 struct ktr_entry *kp;
516
517 if (a_flag == 1 && cncheckc() != -1)
518 return;
519 highest_ts = 0;
520 highest_cpu = -1;
521 /*
522 * Find the lowest timestamp
523 */
524 for (i = 0, counter = 0; i < ncpus; i++) {
ddca1582
MD
525 kcpu = &ktr_cpu[i].core;
526 if (kcpu->ktr_buf == NULL)
d3776285 527 continue;
8e273a1d
EN
528 if (printcpu != -1 && printcpu != i)
529 continue;
530 if (tstate[i].cur == -1) {
531 counter++;
532 if (counter == ncpus) {
533 db_printf("--- End of trace buffer ---\n");
534 return;
535 }
536 continue;
537 }
ddca1582
MD
538 if (kcpu->ktr_buf[tstate[i].cur].ktr_timestamp > highest_ts) {
539 highest_ts = kcpu->ktr_buf[tstate[i].cur].ktr_timestamp;
8e273a1d
EN
540 highest_cpu = i;
541 }
542 }
438c526f
MD
543 if (highest_cpu < 0) {
544 db_printf("no KTR data available\n");
545 break;
546 }
8e273a1d 547 i = highest_cpu;
ddca1582
MD
548 kcpu = &ktr_cpu[i].core;
549 kp = &kcpu->ktr_buf[tstate[i].cur];
8e273a1d
EN
550 if (tstate[i].first == -1)
551 tstate[i].first = tstate[i].cur;
552 if (--tstate[i].cur < 0)
553 tstate[i].cur = KTR_ENTRIES - 1;
554 if (tstate[i].first == tstate[i].cur) {
d3776285 555 db_mach_vtrace(i, kp, tstate[i].cur + 1);
8e273a1d
EN
556 tstate[i].cur = -1;
557 continue;
558 }
ddca1582 559 if (kcpu->ktr_buf[tstate[i].cur].ktr_info == NULL)
8e273a1d
EN
560 tstate[i].cur = -1;
561 if (db_more(&nl) == -1)
562 break;
d3776285 563 if (db_mach_vtrace(i, kp, tstate[i].cur + 1) == 0)
8e273a1d
EN
564 tstate[i].cur = -1;
565 }
81540c2d
EN
566}
567
568static int
d3776285 569db_mach_vtrace(int cpu, struct ktr_entry *kp, int idx)
81540c2d 570{
d3776285 571 if (kp->ktr_info == NULL)
8e273a1d 572 return(0);
d3776285 573 db_printf("cpu%d ", cpu);
8e273a1d 574 db_printf("%d: ", idx);
81540c2d
EN
575 if (db_ktr_verbose) {
576 db_printf("%10.10lld %s.%d\t", (long long)kp->ktr_timestamp,
577 kp->ktr_file, kp->ktr_line);
578 }
d3776285 579 db_printf("%s\t", kp->ktr_info->kf_name);
af6ff89e 580 db_printf("from(%p,%p) ", kp->ktr_caller1, kp->ktr_caller2);
4afe74da 581#ifdef __i386__
00828b33
MD
582 if (kp->ktr_info->kf_format)
583 db_vprintf(kp->ktr_info->kf_format, (__va_list)kp->ktr_data);
4afe74da 584#endif
81540c2d
EN
585 db_printf("\n");
586
8e273a1d 587 return(1);
81540c2d
EN
588}
589
590#endif /* DDB */