Print this page
4374 dn_free_ranges should use range_tree_t
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Max Grossman <max.grossman@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Approved by: Dan McDonald <danmcd@omniti.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/sys/bitmap.h
+++ new/usr/src/uts/common/sys/bitmap.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
|
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 +/*
28 + * Copyright (c) 2014 by Delphix. All rights reserved.
29 + */
30 +
27 31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 32 /* All Rights Reserved */
29 33
30 34
31 35 #ifndef _SYS_BITMAP_H
32 36 #define _SYS_BITMAP_H
33 37
34 -#pragma ident "%Z%%M% %I% %E% SMI"
35 -
36 38 #ifdef __cplusplus
37 39 extern "C" {
38 40 #endif
39 41
40 42 #include <sys/feature_tests.h>
41 43 #if defined(__GNUC__) && defined(_ASM_INLINES) && \
42 44 (defined(__i386) || defined(__amd64))
43 45 #include <asm/bitmap.h>
44 46 #endif
45 47
46 48 /*
47 49 * Operations on bitmaps of arbitrary size
48 50 * A bitmap is a vector of 1 or more ulong_t's.
49 51 * The user of the package is responsible for range checks and keeping
50 52 * track of sizes.
51 53 */
52 54
53 55 #ifdef _LP64
54 56 #define BT_ULSHIFT 6 /* log base 2 of BT_NBIPUL, to extract word index */
55 57 #define BT_ULSHIFT32 5 /* log base 2 of BT_NBIPUL, to extract word index */
56 58 #else
57 59 #define BT_ULSHIFT 5 /* log base 2 of BT_NBIPUL, to extract word index */
58 60 #endif
59 61
60 62 #define BT_NBIPUL (1 << BT_ULSHIFT) /* n bits per ulong_t */
61 63 #define BT_ULMASK (BT_NBIPUL - 1) /* to extract bit index */
62 64
63 65 #ifdef _LP64
64 66 #define BT_NBIPUL32 (1 << BT_ULSHIFT32) /* n bits per ulong_t */
65 67 #define BT_ULMASK32 (BT_NBIPUL32 - 1) /* to extract bit index */
66 68 #define BT_ULMAXMASK 0xffffffffffffffff /* used by bt_getlowbit */
67 69 #else
68 70 #define BT_ULMAXMASK 0xffffffff
69 71 #endif
70 72
71 73 /*
72 74 * bitmap is a ulong_t *, bitindex an index_t
73 75 *
74 76 * The macros BT_WIM and BT_BIW internal; there is no need
75 77 * for users of this package to use them.
76 78 */
77 79
78 80 /*
79 81 * word in map
80 82 */
81 83 #define BT_WIM(bitmap, bitindex) \
82 84 ((bitmap)[(bitindex) >> BT_ULSHIFT])
83 85 /*
84 86 * bit in word
85 87 */
86 88 #define BT_BIW(bitindex) \
87 89 (1UL << ((bitindex) & BT_ULMASK))
88 90
89 91 #ifdef _LP64
90 92 #define BT_WIM32(bitmap, bitindex) \
91 93 ((bitmap)[(bitindex) >> BT_ULSHIFT32])
92 94
93 95 #define BT_BIW32(bitindex) \
94 96 (1UL << ((bitindex) & BT_ULMASK32))
95 97 #endif
96 98
97 99 /*
98 100 * These are public macros
99 101 *
100 102 * BT_BITOUL == n bits to n ulong_t's
101 103 */
102 104 #define BT_BITOUL(nbits) \
103 105 (((nbits) + BT_NBIPUL - 1l) / BT_NBIPUL)
104 106 #define BT_SIZEOFMAP(nbits) \
105 107 (BT_BITOUL(nbits) * sizeof (ulong_t))
106 108 #define BT_TEST(bitmap, bitindex) \
107 109 ((BT_WIM((bitmap), (bitindex)) & BT_BIW(bitindex)) ? 1 : 0)
108 110 #define BT_SET(bitmap, bitindex) \
109 111 { BT_WIM((bitmap), (bitindex)) |= BT_BIW(bitindex); }
110 112 #define BT_CLEAR(bitmap, bitindex) \
111 113 { BT_WIM((bitmap), (bitindex)) &= ~BT_BIW(bitindex); }
112 114
113 115 #ifdef _LP64
114 116 #define BT_BITOUL32(nbits) \
115 117 (((nbits) + BT_NBIPUL32 - 1l) / BT_NBIPUL32)
116 118 #define BT_SIZEOFMAP32(nbits) \
117 119 (BT_BITOUL32(nbits) * sizeof (uint_t))
118 120 #define BT_TEST32(bitmap, bitindex) \
119 121 ((BT_WIM32((bitmap), (bitindex)) & BT_BIW32(bitindex)) ? 1 : 0)
120 122 #define BT_SET32(bitmap, bitindex) \
121 123 { BT_WIM32((bitmap), (bitindex)) |= BT_BIW32(bitindex); }
122 124 #define BT_CLEAR32(bitmap, bitindex) \
123 125 { BT_WIM32((bitmap), (bitindex)) &= ~BT_BIW32(bitindex); }
124 126 #endif /* _LP64 */
125 127
126 128
127 129 /*
128 130 * BIT_ONLYONESET is a private macro not designed for bitmaps of
129 131 * arbitrary size. u must be an unsigned integer/long. It returns
130 132 * true if one and only one bit is set in u.
131 133 */
132 134 #define BIT_ONLYONESET(u) \
133 135 ((((u) == 0) ? 0 : ((u) & ((u) - 1)) == 0))
134 136
135 137 #if defined(_KERNEL) && !defined(_ASM)
136 138 #include <sys/atomic.h>
137 139
138 140 /*
139 141 * return next available bit index from map with specified number of bits
140 142 */
141 143 extern index_t bt_availbit(ulong_t *bitmap, size_t nbits);
142 144 /*
143 145 * find the highest order bit that is on, and is within or below
144 146 * the word specified by wx
|
↓ open down ↓ |
99 lines elided |
↑ open up ↑ |
145 147 */
146 148 extern int bt_gethighbit(ulong_t *mapp, int wx);
147 149 extern int bt_range(ulong_t *bitmap, size_t *pos1, size_t *pos2,
148 150 size_t end_pos);
149 151 /*
150 152 * Find highest and lowest one bit set.
151 153 * Returns bit number + 1 of bit that is set, otherwise returns 0.
152 154 * Low order bit is 0, high order bit is 31.
153 155 */
154 156 extern int highbit(ulong_t);
157 +extern int highbit64(uint64_t);
155 158 extern int lowbit(ulong_t);
156 159 extern int bt_getlowbit(ulong_t *bitmap, size_t start, size_t stop);
157 160 extern void bt_copy(ulong_t *, ulong_t *, ulong_t);
158 161
159 162 /*
160 163 * find the parity
161 164 */
162 165 extern int odd_parity(ulong_t);
163 166
164 167 /*
165 168 * Atomically set/clear bits
166 169 * Atomic exclusive operations will set "result" to "-1"
167 170 * if the bit is already set/cleared. "result" will be set
168 171 * to 0 otherwise.
169 172 */
170 173 #define BT_ATOMIC_SET(bitmap, bitindex) \
171 174 { atomic_or_long(&(BT_WIM(bitmap, bitindex)), BT_BIW(bitindex)); }
172 175 #define BT_ATOMIC_CLEAR(bitmap, bitindex) \
173 176 { atomic_and_long(&(BT_WIM(bitmap, bitindex)), ~BT_BIW(bitindex)); }
174 177
175 178 #define BT_ATOMIC_SET_EXCL(bitmap, bitindex, result) \
176 179 { result = atomic_set_long_excl(&(BT_WIM(bitmap, bitindex)), \
177 180 (bitindex) % BT_NBIPUL); }
178 181 #define BT_ATOMIC_CLEAR_EXCL(bitmap, bitindex, result) \
179 182 { result = atomic_clear_long_excl(&(BT_WIM(bitmap, bitindex)), \
180 183 (bitindex) % BT_NBIPUL); }
181 184
182 185 /*
183 186 * Extracts bits between index h (high, inclusive) and l (low, exclusive) from
184 187 * u, which must be an unsigned integer.
185 188 */
186 189 #define BITX(u, h, l) (((u) >> (l)) & ((1LU << ((h) - (l) + 1LU)) - 1LU))
187 190
188 191 #endif /* _KERNEL && !_ASM */
189 192
190 193 #ifdef __cplusplus
191 194 }
192 195 #endif
193 196
194 197 #endif /* _SYS_BITMAP_H */
|
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX