subr_witness.c (154077) | subr_witness.c (154484) |
---|---|
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. --- 68 unchanged lines hidden (view full) --- 77 * you have two threads T1 and T2 and a sleepable lock X. Suppose that T1 78 * acquires X and blocks on Giant. Then suppose that T2 acquires Giant and 79 * blocks on X. When T2 blocks on X, T2 will release Giant allowing T1 to 80 * execute. Thus, acquiring Giant both before and after a sleepable lock 81 * will not result in a lock order reversal. 82 */ 83 84#include <sys/cdefs.h> | 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. --- 68 unchanged lines hidden (view full) --- 77 * you have two threads T1 and T2 and a sleepable lock X. Suppose that T1 78 * acquires X and blocks on Giant. Then suppose that T2 acquires Giant and 79 * blocks on X. When T2 blocks on X, T2 will release Giant allowing T1 to 80 * execute. Thus, acquiring Giant both before and after a sleepable lock 81 * will not result in a lock order reversal. 82 */ 83 84#include <sys/cdefs.h> |
85__FBSDID("$FreeBSD: head/sys/kern/subr_witness.c 154077 2006-01-06 18:07:32Z jhb $"); | 85__FBSDID("$FreeBSD: head/sys/kern/subr_witness.c 154484 2006-01-17 16:55:17Z jhb $"); |
86 87#include "opt_ddb.h" 88#include "opt_witness.h" 89 90#include <sys/param.h> 91#include <sys/bus.h> 92#include <sys/kdb.h> 93#include <sys/kernel.h> --- 444 unchanged lines hidden (view full) --- 538 539void 540witness_init(struct lock_object *lock) 541{ 542 struct lock_class *class; 543 544 /* Various sanity checks. */ 545 class = LOCK_CLASS(lock); | 86 87#include "opt_ddb.h" 88#include "opt_witness.h" 89 90#include <sys/param.h> 91#include <sys/bus.h> 92#include <sys/kdb.h> 93#include <sys/kernel.h> --- 444 unchanged lines hidden (view full) --- 538 539void 540witness_init(struct lock_object *lock) 541{ 542 struct lock_class *class; 543 544 /* Various sanity checks. */ 545 class = LOCK_CLASS(lock); |
546 if (lock->lo_flags & LO_INITIALIZED) 547 panic("%s: lock (%s) %s is already initialized", __func__, 548 class->lc_name, lock->lo_name); | |
549 if ((lock->lo_flags & LO_RECURSABLE) != 0 && 550 (class->lc_flags & LC_RECURSABLE) == 0) 551 panic("%s: lock (%s) %s can not be recursable", __func__, 552 class->lc_name, lock->lo_name); 553 if ((lock->lo_flags & LO_SLEEPABLE) != 0 && 554 (class->lc_flags & LC_SLEEPABLE) == 0) 555 panic("%s: lock (%s) %s can not be sleepable", __func__, 556 class->lc_name, lock->lo_name); --- 4 unchanged lines hidden (view full) --- 561 562 /* 563 * If we shouldn't watch this lock, then just clear lo_witness. 564 * Otherwise, if witness_cold is set, then it is too early to 565 * enroll this lock, so defer it to witness_initialize() by adding 566 * it to the pending_locks list. If it is not too early, then enroll 567 * the lock now. 568 */ | 546 if ((lock->lo_flags & LO_RECURSABLE) != 0 && 547 (class->lc_flags & LC_RECURSABLE) == 0) 548 panic("%s: lock (%s) %s can not be recursable", __func__, 549 class->lc_name, lock->lo_name); 550 if ((lock->lo_flags & LO_SLEEPABLE) != 0 && 551 (class->lc_flags & LC_SLEEPABLE) == 0) 552 panic("%s: lock (%s) %s can not be sleepable", __func__, 553 class->lc_name, lock->lo_name); --- 4 unchanged lines hidden (view full) --- 558 559 /* 560 * If we shouldn't watch this lock, then just clear lo_witness. 561 * Otherwise, if witness_cold is set, then it is too early to 562 * enroll this lock, so defer it to witness_initialize() by adding 563 * it to the pending_locks list. If it is not too early, then enroll 564 * the lock now. 565 */ |
569 lock->lo_flags |= LO_INITIALIZED; | |
570 if (witness_watch == 0 || panicstr != NULL || 571 (lock->lo_flags & LO_WITNESS) == 0) 572 lock->lo_witness = NULL; 573 else if (witness_cold) { 574 STAILQ_INSERT_TAIL(&pending_locks, lock, lo_list); 575 lock->lo_flags |= LO_ENROLLPEND; 576 } else 577 lock->lo_witness = enroll(lock->lo_type, class); --- 4 unchanged lines hidden (view full) --- 582{ 583 struct lock_class *class; 584 struct witness *w; 585 586 class = LOCK_CLASS(lock); 587 if (witness_cold) 588 panic("lock (%s) %s destroyed while witness_cold", 589 class->lc_name, lock->lo_name); | 566 if (witness_watch == 0 || panicstr != NULL || 567 (lock->lo_flags & LO_WITNESS) == 0) 568 lock->lo_witness = NULL; 569 else if (witness_cold) { 570 STAILQ_INSERT_TAIL(&pending_locks, lock, lo_list); 571 lock->lo_flags |= LO_ENROLLPEND; 572 } else 573 lock->lo_witness = enroll(lock->lo_type, class); --- 4 unchanged lines hidden (view full) --- 578{ 579 struct lock_class *class; 580 struct witness *w; 581 582 class = LOCK_CLASS(lock); 583 if (witness_cold) 584 panic("lock (%s) %s destroyed while witness_cold", 585 class->lc_name, lock->lo_name); |
590 if ((lock->lo_flags & LO_INITIALIZED) == 0) 591 panic("%s: lock (%s) %s is not initialized", __func__, 592 class->lc_name, lock->lo_name); | |
593 594 /* XXX: need to verify that no one holds the lock */ 595 if ((lock->lo_flags & (LO_WITNESS | LO_ENROLLPEND)) == LO_WITNESS && 596 lock->lo_witness != NULL) { 597 w = lock->lo_witness; 598 mtx_lock_spin(&w_mtx); 599 MPASS(w->w_refcount > 0); 600 w->w_refcount--; --- 9 unchanged lines hidden (view full) --- 610 /* 611 * If this lock is destroyed before witness is up and running, 612 * remove it from the pending list. 613 */ 614 if (lock->lo_flags & LO_ENROLLPEND) { 615 STAILQ_REMOVE(&pending_locks, lock, lock_object, lo_list); 616 lock->lo_flags &= ~LO_ENROLLPEND; 617 } | 586 587 /* XXX: need to verify that no one holds the lock */ 588 if ((lock->lo_flags & (LO_WITNESS | LO_ENROLLPEND)) == LO_WITNESS && 589 lock->lo_witness != NULL) { 590 w = lock->lo_witness; 591 mtx_lock_spin(&w_mtx); 592 MPASS(w->w_refcount > 0); 593 w->w_refcount--; --- 9 unchanged lines hidden (view full) --- 603 /* 604 * If this lock is destroyed before witness is up and running, 605 * remove it from the pending list. 606 */ 607 if (lock->lo_flags & LO_ENROLLPEND) { 608 STAILQ_REMOVE(&pending_locks, lock, lock_object, lo_list); 609 lock->lo_flags &= ~LO_ENROLLPEND; 610 } |
618 lock->lo_flags &= ~LO_INITIALIZED; | |
619} 620 621#ifdef DDB 622static void 623witness_levelall (void) 624{ 625 struct witness_list *list; 626 struct witness *w, *w1; --- 1387 unchanged lines hidden --- | 611} 612 613#ifdef DDB 614static void 615witness_levelall (void) 616{ 617 struct witness_list *list; 618 struct witness *w, *w1; --- 1387 unchanged lines hidden --- |