sd: remove 'ssd' driver support
[unleashed/tickless.git] / arch / x86 / include / sys / mutex_impl.h
blobae61ac0a06b7d35a0449b72d167fcbd2da4eed06
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_MUTEX_IMPL_H
27 #define _SYS_MUTEX_IMPL_H
29 #ifndef _ASM
30 #include <sys/types.h>
31 #include <sys/machlock.h>
32 #endif
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
38 #ifndef _ASM
41 * mutex_enter() assumes that the mutex is adaptive and tries to grab the
42 * lock by doing a atomic compare and exchange on the first word of the mutex.
43 * If the compare and exchange fails, it means that either (1) the lock is a
44 * spin lock, or (2) the lock is adaptive but already held.
45 * mutex_vector_enter() distinguishes these cases by looking at the mutex
46 * type, which is encoded in the low-order bits of the owner field.
48 typedef union mutex_impl {
50 * Adaptive mutex.
52 struct adaptive_mutex {
53 uintptr_t _m_owner; /* 0-3/0-7 owner and waiters bit */
54 #ifndef _LP64
55 uintptr_t _m_filler; /* 4-7 unused */
56 #endif
57 } m_adaptive;
60 * Spin Mutex.
62 struct spin_mutex {
63 lock_t m_dummylock; /* 0 dummy lock (always set) */
64 lock_t m_spinlock; /* 1 real lock */
65 ushort_t m_filler; /* 2-3 unused */
66 ushort_t m_oldspl; /* 4-5 old pil value */
67 ushort_t m_minspl; /* 6-7 min pil val if lock held */
68 } m_spin;
70 } mutex_impl_t;
72 #define m_owner m_adaptive._m_owner
74 #define MUTEX_ALIGN _LONG_ALIGNMENT
75 #define MUTEX_ALIGN_WARNINGS 10 /* num of warnings to issue */
77 #define MUTEX_WAITERS 0x1
78 #define MUTEX_DEAD 0x6
79 #define MUTEX_THREAD (-0x8)
81 #define MUTEX_OWNER(lp) ((kthread_id_t)((lp)->m_owner & MUTEX_THREAD))
82 #define MUTEX_NO_OWNER ((kthread_id_t)NULL)
84 #define MUTEX_SET_WAITERS(lp) \
85 { \
86 uintptr_t old; \
87 while ((old = (lp)->m_owner) != 0 && \
88 casip(&(lp)->m_owner, old, old | MUTEX_WAITERS) != old) \
89 continue; \
92 #define MUTEX_HAS_WAITERS(lp) ((lp)->m_owner & MUTEX_WAITERS)
93 #define MUTEX_CLEAR_LOCK_AND_WAITERS(lp) (lp)->m_owner = 0
95 #define MUTEX_SET_TYPE(lp, type)
96 #define MUTEX_TYPE_ADAPTIVE(lp) (((lp)->m_owner & MUTEX_DEAD) == 0)
97 #define MUTEX_TYPE_SPIN(lp) ((lp)->m_spin.m_dummylock == LOCK_HELD_VALUE)
99 #define MUTEX_DESTROY(lp) \
100 (lp)->m_owner = ((uintptr_t)curthread | MUTEX_DEAD)
101 /* mutex backoff delay macro and constants */
102 #define MUTEX_BACKOFF_BASE 1
103 #define MUTEX_BACKOFF_SHIFT 2
104 #define MUTEX_CAP_FACTOR 64
105 #define MUTEX_DELAY() { \
106 mutex_delay(); \
107 SMT_PAUSE(); \
110 /* low overhead clock read */
111 #define MUTEX_GETTICK() tsc_read()
112 extern void null_xcall(void);
113 #define MUTEX_SYNC() { \
114 cpuset_t set; \
115 CPUSET_ALL(set); \
116 xc_call(0, 0, 0, CPUSET2BV(set), \
117 (xc_func_t)null_xcall); \
120 extern int mutex_adaptive_tryenter(mutex_impl_t *);
121 extern void *mutex_owner_running(mutex_impl_t *);
123 #else /* _ASM */
125 #define MUTEX_THREAD -0x8
127 #endif /* _ASM */
129 #ifdef __cplusplus
131 #endif
133 #endif /* _SYS_MUTEX_IMPL_H */