Print this page
5042 stop using deprecated atomic functions
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/i86pc/os/memnode.c
+++ new/usr/src/uts/i86pc/os/memnode.c
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
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/systm.h>
27 27 #include <sys/sysmacros.h>
28 28 #include <sys/bootconf.h>
29 29 #include <sys/atomic.h>
30 30 #include <sys/lgrp.h>
31 31 #include <sys/memlist.h>
32 32 #include <sys/memnode.h>
33 33 #include <sys/platform_module.h>
34 34 #include <vm/vm_dep.h>
35 35
36 36 int max_mem_nodes = 1;
37 37
38 38 struct mem_node_conf mem_node_config[MAX_MEM_NODES];
39 39 int mem_node_pfn_shift;
40 40 /*
41 41 * num_memnodes should be updated atomically and always >=
42 42 * the number of bits in memnodes_mask or the algorithm may fail.
43 43 */
44 44 uint16_t num_memnodes;
45 45 mnodeset_t memnodes_mask; /* assumes 8*(sizeof(mnodeset_t)) >= MAX_MEM_NODES */
46 46
47 47 /*
48 48 * If set, mem_node_physalign should be a power of two, and
49 49 * should reflect the minimum address alignment of each node.
50 50 */
51 51 uint64_t mem_node_physalign;
52 52
53 53 /*
54 54 * Platform hooks we will need.
55 55 */
56 56
57 57 #pragma weak plat_build_mem_nodes
58 58 #pragma weak plat_slice_add
59 59 #pragma weak plat_slice_del
60 60
61 61 /*
62 62 * Adjust the memnode config after a DR operation.
63 63 *
64 64 * It is rather tricky to do these updates since we can't
65 65 * protect the memnode structures with locks, so we must
66 66 * be mindful of the order in which updates and reads to
67 67 * these values can occur.
68 68 */
69 69
70 70 void
71 71 mem_node_add_slice(pfn_t start, pfn_t end)
72 72 {
73 73 int mnode;
74 74 mnodeset_t newmask, oldmask;
75 75
76 76 /*
77 77 * DR will pass us the first pfn that is allocatable.
78 78 * We need to round down to get the real start of
↓ open down ↓ |
78 lines elided |
↑ open up ↑ |
79 79 * the slice.
80 80 */
81 81 if (mem_node_physalign) {
82 82 start &= ~(btop(mem_node_physalign) - 1);
83 83 end = roundup(end, btop(mem_node_physalign)) - 1;
84 84 }
85 85
86 86 mnode = PFN_2_MEM_NODE(start);
87 87 ASSERT(mnode >= 0 && mnode < max_mem_nodes);
88 88
89 - if (cas32((uint32_t *)&mem_node_config[mnode].exists, 0, 1)) {
89 + if (atomic_cas_32((uint32_t *)&mem_node_config[mnode].exists, 0, 1)) {
90 90 /*
91 91 * Add slice to existing node.
92 92 */
93 93 if (start < mem_node_config[mnode].physbase)
94 94 mem_node_config[mnode].physbase = start;
95 95 if (end > mem_node_config[mnode].physmax)
96 96 mem_node_config[mnode].physmax = end;
97 97 } else {
98 98 mem_node_config[mnode].physbase = start;
99 99 mem_node_config[mnode].physmax = end;
100 100 atomic_add_16(&num_memnodes, 1);
101 101 do {
102 102 oldmask = memnodes_mask;
103 103 newmask = memnodes_mask | (1ull << mnode);
104 - } while (cas64(&memnodes_mask, oldmask, newmask) != oldmask);
104 + } while (atomic_cas_64(&memnodes_mask, oldmask, newmask) !=
105 + oldmask);
105 106 }
106 107
107 108 /*
108 109 * Inform the common lgrp framework about the new memory
109 110 */
110 111 lgrp_config(LGRP_CONFIG_MEM_ADD, mnode, MEM_NODE_2_LGRPHAND(mnode));
111 112 }
112 113
113 114 /*
114 115 * Remove a PFN range from a memnode. On some platforms,
115 116 * the memnode will be created with physbase at the first
116 117 * allocatable PFN, but later deleted with the MC slice
117 118 * base address converted to a PFN, in which case we need
118 119 * to assume physbase and up.
119 120 */
120 121 void
121 122 mem_node_del_slice(pfn_t start, pfn_t end)
122 123 {
123 124 int mnode;
124 125 pgcnt_t delta_pgcnt, node_size;
125 126 mnodeset_t omask, nmask;
126 127
127 128 if (mem_node_physalign) {
128 129 start &= ~(btop(mem_node_physalign) - 1);
129 130 end = roundup(end, btop(mem_node_physalign)) - 1;
130 131 }
131 132 mnode = PFN_2_MEM_NODE(start);
132 133
133 134 ASSERT(mnode >= 0 && mnode < max_mem_nodes);
134 135 ASSERT(mem_node_config[mnode].exists == 1);
135 136
136 137 delta_pgcnt = end - start;
137 138 node_size = mem_node_config[mnode].physmax -
138 139 mem_node_config[mnode].physbase;
139 140
140 141 if (node_size > delta_pgcnt) {
141 142 /*
142 143 * Subtract the slice from the memnode.
143 144 */
144 145 if (start <= mem_node_config[mnode].physbase)
145 146 mem_node_config[mnode].physbase = end + 1;
146 147 ASSERT(end <= mem_node_config[mnode].physmax);
147 148 if (end == mem_node_config[mnode].physmax)
148 149 mem_node_config[mnode].physmax = start - 1;
149 150 } else {
150 151 /*
151 152 * Let the common lgrp framework know this mnode is
152 153 * leaving
153 154 */
↓ open down ↓ |
39 lines elided |
↑ open up ↑ |
154 155 lgrp_config(LGRP_CONFIG_MEM_DEL,
155 156 mnode, MEM_NODE_2_LGRPHAND(mnode));
156 157
157 158 /*
158 159 * Delete the whole node.
159 160 */
160 161 ASSERT(MNODE_PGCNT(mnode) == 0);
161 162 do {
162 163 omask = memnodes_mask;
163 164 nmask = omask & ~(1ull << mnode);
164 - } while (cas64(&memnodes_mask, omask, nmask) != omask);
165 + } while (atomic_cas_64(&memnodes_mask, omask, nmask) != omask);
165 166 atomic_add_16(&num_memnodes, -1);
166 167 mem_node_config[mnode].exists = 0;
167 168 }
168 169 }
169 170
170 171 void
171 172 mem_node_add_range(pfn_t start, pfn_t end)
172 173 {
173 174 if (&plat_slice_add)
174 175 plat_slice_add(start, end);
175 176 else
176 177 mem_node_add_slice(start, end);
177 178 }
178 179
179 180 void
180 181 mem_node_del_range(pfn_t start, pfn_t end)
181 182 {
182 183 if (&plat_slice_del)
183 184 plat_slice_del(start, end);
184 185 else
185 186 mem_node_del_slice(start, end);
186 187 }
187 188
188 189 void
189 190 startup_build_mem_nodes(struct memlist *list)
190 191 {
191 192 pfn_t start, end;
192 193
193 194 /* LINTED: ASSERT will always true or false */
194 195 ASSERT(NBBY * sizeof (mnodeset_t) >= max_mem_nodes);
195 196
196 197 if (&plat_build_mem_nodes) {
197 198 plat_build_mem_nodes(list);
198 199 } else {
199 200 /*
200 201 * Boot install lists are arranged <addr, len>, ...
201 202 */
202 203 while (list) {
203 204 start = list->ml_address >> PAGESHIFT;
204 205 if (start > physmax)
205 206 continue;
206 207 end =
207 208 (list->ml_address + list->ml_size - 1) >> PAGESHIFT;
208 209 if (end > physmax)
209 210 end = physmax;
210 211 mem_node_add_range(start, end);
211 212 list = list->ml_next;
212 213 }
213 214 mem_node_physalign = 0;
214 215 mem_node_pfn_shift = 0;
215 216 }
216 217 }
217 218
218 219 /*
219 220 * Allocate an unassigned memnode.
220 221 */
221 222 int
↓ open down ↓ |
47 lines elided |
↑ open up ↑ |
222 223 mem_node_alloc()
223 224 {
224 225 int mnode;
225 226 mnodeset_t newmask, oldmask;
226 227
227 228 /*
228 229 * Find an unused memnode. Update it atomically to prevent
229 230 * a first time memnode creation race.
230 231 */
231 232 for (mnode = 0; mnode < max_mem_nodes; mnode++)
232 - if (cas32((uint32_t *)&mem_node_config[mnode].exists,
233 + if (atomic_cas_32((uint32_t *)&mem_node_config[mnode].exists,
233 234 0, 1) == 0)
234 235 break;
235 236
236 237 if (mnode >= max_mem_nodes)
237 238 panic("Out of free memnodes\n");
238 239
239 240 mem_node_config[mnode].physbase = (pfn_t)-1l;
240 241 mem_node_config[mnode].physmax = 0;
241 242 atomic_add_16(&num_memnodes, 1);
242 243 do {
243 244 oldmask = memnodes_mask;
244 245 newmask = memnodes_mask | (1ull << mnode);
245 - } while (cas64(&memnodes_mask, oldmask, newmask) != oldmask);
246 + } while (atomic_cas_64(&memnodes_mask, oldmask, newmask) != oldmask);
246 247
247 248 return (mnode);
248 249 }
249 250
250 251 /*
251 252 * Find the intersection between a memnode and a memlist
252 253 * and returns the number of pages that overlap.
253 254 *
254 255 * Assumes the list is protected from DR operations by
255 256 * the memlist lock.
256 257 */
257 258 pgcnt_t
258 259 mem_node_memlist_pages(int mnode, struct memlist *mlist)
259 260 {
260 261 pfn_t base, end;
261 262 pfn_t cur_base, cur_end;
262 263 pgcnt_t npgs;
263 264 struct memlist *pmem;
264 265
265 266 base = mem_node_config[mnode].physbase;
266 267 end = mem_node_config[mnode].physmax;
267 268 npgs = 0;
268 269
269 270 memlist_read_lock();
270 271
271 272 for (pmem = mlist; pmem; pmem = pmem->ml_next) {
272 273 cur_base = btop(pmem->ml_address);
273 274 cur_end = cur_base + btop(pmem->ml_size) - 1;
274 275 if (end < cur_base || base > cur_end)
275 276 continue;
276 277 npgs = npgs + (MIN(cur_end, end) -
277 278 MAX(cur_base, base)) + 1;
278 279 }
279 280
280 281 memlist_read_unlock();
281 282
282 283 return (npgs);
283 284 }
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX