2 * Copyright (c) 2015, Adrian Chadd <adrian@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/sysproto.h>
35 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/mutex.h>
41 #include <sys/refcount.h>
42 #include <sys/sched.h>
44 #include <sys/syscallsubr.h>
45 #include <sys/cpuset.h>
47 #include <sys/queue.h>
48 #include <sys/libkern.h>
49 #include <sys/limits.h>
51 #include <sys/interrupt.h>
55 #include <vm/vm_page.h>
56 #include <vm/vm_param.h>
57 #include <vm/vm_phys.h>
58 #include <vm/vm_domain.h>
61 sys_numa_setaffinity(struct thread *td, struct numa_setaffinity_args *uap)
64 struct vm_domain_policy vp;
73 * Copy in just the policy information into the policy
74 * struct. Userland only supplies vm_domain_policy_entry.
76 error = copyin(uap->policy, &vp.p, sizeof(vp.p));
81 * Ensure the seq number is zero - otherwise seq.h
82 * may get very confused.
89 if (vm_domain_policy_validate(&vp) != 0) {
95 * Go find the desired proc/tid for this operation.
97 error = cpuset_which(uap->which, uap->id, &p,
102 /* Only handle CPU_WHICH_TID and CPU_WHICH_PID */
104 * XXX if cpuset_which is called with WHICH_CPUSET and NULL cpuset,
105 * it'll return ESRCH. We should just return EINVAL.
107 switch (uap->which) {
109 vm_domain_policy_copy(&ttd->td_vm_dom_policy, &vp);
112 vm_domain_policy_copy(&p->p_vm_dom_policy, &vp);
127 sys_numa_getaffinity(struct thread *td, struct numa_getaffinity_args *uap)
130 struct vm_domain_policy vp;
138 error = cpuset_which(uap->which, uap->id, &p,
143 /* Only handle CPU_WHICH_TID and CPU_WHICH_PID */
145 * XXX if cpuset_which is called with WHICH_CPUSET and NULL cpuset,
146 * it'll return ESRCH. We should just return EINVAL.
148 switch (uap->which) {
150 vm_domain_policy_localcopy(&vp, &ttd->td_vm_dom_policy);
153 vm_domain_policy_localcopy(&vp, &p->p_vm_dom_policy);
162 * Copy out only the vm_domain_policy_entry part.
165 error = copyout(&vp.p, uap->policy, sizeof(vp.p));