Deleted Added
full compact
kern_sx.c (196772) kern_sx.c (197643)
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:

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

36 * so should not be relied upon in combination with sx locks.
37 */
38
39#include "opt_ddb.h"
40#include "opt_kdtrace.h"
41#include "opt_no_adaptive_sx.h"
42
43#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:

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

36 * so should not be relied upon in combination with sx locks.
37 */
38
39#include "opt_ddb.h"
40#include "opt_kdtrace.h"
41#include "opt_no_adaptive_sx.h"
42
43#include <sys/cdefs.h>
44__FBSDID("$FreeBSD: head/sys/kern/kern_sx.c 196772 2009-09-02 17:33:51Z attilio $");
44__FBSDID("$FreeBSD: head/sys/kern/kern_sx.c 197643 2009-09-30 13:26:31Z attilio $");
45
46#include <sys/param.h>
47#include <sys/ktr.h>
48#include <sys/linker_set.h>
49#include <sys/lock.h>
50#include <sys/mutex.h>
51#include <sys/proc.h>
52#include <sys/sleepqueue.h>

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

926 KASSERT(!(x & SX_LOCK_SHARED_WAITERS),
927 ("%s: waiting sharers", __func__));
928
929 /*
930 * See if there is more than one shared lock held. If
931 * so, just drop one and return.
932 */
933 if (SX_SHARERS(x) > 1) {
45
46#include <sys/param.h>
47#include <sys/ktr.h>
48#include <sys/linker_set.h>
49#include <sys/lock.h>
50#include <sys/mutex.h>
51#include <sys/proc.h>
52#include <sys/sleepqueue.h>

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

926 KASSERT(!(x & SX_LOCK_SHARED_WAITERS),
927 ("%s: waiting sharers", __func__));
928
929 /*
930 * See if there is more than one shared lock held. If
931 * so, just drop one and return.
932 */
933 if (SX_SHARERS(x) > 1) {
934 if (atomic_cmpset_ptr(&sx->sx_lock, x,
934 if (atomic_cmpset_rel_ptr(&sx->sx_lock, x,
935 x - SX_ONE_SHARER)) {
936 if (LOCK_LOG_TEST(&sx->lock_object, 0))
937 CTR4(KTR_LOCK,
938 "%s: %p succeeded %p -> %p",
939 __func__, sx, (void *)x,
940 (void *)(x - SX_ONE_SHARER));
941 break;
942 }
943 continue;
944 }
945
946 /*
947 * If there aren't any waiters for an exclusive lock,
948 * then try to drop it quickly.
949 */
950 if (!(x & SX_LOCK_EXCLUSIVE_WAITERS)) {
951 MPASS(x == SX_SHARERS_LOCK(1));
935 x - SX_ONE_SHARER)) {
936 if (LOCK_LOG_TEST(&sx->lock_object, 0))
937 CTR4(KTR_LOCK,
938 "%s: %p succeeded %p -> %p",
939 __func__, sx, (void *)x,
940 (void *)(x - SX_ONE_SHARER));
941 break;
942 }
943 continue;
944 }
945
946 /*
947 * If there aren't any waiters for an exclusive lock,
948 * then try to drop it quickly.
949 */
950 if (!(x & SX_LOCK_EXCLUSIVE_WAITERS)) {
951 MPASS(x == SX_SHARERS_LOCK(1));
952 if (atomic_cmpset_ptr(&sx->sx_lock, SX_SHARERS_LOCK(1),
953 SX_LOCK_UNLOCKED)) {
952 if (atomic_cmpset_rel_ptr(&sx->sx_lock,
953 SX_SHARERS_LOCK(1), SX_LOCK_UNLOCKED)) {
954 if (LOCK_LOG_TEST(&sx->lock_object, 0))
955 CTR2(KTR_LOCK, "%s: %p last succeeded",
956 __func__, sx);
957 break;
958 }
959 continue;
960 }
961

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

968 sleepq_lock(&sx->lock_object);
969
970 /*
971 * Wake up semantic here is quite simple:
972 * Just wake up all the exclusive waiters.
973 * Note that the state of the lock could have changed,
974 * so if it fails loop back and retry.
975 */
954 if (LOCK_LOG_TEST(&sx->lock_object, 0))
955 CTR2(KTR_LOCK, "%s: %p last succeeded",
956 __func__, sx);
957 break;
958 }
959 continue;
960 }
961

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

968 sleepq_lock(&sx->lock_object);
969
970 /*
971 * Wake up semantic here is quite simple:
972 * Just wake up all the exclusive waiters.
973 * Note that the state of the lock could have changed,
974 * so if it fails loop back and retry.
975 */
976 if (!atomic_cmpset_ptr(&sx->sx_lock,
976 if (!atomic_cmpset_rel_ptr(&sx->sx_lock,
977 SX_SHARERS_LOCK(1) | SX_LOCK_EXCLUSIVE_WAITERS,
978 SX_LOCK_UNLOCKED)) {
979 sleepq_release(&sx->lock_object);
980 continue;
981 }
982 if (LOCK_LOG_TEST(&sx->lock_object, 0))
983 CTR2(KTR_LOCK, "%s: %p waking up all thread on"
984 "exclusive queue", __func__, sx);

--- 174 unchanged lines hidden ---
977 SX_SHARERS_LOCK(1) | SX_LOCK_EXCLUSIVE_WAITERS,
978 SX_LOCK_UNLOCKED)) {
979 sleepq_release(&sx->lock_object);
980 continue;
981 }
982 if (LOCK_LOG_TEST(&sx->lock_object, 0))
983 CTR2(KTR_LOCK, "%s: %p waking up all thread on"
984 "exclusive queue", __func__, sx);

--- 174 unchanged lines hidden ---