summaryrefslogtreecommitdiffstats
path: root/sys/conf
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2002-06-07 05:32:59 +0000
committerjhb <jhb@FreeBSD.org>2002-06-07 05:32:59 +0000
commitab80d12ef1c521cbfb58560aa8d6071aca990d9d (patch)
tree9e3ef22a1b70a7a5c637cc6af818636e553c02f2 /sys/conf
parent92c9b7b198a242afda19ce34dea9c5acf04bd2b0 (diff)
downloadFreeBSD-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/conf')
-rw-r--r--sys/conf/NOTES9
-rw-r--r--sys/conf/options1
2 files changed, 9 insertions, 1 deletions
diff --git a/sys/conf/NOTES b/sys/conf/NOTES
index 9b945a5..2cada40 100644
--- a/sys/conf/NOTES
+++ b/sys/conf/NOTES
@@ -216,9 +216,16 @@ options DDB_UNATTENDED
options GDB_REMOTE_CHAT
#
-# KTRACE enables the system-call tracing facility ktrace(2).
+# KTRACE enables the system-call tracing facility ktrace(2). To be more
+# SMP-friendly, KTRACE uses a worker thread to process most trace events
+# asynchronously to the thread generating the event. This requires a
+# pre-allocated store of objects representing trace events. The
+# KTRACE_REQUEST_POOL option specifies the initial size of this store.
+# The size of the pool can be adjusted both at boottime and runtime via
+# the kern.ktrace_request_pool tunable and sysctl.
#
options KTRACE #kernel tracing
+options KTRACE_REQUEST_POOL=101
#
# KTR is a kernel tracing mechanism imported from BSD/OS. Currently it
diff --git a/sys/conf/options b/sys/conf/options
index cc09da6..b339496 100644
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -77,6 +77,7 @@ GDB_REMOTE_CHAT opt_ddb.h
NODEVFS opt_devfs.h
HW_WDOG
KTRACE
+KTRACE_REQUEST_POOL opt_ktrace.h # Size of ktrace request pool
LIBICONV
MD_ROOT opt_md.h
MD_ROOT_SIZE opt_md.h
OpenPOWER on IntegriCloud