Deleted Added
sdiff udiff text old ( 65856 ) new ( 67352 )
full compact
1/*-
2 * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 12 unchanged lines hidden (view full) ---

21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * from BSDI $Id: mutex_witness.c,v 1.1.2.20 2000/04/27 03:10:27 cp Exp $
29 * $FreeBSD: head/sys/kern/kern_mutex.c 65856 2000-09-14 20:15:16Z jhb $
30 */
31
32/*
33 * Main Entry: witness
34 * Pronunciation: 'wit-n&s
35 * Function: noun
36 * Etymology: Middle English witnesse, from Old English witnes knowledge,
37 * testimony, witness, from 2wit

--- 7 unchanged lines hidden (view full) ---

45 * 5 a : something serving as evidence or proof : SIGN
46 * b : public affirmation by word or example of usually
47 * religious faith or conviction <the heroic witness to divine
48 * life -- Pilot>
49 * 6 capitalized : a member of the Jehovah's Witnesses
50 */
51
52#include <sys/param.h>
53#include <sys/proc.h>
54#include <sys/systm.h>
55#include <sys/ktr.h>
56
57#include <machine/cpu.h>
58#define _KERN_MUTEX_C_ /* Cause non-inlined mtx_*() to be compiled. */
59#include <machine/mutex.h>
60
61/*
62 * The non-inlined versions of the mtx_*() functions are always built (above),
63 * but the witness code depends on the SMP_DEBUG and WITNESS kernel options
64 * being specified.
65 */
66#if (defined(SMP_DEBUG) && defined(WITNESS))
67
68#define WITNESS_COUNT 200
69#define WITNESS_NCHILDREN 2
70
71#ifndef WITNESS
72#define WITNESS 0 /* default off */
73#endif
74

--- 226 unchanged lines hidden (view full) ---

301 goto out;
302 }
303 if (isitmydescendant(m1->mtx_witness, w)) {
304 mtx_exit(&w_mtx, MTX_SPIN);
305 goto out;
306 }
307 for (i = 0; m1 != NULL; m1 = LIST_NEXT(m1, mtx_held), i++) {
308
309 ASS(i < 200);
310 w1 = m1->mtx_witness;
311 if (isitmydescendant(w, w1)) {
312 mtx_exit(&w_mtx, MTX_SPIN);
313 if (blessed(w, w1))
314 goto out;
315 if (m1 == &Giant) {
316 if (w1->w_Giant_squawked)
317 goto out;

--- 32 unchanged lines hidden (view full) ---

350 m->mtx_line = line;
351 m->mtx_file = file;
352
353 /*
354 * If this pays off it likely means that a mutex being witnessed
355 * is acquired in hardclock. Put it in the ignore list. It is
356 * likely not the mutex this assert fails on.
357 */
358 ASS(m->mtx_held.le_prev == NULL);
359 LIST_INSERT_HEAD(&p->p_heldmtx, (struct mtx*)m, mtx_held);
360}
361
362void
363witness_exit(struct mtx *m, int flags, const char *file, int line)
364{
365 struct witness *w;
366

--- 50 unchanged lines hidden (view full) ---

417 if (m->mtx_recurse != 0)
418 return;
419
420 w->w_file = file;
421 w->w_line = line;
422 m->mtx_line = line;
423 m->mtx_file = file;
424 p = CURPROC;
425 ASS(m->mtx_held.le_prev == NULL);
426 LIST_INSERT_HEAD(&p->p_heldmtx, (struct mtx*)m, mtx_held);
427}
428
429void
430witness_display(void(*prnt)(const char *fmt, ...))
431{
432 struct witness *w, *w1;
433

--- 125 unchanged lines hidden (view full) ---

559 while (parent->w_morechildren)
560 parent = parent->w_morechildren;
561
562 if (parent->w_childcnt == WITNESS_NCHILDREN) {
563 if ((parent->w_morechildren = witness_get()) == NULL)
564 return (1);
565 parent = parent->w_morechildren;
566 }
567 ASS(child != NULL);
568 parent->w_children[parent->w_childcnt++] = child;
569 /*
570 * now prune whole tree
571 */
572 if (recursed)
573 return (0);
574 recursed = 1;
575 for (child = w_all; child != NULL; child = child->w_next) {

--- 22 unchanged lines hidden (view full) ---

598 for (i = 0; i < w->w_childcnt; i++)
599 if (w->w_children[i] == child)
600 goto found;
601 return;
602found:
603 for (w1 = w; w1->w_morechildren != NULL; w1 = w1->w_morechildren)
604 continue;
605 w->w_children[i] = w1->w_children[--w1->w_childcnt];
606 ASS(w->w_children[i] != NULL);
607
608 if (w1->w_childcnt != 0)
609 return;
610
611 if (w1 == parent)
612 return;
613 for (w = parent; w->w_morechildren != w1; w = w->w_morechildren)
614 continue;

--- 19 unchanged lines hidden (view full) ---

634static int
635isitmydescendant(struct witness *parent, struct witness *child)
636{
637 struct witness *w;
638 int i;
639 int j;
640
641 for (j = 0, w = parent; w != NULL; w = w->w_morechildren, j++) {
642 ASS(j < 1000);
643 for (i = 0; i < w->w_childcnt; i++) {
644 if (w->w_children[i] == child)
645 return (1);
646 }
647 for (i = 0; i < w->w_childcnt; i++) {
648 if (isitmydescendant(w->w_children[i], child))
649 return (1);
650 }

--- 139 unchanged lines hidden (view full) ---

790
791void
792witness_restore(struct mtx *m, const char *file, int line)
793{
794 m->mtx_witness->w_file = file;
795 m->mtx_witness->w_line = line;
796}
797
798#endif /* (defined(SMP_DEBUG) && defined(WITNESS)) */