diff options
author | jhb <jhb@FreeBSD.org> | 2002-06-07 05:32:59 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2002-06-07 05:32:59 +0000 |
commit | ab80d12ef1c521cbfb58560aa8d6071aca990d9d (patch) | |
tree | 9e3ef22a1b70a7a5c637cc6af818636e553c02f2 /sys/sys | |
parent | 92c9b7b198a242afda19ce34dea9c5acf04bd2b0 (diff) | |
download | FreeBSD-src-ab80d12ef1c521cbfb58560aa8d6071aca990d9d.zip FreeBSD-src-ab80d12ef1c521cbfb58560aa8d6071aca990d9d.tar.gz |
Overhaul the ktrace subsystem a bit. For the most part, the actual vnode
operations to dump a ktrace event out to an output file are now handled
asychronously by a ktrace worker thread. This enables most ktrace events
to not need Giant once p_tracep and p_traceflag are suitably protected by
the new ktrace_lock.
There is a single todo list of pending ktrace requests. The various
ktrace tracepoints allocate a ktrace request object and tack it onto the
end of the queue. The ktrace kernel thread grabs requests off the head of
the queue and processes them using the trace vnode and credentials of the
thread triggering the event.
Since we cannot assume that the user memory referenced when doing a
ktrgenio() will be valid and since we can't access it from the ktrace
worker thread without a bit of hassle anyways, ktrgenio() requests are
still handled synchronously. However, in order to ensure that the requests
from a given thread still maintain relative order to one another, when a
synchronous ktrace event (such as a genio event) is triggered, we still put
the request object on the todo list to synchronize with the worker thread.
The original thread blocks atomically with putting the item on the queue.
When the worker thread comes across an asynchronous request, it wakes up
the original thread and then blocks to ensure it doesn't manage to write a
later event before the original thread has a chance to write out the
synchronous event. When the original thread wakes up, it writes out the
synchronous using its own context and then finally wakes the worker thread
back up. Yuck. The sychronous events aren't pretty but they do work.
Since ktrace events can be triggered in fairly low-level areas (msleep()
and cv_wait() for example) the ktrace code is designed to use very few
locks when posting an event (currently just the ktrace_mtx lock and the
vnode interlock to bump the refcoun on the trace vnode). This also means
that we can't allocate a ktrace request object when an event is triggered.
Instead, ktrace request objects are allocated from a pre-allocated pool
and returned to the pool after a request is serviced.
The size of this pool defaults to 100 objects, which is about 13k on an
i386 kernel. The size of the pool can be adjusted at compile time via the
KTRACE_REQUEST_POOL kernel option, at boot time via the
kern.ktrace_request_pool loader tunable, or at runtime via the
kern.ktrace_request_pool sysctl.
If the pool of request objects is exhausted, then a warning message is
printed to the console. The message is rate-limited in that it is only
printed once until the size of the pool is adjusted via the sysctl.
I have tested all kernel traces but have not tested user traces submitted
by utrace(2), though they should work fine in theory.
Since a ktrace request has several properties (content of event, trace
vnode, details of originating process, credentials for I/O, etc.), I chose
to drop the first argument to the various ktrfoo() functions. Currently
the functions just assume the event is posted from curthread. If there is
a great desire to do so, I suppose I could instead put back the first
argument but this time make it a thread pointer instead of a vnode pointer.
Also, KTRPOINT() now takes a thread as its first argument instead of a
process. This is because the check for a recursive ktrace event is now
per-thread instead of process-wide.
Tested on: i386
Compiles on: sparc64, alpha
Diffstat (limited to 'sys/sys')
-rw-r--r-- | sys/sys/ktrace.h | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index e72a4cb..2970ce0 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -58,14 +58,19 @@ struct ktr_header { pid_t ktr_pid; /* process id */ char ktr_comm[MAXCOMLEN+1]; /* command name */ struct timeval ktr_time; /* timestamp */ - caddr_t ktr_buffer; + void *ktr_buffer; }; /* - * Test for kernel trace point (MP SAFE) + * Test for kernel trace point (MP SAFE). + * + * KTRCHECK() just checks that the type is enabled and is only for + * internal use in the ktrace subsystem. KTRPOINT() checks against + * ktrace recursion as well as checking that the type is enabled and + * is the public interface. */ -#define KTRPOINT(p, type) \ - (((p)->p_traceflag & ((1<<(type))|KTRFAC_ACTIVE)) == (1<<(type))) +#define KTRCHECK(td, type) ((td)->td_proc->p_traceflag & (1 << type)) +#define KTRPOINT(td, type) (KTRCHECK((td), (type)) && !(td)->td_inktrace) /* * ktrace record types @@ -155,15 +160,16 @@ struct ktr_csw { */ #define KTRFAC_ROOT 0x80000000 /* root set this trace */ #define KTRFAC_INHERIT 0x40000000 /* pass trace flags to children */ -#define KTRFAC_ACTIVE 0x20000000 /* ktrace logging in progress, ignore */ #ifdef _KERNEL -void ktrnamei(struct vnode *,char *); -void ktrcsw(struct vnode *,int,int); -void ktrpsig(struct vnode *, int, sig_t, sigset_t *, int); -void ktrgenio(struct vnode *, int, enum uio_rw, struct uio *, int); -void ktrsyscall(struct vnode *, int, int narg, register_t args[]); -void ktrsysret(struct vnode *, int, int, register_t); +extern struct mtx ktrace_mtx; + +void ktrnamei(char *); +void ktrcsw(int, int); +void ktrpsig(int, sig_t, sigset_t *, int); +void ktrgenio(int, enum uio_rw, struct uio *, int); +void ktrsyscall(int, int narg, register_t args[]); +void ktrsysret(int, int, register_t); #else |