freebsd-nq/sys/conf
John Baldwin ea3fc8e4cd 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
2002-06-07 05:32:59 +00:00
..
defines
files 'device hea' is no longer broken. 2002-06-07 02:04:09 +00:00
files.alpha ${MACHINE_ARCH}dump.c -> dump_machdep.c. 2002-05-13 02:40:21 +00:00
files.i386 Added support for 82545EM and 82546EB based adapters. 2002-06-03 22:30:51 +00:00
files.ia64 ${MACHINE_ARCH}dump.c -> dump_machdep.c. 2002-05-13 02:40:21 +00:00
files.pc98 Added support for 82545EM and 82546EB based adapters. 2002-06-03 22:30:51 +00:00
files.powerpc Build the fpu support routines. 2002-05-13 07:53:22 +00:00
files.sparc64 Merge the code in pv.c into pmap.c directly. Place all page mappings onto 2002-05-29 06:08:45 +00:00
kern.mk For now, make the .ifdef GCC3 case default. We should change -Wno-format 2002-05-24 01:02:45 +00:00
kern.post.mk Fixed broken ``make -jX install''. 2002-05-23 07:25:01 +00:00
kern.pre.mk Translated -malign-functions=4 to -falign-functions=16 for the new gcc. 2002-05-12 15:51:38 +00:00
kmod_syms.awk Respect setting of NM to allow cross-building. 2002-04-19 09:04:53 +00:00
kmod.mk Check that kldxref(8) exists before running it. 2002-05-14 07:49:12 +00:00
ldscript.alpha Use the kernbase symbol exported from locore.o instead of hardcoded magic 2001-09-20 09:19:38 +00:00
ldscript.amd64 Remove hard coded magic load address. Now to change the load address, 2001-09-18 01:12:43 +00:00
ldscript.i386 Remove hard coded magic load address. Now to change the load address, 2001-09-18 01:12:43 +00:00
ldscript.ia64 Put symbols at the start and end of the unwind section so that we can 2001-10-29 11:40:14 +00:00
ldscript.powerpc Page align the data segment. 2001-10-08 10:43:34 +00:00
ldscript.sparc64 Add kernbase symbol and use it instead of magic numbers in the 2001-09-21 05:43:38 +00:00
majors Grab a major number for OpenFirmware disk devices. 2002-04-15 10:41:47 +00:00
Makefile.alpha Commit some infrastructure for turning on -Werror for kernel compiles. 2002-02-20 23:35:56 +00:00
Makefile.i386 Commit some infrastructure for turning on -Werror for kernel compiles. 2002-02-20 23:35:56 +00:00
Makefile.ia64 Remove CWARNFLAGS and add GCC3. We handle GCC3.x specific flags 2002-05-19 03:41:48 +00:00
Makefile.pc98 Commit some infrastructure for turning on -Werror for kernel compiles. 2002-02-20 23:35:56 +00:00
Makefile.powerpc Remove the setting of 'FMT'. We now do ELF by default, so only bother 2002-03-24 17:45:46 +00:00
Makefile.sparc64 Remove a hack for using an external compiler if cross compiling. 2002-05-26 15:55:28 +00:00
makeLINT.sed Join the pissing contest: generate LINT with a single sed(1) command. 2002-05-02 16:34:47 +00:00
newvers.sh setlocale(3) has been fixed to match POSIX standard: 2001-03-02 16:52:14 +00:00
NOTES Overhaul the ktrace subsystem a bit. For the most part, the actual vnode 2002-06-07 05:32:59 +00:00
options Overhaul the ktrace subsystem a bit. For the most part, the actual vnode 2002-06-07 05:32:59 +00:00
options.alpha More s/file system/filesystem/g 2002-05-16 21:28:32 +00:00
options.i386 More s/file system/filesystem/g 2002-05-16 21:28:32 +00:00
options.ia64 Allow a kernel to be compiled with both SKI and acpica and still 2002-04-14 04:33:41 +00:00
options.pc98 Remove unneeded entries. 2002-05-19 13:18:10 +00:00
options.powerpc Add a cosmetic comment. 2001-08-02 23:54:23 +00:00
options.sparc64 Add a DEBUGGER_ON_POWERFAIL option. This makes the power button on ultra 10s 2002-03-13 05:58:45 +00:00
systags.sh