2003-09-10 01:09:32 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 John Baldwin <jhb@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
2000-09-07 01:29:44 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2003-09-10 01:09:32 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
2000-09-07 01:29:44 +00:00
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2003-09-10 01:09:32 +00:00
|
|
|
* 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.
|
2000-09-07 01:29:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-11-07 01:49:48 +00:00
|
|
|
* This module holds the global variables used by KTR and the ktr_tracepoint()
|
|
|
|
* function that does the actual tracing.
|
2000-09-07 01:29:44 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-12-15 00:01:20 +00:00
|
|
|
#include "opt_ddb.h"
|
2000-11-07 01:49:48 +00:00
|
|
|
#include "opt_ktr.h"
|
2002-09-22 07:13:45 +00:00
|
|
|
#include "opt_alq.h"
|
2000-11-07 01:49:48 +00:00
|
|
|
|
2000-12-15 00:01:20 +00:00
|
|
|
#include <sys/param.h>
|
2011-05-31 20:48:58 +00:00
|
|
|
#include <sys/queue.h>
|
2002-09-22 07:13:45 +00:00
|
|
|
#include <sys/alq.h>
|
2000-12-15 00:01:20 +00:00
|
|
|
#include <sys/cons.h>
|
2011-05-31 20:48:58 +00:00
|
|
|
#include <sys/cpuset.h>
|
2014-07-02 22:13:07 +00:00
|
|
|
#include <sys/kdb.h>
|
2001-01-06 06:51:43 +00:00
|
|
|
#include <sys/kernel.h>
|
2000-09-07 01:29:44 +00:00
|
|
|
#include <sys/ktr.h>
|
2000-11-07 01:49:48 +00:00
|
|
|
#include <sys/libkern.h>
|
2012-11-15 00:51:57 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mutex.h>
|
2001-12-13 10:33:20 +00:00
|
|
|
#include <sys/proc.h>
|
2012-11-15 00:51:57 +00:00
|
|
|
#include <sys/smp.h>
|
2000-09-07 01:29:44 +00:00
|
|
|
#include <sys/sysctl.h>
|
2000-11-07 01:49:48 +00:00
|
|
|
#include <sys/systm.h>
|
2001-06-25 23:09:31 +00:00
|
|
|
#include <sys/time.h>
|
2002-04-01 05:35:26 +00:00
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
2002-04-06 08:43:17 +00:00
|
|
|
#ifdef __sparc64__
|
|
|
|
#include <machine/ktr.h>
|
|
|
|
#endif
|
2000-11-07 01:49:48 +00:00
|
|
|
|
2006-07-12 21:22:44 +00:00
|
|
|
#ifdef DDB
|
2000-12-15 00:01:20 +00:00
|
|
|
#include <ddb/ddb.h>
|
2006-07-12 21:22:44 +00:00
|
|
|
#include <ddb/db_output.h>
|
|
|
|
#endif
|
2000-12-15 00:01:20 +00:00
|
|
|
|
2013-02-03 09:57:39 +00:00
|
|
|
#ifndef KTR_BOOT_ENTRIES
|
|
|
|
#define KTR_BOOT_ENTRIES 1024
|
|
|
|
#endif
|
|
|
|
|
2001-06-25 23:09:31 +00:00
|
|
|
#ifndef KTR_ENTRIES
|
|
|
|
#define KTR_ENTRIES 1024
|
|
|
|
#endif
|
|
|
|
|
2012-11-15 00:51:57 +00:00
|
|
|
/* Limit the allocations to something manageable. */
|
|
|
|
#define KTR_ENTRIES_MAX (8 * 1024 * 1024)
|
|
|
|
|
2000-11-07 01:49:48 +00:00
|
|
|
#ifndef KTR_MASK
|
2010-07-21 10:14:04 +00:00
|
|
|
#define KTR_MASK (0)
|
2000-11-07 01:49:48 +00:00
|
|
|
#endif
|
|
|
|
|
Post r222812 KTR_CPUMASK started being initialized only as a tunable
handler and not more statically.
Unfortunately, it seems that this is not ideal for new platform bringup
and boot low level development (which needs ktr_cpumask to be effective
before tunables can be setup).
Because of this, add a way to statically initialize cpusets, by passing
an list of initializers, divided by commas. Also, provide a way to enforce
an all-set mask, for above mentioned initializers.
This imposes some differences on how KTR_CPUMASK is setup now as a
kernel option, and in particular this makes the words specifications
backward wrt. what is currently in -CURRENT. In order to avoid mismatches
between KTR_CPUMASK definition and other way to setup the mask
(tunable, sysctl) and to print it, change the ordering how
cpusetobj_print() and cpusetobj_scan() acquire the words belonging
to the set.
Please give a look to sys/conf/NOTES in order to understand how the
new format is supposed to work.
Also, ktr manpages will be updated shortly by gjb which volountereed
for this.
This patch won't be merged because it changes a POLA (at least
from the theoretical standpoint) and this is however a patch that
proves to be effective only in development environments.
Requested by: rpaulo
Reviewed by: jeff, rpaulo
2012-08-30 21:22:47 +00:00
|
|
|
#ifndef KTR_CPUMASK
|
|
|
|
#define KTR_CPUMASK CPUSET_FSET
|
|
|
|
#endif
|
|
|
|
|
2002-04-01 05:35:26 +00:00
|
|
|
#ifndef KTR_TIME
|
|
|
|
#define KTR_TIME get_cyclecount()
|
2001-01-06 06:51:43 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-01 05:35:26 +00:00
|
|
|
#ifndef KTR_CPU
|
|
|
|
#define KTR_CPU PCPU_GET(cpuid)
|
2001-01-06 06:51:43 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-15 00:51:57 +00:00
|
|
|
static MALLOC_DEFINE(M_KTR, "KTR", "KTR");
|
2011-02-25 10:11:01 +00:00
|
|
|
|
2012-11-15 00:51:57 +00:00
|
|
|
FEATURE(ktr, "Kernel support for KTR kernel tracing facility");
|
2001-01-06 06:51:43 +00:00
|
|
|
|
2012-11-15 00:51:57 +00:00
|
|
|
volatile int ktr_idx = 0;
|
2001-06-06 22:17:08 +00:00
|
|
|
int ktr_mask = KTR_MASK;
|
2012-11-15 00:51:57 +00:00
|
|
|
int ktr_compile = KTR_COMPILE;
|
2013-02-03 09:57:39 +00:00
|
|
|
int ktr_entries = KTR_BOOT_ENTRIES;
|
2012-11-15 00:51:57 +00:00
|
|
|
int ktr_version = KTR_VERSION;
|
2013-02-03 09:57:39 +00:00
|
|
|
struct ktr_entry ktr_buf_init[KTR_BOOT_ENTRIES];
|
2012-11-15 00:51:57 +00:00
|
|
|
struct ktr_entry *ktr_buf = ktr_buf_init;
|
|
|
|
cpuset_t ktr_cpumask = CPUSET_T_INITIALIZER(KTR_CPUMASK);
|
|
|
|
|
2014-06-27 22:05:21 +00:00
|
|
|
static SYSCTL_NODE(_debug, OID_AUTO, ktr, CTLFLAG_RD, 0, "KTR options");
|
2014-06-27 16:33:43 +00:00
|
|
|
|
2010-03-11 15:13:55 +00:00
|
|
|
SYSCTL_INT(_debug_ktr, OID_AUTO, version, CTLFLAG_RD,
|
|
|
|
&ktr_version, 0, "Version of the KTR interface");
|
2002-04-01 05:35:26 +00:00
|
|
|
|
2012-12-07 05:55:48 +00:00
|
|
|
SYSCTL_UINT(_debug_ktr, OID_AUTO, compile, CTLFLAG_RD,
|
2012-11-15 00:51:57 +00:00
|
|
|
&ktr_compile, 0, "Bitmask of KTR event classes compiled into the kernel");
|
2011-05-31 20:48:58 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_debug_ktr_cpumask(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
char lktr_cpumask_str[CPUSETBUFSIZ];
|
|
|
|
cpuset_t imask;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
cpusetobj_strprint(lktr_cpumask_str, &ktr_cpumask);
|
|
|
|
error = sysctl_handle_string(oidp, lktr_cpumask_str,
|
|
|
|
sizeof(lktr_cpumask_str), req);
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
|
|
|
if (cpusetobj_strscan(&imask, lktr_cpumask_str) == -1)
|
|
|
|
return (EINVAL);
|
|
|
|
CPU_COPY(&imask, &ktr_cpumask);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
SYSCTL_PROC(_debug_ktr, OID_AUTO, cpumask,
|
2014-06-28 03:56:17 +00:00
|
|
|
CTLFLAG_RWTUN | CTLFLAG_MPSAFE | CTLTYPE_STRING, NULL, 0,
|
2011-05-31 20:48:58 +00:00
|
|
|
sysctl_debug_ktr_cpumask, "S",
|
|
|
|
"Bitmask of CPUs on which KTR logging is enabled");
|
|
|
|
|
2006-01-27 22:17:31 +00:00
|
|
|
static int
|
|
|
|
sysctl_debug_ktr_clear(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int clear, error;
|
|
|
|
|
|
|
|
clear = 0;
|
|
|
|
error = sysctl_handle_int(oidp, &clear, 0, req);
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (clear) {
|
2012-11-15 00:51:57 +00:00
|
|
|
bzero(ktr_buf, sizeof(*ktr_buf) * ktr_entries);
|
2006-01-27 22:17:31 +00:00
|
|
|
ktr_idx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
SYSCTL_PROC(_debug_ktr, OID_AUTO, clear, CTLTYPE_INT|CTLFLAG_RW, 0, 0,
|
|
|
|
sysctl_debug_ktr_clear, "I", "Clear KTR Buffer");
|
|
|
|
|
2012-11-15 00:51:57 +00:00
|
|
|
/*
|
|
|
|
* This is a sysctl proc so that it is serialized as !MPSAFE along with
|
|
|
|
* the other ktr sysctl procs.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sysctl_debug_ktr_mask(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int mask, error;
|
|
|
|
|
|
|
|
mask = ktr_mask;
|
|
|
|
error = sysctl_handle_int(oidp, &mask, 0, req);
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
ktr_mask = mask;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2014-06-28 17:36:18 +00:00
|
|
|
SYSCTL_PROC(_debug_ktr, OID_AUTO, mask, CTLTYPE_UINT|CTLFLAG_RWTUN, 0, 0,
|
2012-12-07 05:55:48 +00:00
|
|
|
sysctl_debug_ktr_mask, "IU",
|
2012-11-15 00:51:57 +00:00
|
|
|
"Bitmask of KTR event classes for which logging is enabled");
|
|
|
|
|
2013-02-04 21:58:57 +00:00
|
|
|
#if KTR_ENTRIES > KTR_BOOT_ENTRIES
|
2013-02-03 09:57:39 +00:00
|
|
|
/*
|
|
|
|
* A simplified version of sysctl_debug_ktr_entries.
|
|
|
|
* No need to care about SMP, scheduling, etc.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ktr_entries_initializer(void *dummy __unused)
|
|
|
|
{
|
|
|
|
int mask;
|
|
|
|
|
|
|
|
/* Temporarily disable ktr in case malloc() is being traced. */
|
|
|
|
mask = ktr_mask;
|
|
|
|
ktr_mask = 0;
|
|
|
|
ktr_buf = malloc(sizeof(*ktr_buf) * KTR_ENTRIES, M_KTR,
|
|
|
|
M_WAITOK | M_ZERO);
|
2013-02-08 07:29:07 +00:00
|
|
|
memcpy(ktr_buf, ktr_buf_init + ktr_idx,
|
|
|
|
(KTR_BOOT_ENTRIES - ktr_idx) * sizeof(*ktr_buf));
|
2014-03-22 22:35:57 +00:00
|
|
|
if (ktr_idx != 0) {
|
2013-02-08 07:29:07 +00:00
|
|
|
memcpy(ktr_buf + KTR_BOOT_ENTRIES - ktr_idx, ktr_buf_init,
|
|
|
|
ktr_idx * sizeof(*ktr_buf));
|
2014-03-22 22:35:57 +00:00
|
|
|
ktr_idx = KTR_BOOT_ENTRIES;
|
|
|
|
}
|
2013-02-03 09:57:39 +00:00
|
|
|
ktr_entries = KTR_ENTRIES;
|
|
|
|
ktr_mask = mask;
|
|
|
|
}
|
|
|
|
SYSINIT(ktr_entries_initializer, SI_SUB_KMEM, SI_ORDER_ANY,
|
|
|
|
ktr_entries_initializer, NULL);
|
|
|
|
#endif
|
|
|
|
|
2012-11-15 00:51:57 +00:00
|
|
|
static int
|
|
|
|
sysctl_debug_ktr_entries(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int entries, error, mask;
|
|
|
|
struct ktr_entry *buf, *oldbuf;
|
|
|
|
|
|
|
|
entries = ktr_entries;
|
|
|
|
error = sysctl_handle_int(oidp, &entries, 0, req);
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
if (entries > KTR_ENTRIES_MAX)
|
|
|
|
return (ERANGE);
|
|
|
|
/* Disable ktr temporarily. */
|
|
|
|
mask = ktr_mask;
|
|
|
|
atomic_store_rel_int(&ktr_mask, 0);
|
|
|
|
/* Wait for threads to go idle. */
|
|
|
|
if ((error = quiesce_all_cpus("ktrent", PCATCH)) != 0) {
|
|
|
|
ktr_mask = mask;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
if (ktr_buf != ktr_buf_init)
|
|
|
|
oldbuf = ktr_buf;
|
|
|
|
else
|
|
|
|
oldbuf = NULL;
|
|
|
|
/* Allocate a new buffer. */
|
|
|
|
buf = malloc(sizeof(*buf) * entries, M_KTR, M_WAITOK | M_ZERO);
|
|
|
|
/* Install the new buffer and restart ktr. */
|
|
|
|
ktr_buf = buf;
|
|
|
|
ktr_entries = entries;
|
|
|
|
ktr_idx = 0;
|
|
|
|
atomic_store_rel_int(&ktr_mask, mask);
|
|
|
|
if (oldbuf != NULL)
|
|
|
|
free(oldbuf, M_KTR);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCTL_PROC(_debug_ktr, OID_AUTO, entries, CTLTYPE_INT|CTLFLAG_RW, 0, 0,
|
|
|
|
sysctl_debug_ktr_entries, "I", "Number of entries in the KTR buffer");
|
|
|
|
|
2002-04-01 05:35:26 +00:00
|
|
|
#ifdef KTR_VERBOSE
|
|
|
|
int ktr_verbose = KTR_VERBOSE;
|
2001-06-08 05:24:21 +00:00
|
|
|
TUNABLE_INT("debug.ktr.verbose", &ktr_verbose);
|
2001-01-06 06:51:43 +00:00
|
|
|
SYSCTL_INT(_debug_ktr, OID_AUTO, verbose, CTLFLAG_RW, &ktr_verbose, 0, "");
|
2002-04-01 05:35:26 +00:00
|
|
|
#endif
|
2000-11-07 01:49:48 +00:00
|
|
|
|
2002-09-22 07:13:45 +00:00
|
|
|
#ifdef KTR_ALQ
|
|
|
|
struct alq *ktr_alq;
|
|
|
|
char ktr_alq_file[MAXPATHLEN] = "/tmp/ktr.out";
|
|
|
|
int ktr_alq_cnt = 0;
|
|
|
|
int ktr_alq_depth = KTR_ENTRIES;
|
|
|
|
int ktr_alq_enabled = 0;
|
|
|
|
int ktr_alq_failed = 0;
|
|
|
|
int ktr_alq_max = 0;
|
|
|
|
|
|
|
|
SYSCTL_INT(_debug_ktr, OID_AUTO, alq_max, CTLFLAG_RW, &ktr_alq_max, 0,
|
|
|
|
"Maximum number of entries to write");
|
|
|
|
SYSCTL_INT(_debug_ktr, OID_AUTO, alq_cnt, CTLFLAG_RD, &ktr_alq_cnt, 0,
|
|
|
|
"Current number of written entries");
|
|
|
|
SYSCTL_INT(_debug_ktr, OID_AUTO, alq_failed, CTLFLAG_RD, &ktr_alq_failed, 0,
|
|
|
|
"Number of times we overran the buffer");
|
|
|
|
SYSCTL_INT(_debug_ktr, OID_AUTO, alq_depth, CTLFLAG_RW, &ktr_alq_depth, 0,
|
|
|
|
"Number of items in the write buffer");
|
|
|
|
SYSCTL_STRING(_debug_ktr, OID_AUTO, alq_file, CTLFLAG_RW, ktr_alq_file,
|
|
|
|
sizeof(ktr_alq_file), "KTR logging file");
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_debug_ktr_alq_enable(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int enable;
|
|
|
|
|
|
|
|
enable = ktr_alq_enabled;
|
|
|
|
|
2006-01-27 23:06:08 +00:00
|
|
|
error = sysctl_handle_int(oidp, &enable, 0, req);
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
2002-09-22 07:13:45 +00:00
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
if (ktr_alq_enabled)
|
|
|
|
return (0);
|
2003-06-22 22:28:56 +00:00
|
|
|
error = alq_open(&ktr_alq, (const char *)ktr_alq_file,
|
2005-04-16 12:12:27 +00:00
|
|
|
req->td->td_ucred, ALQ_DEFAULT_CMODE,
|
|
|
|
sizeof(struct ktr_entry), ktr_alq_depth);
|
2002-09-22 07:13:45 +00:00
|
|
|
if (error == 0) {
|
|
|
|
ktr_alq_cnt = 0;
|
|
|
|
ktr_alq_failed = 0;
|
|
|
|
ktr_alq_enabled = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ktr_alq_enabled == 0)
|
|
|
|
return (0);
|
|
|
|
ktr_alq_enabled = 0;
|
|
|
|
alq_close(ktr_alq);
|
|
|
|
ktr_alq = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
SYSCTL_PROC(_debug_ktr, OID_AUTO, alq_enable,
|
|
|
|
CTLTYPE_INT|CTLFLAG_RW, 0, 0, sysctl_debug_ktr_alq_enable,
|
|
|
|
"I", "Enable KTR logging");
|
|
|
|
#endif
|
|
|
|
|
2000-11-07 01:49:48 +00:00
|
|
|
void
|
2002-04-01 05:35:26 +00:00
|
|
|
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)
|
2000-11-07 01:49:48 +00:00
|
|
|
{
|
|
|
|
struct ktr_entry *entry;
|
2002-09-22 07:13:45 +00:00
|
|
|
#ifdef KTR_ALQ
|
|
|
|
struct ale *ale = NULL;
|
|
|
|
#endif
|
2010-04-14 21:42:29 +00:00
|
|
|
int newindex, saveindex;
|
2002-09-22 07:13:45 +00:00
|
|
|
#if defined(KTR_VERBOSE) || defined(KTR_ALQ)
|
2001-12-13 10:33:20 +00:00
|
|
|
struct thread *td;
|
2000-11-07 01:49:48 +00:00
|
|
|
#endif
|
2002-04-01 05:35:26 +00:00
|
|
|
int cpu;
|
2000-11-07 01:49:48 +00:00
|
|
|
|
2014-07-02 22:13:07 +00:00
|
|
|
if (panicstr || kdb_active)
|
2000-12-12 00:43:50 +00:00
|
|
|
return;
|
2012-11-15 00:51:57 +00:00
|
|
|
if ((ktr_mask & mask) == 0 || ktr_buf == NULL)
|
2000-11-07 01:49:48 +00:00
|
|
|
return;
|
2002-03-08 18:55:59 +00:00
|
|
|
cpu = KTR_CPU;
|
2011-05-31 20:48:58 +00:00
|
|
|
if (!CPU_ISSET(cpu, &ktr_cpumask))
|
2001-06-25 23:09:31 +00:00
|
|
|
return;
|
2002-09-22 07:13:45 +00:00
|
|
|
#if defined(KTR_VERBOSE) || defined(KTR_ALQ)
|
2002-04-01 05:35:26 +00:00
|
|
|
td = curthread;
|
2003-06-09 17:38:32 +00:00
|
|
|
if (td->td_pflags & TDP_INKTR)
|
2002-04-01 05:35:26 +00:00
|
|
|
return;
|
2003-06-09 17:38:32 +00:00
|
|
|
td->td_pflags |= TDP_INKTR;
|
2002-04-01 05:35:26 +00:00
|
|
|
#endif
|
2002-09-22 07:13:45 +00:00
|
|
|
#ifdef KTR_ALQ
|
2010-04-14 21:42:29 +00:00
|
|
|
if (ktr_alq_enabled) {
|
|
|
|
if (td->td_critnest == 0 &&
|
|
|
|
(td->td_flags & TDF_IDLETD) == 0 &&
|
|
|
|
td != ald_thread) {
|
|
|
|
if (ktr_alq_max && ktr_alq_cnt > ktr_alq_max)
|
|
|
|
goto done;
|
|
|
|
if ((ale = alq_get(ktr_alq, ALQ_NOWAIT)) == NULL) {
|
|
|
|
ktr_alq_failed++;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
ktr_alq_cnt++;
|
|
|
|
entry = (struct ktr_entry *)ale->ae_data;
|
|
|
|
} else {
|
2002-09-22 07:13:45 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
2010-04-14 21:42:29 +00:00
|
|
|
{
|
|
|
|
do {
|
|
|
|
saveindex = ktr_idx;
|
2012-11-15 00:51:57 +00:00
|
|
|
newindex = (saveindex + 1) % ktr_entries;
|
2010-04-14 21:42:29 +00:00
|
|
|
} while (atomic_cmpset_rel_int(&ktr_idx, saveindex, newindex) == 0);
|
|
|
|
entry = &ktr_buf[saveindex];
|
|
|
|
}
|
2002-04-01 05:35:26 +00:00
|
|
|
entry->ktr_timestamp = KTR_TIME;
|
2002-03-08 18:55:59 +00:00
|
|
|
entry->ktr_cpu = cpu;
|
2005-06-10 23:21:29 +00:00
|
|
|
entry->ktr_thread = curthread;
|
2003-03-11 19:56:16 +00:00
|
|
|
if (file != NULL)
|
|
|
|
while (strncmp(file, "../", 3) == 0)
|
|
|
|
file += 3;
|
2002-04-01 05:35:26 +00:00
|
|
|
entry->ktr_file = file;
|
2000-11-07 01:49:48 +00:00
|
|
|
entry->ktr_line = line;
|
2002-04-01 05:35:26 +00:00
|
|
|
#ifdef KTR_VERBOSE
|
2000-11-07 01:49:48 +00:00
|
|
|
if (ktr_verbose) {
|
2000-11-15 21:51:53 +00:00
|
|
|
#ifdef SMP
|
2002-04-01 05:35:26 +00:00
|
|
|
printf("cpu%d ", cpu);
|
2000-11-15 21:51:53 +00:00
|
|
|
#endif
|
2002-04-01 05:35:26 +00:00
|
|
|
if (ktr_verbose > 1) {
|
|
|
|
printf("%s.%d\t", entry->ktr_file,
|
|
|
|
entry->ktr_line);
|
|
|
|
}
|
|
|
|
printf(format, arg1, arg2, arg3, arg4, arg5, arg6);
|
2000-11-07 01:49:48 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2002-04-01 05:35:26 +00:00
|
|
|
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;
|
2002-09-22 07:13:45 +00:00
|
|
|
#ifdef KTR_ALQ
|
2010-04-14 21:42:29 +00:00
|
|
|
if (ktr_alq_enabled && ale)
|
2002-09-22 07:13:45 +00:00
|
|
|
alq_post(ktr_alq, ale);
|
|
|
|
done:
|
|
|
|
#endif
|
|
|
|
#if defined(KTR_VERBOSE) || defined(KTR_ALQ)
|
2003-06-09 17:38:32 +00:00
|
|
|
td->td_pflags &= ~TDP_INKTR;
|
2002-04-01 05:35:26 +00:00
|
|
|
#endif
|
2000-11-07 01:49:48 +00:00
|
|
|
}
|
2000-12-15 00:01:20 +00:00
|
|
|
|
|
|
|
#ifdef DDB
|
|
|
|
|
|
|
|
struct tstate {
|
|
|
|
int cur;
|
|
|
|
int first;
|
|
|
|
};
|
|
|
|
static struct tstate tstate;
|
|
|
|
static int db_ktr_verbose;
|
|
|
|
static int db_mach_vtrace(void);
|
|
|
|
|
2001-02-20 09:53:27 +00:00
|
|
|
DB_SHOW_COMMAND(ktr, db_ktr_all)
|
2000-12-15 00:01:20 +00:00
|
|
|
{
|
2003-07-31 17:29:42 +00:00
|
|
|
|
2012-11-15 00:51:57 +00:00
|
|
|
tstate.cur = (ktr_idx - 1) % ktr_entries;
|
2000-12-15 00:01:20 +00:00
|
|
|
tstate.first = -1;
|
2010-04-14 21:42:29 +00:00
|
|
|
db_ktr_verbose = 0;
|
2012-01-02 12:12:10 +00:00
|
|
|
db_ktr_verbose |= (strchr(modif, 'v') != NULL) ? 2 : 0;
|
|
|
|
db_ktr_verbose |= (strchr(modif, 'V') != NULL) ? 1 : 0; /* just timestap please */
|
|
|
|
if (strchr(modif, 'a') != NULL) {
|
2006-07-12 21:22:44 +00:00
|
|
|
db_disable_pager();
|
2003-07-31 17:29:42 +00:00
|
|
|
while (cncheckc() != -1)
|
|
|
|
if (db_mach_vtrace() == 0)
|
2001-02-20 09:53:27 +00:00
|
|
|
break;
|
2003-07-31 17:29:42 +00:00
|
|
|
} else {
|
2006-07-12 21:22:44 +00:00
|
|
|
while (!db_pager_quit)
|
2003-07-31 17:29:42 +00:00
|
|
|
if (db_mach_vtrace() == 0)
|
2001-02-20 09:53:27 +00:00
|
|
|
break;
|
2003-07-31 17:29:42 +00:00
|
|
|
}
|
2000-12-15 00:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
db_mach_vtrace(void)
|
|
|
|
{
|
|
|
|
struct ktr_entry *kp;
|
|
|
|
|
2012-11-15 00:51:57 +00:00
|
|
|
if (tstate.cur == tstate.first || ktr_buf == NULL) {
|
2000-12-15 00:01:20 +00:00
|
|
|
db_printf("--- End of trace buffer ---\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
kp = &ktr_buf[tstate.cur];
|
|
|
|
|
|
|
|
/* Skip over unused entries. */
|
2001-02-20 09:53:27 +00:00
|
|
|
if (kp->ktr_desc == NULL) {
|
|
|
|
db_printf("--- End of trace buffer ---\n");
|
|
|
|
return (0);
|
|
|
|
}
|
2005-06-10 23:21:29 +00:00
|
|
|
db_printf("%d (%p", tstate.cur, kp->ktr_thread);
|
2000-12-15 00:01:20 +00:00
|
|
|
#ifdef SMP
|
2005-06-10 23:21:29 +00:00
|
|
|
db_printf(":cpu%d", kp->ktr_cpu);
|
2000-12-15 00:01:20 +00:00
|
|
|
#endif
|
2005-06-10 23:21:29 +00:00
|
|
|
db_printf(")");
|
2010-04-14 21:42:29 +00:00
|
|
|
if (db_ktr_verbose >= 1) {
|
|
|
|
db_printf(" %10.10lld", (long long)kp->ktr_timestamp);
|
|
|
|
}
|
|
|
|
if (db_ktr_verbose >= 2) {
|
|
|
|
db_printf(" %s.%d", kp->ktr_file, kp->ktr_line);
|
2002-04-01 05:35:26 +00:00
|
|
|
}
|
2005-06-10 23:21:29 +00:00
|
|
|
db_printf(": ");
|
2002-04-01 05:35:26 +00:00
|
|
|
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]);
|
2001-02-20 09:53:27 +00:00
|
|
|
db_printf("\n");
|
2000-12-15 00:01:20 +00:00
|
|
|
|
|
|
|
if (tstate.first == -1)
|
|
|
|
tstate.first = tstate.cur;
|
|
|
|
|
|
|
|
if (--tstate.cur < 0)
|
2012-11-15 00:51:57 +00:00
|
|
|
tstate.cur = ktr_entries - 1;
|
2000-12-15 00:01:20 +00:00
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DDB */
|