sys_pset.c revision 1.4.10.2 1 1.4.10.2 matt /* $NetBSD: sys_pset.c,v 1.4.10.2 2008/03/23 02:05:00 matt Exp $ */
2 1.4.10.2 matt
3 1.4.10.2 matt /*
4 1.4.10.2 matt * Copyright (c) 2008, Mindaugas Rasiukevicius <rmind at NetBSD org>
5 1.4.10.2 matt * All rights reserved.
6 1.4.10.2 matt *
7 1.4.10.2 matt * Redistribution and use in source and binary forms, with or without
8 1.4.10.2 matt * modification, are permitted provided that the following conditions
9 1.4.10.2 matt * are met:
10 1.4.10.2 matt * 1. Redistributions of source code must retain the above copyright
11 1.4.10.2 matt * notice, this list of conditions and the following disclaimer.
12 1.4.10.2 matt * 2. Redistributions in binary form must reproduce the above copyright
13 1.4.10.2 matt * notice, this list of conditions and the following disclaimer in the
14 1.4.10.2 matt * documentation and/or other materials provided with the distribution.
15 1.4.10.2 matt *
16 1.4.10.2 matt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 1.4.10.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.4.10.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.4.10.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.4.10.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.4.10.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.4.10.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.4.10.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.4.10.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.4.10.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.4.10.2 matt * POSSIBILITY OF SUCH DAMAGE.
27 1.4.10.2 matt */
28 1.4.10.2 matt
29 1.4.10.2 matt /*
30 1.4.10.2 matt * Implementation of the Processor Sets.
31 1.4.10.2 matt *
32 1.4.10.2 matt * Locking
33 1.4.10.2 matt * The array of the processor-set structures and its members are protected
34 1.4.10.2 matt * by the global psets_lock. Note that in scheduler, the very l_psid value
35 1.4.10.2 matt * might be used without lock held.
36 1.4.10.2 matt */
37 1.4.10.2 matt
38 1.4.10.2 matt #include <sys/cdefs.h>
39 1.4.10.2 matt __KERNEL_RCSID(0, "$NetBSD: sys_pset.c,v 1.4.10.2 2008/03/23 02:05:00 matt Exp $");
40 1.4.10.2 matt
41 1.4.10.2 matt #include <sys/param.h>
42 1.4.10.2 matt
43 1.4.10.2 matt #include <sys/cpu.h>
44 1.4.10.2 matt #include <sys/kauth.h>
45 1.4.10.2 matt #include <sys/kmem.h>
46 1.4.10.2 matt #include <sys/lwp.h>
47 1.4.10.2 matt #include <sys/mutex.h>
48 1.4.10.2 matt #include <sys/proc.h>
49 1.4.10.2 matt #include <sys/pset.h>
50 1.4.10.2 matt #include <sys/sched.h>
51 1.4.10.2 matt #include <sys/syscallargs.h>
52 1.4.10.2 matt #include <sys/sysctl.h>
53 1.4.10.2 matt #include <sys/systm.h>
54 1.4.10.2 matt #include <sys/types.h>
55 1.4.10.2 matt
56 1.4.10.2 matt static pset_info_t ** psets;
57 1.4.10.2 matt static kmutex_t psets_lock;
58 1.4.10.2 matt static u_int psets_max;
59 1.4.10.2 matt static u_int psets_count;
60 1.4.10.2 matt
61 1.4.10.2 matt static int psets_realloc(int);
62 1.4.10.2 matt static int psid_validate(psetid_t, bool);
63 1.4.10.2 matt static int kern_pset_create(psetid_t *);
64 1.4.10.2 matt static int kern_pset_destroy(psetid_t);
65 1.4.10.2 matt
66 1.4.10.2 matt /*
67 1.4.10.2 matt * Initialization of the processor-sets.
68 1.4.10.2 matt */
69 1.4.10.2 matt void
70 1.4.10.2 matt psets_init(void)
71 1.4.10.2 matt {
72 1.4.10.2 matt
73 1.4.10.2 matt psets_max = max(MAXCPUS, 32);
74 1.4.10.2 matt psets = kmem_zalloc(psets_max * sizeof(void *), KM_SLEEP);
75 1.4.10.2 matt mutex_init(&psets_lock, MUTEX_DEFAULT, IPL_NONE);
76 1.4.10.2 matt psets_count = 0;
77 1.4.10.2 matt }
78 1.4.10.2 matt
79 1.4.10.2 matt /*
80 1.4.10.2 matt * Reallocate the array of the processor-set structures.
81 1.4.10.2 matt */
82 1.4.10.2 matt static int
83 1.4.10.2 matt psets_realloc(int new_psets_max)
84 1.4.10.2 matt {
85 1.4.10.2 matt pset_info_t **new_psets, **old_psets;
86 1.4.10.2 matt const u_int newsize = new_psets_max * sizeof(void *);
87 1.4.10.2 matt u_int i, oldsize;
88 1.4.10.2 matt
89 1.4.10.2 matt if (new_psets_max < 1)
90 1.4.10.2 matt return EINVAL;
91 1.4.10.2 matt
92 1.4.10.2 matt new_psets = kmem_zalloc(newsize, KM_SLEEP);
93 1.4.10.2 matt mutex_enter(&psets_lock);
94 1.4.10.2 matt old_psets = psets;
95 1.4.10.2 matt oldsize = psets_max * sizeof(void *);
96 1.4.10.2 matt
97 1.4.10.2 matt /* Check if we can lower the size of the array */
98 1.4.10.2 matt if (new_psets_max < psets_max) {
99 1.4.10.2 matt for (i = new_psets_max; i < psets_max; i++) {
100 1.4.10.2 matt if (psets[i] == NULL)
101 1.4.10.2 matt continue;
102 1.4.10.2 matt mutex_exit(&psets_lock);
103 1.4.10.2 matt kmem_free(new_psets, newsize);
104 1.4.10.2 matt return EBUSY;
105 1.4.10.2 matt }
106 1.4.10.2 matt }
107 1.4.10.2 matt
108 1.4.10.2 matt /* Copy all pointers to the new array */
109 1.4.10.2 matt memcpy(new_psets, psets, newsize);
110 1.4.10.2 matt psets_max = new_psets_max;
111 1.4.10.2 matt psets = new_psets;
112 1.4.10.2 matt mutex_exit(&psets_lock);
113 1.4.10.2 matt
114 1.4.10.2 matt kmem_free(old_psets, oldsize);
115 1.4.10.2 matt return 0;
116 1.4.10.2 matt }
117 1.4.10.2 matt
118 1.4.10.2 matt /*
119 1.4.10.2 matt * Validate processor-set ID.
120 1.4.10.2 matt */
121 1.4.10.2 matt static int
122 1.4.10.2 matt psid_validate(psetid_t psid, bool chkps)
123 1.4.10.2 matt {
124 1.4.10.2 matt
125 1.4.10.2 matt KASSERT(mutex_owned(&psets_lock));
126 1.4.10.2 matt
127 1.4.10.2 matt if (chkps && (psid == PS_NONE || psid == PS_QUERY || psid == PS_MYID))
128 1.4.10.2 matt return 0;
129 1.4.10.2 matt if (psid <= 0 || psid > psets_max)
130 1.4.10.2 matt return EINVAL;
131 1.4.10.2 matt if (psets[psid - 1] == NULL)
132 1.4.10.2 matt return EINVAL;
133 1.4.10.2 matt if (psets[psid - 1]->ps_flags & PSET_BUSY)
134 1.4.10.2 matt return EBUSY;
135 1.4.10.2 matt
136 1.4.10.2 matt return 0;
137 1.4.10.2 matt }
138 1.4.10.2 matt
139 1.4.10.2 matt /*
140 1.4.10.2 matt * Create a processor-set.
141 1.4.10.2 matt */
142 1.4.10.2 matt static int
143 1.4.10.2 matt kern_pset_create(psetid_t *psid)
144 1.4.10.2 matt {
145 1.4.10.2 matt pset_info_t *pi;
146 1.4.10.2 matt u_int i;
147 1.4.10.2 matt
148 1.4.10.2 matt if (psets_count == psets_max)
149 1.4.10.2 matt return ENOMEM;
150 1.4.10.2 matt
151 1.4.10.2 matt pi = kmem_zalloc(sizeof(pset_info_t), KM_SLEEP);
152 1.4.10.2 matt
153 1.4.10.2 matt mutex_enter(&psets_lock);
154 1.4.10.2 matt if (psets_count == psets_max) {
155 1.4.10.2 matt mutex_exit(&psets_lock);
156 1.4.10.2 matt kmem_free(pi, sizeof(pset_info_t));
157 1.4.10.2 matt return ENOMEM;
158 1.4.10.2 matt }
159 1.4.10.2 matt
160 1.4.10.2 matt /* Find a free entry in the array */
161 1.4.10.2 matt for (i = 0; i < psets_max; i++)
162 1.4.10.2 matt if (psets[i] == NULL)
163 1.4.10.2 matt break;
164 1.4.10.2 matt KASSERT(i != psets_max);
165 1.4.10.2 matt
166 1.4.10.2 matt psets[i] = pi;
167 1.4.10.2 matt psets_count++;
168 1.4.10.2 matt mutex_exit(&psets_lock);
169 1.4.10.2 matt
170 1.4.10.2 matt *psid = i + 1;
171 1.4.10.2 matt return 0;
172 1.4.10.2 matt }
173 1.4.10.2 matt
174 1.4.10.2 matt /*
175 1.4.10.2 matt * Destroy a processor-set.
176 1.4.10.2 matt */
177 1.4.10.2 matt static int
178 1.4.10.2 matt kern_pset_destroy(psetid_t psid)
179 1.4.10.2 matt {
180 1.4.10.2 matt struct cpu_info *ci;
181 1.4.10.2 matt pset_info_t *pi;
182 1.4.10.2 matt struct lwp *l;
183 1.4.10.2 matt CPU_INFO_ITERATOR cii;
184 1.4.10.2 matt int error;
185 1.4.10.2 matt
186 1.4.10.2 matt mutex_enter(&psets_lock);
187 1.4.10.2 matt if (psid == PS_MYID) {
188 1.4.10.2 matt /* Use caller's processor-set ID */
189 1.4.10.2 matt psid = curlwp->l_psid;
190 1.4.10.2 matt }
191 1.4.10.2 matt error = psid_validate(psid, false);
192 1.4.10.2 matt if (error) {
193 1.4.10.2 matt mutex_exit(&psets_lock);
194 1.4.10.2 matt return error;
195 1.4.10.2 matt }
196 1.4.10.2 matt
197 1.4.10.2 matt /* Release the processor-set from all CPUs */
198 1.4.10.2 matt for (CPU_INFO_FOREACH(cii, ci)) {
199 1.4.10.2 matt struct schedstate_percpu *spc;
200 1.4.10.2 matt
201 1.4.10.2 matt spc = &ci->ci_schedstate;
202 1.4.10.2 matt if (spc->spc_psid != psid)
203 1.4.10.2 matt continue;
204 1.4.10.2 matt spc->spc_psid = PS_NONE;
205 1.4.10.2 matt }
206 1.4.10.2 matt /* Mark that processor-set is going to be destroyed */
207 1.4.10.2 matt pi = psets[psid - 1];
208 1.4.10.2 matt pi->ps_flags |= PSET_BUSY;
209 1.4.10.2 matt mutex_exit(&psets_lock);
210 1.4.10.2 matt
211 1.4.10.2 matt /* Unmark the processor-set ID from each thread */
212 1.4.10.2 matt mutex_enter(&proclist_lock);
213 1.4.10.2 matt LIST_FOREACH(l, &alllwp, l_list) {
214 1.4.10.2 matt /* Safe to check and set without lock held */
215 1.4.10.2 matt if (l->l_psid != psid)
216 1.4.10.2 matt continue;
217 1.4.10.2 matt l->l_psid = PS_NONE;
218 1.4.10.2 matt }
219 1.4.10.2 matt mutex_exit(&proclist_lock);
220 1.4.10.2 matt
221 1.4.10.2 matt /* Destroy the processor-set */
222 1.4.10.2 matt mutex_enter(&psets_lock);
223 1.4.10.2 matt psets[psid - 1] = NULL;
224 1.4.10.2 matt psets_count--;
225 1.4.10.2 matt mutex_exit(&psets_lock);
226 1.4.10.2 matt
227 1.4.10.2 matt kmem_free(pi, sizeof(pset_info_t));
228 1.4.10.2 matt return 0;
229 1.4.10.2 matt }
230 1.4.10.2 matt
231 1.4.10.2 matt /*
232 1.4.10.2 matt * General system calls for the processor-sets.
233 1.4.10.2 matt */
234 1.4.10.2 matt
235 1.4.10.2 matt int
236 1.4.10.2 matt sys_pset_create(struct lwp *l, const struct sys_pset_create_args *uap,
237 1.4.10.2 matt register_t *retval)
238 1.4.10.2 matt {
239 1.4.10.2 matt /* {
240 1.4.10.2 matt syscallarg(psetid_t) *psid;
241 1.4.10.2 matt } */
242 1.4.10.2 matt psetid_t psid;
243 1.4.10.2 matt int error;
244 1.4.10.2 matt
245 1.4.10.2 matt /* Available only for super-user */
246 1.4.10.2 matt if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_PSET,
247 1.4.10.2 matt KAUTH_REQ_SYSTEM_PSET_CREATE, NULL, NULL, NULL))
248 1.4.10.2 matt return EPERM;
249 1.4.10.2 matt
250 1.4.10.2 matt error = kern_pset_create(&psid);
251 1.4.10.2 matt if (error)
252 1.4.10.2 matt return error;
253 1.4.10.2 matt
254 1.4.10.2 matt error = copyout(&psid, SCARG(uap, psid), sizeof(psetid_t));
255 1.4.10.2 matt if (error)
256 1.4.10.2 matt (void)kern_pset_destroy(psid);
257 1.4.10.2 matt
258 1.4.10.2 matt return error;
259 1.4.10.2 matt }
260 1.4.10.2 matt
261 1.4.10.2 matt int
262 1.4.10.2 matt sys_pset_destroy(struct lwp *l, const struct sys_pset_destroy_args *uap,
263 1.4.10.2 matt register_t *retval)
264 1.4.10.2 matt {
265 1.4.10.2 matt /* {
266 1.4.10.2 matt syscallarg(psetid_t) psid;
267 1.4.10.2 matt } */
268 1.4.10.2 matt
269 1.4.10.2 matt /* Available only for super-user */
270 1.4.10.2 matt if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_PSET,
271 1.4.10.2 matt KAUTH_REQ_SYSTEM_PSET_DESTROY,
272 1.4.10.2 matt KAUTH_ARG(SCARG(uap, psid)), NULL, NULL))
273 1.4.10.2 matt return EPERM;
274 1.4.10.2 matt
275 1.4.10.2 matt return kern_pset_destroy(SCARG(uap, psid));
276 1.4.10.2 matt }
277 1.4.10.2 matt
278 1.4.10.2 matt int
279 1.4.10.2 matt sys_pset_assign(struct lwp *l, const struct sys_pset_assign_args *uap,
280 1.4.10.2 matt register_t *retval)
281 1.4.10.2 matt {
282 1.4.10.2 matt /* {
283 1.4.10.2 matt syscallarg(psetid_t) psid;
284 1.4.10.2 matt syscallarg(cpuid_t) cpuid;
285 1.4.10.2 matt syscallarg(psetid_t) *opsid;
286 1.4.10.2 matt } */
287 1.4.10.2 matt struct cpu_info *ci;
288 1.4.10.2 matt struct schedstate_percpu *spc;
289 1.4.10.2 matt psetid_t psid = SCARG(uap, psid), opsid = 0;
290 1.4.10.2 matt CPU_INFO_ITERATOR cii;
291 1.4.10.2 matt int error = 0;
292 1.4.10.2 matt
293 1.4.10.2 matt /* Available only for super-user, except the case of PS_QUERY */
294 1.4.10.2 matt if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_PSET,
295 1.4.10.2 matt KAUTH_REQ_SYSTEM_PSET_ASSIGN, KAUTH_ARG(SCARG(uap, psid)), NULL,
296 1.4.10.2 matt NULL))
297 1.4.10.2 matt return EPERM;
298 1.4.10.2 matt
299 1.4.10.2 matt /* Find the target CPU */
300 1.4.10.2 matt for (CPU_INFO_FOREACH(cii, ci))
301 1.4.10.2 matt if (cpu_index(ci) == SCARG(uap, cpuid))
302 1.4.10.2 matt break;
303 1.4.10.2 matt if (ci == NULL)
304 1.4.10.2 matt return EINVAL;
305 1.4.10.2 matt spc = &ci->ci_schedstate;
306 1.4.10.2 matt
307 1.4.10.2 matt mutex_enter(&psets_lock);
308 1.4.10.2 matt error = psid_validate(psid, true);
309 1.4.10.2 matt if (error) {
310 1.4.10.2 matt mutex_exit(&psets_lock);
311 1.4.10.2 matt return error;
312 1.4.10.2 matt }
313 1.4.10.2 matt opsid = spc->spc_psid;
314 1.4.10.2 matt switch (psid) {
315 1.4.10.2 matt case PS_QUERY:
316 1.4.10.2 matt break;
317 1.4.10.2 matt case PS_MYID:
318 1.4.10.2 matt psid = curlwp->l_psid;
319 1.4.10.2 matt default:
320 1.4.10.2 matt spc->spc_psid = psid;
321 1.4.10.2 matt }
322 1.4.10.2 matt mutex_exit(&psets_lock);
323 1.4.10.2 matt
324 1.4.10.2 matt if (SCARG(uap, opsid) != NULL)
325 1.4.10.2 matt error = copyout(&opsid, SCARG(uap, opsid), sizeof(psetid_t));
326 1.4.10.2 matt
327 1.4.10.2 matt return error;
328 1.4.10.2 matt }
329 1.4.10.2 matt
330 1.4.10.2 matt int
331 1.4.10.2 matt sys__pset_bind(struct lwp *l, const struct sys__pset_bind_args *uap,
332 1.4.10.2 matt register_t *retval)
333 1.4.10.2 matt {
334 1.4.10.2 matt /* {
335 1.4.10.2 matt syscallarg(idtype_t) idtype;
336 1.4.10.2 matt syscallarg(id_t) first_id;
337 1.4.10.2 matt syscallarg(id_t) second_id;
338 1.4.10.2 matt syscallarg(psetid_t) psid;
339 1.4.10.2 matt syscallarg(psetid_t) *opsid;
340 1.4.10.2 matt } */
341 1.4.10.2 matt struct cpu_info *ci;
342 1.4.10.2 matt struct proc *p;
343 1.4.10.2 matt struct lwp *t;
344 1.4.10.2 matt id_t id1, id2;
345 1.4.10.2 matt pid_t pid = 0;
346 1.4.10.2 matt lwpid_t lid = 0;
347 1.4.10.2 matt psetid_t psid, opsid;
348 1.4.10.2 matt int error = 0, lcnt;
349 1.4.10.2 matt
350 1.4.10.2 matt psid = SCARG(uap, psid);
351 1.4.10.2 matt
352 1.4.10.2 matt /* Available only for super-user, except the case of PS_QUERY */
353 1.4.10.2 matt if (kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_PSET,
354 1.4.10.2 matt KAUTH_REQ_SYSTEM_PSET_BIND, KAUTH_ARG(SCARG(uap, psid)), NULL,
355 1.4.10.2 matt NULL))
356 1.4.10.2 matt return EPERM;
357 1.4.10.2 matt
358 1.4.10.2 matt mutex_enter(&psets_lock);
359 1.4.10.2 matt error = psid_validate(psid, true);
360 1.4.10.2 matt if (error) {
361 1.4.10.2 matt mutex_exit(&psets_lock);
362 1.4.10.2 matt return error;
363 1.4.10.2 matt }
364 1.4.10.2 matt if (psid == PS_MYID)
365 1.4.10.2 matt psid = curlwp->l_psid;
366 1.4.10.2 matt if (psid != PS_QUERY && psid != PS_NONE)
367 1.4.10.2 matt psets[psid - 1]->ps_flags |= PSET_BUSY;
368 1.4.10.2 matt mutex_exit(&psets_lock);
369 1.4.10.2 matt
370 1.4.10.2 matt /*
371 1.4.10.2 matt * Get PID and LID from the ID.
372 1.4.10.2 matt */
373 1.4.10.2 matt p = l->l_proc;
374 1.4.10.2 matt id1 = SCARG(uap, first_id);
375 1.4.10.2 matt id2 = SCARG(uap, second_id);
376 1.4.10.2 matt
377 1.4.10.2 matt switch (SCARG(uap, idtype)) {
378 1.4.10.2 matt case P_PID:
379 1.4.10.2 matt /*
380 1.4.10.2 matt * Process:
381 1.4.10.2 matt * First ID - PID;
382 1.4.10.2 matt * Second ID - ignored;
383 1.4.10.2 matt */
384 1.4.10.2 matt pid = (id1 == P_MYID) ? p->p_pid : id1;
385 1.4.10.2 matt lid = 0;
386 1.4.10.2 matt break;
387 1.4.10.2 matt case P_LWPID:
388 1.4.10.2 matt /*
389 1.4.10.2 matt * Thread (LWP):
390 1.4.10.2 matt * First ID - LID;
391 1.4.10.2 matt * Second ID - PID;
392 1.4.10.2 matt */
393 1.4.10.2 matt if (id1 == P_MYID) {
394 1.4.10.2 matt pid = p->p_pid;
395 1.4.10.2 matt lid = l->l_lid;
396 1.4.10.2 matt break;
397 1.4.10.2 matt }
398 1.4.10.2 matt lid = id1;
399 1.4.10.2 matt pid = (id2 == P_MYID) ? p->p_pid : id2;
400 1.4.10.2 matt break;
401 1.4.10.2 matt default:
402 1.4.10.2 matt error = EINVAL;
403 1.4.10.2 matt goto error;
404 1.4.10.2 matt }
405 1.4.10.2 matt
406 1.4.10.2 matt /* Find the process */
407 1.4.10.2 matt p = p_find(pid, PFIND_UNLOCK_FAIL);
408 1.4.10.2 matt if (p == NULL) {
409 1.4.10.2 matt error = ESRCH;
410 1.4.10.2 matt goto error;
411 1.4.10.2 matt }
412 1.4.10.2 matt mutex_enter(&p->p_smutex);
413 1.4.10.2 matt mutex_exit(&proclist_lock);
414 1.4.10.2 matt
415 1.4.10.2 matt /* Disallow modification of the system processes */
416 1.4.10.2 matt if (p->p_flag & PK_SYSTEM) {
417 1.4.10.2 matt mutex_exit(&p->p_smutex);
418 1.4.10.2 matt error = EPERM;
419 1.4.10.2 matt goto error;
420 1.4.10.2 matt }
421 1.4.10.2 matt
422 1.4.10.2 matt /* Find the LWP(s) */
423 1.4.10.2 matt lcnt = 0;
424 1.4.10.2 matt ci = NULL;
425 1.4.10.2 matt LIST_FOREACH(t, &p->p_lwps, l_sibling) {
426 1.4.10.2 matt if (lid && lid != t->l_lid)
427 1.4.10.2 matt continue;
428 1.4.10.2 matt /*
429 1.4.10.2 matt * Bind the thread to the processor-set,
430 1.4.10.2 matt * take some CPU and migrate.
431 1.4.10.2 matt */
432 1.4.10.2 matt lwp_lock(t);
433 1.4.10.2 matt opsid = t->l_psid;
434 1.4.10.2 matt t->l_psid = psid;
435 1.4.10.2 matt ci = sched_takecpu(l);
436 1.4.10.2 matt /* Unlocks LWP */
437 1.4.10.2 matt lwp_migrate(t, ci);
438 1.4.10.2 matt lcnt++;
439 1.4.10.2 matt }
440 1.4.10.2 matt mutex_exit(&p->p_smutex);
441 1.4.10.2 matt if (lcnt == 0) {
442 1.4.10.2 matt error = ESRCH;
443 1.4.10.2 matt goto error;
444 1.4.10.2 matt }
445 1.4.10.2 matt if (SCARG(uap, opsid))
446 1.4.10.2 matt error = copyout(&opsid, SCARG(uap, opsid), sizeof(psetid_t));
447 1.4.10.2 matt error:
448 1.4.10.2 matt if (psid != PS_QUERY && psid != PS_NONE) {
449 1.4.10.2 matt mutex_enter(&psets_lock);
450 1.4.10.2 matt psets[psid - 1]->ps_flags &= ~PSET_BUSY;
451 1.4.10.2 matt mutex_exit(&psets_lock);
452 1.4.10.2 matt }
453 1.4.10.2 matt return error;
454 1.4.10.2 matt }
455 1.4.10.2 matt
456 1.4.10.2 matt /*
457 1.4.10.2 matt * Sysctl nodes and initialization.
458 1.4.10.2 matt */
459 1.4.10.2 matt
460 1.4.10.2 matt static int
461 1.4.10.2 matt sysctl_psets_max(SYSCTLFN_ARGS)
462 1.4.10.2 matt {
463 1.4.10.2 matt struct sysctlnode node;
464 1.4.10.2 matt int error, newsize;
465 1.4.10.2 matt
466 1.4.10.2 matt node = *rnode;
467 1.4.10.2 matt node.sysctl_data = &newsize;
468 1.4.10.2 matt
469 1.4.10.2 matt newsize = psets_max;
470 1.4.10.2 matt error = sysctl_lookup(SYSCTLFN_CALL(&node));
471 1.4.10.2 matt if (error || newp == NULL)
472 1.4.10.2 matt return error;
473 1.4.10.2 matt
474 1.4.10.2 matt if (newsize <= 0)
475 1.4.10.2 matt return EINVAL;
476 1.4.10.2 matt
477 1.4.10.2 matt sysctl_unlock();
478 1.4.10.2 matt error = psets_realloc(newsize);
479 1.4.10.2 matt sysctl_relock();
480 1.4.10.2 matt return error;
481 1.4.10.2 matt }
482 1.4.10.2 matt
483 1.4.10.2 matt SYSCTL_SETUP(sysctl_pset_setup, "sysctl kern.pset subtree setup")
484 1.4.10.2 matt {
485 1.4.10.2 matt const struct sysctlnode *node = NULL;
486 1.4.10.2 matt
487 1.4.10.2 matt sysctl_createv(clog, 0, NULL, NULL,
488 1.4.10.2 matt CTLFLAG_PERMANENT,
489 1.4.10.2 matt CTLTYPE_NODE, "kern", NULL,
490 1.4.10.2 matt NULL, 0, NULL, 0,
491 1.4.10.2 matt CTL_KERN, CTL_EOL);
492 1.4.10.2 matt sysctl_createv(clog, 0, NULL, &node,
493 1.4.10.2 matt CTLFLAG_PERMANENT,
494 1.4.10.2 matt CTLTYPE_NODE, "pset",
495 1.4.10.2 matt SYSCTL_DESCR("Processor-set options"),
496 1.4.10.2 matt NULL, 0, NULL, 0,
497 1.4.10.2 matt CTL_KERN, CTL_CREATE, CTL_EOL);
498 1.4.10.2 matt
499 1.4.10.2 matt if (node == NULL)
500 1.4.10.2 matt return;
501 1.4.10.2 matt
502 1.4.10.2 matt sysctl_createv(clog, 0, &node, NULL,
503 1.4.10.2 matt CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
504 1.4.10.2 matt CTLTYPE_INT, "psets_max",
505 1.4.10.2 matt SYSCTL_DESCR("Maximal count of the processor-sets"),
506 1.4.10.2 matt sysctl_psets_max, 0, &psets_max, 0,
507 1.4.10.2 matt CTL_CREATE, CTL_EOL);
508 1.4.10.2 matt }
509