Lines Matching +full:- +full:set
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
85 * Each process belongs to an identified set, by default this is set 1. Each
87 * named set. This creates an anonymous set which other threads and processes
90 * The named set is referred to herein as the 'base' set to avoid ambiguity.
91 * This set is usually a child of a 'root' set while the anonymous set may
95 * Threads inherit their set from their creator whether it be anonymous or
97 * shared. To modify an anonymous set a new set is created with the desired
98 * mask and the same parent as the existing anonymous set. This gives the
102 * or mask that is discovered via a pid, tid, or setid. Modifying a set
105 * exist within the assigned parent set.
117 * rather apply masks to its own threads via CPU_WHICH_TID and a -1 id
119 * getaffinity call using (CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1, ...).
156 * Find the first non-anonymous set starting from 'set'.
159 cpuset_getbase(struct cpuset *set) in cpuset_getbase() argument
162 if (set->cs_id == CPUSET_INVALID) in cpuset_getbase()
163 set = set->cs_parent; in cpuset_getbase()
164 return (set); in cpuset_getbase()
168 * Walks up the tree from 'set' to find the root.
171 cpuset_getroot(struct cpuset *set) in cpuset_getroot() argument
174 while ((set->cs_flags & CPU_SET_ROOT) == 0 && set->cs_parent != NULL) in cpuset_getroot()
175 set = set->cs_parent; in cpuset_getroot()
176 return (set); in cpuset_getroot()
183 cpuset_ref(struct cpuset *set) in cpuset_ref() argument
186 refcount_acquire(&set->cs_ref); in cpuset_ref()
187 return (set); in cpuset_ref()
191 * Walks up the tree from 'set' to find the root. Returns the root
195 cpuset_refroot(struct cpuset *set) in cpuset_refroot() argument
198 return (cpuset_ref(cpuset_getroot(set))); in cpuset_refroot()
202 * Find the first non-anonymous set starting from 'set'. Returns this set
203 * referenced. May return the passed in set with an extra ref if it is
207 cpuset_refbase(struct cpuset *set) in cpuset_refbase() argument
210 return (cpuset_ref(cpuset_getbase(set))); in cpuset_refbase()
217 cpuset_rel(struct cpuset *set) in cpuset_rel() argument
221 if (refcount_release_if_not_last(&set->cs_ref)) in cpuset_rel()
224 if (!refcount_release(&set->cs_ref)) { in cpuset_rel()
228 LIST_REMOVE(set, cs_siblings); in cpuset_rel()
229 id = set->cs_id; in cpuset_rel()
231 LIST_REMOVE(set, cs_link); in cpuset_rel()
233 cpuset_rel(set->cs_parent); in cpuset_rel()
234 uma_zfree(cpuset_zone, set); in cpuset_rel()
244 cpuset_rel_defer(struct setlist *head, struct cpuset *set) in cpuset_rel_defer() argument
247 if (refcount_release_if_not_last(&set->cs_ref)) in cpuset_rel_defer()
250 if (!refcount_release(&set->cs_ref)) { in cpuset_rel_defer()
254 LIST_REMOVE(set, cs_siblings); in cpuset_rel_defer()
255 if (set->cs_id != CPUSET_INVALID) in cpuset_rel_defer()
256 LIST_REMOVE(set, cs_link); in cpuset_rel_defer()
257 LIST_INSERT_HEAD(head, set, cs_link); in cpuset_rel_defer()
262 * Complete a deferred release. Removes the set from the list provided to
266 cpuset_rel_complete(struct cpuset *set) in cpuset_rel_complete() argument
270 id = set->cs_id; in cpuset_rel_complete()
271 LIST_REMOVE(set, cs_link); in cpuset_rel_complete()
272 cpuset_rel(set->cs_parent); in cpuset_rel_complete()
273 uma_zfree(cpuset_zone, set); in cpuset_rel_complete()
279 * Find a set based on an id. Returns it with a ref.
284 struct cpuset *set; in cpuset_lookup() local
289 LIST_FOREACH(set, &cpuset_ids, cs_link) in cpuset_lookup()
290 if (set->cs_id == setid) in cpuset_lookup()
292 if (set) in cpuset_lookup()
293 cpuset_ref(set); in cpuset_lookup()
297 if (set != NULL && jailed(td->td_ucred)) { in cpuset_lookup()
300 jset = td->td_ucred->cr_prison->pr_cpuset; in cpuset_lookup()
301 for (tset = set; tset != NULL; tset = tset->cs_parent) in cpuset_lookup()
305 cpuset_rel(set); in cpuset_lookup()
306 set = NULL; in cpuset_lookup()
310 return (set); in cpuset_lookup()
314 * Initialize a set in the space provided in 'set' with the provided parameters.
315 * The set is returned with a single ref. May return EDEADLK if the set
319 cpuset_init(struct cpuset *set, struct cpuset *parent, in cpuset_init() argument
324 domain = parent->cs_domain; in cpuset_init()
326 mask = &parent->cs_mask; in cpuset_init()
327 if (!CPU_OVERLAP(&parent->cs_mask, mask)) in cpuset_init()
330 if (!domainset_valid(parent->cs_domain, domain)) in cpuset_init()
332 CPU_COPY(mask, &set->cs_mask); in cpuset_init()
333 LIST_INIT(&set->cs_children); in cpuset_init()
334 refcount_init(&set->cs_ref, 1); in cpuset_init()
335 set->cs_flags = 0; in cpuset_init()
337 set->cs_domain = domain; in cpuset_init()
338 CPU_AND(&set->cs_mask, &set->cs_mask, &parent->cs_mask); in cpuset_init()
339 set->cs_id = id; in cpuset_init()
340 set->cs_parent = cpuset_ref(parent); in cpuset_init()
341 LIST_INSERT_HEAD(&parent->cs_children, set, cs_siblings); in cpuset_init()
342 if (set->cs_id != CPUSET_INVALID) in cpuset_init()
343 LIST_INSERT_HEAD(&cpuset_ids, set, cs_link); in cpuset_init()
350 * Create a new non-anonymous set with the requested parent and mask. May
354 * If *setp is not NULL, then it will be used as-is. The caller must take
361 struct cpuset *set; in cpuset_create() local
367 if (id == -1) in cpuset_create()
371 set = *setp; in cpuset_create()
373 *setp = set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); in cpuset_create()
374 error = cpuset_init(set, parent, mask, NULL, id); in cpuset_create()
379 uma_zfree(cpuset_zone, set); in cpuset_create()
387 struct cpuset *set; in cpuset_freelist_add() local
391 set = uma_zalloc(cpuset_zone, M_ZERO | M_WAITOK); in cpuset_freelist_add()
392 LIST_INSERT_HEAD(list, set, cs_link); in cpuset_freelist_add()
407 struct cpuset *set; in cpuset_freelist_free() local
409 while ((set = LIST_FIRST(list)) != NULL) { in cpuset_freelist_free()
410 LIST_REMOVE(set, cs_link); in cpuset_freelist_free()
411 uma_zfree(cpuset_zone, set); in cpuset_freelist_free()
418 struct domainset *set; in domainset_freelist_add() local
422 set = uma_zalloc(domainset_zone, M_ZERO | M_WAITOK); in domainset_freelist_add()
423 LIST_INSERT_HEAD(list, set, ds_link); in domainset_freelist_add()
438 struct domainset *set; in domainset_freelist_free() local
440 while ((set = LIST_FIRST(list)) != NULL) { in domainset_freelist_free()
441 LIST_REMOVE(set, ds_link); in domainset_freelist_free()
442 uma_zfree(domainset_zone, set); in domainset_freelist_free()
451 DOMAINSET_COPY(&from->ds_mask, &to->ds_mask); in domainset_copy()
452 to->ds_policy = from->ds_policy; in domainset_copy()
453 to->ds_prefer = from->ds_prefer; in domainset_copy()
461 return (DOMAINSET_CMP(&one->ds_mask, &two->ds_mask) == 0 && in domainset_equal()
462 one->ds_policy == two->ds_policy && in domainset_equal()
463 one->ds_prefer == two->ds_prefer); in domainset_equal()
470 if (child->ds_policy != DOMAINSET_POLICY_PREFER) in domainset_valid()
471 return (DOMAINSET_SUBSET(&parent->ds_mask, &child->ds_mask)); in domainset_valid()
472 return (DOMAINSET_ISSET(child->ds_prefer, &parent->ds_mask)); in domainset_valid()
479 if (child->ds_policy != DOMAINSET_POLICY_PREFER) in domainset_restrict()
480 return (DOMAINSET_OVERLAP(&parent->ds_mask, &child->ds_mask)); in domainset_restrict()
481 return (DOMAINSET_ISSET(child->ds_prefer, &parent->ds_mask)); in domainset_restrict()
496 KASSERT(domain->ds_cnt <= vm_ndomains, in _domainset_create()
498 KASSERT(domain->ds_policy != DOMAINSET_POLICY_PREFER || in _domainset_create()
499 domain->ds_prefer < vm_ndomains, in _domainset_create()
512 domain->ds_cnt = DOMAINSET_COUNT(&domain->ds_mask); in _domainset_create()
513 for (i = 0, j = 0; i < DOMAINSET_FLS(&domain->ds_mask); i++) in _domainset_create()
514 if (DOMAINSET_ISSET(i, &domain->ds_mask)) in _domainset_create()
515 domain->ds_order[j++] = i; in _domainset_create()
543 if (DOMAINSET_SUBSET(&empty, &domain->ds_mask)) in domainset_empty_vm()
546 /* Remove empty domains from the set and recompute. */ in domainset_empty_vm()
547 DOMAINSET_ANDNOT(&domain->ds_mask, &empty); in domainset_empty_vm()
548 domain->ds_cnt = DOMAINSET_COUNT(&domain->ds_mask); in domainset_empty_vm()
549 for (i = j = 0; i < DOMAINSET_FLS(&domain->ds_mask); i++) in domainset_empty_vm()
550 if (DOMAINSET_ISSET(i, &domain->ds_mask)) in domainset_empty_vm()
551 domain->ds_order[j++] = i; in domainset_empty_vm()
554 if (domain->ds_policy == DOMAINSET_POLICY_PREFER && in domainset_empty_vm()
555 DOMAINSET_ISSET(domain->ds_prefer, &empty)) { in domainset_empty_vm()
556 domain->ds_policy = DOMAINSET_POLICY_ROUNDROBIN; in domainset_empty_vm()
557 domain->ds_prefer = -1; in domainset_empty_vm()
576 if (domain->ds_policy <= DOMAINSET_POLICY_INVALID || in domainset_create()
577 domain->ds_policy > DOMAINSET_POLICY_MAX) in domainset_create()
579 if (domain->ds_policy == DOMAINSET_POLICY_PREFER && in domainset_create()
580 !DOMAINSET_ISSET(domain->ds_prefer, &domain->ds_mask)) in domainset_create()
582 if (!DOMAINSET_SUBSET(&domainset0->ds_mask, &domain->ds_mask)) in domainset_create()
601 if (p->p_state == PRS_NEW) { in domainset_notify()
607 td->td_domain.dr_policy = td->td_cpuset->cs_domain; in domainset_notify()
613 kernel_object->domain.dr_policy = cpuset_kernel->cs_domain; in domainset_notify()
617 * Create a new set that is a subset of a parent.
636 DOMAINSET_AND(&ndomain->ds_mask, &pdomain->ds_mask); in domainset_shadow()
643 * the tree of sets starting at 'set'. Checks for sets that would become
647 cpuset_testupdate(struct cpuset *set, cpuset_t *mask, int augment_mask) in cpuset_testupdate() argument
654 if (set->cs_flags & CPU_SET_RDONLY) in cpuset_testupdate()
657 CPU_AND(&newmask, &set->cs_mask, mask); in cpuset_testupdate()
664 LIST_FOREACH(nset, &set->cs_children, cs_siblings) in cpuset_testupdate()
674 cpuset_update(struct cpuset *set, cpuset_t *mask) in cpuset_update() argument
679 CPU_AND(&set->cs_mask, &set->cs_mask, mask); in cpuset_update()
680 LIST_FOREACH(nset, &set->cs_children, cs_siblings) in cpuset_update()
681 cpuset_update(nset, &set->cs_mask); in cpuset_update()
687 * Modify the set 'set' to use a copy of the mask provided. Apply this new
692 cpuset_modify(struct cpuset *set, cpuset_t *mask) in cpuset_modify() argument
707 if ((set->cs_flags & CPU_SET_ROOT) != 0 && in cpuset_modify()
708 jailed(curthread->td_ucred) && in cpuset_modify()
709 set == curthread->td_ucred->cr_prison->pr_cpuset) in cpuset_modify()
712 * Verify that we have access to this set of in cpuset_modify()
715 if ((set->cs_flags & (CPU_SET_ROOT | CPU_SET_RDONLY)) == CPU_SET_ROOT) { in cpuset_modify()
716 KASSERT(set->cs_parent != NULL, in cpuset_modify()
718 set->cs_id)); in cpuset_modify()
721 * cpuset_getroot() cannot work here due to how top-level jail in cpuset_modify()
722 * roots are constructed. Top-level jails are parented to in cpuset_modify()
725 root = set->cs_parent; in cpuset_modify()
727 root = cpuset_getroot(set); in cpuset_modify()
730 if (root && !CPU_SUBSET(&root->cs_mask, mask)) { in cpuset_modify()
734 error = cpuset_testupdate(set, mask, 0); in cpuset_modify()
737 CPU_COPY(mask, &set->cs_mask); in cpuset_modify()
738 cpuset_update(set, mask); in cpuset_modify()
747 * the tree of sets starting at 'set'. Checks for sets that would become
751 cpuset_testupdate_domain(struct cpuset *set, struct domainset *dset, in cpuset_testupdate_domain() argument
760 if (set->cs_flags & CPU_SET_RDONLY) in cpuset_testupdate_domain()
762 domain = set->cs_domain; in cpuset_testupdate_domain()
767 DOMAINSET_AND(&newset.ds_mask, &dset->ds_mask); in cpuset_testupdate_domain()
772 LIST_FOREACH(nset, &set->cs_children, cs_siblings) in cpuset_testupdate_domain()
783 cpuset_update_domain(struct cpuset *set, struct domainset *domain, in cpuset_update_domain() argument
791 * a new set. Otherwise it simply inherits from the parent. When in cpuset_update_domain()
793 * set is modified from the parent we keep the policy and only in cpuset_update_domain()
796 if (set->cs_domain != orig) { in cpuset_update_domain()
797 orig = set->cs_domain; in cpuset_update_domain()
798 set->cs_domain = domainset_shadow(domain, orig, domains); in cpuset_update_domain()
800 set->cs_domain = domain; in cpuset_update_domain()
801 LIST_FOREACH(nset, &set->cs_children, cs_siblings) in cpuset_update_domain()
802 cpuset_update_domain(nset, set->cs_domain, orig, domains); in cpuset_update_domain()
808 * Modify the set 'set' to use a copy the domainset provided. Apply this new
813 cpuset_modify_domain(struct cpuset *set, struct domainset *domain) in cpuset_modify_domain() argument
831 if (jailed(curthread->td_ucred) && in cpuset_modify_domain()
832 set->cs_flags & CPU_SET_ROOT) in cpuset_modify_domain()
840 root = cpuset_getroot(set); in cpuset_modify_domain()
841 dset = root->cs_domain; in cpuset_modify_domain()
843 * Verify that we have access to this set of domains. in cpuset_modify_domain()
850 * If applying prefer we keep the current set as the fallback. in cpuset_modify_domain()
852 if (domain->ds_policy == DOMAINSET_POLICY_PREFER) in cpuset_modify_domain()
853 DOMAINSET_COPY(&set->cs_domain->ds_mask, in cpuset_modify_domain()
854 &domain->ds_mask); in cpuset_modify_domain()
856 * Determine whether we can apply this set of domains and in cpuset_modify_domain()
861 error = cpuset_testupdate_domain(set, &temp, set->cs_domain, in cpuset_modify_domain()
868 /* Dropping the lock; we'll need to re-evaluate again. */ in cpuset_modify_domain()
870 domainset_freelist_add(&domains, needed - ndomains); in cpuset_modify_domain()
874 dset = set->cs_domain; in cpuset_modify_domain()
875 cpuset_update_domain(set, domain, dset, &domains); in cpuset_modify_domain()
891 * For WHICH_SET returns a valid set with a new reference.
893 * -1 may be supplied for any argument to mean the current proc/thread or
894 * the base set of the current thread. May fail with ESRCH/EPERM.
900 struct cpuset *set; in cpuset_which() local
907 *setp = set = NULL; in cpuset_which()
910 if (id == -1) { in cpuset_which()
919 if (id == -1) { in cpuset_which()
925 td = tdfind(id, -1); in cpuset_which()
928 p = td->td_proc; in cpuset_which()
931 if (id == -1) { in cpuset_which()
936 td = tdfind(id, -1); in cpuset_which()
939 p = td->td_proc; in cpuset_which()
947 if (id == -1) { in cpuset_which()
949 set = cpuset_refbase(curthread->td_cpuset); in cpuset_which()
952 set = cpuset_lookup(id, curthread); in cpuset_which()
953 if (set) { in cpuset_which()
954 *setp = set; in cpuset_which()
960 /* Find `set' for prison with given id. */ in cpuset_which()
964 pr = prison_find_child(curthread->td_ucred->cr_prison, id); in cpuset_which()
968 cpuset_ref(pr->pr_cpuset); in cpuset_which()
969 *setp = pr->pr_cpuset; in cpuset_which()
970 mtx_unlock(&pr->pr_mtx); in cpuset_which()
997 if (id == -1 || id > PID_MAX) in cpuset_which2()
1006 cpuset_testshadow(struct cpuset *set, const cpuset_t *mask, in cpuset_testshadow() argument
1012 parent = cpuset_getbase(set); in cpuset_testshadow()
1017 if (mask != NULL && !CPU_SUBSET(&parent->cs_mask, mask)) in cpuset_testshadow()
1024 dset = parent->cs_domain; in cpuset_testshadow()
1032 * Create an anonymous set with the provided mask in the space provided by
1033 * 'nset'. If the passed in set is anonymous we use its parent otherwise
1034 * the new set is a child of 'set'.
1037 cpuset_shadow(struct cpuset *set, struct cpuset **nsetp, in cpuset_shadow() argument
1047 error = cpuset_testshadow(set, mask, domain); in cpuset_shadow()
1051 parent = cpuset_getbase(set); in cpuset_shadow()
1052 dset = parent->cs_domain; in cpuset_shadow()
1054 mask = &set->cs_mask; in cpuset_shadow()
1058 d = set->cs_domain; in cpuset_shadow()
1073 tdset = td->td_cpuset; in cpuset_update_thread()
1074 td->td_cpuset = nset; in cpuset_update_thread()
1075 td->td_domain.dr_policy = nset->cs_domain; in cpuset_update_thread()
1089 mask = &tdset->cs_mask; in cpuset_setproc_test_maskthread()
1091 domain = tdset->cs_domain; in cpuset_setproc_test_maskthread()
1104 mask = &tdset->cs_mask; in cpuset_setproc_maskthread()
1106 domain = tdset->cs_domain; in cpuset_setproc_maskthread()
1112 cpuset_setproc_setthread_mask(struct cpuset *tdset, struct cpuset *set, in cpuset_setproc_setthread_mask() argument
1121 * restriction to the new set, otherwise take it wholesale. in cpuset_setproc_setthread_mask()
1123 if (CPU_CMP(&tdset->cs_mask, &parent->cs_mask) != 0) { in cpuset_setproc_setthread_mask()
1124 CPU_AND(mask, &tdset->cs_mask, &set->cs_mask); in cpuset_setproc_setthread_mask()
1126 CPU_COPY(&set->cs_mask, mask); in cpuset_setproc_setthread_mask()
1130 * restriction to the new set but retain the policy. in cpuset_setproc_setthread_mask()
1132 if (tdset->cs_domain != parent->cs_domain) { in cpuset_setproc_setthread_mask()
1133 domainset_copy(tdset->cs_domain, domain); in cpuset_setproc_setthread_mask()
1134 DOMAINSET_AND(&domain->ds_mask, &set->cs_domain->ds_mask); in cpuset_setproc_setthread_mask()
1136 domainset_copy(set->cs_domain, domain); in cpuset_setproc_setthread_mask()
1138 if (CPU_EMPTY(mask) || DOMAINSET_EMPTY(&domain->ds_mask)) in cpuset_setproc_setthread_mask()
1145 cpuset_setproc_test_setthread(struct cpuset *tdset, struct cpuset *set) in cpuset_setproc_test_setthread() argument
1150 if (tdset->cs_id != CPUSET_INVALID) in cpuset_setproc_test_setthread()
1152 return cpuset_setproc_setthread_mask(tdset, set, &mask, &domain); in cpuset_setproc_test_setthread()
1156 cpuset_setproc_setthread(struct cpuset *tdset, struct cpuset *set, in cpuset_setproc_setthread() argument
1166 * original set we can simply accept the new set. in cpuset_setproc_setthread()
1168 if (tdset->cs_id != CPUSET_INVALID) { in cpuset_setproc_setthread()
1169 *nsetp = cpuset_ref(set); in cpuset_setproc_setthread()
1172 error = cpuset_setproc_setthread_mask(tdset, set, &mask, &domain); in cpuset_setproc_setthread()
1176 return cpuset_shadow(set, nsetp, &mask, &domain, freelist, in cpuset_setproc_setthread()
1181 cpuset_setproc_newbase(struct thread *td, struct cpuset *set, in cpuset_setproc_newbase() argument
1190 pbase = cpuset_getbase(td->td_cpuset); in cpuset_setproc_newbase()
1193 CPU_AND(&nmask, &pbase->cs_mask, &nroot->cs_mask); in cpuset_setproc_newbase()
1195 domainset_copy(pbase->cs_domain, &ndomain); in cpuset_setproc_newbase()
1196 DOMAINSET_AND(&ndomain.ds_mask, &set->cs_domain->ds_mask); in cpuset_setproc_newbase()
1210 error = cpuset_create(&pbase, set, &nmask); in cpuset_setproc_newbase()
1217 pbase->cs_domain = domainset_shadow(set->cs_domain, &ndomain, in cpuset_setproc_newbase()
1226 * 1) Set is non-null and the process is not rebasing onto a new root. This
1227 * reparents all anonymous sets to the provided set and replaces all
1228 * non-anonymous td_cpusets with the provided set.
1229 * 2) Set is non-null and the process is rebasing onto a new root. This
1230 * creates a new base set if the process previously had its own base set,
1231 * then reparents all anonymous sets either to that set or the provided set
1232 * if one was not created. Non-anonymous sets are similarly replaced.
1233 * 3) Mask is non-null. This replaces or creates anonymous sets for every
1235 * 4) domain is non-null. This creates anonymous sets for every thread
1236 * and replaces the domain set.
1243 cpuset_setproc(pid_t pid, struct cpuset *set, cpuset_t *mask, in cpuset_setproc() argument
1268 base = set; in cpuset_setproc()
1270 if (set != NULL) in cpuset_setproc()
1271 nroot = cpuset_getroot(set); in cpuset_setproc()
1276 tdroot = cpuset_getroot(td->td_cpuset); in cpuset_setproc()
1277 needed = p->p_numthreads; in cpuset_setproc()
1278 if (set != NULL && rebase && tdroot != nroot) in cpuset_setproc()
1284 cpuset_freelist_add(&freelist, needed - nfree); in cpuset_setproc()
1285 domainset_freelist_add(&domainlist, needed - nfree); in cpuset_setproc()
1292 * If we're changing roots and the root set is what has been specified in cpuset_setproc()
1294 * the root set and, if it wasn't, create a new base with the process's in cpuset_setproc()
1302 if (set != NULL && rebase && nroot != tdroot) { in cpuset_setproc()
1305 root_id = td->td_ucred->cr_prison->pr_cpuset->cs_id; in cpuset_setproc()
1306 base_id = cpuset_getbase(td->td_cpuset)->cs_id; in cpuset_setproc()
1309 error = cpuset_setproc_newbase(td, set, nroot, &base, in cpuset_setproc()
1327 if (set != NULL) in cpuset_setproc()
1328 error = cpuset_setproc_test_setthread(td->td_cpuset, in cpuset_setproc()
1331 error = cpuset_setproc_test_maskthread(td->td_cpuset, in cpuset_setproc()
1344 if (set != NULL) in cpuset_setproc()
1345 error = cpuset_setproc_setthread(td->td_cpuset, base, in cpuset_setproc()
1348 error = cpuset_setproc_maskthread(td->td_cpuset, mask, in cpuset_setproc()
1360 if (base != NULL && base != set) in cpuset_setproc()
1370 bitset_strprint(char *buf, size_t bufsiz, const struct bitset *set, int setlen) in bitset_strprint() argument
1384 bufsiz--; in bitset_strprint()
1389 bytes = snprintf(p, bufsiz, "%lx", set->__bits[i]); in bitset_strprint()
1391 bufsiz -= bytes; in bitset_strprint()
1393 return (p - buf); in bitset_strprint()
1397 bitset_strscan(struct bitset *set, int setlen, const char *buf) in bitset_strscan() argument
1402 BIT_ZERO(setlen, set); in bitset_strscan()
1409 ret = sscanf(p, "%lx", &set->__bits[i]); in bitset_strscan()
1410 if (ret == 0 || ret == -1) in bitset_strscan()
1415 return (p - buf); in bitset_strscan()
1423 cpusetobj_strprint(char *buf, const cpuset_t *set) in cpusetobj_strprint() argument
1426 bitset_strprint(buf, CPUSETBUFSIZ, (const struct bitset *)set, in cpusetobj_strprint()
1436 cpusetobj_strscan(cpuset_t *set, const char *buf) in cpusetobj_strscan() argument
1440 if (strlen(buf) > CPUSETBUFSIZ - 1) in cpusetobj_strscan()
1441 return (-1); in cpusetobj_strscan()
1443 p = buf[bitset_strscan((struct bitset *)set, CPU_SETSIZE, buf)]; in cpusetobj_strscan()
1445 return (-1); in cpusetobj_strscan()
1472 (const struct bitset *)&dset->ds_mask, DOMAINSET_SETSIZE); in sysctl_handle_domainset()
1473 sprintf(p, ":%d:%d", dset->ds_policy, dset->ds_prefer); in sysctl_handle_domainset()
1477 if (error != 0 || req->newptr == NULL) in sysctl_handle_domainset()
1511 struct cpuset *set; in _cpuset_setthread() local
1518 error = cpuset_which(CPU_WHICH_TID, id, &p, &td, &set); in _cpuset_setthread()
1521 set = NULL; in _cpuset_setthread()
1523 error = cpuset_shadow(td->td_cpuset, &nset, mask, domain, in _cpuset_setthread()
1526 set = cpuset_update_thread(td, nset); in _cpuset_setthread()
1529 if (set) in _cpuset_setthread()
1530 cpuset_rel(set); in _cpuset_setthread()
1574 DOMAINSET_COPY(&all_domains, &dset->ds_mask); in domainset_init()
1575 dset->ds_policy = DOMAINSET_POLICY_FIRSTTOUCH; in domainset_init()
1576 dset->ds_prefer = -1; in domainset_init()
1580 DOMAINSET_COPY(&all_domains, &dset->ds_mask); in domainset_init()
1581 dset->ds_policy = DOMAINSET_POLICY_INTERLEAVE; in domainset_init()
1582 dset->ds_prefer = -1; in domainset_init()
1586 DOMAINSET_COPY(&all_domains, &dset->ds_mask); in domainset_init()
1587 dset->ds_policy = DOMAINSET_POLICY_ROUNDROBIN; in domainset_init()
1588 dset->ds_prefer = -1; in domainset_init()
1593 DOMAINSET_ZERO(&dset->ds_mask); in domainset_init()
1594 DOMAINSET_SET(i, &dset->ds_mask); in domainset_init()
1595 dset->ds_policy = DOMAINSET_POLICY_ROUNDROBIN; in domainset_init()
1599 DOMAINSET_COPY(&all_domains, &dset->ds_mask); in domainset_init()
1600 dset->ds_policy = DOMAINSET_POLICY_PREFER; in domainset_init()
1601 dset->ds_prefer = i; in domainset_init()
1617 curthread->td_domain.dr_policy = domainset0; in domainset_zero()
1620 kernel_object->domain.dr_policy = domainset2; in domainset_zero()
1629 * Creates system-wide cpusets and the cpuset for thread0 including three
1632 * 0 - The root set which should represent all valid processors in the
1633 * system. This set is immutable.
1634 * 1 - The default set which all processes are a member of until changed.
1637 * 2 - The kernel set which allows restriction and policy to be applied only
1643 struct cpuset *set; in cpuset_thread0() local
1653 * Create the root system set (0) for the whole machine. Doesn't use in cpuset_thread0()
1656 set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); in cpuset_thread0()
1657 CPU_COPY(&all_cpus, &set->cs_mask); in cpuset_thread0()
1658 LIST_INIT(&set->cs_children); in cpuset_thread0()
1659 LIST_INSERT_HEAD(&cpuset_ids, set, cs_link); in cpuset_thread0()
1660 refcount_init(&set->cs_ref, 1); in cpuset_thread0()
1661 set->cs_flags = CPU_SET_ROOT | CPU_SET_RDONLY; in cpuset_thread0()
1662 set->cs_domain = domainset0; in cpuset_thread0()
1663 cpuset_zero = set; in cpuset_thread0()
1664 cpuset_root = &set->cs_mask; in cpuset_thread0()
1667 * Now derive a default (1), modifiable set from that to give out. in cpuset_thread0()
1669 set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); in cpuset_thread0()
1670 error = cpuset_init(set, cpuset_zero, NULL, NULL, 1); in cpuset_thread0()
1671 KASSERT(error == 0, ("Error creating default set: %d\n", error)); in cpuset_thread0()
1672 cpuset_default = set; in cpuset_thread0()
1674 * Create the kernel set (2). in cpuset_thread0()
1676 set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); in cpuset_thread0()
1677 error = cpuset_init(set, cpuset_zero, NULL, NULL, 2); in cpuset_thread0()
1678 KASSERT(error == 0, ("Error creating kernel set: %d\n", error)); in cpuset_thread0()
1679 set->cs_domain = domainset2; in cpuset_thread0()
1680 cpuset_kernel = set; in cpuset_thread0()
1688 * If MD code has not initialized per-domain cpusets, place all in cpuset_thread0()
1703 struct cpuset *set; in cpuset_kernthread() local
1706 set = td->td_cpuset; in cpuset_kernthread()
1707 td->td_cpuset = cpuset_ref(cpuset_kernel); in cpuset_kernthread()
1709 cpuset_rel(set); in cpuset_kernthread()
1714 * mark the new 'set' as root.
1719 * In case of no error, returns the set in *setp locked with a reference.
1724 struct cpuset *set; in cpuset_create_root() local
1730 set = NULL; in cpuset_create_root()
1731 error = cpuset_create(&set, pr->pr_cpuset, &pr->pr_cpuset->cs_mask); in cpuset_create_root()
1735 KASSERT(set != NULL, ("[%s:%d] cpuset_create returned invalid data", in cpuset_create_root()
1738 /* Mark the set as root. */ in cpuset_create_root()
1739 set->cs_flags |= CPU_SET_ROOT; in cpuset_create_root()
1740 *setp = set; in cpuset_create_root()
1746 cpuset_setproc_update_set(struct proc *p, struct cpuset *set) in cpuset_setproc_update_set() argument
1751 KASSERT(set != NULL, ("[%s:%d] invalid set", __func__, __LINE__)); in cpuset_setproc_update_set()
1753 cpuset_ref(set); in cpuset_setproc_update_set()
1754 error = cpuset_setproc(p->p_pid, set, NULL, NULL, true); in cpuset_setproc_update_set()
1757 cpuset_rel(set); in cpuset_setproc_update_set()
1774 if (id != -1 && which == CPU_WHICH_TIDPID && in cpuset_capmode_allowed()
1775 id != td->td_tid && id != td->td_proc->p_pid) in cpuset_capmode_allowed()
1777 if (id != -1 && in cpuset_capmode_allowed()
1778 !(which == CPU_WHICH_TID && id == td->td_tid) && in cpuset_capmode_allowed()
1779 !(which == CPU_WHICH_PID && id == td->td_proc->p_pid)) in cpuset_capmode_allowed()
1806 * are set as a function pointer in cpuset_copy_cb struct and called by
1848 struct cpuset *set; in sys_cpuset() local
1852 root = cpuset_refroot(td->td_cpuset); in sys_cpuset()
1854 set = NULL; in sys_cpuset()
1855 error = cpuset_create(&set, root, &root->cs_mask); in sys_cpuset()
1859 error = copyout(&set->cs_id, uap->setid, sizeof(set->cs_id)); in sys_cpuset()
1861 error = cpuset_setproc(-1, set, NULL, NULL, false); in sys_cpuset()
1862 cpuset_rel(set); in sys_cpuset()
1877 return (kern_cpuset_setid(td, uap->which, uap->id, uap->setid)); in sys_cpuset_setid()
1884 struct cpuset *set; in kern_cpuset_setid() local
1888 * Presently we only support per-process sets. in kern_cpuset_setid()
1892 set = cpuset_lookup(setid, td); in kern_cpuset_setid()
1893 if (set == NULL) in kern_cpuset_setid()
1895 error = cpuset_setproc(id, set, NULL, NULL, false); in kern_cpuset_setid()
1896 cpuset_rel(set); in kern_cpuset_setid()
1912 return (kern_cpuset_getid(td, uap->level, uap->which, uap->id, in sys_cpuset_getid()
1913 uap->setid)); in sys_cpuset_getid()
1921 struct cpuset *set; in kern_cpuset_getid() local
1929 error = cpuset_which(which, id, &p, &ttd, &set); in kern_cpuset_getid()
1937 set = cpuset_refbase(ttd->td_cpuset); in kern_cpuset_getid()
1950 nset = cpuset_refroot(set); in kern_cpuset_getid()
1951 cpuset_rel(set); in kern_cpuset_getid()
1952 set = nset; in kern_cpuset_getid()
1959 tmpid = set->cs_id; in kern_cpuset_getid()
1960 cpuset_rel(set); in kern_cpuset_getid()
1980 return (user_cpuset_getaffinity(td, uap->level, uap->which, in sys_cpuset_getaffinity()
1981 uap->id, uap->cpusetsize, uap->mask, ©_set)); in sys_cpuset_getaffinity()
1990 struct cpuset *set; in kern_cpuset_getaffinity() local
1997 error = cpuset_which2(&which, id, &p, &ttd, &set); in kern_cpuset_getaffinity()
2007 set = cpuset_ref(ttd->td_cpuset); in kern_cpuset_getaffinity()
2020 nset = cpuset_refroot(set); in kern_cpuset_getaffinity()
2022 nset = cpuset_refbase(set); in kern_cpuset_getaffinity()
2023 CPU_COPY(&nset->cs_mask, mask); in kern_cpuset_getaffinity()
2030 CPU_COPY(&ttd->td_cpuset->cs_mask, mask); in kern_cpuset_getaffinity()
2036 CPU_OR(mask, mask, &ttd->td_cpuset->cs_mask); in kern_cpuset_getaffinity()
2042 CPU_COPY(&set->cs_mask, mask); in kern_cpuset_getaffinity()
2061 if (set) in kern_cpuset_getaffinity()
2062 cpuset_rel(set); in kern_cpuset_getaffinity()
2088 error = cb->cpuset_copyout(mask, maskp, size); in user_cpuset_getaffinity()
2096 end = cp = (char *)&maskp->__bits; in user_cpuset_getaffinity()
2101 if (rv == -1) { in user_cpuset_getaffinity()
2127 return (user_cpuset_setaffinity(td, uap->level, uap->which, in sys_cpuset_setaffinity()
2128 uap->id, uap->cpusetsize, uap->mask, ©_set)); in sys_cpuset_setaffinity()
2136 struct cpuset *set; in kern_cpuset_setaffinity() local
2153 error = cpuset_which(which, id, &p, &ttd, &set); in kern_cpuset_setaffinity()
2161 set = cpuset_ref(ttd->td_cpuset); in kern_cpuset_setaffinity()
2175 nset = cpuset_refroot(set); in kern_cpuset_setaffinity()
2177 nset = cpuset_refbase(set); in kern_cpuset_setaffinity()
2180 cpuset_rel(set); in kern_cpuset_setaffinity()
2191 if (id > PID_MAX || id == -1) in kern_cpuset_setaffinity()
2199 error = cpuset_which(which, id, &p, &ttd, &set); in kern_cpuset_setaffinity()
2201 error = cpuset_modify(set, mask); in kern_cpuset_setaffinity()
2202 cpuset_rel(set); in kern_cpuset_setaffinity()
2232 error = cb->cpuset_copyin(maskp, mask, size); in user_cpuset_setaffinity()
2236 * Verify that no high bits are set. in user_cpuset_setaffinity()
2241 end = cp = (const char *)&maskp->__bits; in user_cpuset_setaffinity()
2247 if (val == -1) { in user_cpuset_setaffinity()
2279 return (kern_cpuset_getdomain(td, uap->level, uap->which, in sys_cpuset_getdomain()
2280 uap->id, uap->domainsetsize, uap->mask, uap->policy, ©_set)); in sys_cpuset_getdomain()
2291 struct cpuset *set; in kern_cpuset_getdomain() local
2305 error = cpuset_which2(&which, id, &p, &ttd, &set); in kern_cpuset_getdomain()
2315 set = cpuset_ref(ttd->td_cpuset); in kern_cpuset_getdomain()
2329 nset = cpuset_refroot(set); in kern_cpuset_getdomain()
2331 nset = cpuset_refbase(set); in kern_cpuset_getdomain()
2332 domainset_copy(nset->cs_domain, &outset); in kern_cpuset_getdomain()
2339 domainset_copy(ttd->td_cpuset->cs_domain, &outset); in kern_cpuset_getdomain()
2345 dset = ttd->td_cpuset->cs_domain; in kern_cpuset_getdomain()
2347 DOMAINSET_OR(&outset.ds_mask, &dset->ds_mask); in kern_cpuset_getdomain()
2349 outset.ds_policy = dset->ds_policy; in kern_cpuset_getdomain()
2350 outset.ds_prefer = dset->ds_prefer; in kern_cpuset_getdomain()
2356 domainset_copy(set->cs_domain, &outset); in kern_cpuset_getdomain()
2370 if (set) in kern_cpuset_getdomain()
2371 cpuset_rel(set); in kern_cpuset_getdomain()
2375 * Translate prefer into a set containing only the preferred domain, in kern_cpuset_getdomain()
2376 * not the entire fallback set. in kern_cpuset_getdomain()
2384 error = cb->cpuset_copyout(mask, maskp, domainsetsize); in kern_cpuset_getdomain()
2407 return (kern_cpuset_setdomain(td, uap->level, uap->which, in sys_cpuset_setdomain()
2408 uap->id, uap->domainsetsize, uap->mask, uap->policy, ©_set)); in sys_cpuset_setdomain()
2422 * Verify that no high bits are set. in domainset_populate()
2428 end = cp = (const char *)&mask->__bits; in domainset_populate()
2440 DOMAINSET_COPY(mask, &domain->ds_mask); in domainset_populate()
2441 domain->ds_policy = policy; in domainset_populate()
2446 if (!DOMAINSET_SUBSET(&all_domains, &domain->ds_mask)) { in domainset_populate()
2453 if (DOMAINSET_COUNT(&domain->ds_mask) != 1) { in domainset_populate()
2456 domain->ds_prefer = DOMAINSET_FFS(&domain->ds_mask) - 1; in domainset_populate()
2458 DOMAINSET_COPY(&all_domains, &domain->ds_mask); in domainset_populate()
2470 struct cpuset *set; in kern_cpuset_setdomain() local
2485 error = cb->cpuset_copyin(maskp, mask, domainsetsize); in kern_cpuset_setdomain()
2501 error = cpuset_which(which, id, &p, &ttd, &set); in kern_cpuset_setdomain()
2509 set = cpuset_ref(ttd->td_cpuset); in kern_cpuset_setdomain()
2524 nset = cpuset_refroot(set); in kern_cpuset_setdomain()
2526 nset = cpuset_refbase(set); in kern_cpuset_setdomain()
2529 cpuset_rel(set); in kern_cpuset_setdomain()
2540 if (id > PID_MAX || id == -1) in kern_cpuset_setdomain()
2548 error = cpuset_which(which, id, &p, &ttd, &set); in kern_cpuset_setdomain()
2550 error = cpuset_modify_domain(set, &domain); in kern_cpuset_setdomain()
2551 cpuset_rel(set); in kern_cpuset_setdomain()
2574 ddb_display_bitset(const struct bitset *set, int size) in ddb_display_bitset() argument
2579 if (CPU_ISSET(bit, set)) { in ddb_display_bitset()
2592 ddb_display_cpuset(const cpuset_t *set) in ddb_display_cpuset() argument
2594 ddb_display_bitset((const struct bitset *)set, CPU_SETSIZE); in ddb_display_cpuset()
2598 ddb_display_domainset(const domainset_t *set) in ddb_display_domainset() argument
2600 ddb_display_bitset((const struct bitset *)set, DOMAINSET_SETSIZE); in ddb_display_domainset()
2605 struct cpuset *set; in DB_SHOW_COMMAND_FLAGS() local
2607 LIST_FOREACH(set, &cpuset_ids, cs_link) { in DB_SHOW_COMMAND_FLAGS()
2608 db_printf("set=%p id=%-6u ref=%-6d flags=0x%04x parent id=%d\n", in DB_SHOW_COMMAND_FLAGS()
2609 set, set->cs_id, refcount_load(&set->cs_ref), set->cs_flags, in DB_SHOW_COMMAND_FLAGS()
2610 (set->cs_parent != NULL) ? set->cs_parent->cs_id : 0); in DB_SHOW_COMMAND_FLAGS()
2612 ddb_display_cpuset(&set->cs_mask); in DB_SHOW_COMMAND_FLAGS()
2615 set->cs_domain->ds_policy, set->cs_domain->ds_prefer); in DB_SHOW_COMMAND_FLAGS()
2616 ddb_display_domainset(&set->cs_domain->ds_mask); in DB_SHOW_COMMAND_FLAGS()
2625 struct domainset *set; in DB_SHOW_COMMAND_FLAGS() local
2627 LIST_FOREACH(set, &cpuset_domains, ds_link) { in DB_SHOW_COMMAND_FLAGS()
2628 db_printf("set=%p policy %d prefer %d cnt %d\n", in DB_SHOW_COMMAND_FLAGS()
2629 set, set->ds_policy, set->ds_prefer, set->ds_cnt); in DB_SHOW_COMMAND_FLAGS()
2631 ddb_display_domainset(&set->ds_mask); in DB_SHOW_COMMAND_FLAGS()