Deleted Added
full compact
kern_sx.c (174629) kern_sx.c (177085)
1/*-
2 * Copyright (c) 2007 Attilio Rao <attilio@freebsd.org>
3 * Copyright (c) 2001 Jason Evans <jasone@freebsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

35 * Priority propagation will not generally raise the priority of lock holders,
36 * so should not be relied upon in combination with sx locks.
37 */
38
39#include "opt_adaptive_sx.h"
40#include "opt_ddb.h"
41
42#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2007 Attilio Rao <attilio@freebsd.org>
3 * Copyright (c) 2001 Jason Evans <jasone@freebsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

35 * Priority propagation will not generally raise the priority of lock holders,
36 * so should not be relied upon in combination with sx locks.
37 */
38
39#include "opt_adaptive_sx.h"
40#include "opt_ddb.h"
41
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: head/sys/kern/kern_sx.c 174629 2007-12-15 23:13:31Z jeff $");
43__FBSDID("$FreeBSD: head/sys/kern/kern_sx.c 177085 2008-03-12 06:31:06Z jeff $");
44
45#include <sys/param.h>
46#include <sys/ktr.h>
47#include <sys/lock.h>
48#include <sys/mutex.h>
49#include <sys/proc.h>
50#include <sys/sleepqueue.h>
51#include <sys/sx.h>

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

399 /*
400 * Preserve SX_LOCK_EXCLUSIVE_WAITERS while downgraded to a single
401 * shared lock. If there are any shared waiters, wake them up.
402 */
403 x = sx->sx_lock;
404 atomic_store_rel_ptr(&sx->sx_lock, SX_SHARERS_LOCK(1) |
405 (x & SX_LOCK_EXCLUSIVE_WAITERS));
406 if (x & SX_LOCK_SHARED_WAITERS)
44
45#include <sys/param.h>
46#include <sys/ktr.h>
47#include <sys/lock.h>
48#include <sys/mutex.h>
49#include <sys/proc.h>
50#include <sys/sleepqueue.h>
51#include <sys/sx.h>

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

399 /*
400 * Preserve SX_LOCK_EXCLUSIVE_WAITERS while downgraded to a single
401 * shared lock. If there are any shared waiters, wake them up.
402 */
403 x = sx->sx_lock;
404 atomic_store_rel_ptr(&sx->sx_lock, SX_SHARERS_LOCK(1) |
405 (x & SX_LOCK_EXCLUSIVE_WAITERS));
406 if (x & SX_LOCK_SHARED_WAITERS)
407 sleepq_broadcast(&sx->lock_object, SLEEPQ_SX, -1,
407 sleepq_broadcast(&sx->lock_object, SLEEPQ_SX, 0,
408 SQ_SHARED_QUEUE);
408 SQ_SHARED_QUEUE);
409 else
410 sleepq_release(&sx->lock_object);
409 sleepq_release(&sx->lock_object);
411
412 LOCK_LOG_LOCK("XDOWNGRADE", &sx->lock_object, 0, 0, file, line);
413}
414
415/*
416 * This function represents the so-called 'hard case' for sx_xlock
417 * operation. All 'easy case' failures are redirected to this. Note
418 * that ideally this would be a static function, but it needs to be

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

551 CTR2(KTR_LOCK, "%s: %p blocking on sleep queue",
552 __func__, sx);
553
554 GIANT_SAVE();
555 sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name,
556 SLEEPQ_SX | ((opts & SX_INTERRUPTIBLE) ?
557 SLEEPQ_INTERRUPTIBLE : 0), SQ_EXCLUSIVE_QUEUE);
558 if (!(opts & SX_INTERRUPTIBLE))
410
411 LOCK_LOG_LOCK("XDOWNGRADE", &sx->lock_object, 0, 0, file, line);
412}
413
414/*
415 * This function represents the so-called 'hard case' for sx_xlock
416 * operation. All 'easy case' failures are redirected to this. Note
417 * that ideally this would be a static function, but it needs to be

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

550 CTR2(KTR_LOCK, "%s: %p blocking on sleep queue",
551 __func__, sx);
552
553 GIANT_SAVE();
554 sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name,
555 SLEEPQ_SX | ((opts & SX_INTERRUPTIBLE) ?
556 SLEEPQ_INTERRUPTIBLE : 0), SQ_EXCLUSIVE_QUEUE);
557 if (!(opts & SX_INTERRUPTIBLE))
559 sleepq_wait(&sx->lock_object);
558 sleepq_wait(&sx->lock_object, 0);
560 else
559 else
561 error = sleepq_wait_sig(&sx->lock_object);
560 error = sleepq_wait_sig(&sx->lock_object, 0);
562
563 if (error) {
564 if (LOCK_LOG_TEST(&sx->lock_object, 0))
565 CTR2(KTR_LOCK,
566 "%s: interruptible sleep by %p suspended by signal",
567 __func__, sx);
568 break;
569 }

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

622 queue = SQ_EXCLUSIVE_QUEUE;
623
624 /* Wake up all the waiters for the specific queue. */
625 if (LOCK_LOG_TEST(&sx->lock_object, 0))
626 CTR3(KTR_LOCK, "%s: %p waking up all threads on %s queue",
627 __func__, sx, queue == SQ_SHARED_QUEUE ? "shared" :
628 "exclusive");
629 atomic_store_rel_ptr(&sx->sx_lock, x);
561
562 if (error) {
563 if (LOCK_LOG_TEST(&sx->lock_object, 0))
564 CTR2(KTR_LOCK,
565 "%s: interruptible sleep by %p suspended by signal",
566 __func__, sx);
567 break;
568 }

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

621 queue = SQ_EXCLUSIVE_QUEUE;
622
623 /* Wake up all the waiters for the specific queue. */
624 if (LOCK_LOG_TEST(&sx->lock_object, 0))
625 CTR3(KTR_LOCK, "%s: %p waking up all threads on %s queue",
626 __func__, sx, queue == SQ_SHARED_QUEUE ? "shared" :
627 "exclusive");
628 atomic_store_rel_ptr(&sx->sx_lock, x);
630 sleepq_broadcast(&sx->lock_object, SLEEPQ_SX, -1, queue);
629 sleepq_broadcast(&sx->lock_object, SLEEPQ_SX, 0, queue);
630 sleepq_release(&sx->lock_object);
631}
632
633/*
634 * This function represents the so-called 'hard case' for sx_slock
635 * operation. All 'easy case' failures are redirected to this. Note
636 * that ideally this would be a static function, but it needs to be
637 * accessible from at least sx.h.
638 */

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

756 CTR2(KTR_LOCK, "%s: %p blocking on sleep queue",
757 __func__, sx);
758
759 GIANT_SAVE();
760 sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name,
761 SLEEPQ_SX | ((opts & SX_INTERRUPTIBLE) ?
762 SLEEPQ_INTERRUPTIBLE : 0), SQ_SHARED_QUEUE);
763 if (!(opts & SX_INTERRUPTIBLE))
631}
632
633/*
634 * This function represents the so-called 'hard case' for sx_slock
635 * operation. All 'easy case' failures are redirected to this. Note
636 * that ideally this would be a static function, but it needs to be
637 * accessible from at least sx.h.
638 */

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

756 CTR2(KTR_LOCK, "%s: %p blocking on sleep queue",
757 __func__, sx);
758
759 GIANT_SAVE();
760 sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name,
761 SLEEPQ_SX | ((opts & SX_INTERRUPTIBLE) ?
762 SLEEPQ_INTERRUPTIBLE : 0), SQ_SHARED_QUEUE);
763 if (!(opts & SX_INTERRUPTIBLE))
764 sleepq_wait(&sx->lock_object);
764 sleepq_wait(&sx->lock_object, 0);
765 else
765 else
766 error = sleepq_wait_sig(&sx->lock_object);
766 error = sleepq_wait_sig(&sx->lock_object, 0);
767
768 if (error) {
769 if (LOCK_LOG_TEST(&sx->lock_object, 0))
770 CTR2(KTR_LOCK,
771 "%s: interruptible sleep by %p suspended by signal",
772 __func__, sx);
773 break;
774 }

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

856 SX_SHARERS_LOCK(1) | SX_LOCK_EXCLUSIVE_WAITERS,
857 SX_LOCK_UNLOCKED)) {
858 sleepq_release(&sx->lock_object);
859 continue;
860 }
861 if (LOCK_LOG_TEST(&sx->lock_object, 0))
862 CTR2(KTR_LOCK, "%s: %p waking up all thread on"
863 "exclusive queue", __func__, sx);
767
768 if (error) {
769 if (LOCK_LOG_TEST(&sx->lock_object, 0))
770 CTR2(KTR_LOCK,
771 "%s: interruptible sleep by %p suspended by signal",
772 __func__, sx);
773 break;
774 }

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

856 SX_SHARERS_LOCK(1) | SX_LOCK_EXCLUSIVE_WAITERS,
857 SX_LOCK_UNLOCKED)) {
858 sleepq_release(&sx->lock_object);
859 continue;
860 }
861 if (LOCK_LOG_TEST(&sx->lock_object, 0))
862 CTR2(KTR_LOCK, "%s: %p waking up all thread on"
863 "exclusive queue", __func__, sx);
864 sleepq_broadcast(&sx->lock_object, SLEEPQ_SX, -1,
864 sleepq_broadcast(&sx->lock_object, SLEEPQ_SX, 0,
865 SQ_EXCLUSIVE_QUEUE);
865 SQ_EXCLUSIVE_QUEUE);
866 sleepq_release(&sx->lock_object);
866 break;
867 }
868}
869
870#ifdef INVARIANT_SUPPORT
871#ifndef INVARIANTS
872#undef _sx_assert
873#endif

--- 161 unchanged lines hidden ---
867 break;
868 }
869}
870
871#ifdef INVARIANT_SUPPORT
872#ifndef INVARIANTS
873#undef _sx_assert
874#endif

--- 161 unchanged lines hidden ---