xref: /freebsd/sys/kern/subr_lock.c (revision a98ff317388a00b992f1bf8404dee596f9383f5e)
1 /*-
2  * Copyright (c) 2006 John Baldwin <jhb@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the author nor the names of any co-contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 /*
31  * This module holds the global variables and functions used to maintain
32  * lock_object structures.
33  */
34 
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37 
38 #include "opt_ddb.h"
39 #include "opt_mprof.h"
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/ktr.h>
45 #include <sys/lock.h>
46 #include <sys/lock_profile.h>
47 #include <sys/malloc.h>
48 #include <sys/mutex.h>
49 #include <sys/pcpu.h>
50 #include <sys/proc.h>
51 #include <sys/sbuf.h>
52 #include <sys/sched.h>
53 #include <sys/smp.h>
54 #include <sys/sysctl.h>
55 
56 #ifdef DDB
57 #include <ddb/ddb.h>
58 #endif
59 
60 #include <machine/cpufunc.h>
61 
62 CTASSERT(LOCK_CLASS_MAX == 15);
63 
64 struct lock_class *lock_classes[LOCK_CLASS_MAX + 1] = {
65 	&lock_class_mtx_spin,
66 	&lock_class_mtx_sleep,
67 	&lock_class_sx,
68 	&lock_class_rm,
69 	&lock_class_rm_sleepable,
70 	&lock_class_rw,
71 	&lock_class_lockmgr,
72 };
73 
74 void
75 lock_init(struct lock_object *lock, struct lock_class *class, const char *name,
76     const char *type, int flags)
77 {
78 	int i;
79 
80 	/* Check for double-init and zero object. */
81 	KASSERT(!lock_initalized(lock), ("lock \"%s\" %p already initialized",
82 	    name, lock));
83 
84 	/* Look up lock class to find its index. */
85 	for (i = 0; i < LOCK_CLASS_MAX; i++)
86 		if (lock_classes[i] == class) {
87 			lock->lo_flags = i << LO_CLASSSHIFT;
88 			break;
89 		}
90 	KASSERT(i < LOCK_CLASS_MAX, ("unknown lock class %p", class));
91 
92 	/* Initialize the lock object. */
93 	lock->lo_name = name;
94 	lock->lo_flags |= flags | LO_INITIALIZED;
95 	LOCK_LOG_INIT(lock, 0);
96 	WITNESS_INIT(lock, (type != NULL) ? type : name);
97 }
98 
99 void
100 lock_destroy(struct lock_object *lock)
101 {
102 
103 	KASSERT(lock_initalized(lock), ("lock %p is not initialized", lock));
104 	WITNESS_DESTROY(lock);
105 	LOCK_LOG_DESTROY(lock, 0);
106 	lock->lo_flags &= ~LO_INITIALIZED;
107 }
108 
109 #ifdef DDB
110 DB_SHOW_COMMAND(lock, db_show_lock)
111 {
112 	struct lock_object *lock;
113 	struct lock_class *class;
114 
115 	if (!have_addr)
116 		return;
117 	lock = (struct lock_object *)addr;
118 	if (LO_CLASSINDEX(lock) > LOCK_CLASS_MAX) {
119 		db_printf("Unknown lock class: %d\n", LO_CLASSINDEX(lock));
120 		return;
121 	}
122 	class = LOCK_CLASS(lock);
123 	db_printf(" class: %s\n", class->lc_name);
124 	db_printf(" name: %s\n", lock->lo_name);
125 	class->lc_ddb_show(lock);
126 }
127 #endif
128 
129 #ifdef LOCK_PROFILING
130 
131 /*
132  * One object per-thread for each lock the thread owns.  Tracks individual
133  * lock instances.
134  */
135 struct lock_profile_object {
136 	LIST_ENTRY(lock_profile_object) lpo_link;
137 	struct lock_object *lpo_obj;
138 	const char	*lpo_file;
139 	int		lpo_line;
140 	uint16_t	lpo_ref;
141 	uint16_t	lpo_cnt;
142 	uint64_t	lpo_acqtime;
143 	uint64_t	lpo_waittime;
144 	u_int		lpo_contest_locking;
145 };
146 
147 /*
148  * One lock_prof for each (file, line, lock object) triple.
149  */
150 struct lock_prof {
151 	SLIST_ENTRY(lock_prof) link;
152 	struct lock_class *class;
153 	const char	*file;
154 	const char	*name;
155 	int		line;
156 	int		ticks;
157 	uintmax_t	cnt_wait_max;
158 	uintmax_t	cnt_max;
159 	uintmax_t	cnt_tot;
160 	uintmax_t	cnt_wait;
161 	uintmax_t	cnt_cur;
162 	uintmax_t	cnt_contest_locking;
163 };
164 
165 SLIST_HEAD(lphead, lock_prof);
166 
167 #define	LPROF_HASH_SIZE		4096
168 #define	LPROF_HASH_MASK		(LPROF_HASH_SIZE - 1)
169 #define	LPROF_CACHE_SIZE	4096
170 
171 /*
172  * Array of objects and profs for each type of object for each cpu.  Spinlocks
173  * are handled separately because a thread may be preempted and acquire a
174  * spinlock while in the lock profiling code of a non-spinlock.  In this way
175  * we only need a critical section to protect the per-cpu lists.
176  */
177 struct lock_prof_type {
178 	struct lphead		lpt_lpalloc;
179 	struct lpohead		lpt_lpoalloc;
180 	struct lphead		lpt_hash[LPROF_HASH_SIZE];
181 	struct lock_prof	lpt_prof[LPROF_CACHE_SIZE];
182 	struct lock_profile_object lpt_objs[LPROF_CACHE_SIZE];
183 };
184 
185 struct lock_prof_cpu {
186 	struct lock_prof_type	lpc_types[2]; /* One for spin one for other. */
187 };
188 
189 struct lock_prof_cpu *lp_cpu[MAXCPU];
190 
191 volatile int lock_prof_enable = 0;
192 static volatile int lock_prof_resetting;
193 
194 #define LPROF_SBUF_SIZE		256
195 
196 static int lock_prof_rejected;
197 static int lock_prof_skipspin;
198 static int lock_prof_skipcount;
199 
200 #ifndef USE_CPU_NANOSECONDS
201 uint64_t
202 nanoseconds(void)
203 {
204 	struct bintime bt;
205 	uint64_t ns;
206 
207 	binuptime(&bt);
208 	/* From bintime2timespec */
209 	ns = bt.sec * (uint64_t)1000000000;
210 	ns += ((uint64_t)1000000000 * (uint32_t)(bt.frac >> 32)) >> 32;
211 	return (ns);
212 }
213 #endif
214 
215 static void
216 lock_prof_init_type(struct lock_prof_type *type)
217 {
218 	int i;
219 
220 	SLIST_INIT(&type->lpt_lpalloc);
221 	LIST_INIT(&type->lpt_lpoalloc);
222 	for (i = 0; i < LPROF_CACHE_SIZE; i++) {
223 		SLIST_INSERT_HEAD(&type->lpt_lpalloc, &type->lpt_prof[i],
224 		    link);
225 		LIST_INSERT_HEAD(&type->lpt_lpoalloc, &type->lpt_objs[i],
226 		    lpo_link);
227 	}
228 }
229 
230 static void
231 lock_prof_init(void *arg)
232 {
233 	int cpu;
234 
235 	for (cpu = 0; cpu <= mp_maxid; cpu++) {
236 		lp_cpu[cpu] = malloc(sizeof(*lp_cpu[cpu]), M_DEVBUF,
237 		    M_WAITOK | M_ZERO);
238 		lock_prof_init_type(&lp_cpu[cpu]->lpc_types[0]);
239 		lock_prof_init_type(&lp_cpu[cpu]->lpc_types[1]);
240 	}
241 }
242 SYSINIT(lockprof, SI_SUB_SMP, SI_ORDER_ANY, lock_prof_init, NULL);
243 
244 static void
245 lock_prof_reset_wait(void)
246 {
247 
248 	/*
249 	 * Spin relinquishing our cpu so that quiesce_all_cpus may
250 	 * complete.
251 	 */
252 	while (lock_prof_resetting)
253 		sched_relinquish(curthread);
254 }
255 
256 static void
257 lock_prof_reset(void)
258 {
259 	struct lock_prof_cpu *lpc;
260 	int enabled, i, cpu;
261 
262 	/*
263 	 * We not only race with acquiring and releasing locks but also
264 	 * thread exit.  To be certain that threads exit without valid head
265 	 * pointers they must see resetting set before enabled is cleared.
266 	 * Otherwise a lock may not be removed from a per-thread list due
267 	 * to disabled being set but not wait for reset() to remove it below.
268 	 */
269 	atomic_store_rel_int(&lock_prof_resetting, 1);
270 	enabled = lock_prof_enable;
271 	lock_prof_enable = 0;
272 	quiesce_all_cpus("profreset", 0);
273 	/*
274 	 * Some objects may have migrated between CPUs.  Clear all links
275 	 * before we zero the structures.  Some items may still be linked
276 	 * into per-thread lists as well.
277 	 */
278 	for (cpu = 0; cpu <= mp_maxid; cpu++) {
279 		lpc = lp_cpu[cpu];
280 		for (i = 0; i < LPROF_CACHE_SIZE; i++) {
281 			LIST_REMOVE(&lpc->lpc_types[0].lpt_objs[i], lpo_link);
282 			LIST_REMOVE(&lpc->lpc_types[1].lpt_objs[i], lpo_link);
283 		}
284 	}
285 	for (cpu = 0; cpu <= mp_maxid; cpu++) {
286 		lpc = lp_cpu[cpu];
287 		bzero(lpc, sizeof(*lpc));
288 		lock_prof_init_type(&lpc->lpc_types[0]);
289 		lock_prof_init_type(&lpc->lpc_types[1]);
290 	}
291 	atomic_store_rel_int(&lock_prof_resetting, 0);
292 	lock_prof_enable = enabled;
293 }
294 
295 static void
296 lock_prof_output(struct lock_prof *lp, struct sbuf *sb)
297 {
298 	const char *p;
299 
300 	for (p = lp->file; p != NULL && strncmp(p, "../", 3) == 0; p += 3);
301 	sbuf_printf(sb,
302 	    "%8ju %9ju %11ju %11ju %11ju %6ju %6ju %2ju %6ju %s:%d (%s:%s)\n",
303 	    lp->cnt_max / 1000, lp->cnt_wait_max / 1000, lp->cnt_tot / 1000,
304 	    lp->cnt_wait / 1000, lp->cnt_cur,
305 	    lp->cnt_cur == 0 ? (uintmax_t)0 :
306 	    lp->cnt_tot / (lp->cnt_cur * 1000),
307 	    lp->cnt_cur == 0 ? (uintmax_t)0 :
308 	    lp->cnt_wait / (lp->cnt_cur * 1000),
309 	    (uintmax_t)0, lp->cnt_contest_locking,
310 	    p, lp->line, lp->class->lc_name, lp->name);
311 }
312 
313 static void
314 lock_prof_sum(struct lock_prof *match, struct lock_prof *dst, int hash,
315     int spin, int t)
316 {
317 	struct lock_prof_type *type;
318 	struct lock_prof *l;
319 	int cpu;
320 
321 	dst->file = match->file;
322 	dst->line = match->line;
323 	dst->class = match->class;
324 	dst->name = match->name;
325 
326 	for (cpu = 0; cpu <= mp_maxid; cpu++) {
327 		if (lp_cpu[cpu] == NULL)
328 			continue;
329 		type = &lp_cpu[cpu]->lpc_types[spin];
330 		SLIST_FOREACH(l, &type->lpt_hash[hash], link) {
331 			if (l->ticks == t)
332 				continue;
333 			if (l->file != match->file || l->line != match->line ||
334 			    l->name != match->name)
335 				continue;
336 			l->ticks = t;
337 			if (l->cnt_max > dst->cnt_max)
338 				dst->cnt_max = l->cnt_max;
339 			if (l->cnt_wait_max > dst->cnt_wait_max)
340 				dst->cnt_wait_max = l->cnt_wait_max;
341 			dst->cnt_tot += l->cnt_tot;
342 			dst->cnt_wait += l->cnt_wait;
343 			dst->cnt_cur += l->cnt_cur;
344 			dst->cnt_contest_locking += l->cnt_contest_locking;
345 		}
346 	}
347 
348 }
349 
350 static void
351 lock_prof_type_stats(struct lock_prof_type *type, struct sbuf *sb, int spin,
352     int t)
353 {
354 	struct lock_prof *l;
355 	int i;
356 
357 	for (i = 0; i < LPROF_HASH_SIZE; ++i) {
358 		SLIST_FOREACH(l, &type->lpt_hash[i], link) {
359 			struct lock_prof lp = {};
360 
361 			if (l->ticks == t)
362 				continue;
363 			lock_prof_sum(l, &lp, i, spin, t);
364 			lock_prof_output(&lp, sb);
365 		}
366 	}
367 }
368 
369 static int
370 dump_lock_prof_stats(SYSCTL_HANDLER_ARGS)
371 {
372 	struct sbuf *sb;
373 	int error, cpu, t;
374 	int enabled;
375 
376 	error = sysctl_wire_old_buffer(req, 0);
377 	if (error != 0)
378 		return (error);
379 	sb = sbuf_new_for_sysctl(NULL, NULL, LPROF_SBUF_SIZE, req);
380 	sbuf_printf(sb, "\n%8s %9s %11s %11s %11s %6s %6s %2s %6s %s\n",
381 	    "max", "wait_max", "total", "wait_total", "count", "avg", "wait_avg", "cnt_hold", "cnt_lock", "name");
382 	enabled = lock_prof_enable;
383 	lock_prof_enable = 0;
384 	quiesce_all_cpus("profstat", 0);
385 	t = ticks;
386 	for (cpu = 0; cpu <= mp_maxid; cpu++) {
387 		if (lp_cpu[cpu] == NULL)
388 			continue;
389 		lock_prof_type_stats(&lp_cpu[cpu]->lpc_types[0], sb, 0, t);
390 		lock_prof_type_stats(&lp_cpu[cpu]->lpc_types[1], sb, 1, t);
391 	}
392 	lock_prof_enable = enabled;
393 
394 	error = sbuf_finish(sb);
395 	/* Output a trailing NUL. */
396 	if (error == 0)
397 		error = SYSCTL_OUT(req, "", 1);
398 	sbuf_delete(sb);
399 	return (error);
400 }
401 
402 static int
403 enable_lock_prof(SYSCTL_HANDLER_ARGS)
404 {
405 	int error, v;
406 
407 	v = lock_prof_enable;
408 	error = sysctl_handle_int(oidp, &v, v, req);
409 	if (error)
410 		return (error);
411 	if (req->newptr == NULL)
412 		return (error);
413 	if (v == lock_prof_enable)
414 		return (0);
415 	if (v == 1)
416 		lock_prof_reset();
417 	lock_prof_enable = !!v;
418 
419 	return (0);
420 }
421 
422 static int
423 reset_lock_prof_stats(SYSCTL_HANDLER_ARGS)
424 {
425 	int error, v;
426 
427 	v = 0;
428 	error = sysctl_handle_int(oidp, &v, 0, req);
429 	if (error)
430 		return (error);
431 	if (req->newptr == NULL)
432 		return (error);
433 	if (v == 0)
434 		return (0);
435 	lock_prof_reset();
436 
437 	return (0);
438 }
439 
440 static struct lock_prof *
441 lock_profile_lookup(struct lock_object *lo, int spin, const char *file,
442     int line)
443 {
444 	const char *unknown = "(unknown)";
445 	struct lock_prof_type *type;
446 	struct lock_prof *lp;
447 	struct lphead *head;
448 	const char *p;
449 	u_int hash;
450 
451 	p = file;
452 	if (p == NULL || *p == '\0')
453 		p = unknown;
454 	hash = (uintptr_t)lo->lo_name * 31 + (uintptr_t)p * 31 + line;
455 	hash &= LPROF_HASH_MASK;
456 	type = &lp_cpu[PCPU_GET(cpuid)]->lpc_types[spin];
457 	head = &type->lpt_hash[hash];
458 	SLIST_FOREACH(lp, head, link) {
459 		if (lp->line == line && lp->file == p &&
460 		    lp->name == lo->lo_name)
461 			return (lp);
462 
463 	}
464 	lp = SLIST_FIRST(&type->lpt_lpalloc);
465 	if (lp == NULL) {
466 		lock_prof_rejected++;
467 		return (lp);
468 	}
469 	SLIST_REMOVE_HEAD(&type->lpt_lpalloc, link);
470 	lp->file = p;
471 	lp->line = line;
472 	lp->class = LOCK_CLASS(lo);
473 	lp->name = lo->lo_name;
474 	SLIST_INSERT_HEAD(&type->lpt_hash[hash], lp, link);
475 	return (lp);
476 }
477 
478 static struct lock_profile_object *
479 lock_profile_object_lookup(struct lock_object *lo, int spin, const char *file,
480     int line)
481 {
482 	struct lock_profile_object *l;
483 	struct lock_prof_type *type;
484 	struct lpohead *head;
485 
486 	head = &curthread->td_lprof[spin];
487 	LIST_FOREACH(l, head, lpo_link)
488 		if (l->lpo_obj == lo && l->lpo_file == file &&
489 		    l->lpo_line == line)
490 			return (l);
491 	type = &lp_cpu[PCPU_GET(cpuid)]->lpc_types[spin];
492 	l = LIST_FIRST(&type->lpt_lpoalloc);
493 	if (l == NULL) {
494 		lock_prof_rejected++;
495 		return (NULL);
496 	}
497 	LIST_REMOVE(l, lpo_link);
498 	l->lpo_obj = lo;
499 	l->lpo_file = file;
500 	l->lpo_line = line;
501 	l->lpo_cnt = 0;
502 	LIST_INSERT_HEAD(head, l, lpo_link);
503 
504 	return (l);
505 }
506 
507 void
508 lock_profile_obtain_lock_success(struct lock_object *lo, int contested,
509     uint64_t waittime, const char *file, int line)
510 {
511 	static int lock_prof_count;
512 	struct lock_profile_object *l;
513 	int spin;
514 
515 	if (SCHEDULER_STOPPED())
516 		return;
517 
518 	/* don't reset the timer when/if recursing */
519 	if (!lock_prof_enable || (lo->lo_flags & LO_NOPROFILE))
520 		return;
521 	if (lock_prof_skipcount &&
522 	    (++lock_prof_count % lock_prof_skipcount) != 0)
523 		return;
524 	spin = (LOCK_CLASS(lo)->lc_flags & LC_SPINLOCK) ? 1 : 0;
525 	if (spin && lock_prof_skipspin == 1)
526 		return;
527 	critical_enter();
528 	/* Recheck enabled now that we're in a critical section. */
529 	if (lock_prof_enable == 0)
530 		goto out;
531 	l = lock_profile_object_lookup(lo, spin, file, line);
532 	if (l == NULL)
533 		goto out;
534 	l->lpo_cnt++;
535 	if (++l->lpo_ref > 1)
536 		goto out;
537 	l->lpo_contest_locking = contested;
538 	l->lpo_acqtime = nanoseconds();
539 	if (waittime && (l->lpo_acqtime > waittime))
540 		l->lpo_waittime = l->lpo_acqtime - waittime;
541 	else
542 		l->lpo_waittime = 0;
543 out:
544 	critical_exit();
545 }
546 
547 void
548 lock_profile_thread_exit(struct thread *td)
549 {
550 #ifdef INVARIANTS
551 	struct lock_profile_object *l;
552 
553 	MPASS(curthread->td_critnest == 0);
554 #endif
555 	/*
556 	 * If lock profiling was disabled we have to wait for reset to
557 	 * clear our pointers before we can exit safely.
558 	 */
559 	lock_prof_reset_wait();
560 #ifdef INVARIANTS
561 	LIST_FOREACH(l, &td->td_lprof[0], lpo_link)
562 		printf("thread still holds lock acquired at %s:%d\n",
563 		    l->lpo_file, l->lpo_line);
564 	LIST_FOREACH(l, &td->td_lprof[1], lpo_link)
565 		printf("thread still holds lock acquired at %s:%d\n",
566 		    l->lpo_file, l->lpo_line);
567 #endif
568 	MPASS(LIST_FIRST(&td->td_lprof[0]) == NULL);
569 	MPASS(LIST_FIRST(&td->td_lprof[1]) == NULL);
570 }
571 
572 void
573 lock_profile_release_lock(struct lock_object *lo)
574 {
575 	struct lock_profile_object *l;
576 	struct lock_prof_type *type;
577 	struct lock_prof *lp;
578 	uint64_t curtime, holdtime;
579 	struct lpohead *head;
580 	int spin;
581 
582 	if (SCHEDULER_STOPPED())
583 		return;
584 	if (lo->lo_flags & LO_NOPROFILE)
585 		return;
586 	spin = (LOCK_CLASS(lo)->lc_flags & LC_SPINLOCK) ? 1 : 0;
587 	head = &curthread->td_lprof[spin];
588 	if (LIST_FIRST(head) == NULL)
589 		return;
590 	critical_enter();
591 	/* Recheck enabled now that we're in a critical section. */
592 	if (lock_prof_enable == 0 && lock_prof_resetting == 1)
593 		goto out;
594 	/*
595 	 * If lock profiling is not enabled we still want to remove the
596 	 * lpo from our queue.
597 	 */
598 	LIST_FOREACH(l, head, lpo_link)
599 		if (l->lpo_obj == lo)
600 			break;
601 	if (l == NULL)
602 		goto out;
603 	if (--l->lpo_ref > 0)
604 		goto out;
605 	lp = lock_profile_lookup(lo, spin, l->lpo_file, l->lpo_line);
606 	if (lp == NULL)
607 		goto release;
608 	curtime = nanoseconds();
609 	if (curtime < l->lpo_acqtime)
610 		goto release;
611 	holdtime = curtime - l->lpo_acqtime;
612 
613 	/*
614 	 * Record if the lock has been held longer now than ever
615 	 * before.
616 	 */
617 	if (holdtime > lp->cnt_max)
618 		lp->cnt_max = holdtime;
619 	if (l->lpo_waittime > lp->cnt_wait_max)
620 		lp->cnt_wait_max = l->lpo_waittime;
621 	lp->cnt_tot += holdtime;
622 	lp->cnt_wait += l->lpo_waittime;
623 	lp->cnt_contest_locking += l->lpo_contest_locking;
624 	lp->cnt_cur += l->lpo_cnt;
625 release:
626 	LIST_REMOVE(l, lpo_link);
627 	type = &lp_cpu[PCPU_GET(cpuid)]->lpc_types[spin];
628 	LIST_INSERT_HEAD(&type->lpt_lpoalloc, l, lpo_link);
629 out:
630 	critical_exit();
631 }
632 
633 static SYSCTL_NODE(_debug, OID_AUTO, lock, CTLFLAG_RD, NULL, "lock debugging");
634 static SYSCTL_NODE(_debug_lock, OID_AUTO, prof, CTLFLAG_RD, NULL,
635     "lock profiling");
636 SYSCTL_INT(_debug_lock_prof, OID_AUTO, skipspin, CTLFLAG_RW,
637     &lock_prof_skipspin, 0, "Skip profiling on spinlocks.");
638 SYSCTL_INT(_debug_lock_prof, OID_AUTO, skipcount, CTLFLAG_RW,
639     &lock_prof_skipcount, 0, "Sample approximately every N lock acquisitions.");
640 SYSCTL_INT(_debug_lock_prof, OID_AUTO, rejected, CTLFLAG_RD,
641     &lock_prof_rejected, 0, "Number of rejected profiling records");
642 SYSCTL_PROC(_debug_lock_prof, OID_AUTO, stats, CTLTYPE_STRING | CTLFLAG_RD,
643     NULL, 0, dump_lock_prof_stats, "A", "Lock profiling statistics");
644 SYSCTL_PROC(_debug_lock_prof, OID_AUTO, reset, CTLTYPE_INT | CTLFLAG_RW,
645     NULL, 0, reset_lock_prof_stats, "I", "Reset lock profiling statistics");
646 SYSCTL_PROC(_debug_lock_prof, OID_AUTO, enable, CTLTYPE_INT | CTLFLAG_RW,
647     NULL, 0, enable_lock_prof, "I", "Enable lock profiling");
648 
649 #endif
650