1d7f687fcSJeff Roberson /*- 2d7f687fcSJeff Roberson * Copyright (c) 2008, Jeffrey Roberson <jeff@freebsd.org> 3d7f687fcSJeff Roberson * All rights reserved. 4d7f687fcSJeff Roberson * 53bc8c68dSJeff Roberson * Copyright (c) 2008 Nokia Corporation 63bc8c68dSJeff Roberson * All rights reserved. 73bc8c68dSJeff Roberson * 8d7f687fcSJeff Roberson * Redistribution and use in source and binary forms, with or without 9d7f687fcSJeff Roberson * modification, are permitted provided that the following conditions 10d7f687fcSJeff Roberson * are met: 11d7f687fcSJeff Roberson * 1. Redistributions of source code must retain the above copyright 12d7f687fcSJeff Roberson * notice unmodified, this list of conditions, and the following 13d7f687fcSJeff Roberson * disclaimer. 14d7f687fcSJeff Roberson * 2. Redistributions in binary form must reproduce the above copyright 15d7f687fcSJeff Roberson * notice, this list of conditions and the following disclaimer in the 16d7f687fcSJeff Roberson * documentation and/or other materials provided with the distribution. 17d7f687fcSJeff Roberson * 18d7f687fcSJeff Roberson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19d7f687fcSJeff Roberson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20d7f687fcSJeff Roberson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21d7f687fcSJeff Roberson * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22d7f687fcSJeff Roberson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23d7f687fcSJeff Roberson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24d7f687fcSJeff Roberson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25d7f687fcSJeff Roberson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26d7f687fcSJeff Roberson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27d7f687fcSJeff Roberson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28d7f687fcSJeff Roberson * 29d7f687fcSJeff Roberson */ 30d7f687fcSJeff Roberson 31d7f687fcSJeff Roberson #include <sys/cdefs.h> 32d7f687fcSJeff Roberson __FBSDID("$FreeBSD$"); 33d7f687fcSJeff Roberson 34dea0ed66SBjoern A. Zeeb #include "opt_ddb.h" 35dea0ed66SBjoern A. Zeeb 36d7f687fcSJeff Roberson #include <sys/param.h> 37d7f687fcSJeff Roberson #include <sys/systm.h> 38d7f687fcSJeff Roberson #include <sys/sysproto.h> 390304c731SJamie Gritton #include <sys/jail.h> 40d7f687fcSJeff Roberson #include <sys/kernel.h> 41d7f687fcSJeff Roberson #include <sys/lock.h> 42d7f687fcSJeff Roberson #include <sys/malloc.h> 43d7f687fcSJeff Roberson #include <sys/mutex.h> 44d7f687fcSJeff Roberson #include <sys/priv.h> 45d7f687fcSJeff Roberson #include <sys/proc.h> 46d7f687fcSJeff Roberson #include <sys/refcount.h> 47d7f687fcSJeff Roberson #include <sys/sched.h> 48d7f687fcSJeff Roberson #include <sys/smp.h> 49d7f687fcSJeff Roberson #include <sys/syscallsubr.h> 50d7f687fcSJeff Roberson #include <sys/cpuset.h> 51d7f687fcSJeff Roberson #include <sys/sx.h> 52d7f687fcSJeff Roberson #include <sys/queue.h> 53d7f687fcSJeff Roberson #include <sys/limits.h> 54a03ee000SJeff Roberson #include <sys/bus.h> 55a03ee000SJeff Roberson #include <sys/interrupt.h> 56d7f687fcSJeff Roberson 57d7f687fcSJeff Roberson #include <vm/uma.h> 58d7f687fcSJeff Roberson 59dea0ed66SBjoern A. Zeeb #ifdef DDB 60dea0ed66SBjoern A. Zeeb #include <ddb/ddb.h> 61dea0ed66SBjoern A. Zeeb #endif /* DDB */ 62dea0ed66SBjoern A. Zeeb 63d7f687fcSJeff Roberson /* 64d7f687fcSJeff Roberson * cpusets provide a mechanism for creating and manipulating sets of 65d7f687fcSJeff Roberson * processors for the purpose of constraining the scheduling of threads to 66d7f687fcSJeff Roberson * specific processors. 67d7f687fcSJeff Roberson * 68d7f687fcSJeff Roberson * Each process belongs to an identified set, by default this is set 1. Each 69d7f687fcSJeff Roberson * thread may further restrict the cpus it may run on to a subset of this 70d7f687fcSJeff Roberson * named set. This creates an anonymous set which other threads and processes 71d7f687fcSJeff Roberson * may not join by number. 72d7f687fcSJeff Roberson * 73d7f687fcSJeff Roberson * The named set is referred to herein as the 'base' set to avoid ambiguity. 74d7f687fcSJeff Roberson * This set is usually a child of a 'root' set while the anonymous set may 75d7f687fcSJeff Roberson * simply be referred to as a mask. In the syscall api these are referred to 76d7f687fcSJeff Roberson * as the ROOT, CPUSET, and MASK levels where CPUSET is called 'base' here. 77d7f687fcSJeff Roberson * 78d7f687fcSJeff Roberson * Threads inherit their set from their creator whether it be anonymous or 79d7f687fcSJeff Roberson * not. This means that anonymous sets are immutable because they may be 80d7f687fcSJeff Roberson * shared. To modify an anonymous set a new set is created with the desired 81d7f687fcSJeff Roberson * mask and the same parent as the existing anonymous set. This gives the 8293902625SJohn Baldwin * illusion of each thread having a private mask. 83d7f687fcSJeff Roberson * 84d7f687fcSJeff Roberson * Via the syscall apis a user may ask to retrieve or modify the root, base, 85d7f687fcSJeff Roberson * or mask that is discovered via a pid, tid, or setid. Modifying a set 86d7f687fcSJeff Roberson * modifies all numbered and anonymous child sets to comply with the new mask. 87d7f687fcSJeff Roberson * Modifying a pid or tid's mask applies only to that tid but must still 88d7f687fcSJeff Roberson * exist within the assigned parent set. 89d7f687fcSJeff Roberson * 9086855bf5SJohn Baldwin * A thread may not be assigned to a group separate from other threads in 91d7f687fcSJeff Roberson * the process. This is to remove ambiguity when the setid is queried with 92d7f687fcSJeff Roberson * a pid argument. There is no other technical limitation. 93d7f687fcSJeff Roberson * 94d7f687fcSJeff Roberson * This somewhat complex arrangement is intended to make it easy for 95d7f687fcSJeff Roberson * applications to query available processors and bind their threads to 96d7f687fcSJeff Roberson * specific processors while also allowing administrators to dynamically 97d7f687fcSJeff Roberson * reprovision by changing sets which apply to groups of processes. 98d7f687fcSJeff Roberson * 99d7f687fcSJeff Roberson * A simple application should not concern itself with sets at all and 100d7f687fcSJeff Roberson * rather apply masks to its own threads via CPU_WHICH_TID and a -1 id 10193902625SJohn Baldwin * meaning 'curthread'. It may query available cpus for that tid with a 102d7f687fcSJeff Roberson * getaffinity call using (CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1, ...). 103d7f687fcSJeff Roberson */ 104d7f687fcSJeff Roberson static uma_zone_t cpuset_zone; 105d7f687fcSJeff Roberson static struct mtx cpuset_lock; 106d7f687fcSJeff Roberson static struct setlist cpuset_ids; 107d7f687fcSJeff Roberson static struct unrhdr *cpuset_unr; 108a03ee000SJeff Roberson static struct cpuset *cpuset_zero; 109a03ee000SJeff Roberson 110444528c0SDavid Xu /* Return the size of cpuset_t at the kernel level */ 111444528c0SDavid Xu SYSCTL_INT(_kern_sched, OID_AUTO, cpusetsize, CTLFLAG_RD, 112444528c0SDavid Xu 0, sizeof(cpuset_t), "sizeof(cpuset_t)"); 113444528c0SDavid Xu 114a03ee000SJeff Roberson cpuset_t *cpuset_root; 115d7f687fcSJeff Roberson 116d7f687fcSJeff Roberson /* 117d7f687fcSJeff Roberson * Acquire a reference to a cpuset, all pointers must be tracked with refs. 118d7f687fcSJeff Roberson */ 119d7f687fcSJeff Roberson struct cpuset * 120d7f687fcSJeff Roberson cpuset_ref(struct cpuset *set) 121d7f687fcSJeff Roberson { 122d7f687fcSJeff Roberson 123d7f687fcSJeff Roberson refcount_acquire(&set->cs_ref); 124d7f687fcSJeff Roberson return (set); 125d7f687fcSJeff Roberson } 126d7f687fcSJeff Roberson 127d7f687fcSJeff Roberson /* 1287a8f695aSBjoern A. Zeeb * Walks up the tree from 'set' to find the root. Returns the root 1297a8f695aSBjoern A. Zeeb * referenced. 1307a8f695aSBjoern A. Zeeb */ 1317a8f695aSBjoern A. Zeeb static struct cpuset * 1327a8f695aSBjoern A. Zeeb cpuset_refroot(struct cpuset *set) 1337a8f695aSBjoern A. Zeeb { 1347a8f695aSBjoern A. Zeeb 1357a8f695aSBjoern A. Zeeb for (; set->cs_parent != NULL; set = set->cs_parent) 1367a8f695aSBjoern A. Zeeb if (set->cs_flags & CPU_SET_ROOT) 1377a8f695aSBjoern A. Zeeb break; 1387a8f695aSBjoern A. Zeeb cpuset_ref(set); 1397a8f695aSBjoern A. Zeeb 1407a8f695aSBjoern A. Zeeb return (set); 1417a8f695aSBjoern A. Zeeb } 1427a8f695aSBjoern A. Zeeb 1437a8f695aSBjoern A. Zeeb /* 1447a8f695aSBjoern A. Zeeb * Find the first non-anonymous set starting from 'set'. Returns this set 1457a8f695aSBjoern A. Zeeb * referenced. May return the passed in set with an extra ref if it is 1467a8f695aSBjoern A. Zeeb * not anonymous. 1477a8f695aSBjoern A. Zeeb */ 1487a8f695aSBjoern A. Zeeb static struct cpuset * 1497a8f695aSBjoern A. Zeeb cpuset_refbase(struct cpuset *set) 1507a8f695aSBjoern A. Zeeb { 1517a8f695aSBjoern A. Zeeb 1527a8f695aSBjoern A. Zeeb if (set->cs_id == CPUSET_INVALID) 1537a8f695aSBjoern A. Zeeb set = set->cs_parent; 1547a8f695aSBjoern A. Zeeb cpuset_ref(set); 1557a8f695aSBjoern A. Zeeb 1567a8f695aSBjoern A. Zeeb return (set); 1577a8f695aSBjoern A. Zeeb } 1587a8f695aSBjoern A. Zeeb 1597a8f695aSBjoern A. Zeeb /* 16093902625SJohn Baldwin * Release a reference in a context where it is safe to allocate. 161d7f687fcSJeff Roberson */ 162d7f687fcSJeff Roberson void 163d7f687fcSJeff Roberson cpuset_rel(struct cpuset *set) 164d7f687fcSJeff Roberson { 165d7f687fcSJeff Roberson cpusetid_t id; 166d7f687fcSJeff Roberson 167d7f687fcSJeff Roberson if (refcount_release(&set->cs_ref) == 0) 168d7f687fcSJeff Roberson return; 169d7f687fcSJeff Roberson mtx_lock_spin(&cpuset_lock); 170d7f687fcSJeff Roberson LIST_REMOVE(set, cs_siblings); 171d7f687fcSJeff Roberson id = set->cs_id; 172d7f687fcSJeff Roberson if (id != CPUSET_INVALID) 173d7f687fcSJeff Roberson LIST_REMOVE(set, cs_link); 174d7f687fcSJeff Roberson mtx_unlock_spin(&cpuset_lock); 175d7f687fcSJeff Roberson cpuset_rel(set->cs_parent); 176d7f687fcSJeff Roberson uma_zfree(cpuset_zone, set); 177d7f687fcSJeff Roberson if (id != CPUSET_INVALID) 178d7f687fcSJeff Roberson free_unr(cpuset_unr, id); 179d7f687fcSJeff Roberson } 180d7f687fcSJeff Roberson 181d7f687fcSJeff Roberson /* 182d7f687fcSJeff Roberson * Deferred release must be used when in a context that is not safe to 183d7f687fcSJeff Roberson * allocate/free. This places any unreferenced sets on the list 'head'. 184d7f687fcSJeff Roberson */ 185d7f687fcSJeff Roberson static void 186d7f687fcSJeff Roberson cpuset_rel_defer(struct setlist *head, struct cpuset *set) 187d7f687fcSJeff Roberson { 188d7f687fcSJeff Roberson 189d7f687fcSJeff Roberson if (refcount_release(&set->cs_ref) == 0) 190d7f687fcSJeff Roberson return; 191d7f687fcSJeff Roberson mtx_lock_spin(&cpuset_lock); 192d7f687fcSJeff Roberson LIST_REMOVE(set, cs_siblings); 193d7f687fcSJeff Roberson if (set->cs_id != CPUSET_INVALID) 194d7f687fcSJeff Roberson LIST_REMOVE(set, cs_link); 195d7f687fcSJeff Roberson LIST_INSERT_HEAD(head, set, cs_link); 196d7f687fcSJeff Roberson mtx_unlock_spin(&cpuset_lock); 197d7f687fcSJeff Roberson } 198d7f687fcSJeff Roberson 199d7f687fcSJeff Roberson /* 200d7f687fcSJeff Roberson * Complete a deferred release. Removes the set from the list provided to 201d7f687fcSJeff Roberson * cpuset_rel_defer. 202d7f687fcSJeff Roberson */ 203d7f687fcSJeff Roberson static void 204d7f687fcSJeff Roberson cpuset_rel_complete(struct cpuset *set) 205d7f687fcSJeff Roberson { 206d7f687fcSJeff Roberson LIST_REMOVE(set, cs_link); 207d7f687fcSJeff Roberson cpuset_rel(set->cs_parent); 208d7f687fcSJeff Roberson uma_zfree(cpuset_zone, set); 209d7f687fcSJeff Roberson } 210d7f687fcSJeff Roberson 211d7f687fcSJeff Roberson /* 212d7f687fcSJeff Roberson * Find a set based on an id. Returns it with a ref. 213d7f687fcSJeff Roberson */ 214d7f687fcSJeff Roberson static struct cpuset * 215413628a7SBjoern A. Zeeb cpuset_lookup(cpusetid_t setid, struct thread *td) 216d7f687fcSJeff Roberson { 217d7f687fcSJeff Roberson struct cpuset *set; 218d7f687fcSJeff Roberson 219d7f687fcSJeff Roberson if (setid == CPUSET_INVALID) 220d7f687fcSJeff Roberson return (NULL); 221d7f687fcSJeff Roberson mtx_lock_spin(&cpuset_lock); 222d7f687fcSJeff Roberson LIST_FOREACH(set, &cpuset_ids, cs_link) 223d7f687fcSJeff Roberson if (set->cs_id == setid) 224d7f687fcSJeff Roberson break; 225d7f687fcSJeff Roberson if (set) 226d7f687fcSJeff Roberson cpuset_ref(set); 227d7f687fcSJeff Roberson mtx_unlock_spin(&cpuset_lock); 228413628a7SBjoern A. Zeeb 229413628a7SBjoern A. Zeeb KASSERT(td != NULL, ("[%s:%d] td is NULL", __func__, __LINE__)); 230413628a7SBjoern A. Zeeb if (set != NULL && jailed(td->td_ucred)) { 2310304c731SJamie Gritton struct cpuset *jset, *tset; 232413628a7SBjoern A. Zeeb 2330304c731SJamie Gritton jset = td->td_ucred->cr_prison->pr_cpuset; 2340304c731SJamie Gritton for (tset = set; tset != NULL; tset = tset->cs_parent) 2350304c731SJamie Gritton if (tset == jset) 2360304c731SJamie Gritton break; 2370304c731SJamie Gritton if (tset == NULL) { 238413628a7SBjoern A. Zeeb cpuset_rel(set); 239413628a7SBjoern A. Zeeb set = NULL; 240413628a7SBjoern A. Zeeb } 241413628a7SBjoern A. Zeeb } 242413628a7SBjoern A. Zeeb 243d7f687fcSJeff Roberson return (set); 244d7f687fcSJeff Roberson } 245d7f687fcSJeff Roberson 246d7f687fcSJeff Roberson /* 247d7f687fcSJeff Roberson * Create a set in the space provided in 'set' with the provided parameters. 248d7f687fcSJeff Roberson * The set is returned with a single ref. May return EDEADLK if the set 249d7f687fcSJeff Roberson * will have no valid cpu based on restrictions from the parent. 250d7f687fcSJeff Roberson */ 251d7f687fcSJeff Roberson static int 252e84c2db1SJohn Baldwin _cpuset_create(struct cpuset *set, struct cpuset *parent, const cpuset_t *mask, 253d7f687fcSJeff Roberson cpusetid_t id) 254d7f687fcSJeff Roberson { 255d7f687fcSJeff Roberson 25673c40187SJeff Roberson if (!CPU_OVERLAP(&parent->cs_mask, mask)) 25773c40187SJeff Roberson return (EDEADLK); 258d7f687fcSJeff Roberson CPU_COPY(mask, &set->cs_mask); 259d7f687fcSJeff Roberson LIST_INIT(&set->cs_children); 260d7f687fcSJeff Roberson refcount_init(&set->cs_ref, 1); 261d7f687fcSJeff Roberson set->cs_flags = 0; 262d7f687fcSJeff Roberson mtx_lock_spin(&cpuset_lock); 263e84c2db1SJohn Baldwin CPU_AND(&set->cs_mask, &parent->cs_mask); 264d7f687fcSJeff Roberson set->cs_id = id; 265d7f687fcSJeff Roberson set->cs_parent = cpuset_ref(parent); 266d7f687fcSJeff Roberson LIST_INSERT_HEAD(&parent->cs_children, set, cs_siblings); 267d7f687fcSJeff Roberson if (set->cs_id != CPUSET_INVALID) 268d7f687fcSJeff Roberson LIST_INSERT_HEAD(&cpuset_ids, set, cs_link); 269d7f687fcSJeff Roberson mtx_unlock_spin(&cpuset_lock); 270d7f687fcSJeff Roberson 27173c40187SJeff Roberson return (0); 272d7f687fcSJeff Roberson } 273d7f687fcSJeff Roberson 274d7f687fcSJeff Roberson /* 275d7f687fcSJeff Roberson * Create a new non-anonymous set with the requested parent and mask. May 276d7f687fcSJeff Roberson * return failures if the mask is invalid or a new number can not be 277d7f687fcSJeff Roberson * allocated. 278d7f687fcSJeff Roberson */ 279d7f687fcSJeff Roberson static int 280e84c2db1SJohn Baldwin cpuset_create(struct cpuset **setp, struct cpuset *parent, const cpuset_t *mask) 281d7f687fcSJeff Roberson { 282d7f687fcSJeff Roberson struct cpuset *set; 283d7f687fcSJeff Roberson cpusetid_t id; 284d7f687fcSJeff Roberson int error; 285d7f687fcSJeff Roberson 286d7f687fcSJeff Roberson id = alloc_unr(cpuset_unr); 287d7f687fcSJeff Roberson if (id == -1) 288d7f687fcSJeff Roberson return (ENFILE); 289d7f687fcSJeff Roberson *setp = set = uma_zalloc(cpuset_zone, M_WAITOK); 290d7f687fcSJeff Roberson error = _cpuset_create(set, parent, mask, id); 291d7f687fcSJeff Roberson if (error == 0) 292d7f687fcSJeff Roberson return (0); 293d7f687fcSJeff Roberson free_unr(cpuset_unr, id); 294d7f687fcSJeff Roberson uma_zfree(cpuset_zone, set); 295d7f687fcSJeff Roberson 296d7f687fcSJeff Roberson return (error); 297d7f687fcSJeff Roberson } 298d7f687fcSJeff Roberson 299d7f687fcSJeff Roberson /* 300d7f687fcSJeff Roberson * Recursively check for errors that would occur from applying mask to 301d7f687fcSJeff Roberson * the tree of sets starting at 'set'. Checks for sets that would become 302d7f687fcSJeff Roberson * empty as well as RDONLY flags. 303d7f687fcSJeff Roberson */ 304d7f687fcSJeff Roberson static int 305d7f687fcSJeff Roberson cpuset_testupdate(struct cpuset *set, cpuset_t *mask) 306d7f687fcSJeff Roberson { 307d7f687fcSJeff Roberson struct cpuset *nset; 308d7f687fcSJeff Roberson cpuset_t newmask; 309d7f687fcSJeff Roberson int error; 310d7f687fcSJeff Roberson 311d7f687fcSJeff Roberson mtx_assert(&cpuset_lock, MA_OWNED); 312d7f687fcSJeff Roberson if (set->cs_flags & CPU_SET_RDONLY) 313d7f687fcSJeff Roberson return (EPERM); 31473c40187SJeff Roberson if (!CPU_OVERLAP(&set->cs_mask, mask)) 31573c40187SJeff Roberson return (EDEADLK); 316d7f687fcSJeff Roberson CPU_COPY(&set->cs_mask, &newmask); 317d7f687fcSJeff Roberson CPU_AND(&newmask, mask); 31873c40187SJeff Roberson error = 0; 319d7f687fcSJeff Roberson LIST_FOREACH(nset, &set->cs_children, cs_siblings) 320d7f687fcSJeff Roberson if ((error = cpuset_testupdate(nset, &newmask)) != 0) 321d7f687fcSJeff Roberson break; 322d7f687fcSJeff Roberson return (error); 323d7f687fcSJeff Roberson } 324d7f687fcSJeff Roberson 325d7f687fcSJeff Roberson /* 326d7f687fcSJeff Roberson * Applies the mask 'mask' without checking for empty sets or permissions. 327d7f687fcSJeff Roberson */ 328d7f687fcSJeff Roberson static void 329d7f687fcSJeff Roberson cpuset_update(struct cpuset *set, cpuset_t *mask) 330d7f687fcSJeff Roberson { 331d7f687fcSJeff Roberson struct cpuset *nset; 332d7f687fcSJeff Roberson 333d7f687fcSJeff Roberson mtx_assert(&cpuset_lock, MA_OWNED); 334d7f687fcSJeff Roberson CPU_AND(&set->cs_mask, mask); 335d7f687fcSJeff Roberson LIST_FOREACH(nset, &set->cs_children, cs_siblings) 336d7f687fcSJeff Roberson cpuset_update(nset, &set->cs_mask); 337d7f687fcSJeff Roberson 338d7f687fcSJeff Roberson return; 339d7f687fcSJeff Roberson } 340d7f687fcSJeff Roberson 341d7f687fcSJeff Roberson /* 342d7f687fcSJeff Roberson * Modify the set 'set' to use a copy of the mask provided. Apply this new 343d7f687fcSJeff Roberson * mask to restrict all children in the tree. Checks for validity before 344d7f687fcSJeff Roberson * applying the changes. 345d7f687fcSJeff Roberson */ 346d7f687fcSJeff Roberson static int 347d7f687fcSJeff Roberson cpuset_modify(struct cpuset *set, cpuset_t *mask) 348d7f687fcSJeff Roberson { 34973c40187SJeff Roberson struct cpuset *root; 350d7f687fcSJeff Roberson int error; 351d7f687fcSJeff Roberson 352ba931c08SBjoern A. Zeeb error = priv_check(curthread, PRIV_SCHED_CPUSET); 353d7f687fcSJeff Roberson if (error) 354d7f687fcSJeff Roberson return (error); 35573c40187SJeff Roberson /* 3566aaa0b3cSBjoern A. Zeeb * In case we are called from within the jail 3576aaa0b3cSBjoern A. Zeeb * we do not allow modifying the dedicated root 3586aaa0b3cSBjoern A. Zeeb * cpuset of the jail but may still allow to 3596aaa0b3cSBjoern A. Zeeb * change child sets. 3606aaa0b3cSBjoern A. Zeeb */ 3616aaa0b3cSBjoern A. Zeeb if (jailed(curthread->td_ucred) && 3626aaa0b3cSBjoern A. Zeeb set->cs_flags & CPU_SET_ROOT) 3636aaa0b3cSBjoern A. Zeeb return (EPERM); 3646aaa0b3cSBjoern A. Zeeb /* 36573c40187SJeff Roberson * Verify that we have access to this set of 36673c40187SJeff Roberson * cpus. 36773c40187SJeff Roberson */ 36873c40187SJeff Roberson root = set->cs_parent; 36973c40187SJeff Roberson if (root && !CPU_SUBSET(&root->cs_mask, mask)) 37073c40187SJeff Roberson return (EINVAL); 371d7f687fcSJeff Roberson mtx_lock_spin(&cpuset_lock); 372d7f687fcSJeff Roberson error = cpuset_testupdate(set, mask); 373d7f687fcSJeff Roberson if (error) 374d7f687fcSJeff Roberson goto out; 375d7f687fcSJeff Roberson cpuset_update(set, mask); 376d7f687fcSJeff Roberson CPU_COPY(mask, &set->cs_mask); 377d7f687fcSJeff Roberson out: 378d7f687fcSJeff Roberson mtx_unlock_spin(&cpuset_lock); 379d7f687fcSJeff Roberson 380d7f687fcSJeff Roberson return (error); 381d7f687fcSJeff Roberson } 382d7f687fcSJeff Roberson 383d7f687fcSJeff Roberson /* 384d7f687fcSJeff Roberson * Resolve the 'which' parameter of several cpuset apis. 385d7f687fcSJeff Roberson * 386d7f687fcSJeff Roberson * For WHICH_PID and WHICH_TID return a locked proc and valid proc/tid. Also 387d7f687fcSJeff Roberson * checks for permission via p_cansched(). 388d7f687fcSJeff Roberson * 389d7f687fcSJeff Roberson * For WHICH_SET returns a valid set with a new reference. 390d7f687fcSJeff Roberson * 391d7f687fcSJeff Roberson * -1 may be supplied for any argument to mean the current proc/thread or 392d7f687fcSJeff Roberson * the base set of the current thread. May fail with ESRCH/EPERM. 393d7f687fcSJeff Roberson */ 394d7f687fcSJeff Roberson static int 395d7f687fcSJeff Roberson cpuset_which(cpuwhich_t which, id_t id, struct proc **pp, struct thread **tdp, 396d7f687fcSJeff Roberson struct cpuset **setp) 397d7f687fcSJeff Roberson { 398d7f687fcSJeff Roberson struct cpuset *set; 399d7f687fcSJeff Roberson struct thread *td; 400d7f687fcSJeff Roberson struct proc *p; 401d7f687fcSJeff Roberson int error; 402d7f687fcSJeff Roberson 403d7f687fcSJeff Roberson *pp = p = NULL; 404d7f687fcSJeff Roberson *tdp = td = NULL; 405d7f687fcSJeff Roberson *setp = set = NULL; 406d7f687fcSJeff Roberson switch (which) { 407d7f687fcSJeff Roberson case CPU_WHICH_PID: 408d7f687fcSJeff Roberson if (id == -1) { 409d7f687fcSJeff Roberson PROC_LOCK(curproc); 410d7f687fcSJeff Roberson p = curproc; 411d7f687fcSJeff Roberson break; 412d7f687fcSJeff Roberson } 413d7f687fcSJeff Roberson if ((p = pfind(id)) == NULL) 414d7f687fcSJeff Roberson return (ESRCH); 415d7f687fcSJeff Roberson break; 416d7f687fcSJeff Roberson case CPU_WHICH_TID: 417d7f687fcSJeff Roberson if (id == -1) { 418d7f687fcSJeff Roberson PROC_LOCK(curproc); 419d7f687fcSJeff Roberson p = curproc; 420d7f687fcSJeff Roberson td = curthread; 421d7f687fcSJeff Roberson break; 422d7f687fcSJeff Roberson } 42342fe684cSDavid Xu td = tdfind(id, -1); 424d7f687fcSJeff Roberson if (td == NULL) 425d7f687fcSJeff Roberson return (ESRCH); 42642fe684cSDavid Xu p = td->td_proc; 427d7f687fcSJeff Roberson break; 428d7f687fcSJeff Roberson case CPU_WHICH_CPUSET: 429d7f687fcSJeff Roberson if (id == -1) { 430d7f687fcSJeff Roberson thread_lock(curthread); 431a03ee000SJeff Roberson set = cpuset_refbase(curthread->td_cpuset); 432d7f687fcSJeff Roberson thread_unlock(curthread); 433d7f687fcSJeff Roberson } else 434413628a7SBjoern A. Zeeb set = cpuset_lookup(id, curthread); 435d7f687fcSJeff Roberson if (set) { 436d7f687fcSJeff Roberson *setp = set; 437d7f687fcSJeff Roberson return (0); 438d7f687fcSJeff Roberson } 439d7f687fcSJeff Roberson return (ESRCH); 440413628a7SBjoern A. Zeeb case CPU_WHICH_JAIL: 441413628a7SBjoern A. Zeeb { 442413628a7SBjoern A. Zeeb /* Find `set' for prison with given id. */ 443413628a7SBjoern A. Zeeb struct prison *pr; 444413628a7SBjoern A. Zeeb 445413628a7SBjoern A. Zeeb sx_slock(&allprison_lock); 4460304c731SJamie Gritton pr = prison_find_child(curthread->td_ucred->cr_prison, id); 447413628a7SBjoern A. Zeeb sx_sunlock(&allprison_lock); 448413628a7SBjoern A. Zeeb if (pr == NULL) 449413628a7SBjoern A. Zeeb return (ESRCH); 450413628a7SBjoern A. Zeeb cpuset_ref(pr->pr_cpuset); 4510304c731SJamie Gritton *setp = pr->pr_cpuset; 452413628a7SBjoern A. Zeeb mtx_unlock(&pr->pr_mtx); 453413628a7SBjoern A. Zeeb return (0); 454413628a7SBjoern A. Zeeb } 4559b33b154SJeff Roberson case CPU_WHICH_IRQ: 4569b33b154SJeff Roberson return (0); 457d7f687fcSJeff Roberson default: 458d7f687fcSJeff Roberson return (EINVAL); 459d7f687fcSJeff Roberson } 460d7f687fcSJeff Roberson error = p_cansched(curthread, p); 461d7f687fcSJeff Roberson if (error) { 462d7f687fcSJeff Roberson PROC_UNLOCK(p); 463d7f687fcSJeff Roberson return (error); 464d7f687fcSJeff Roberson } 465d7f687fcSJeff Roberson if (td == NULL) 466d7f687fcSJeff Roberson td = FIRST_THREAD_IN_PROC(p); 467d7f687fcSJeff Roberson *pp = p; 468d7f687fcSJeff Roberson *tdp = td; 469d7f687fcSJeff Roberson return (0); 470d7f687fcSJeff Roberson } 471d7f687fcSJeff Roberson 472d7f687fcSJeff Roberson /* 473d7f687fcSJeff Roberson * Create an anonymous set with the provided mask in the space provided by 474d7f687fcSJeff Roberson * 'fset'. If the passed in set is anonymous we use its parent otherwise 475d7f687fcSJeff Roberson * the new set is a child of 'set'. 476d7f687fcSJeff Roberson */ 477d7f687fcSJeff Roberson static int 478e84c2db1SJohn Baldwin cpuset_shadow(struct cpuset *set, struct cpuset *fset, const cpuset_t *mask) 479d7f687fcSJeff Roberson { 480d7f687fcSJeff Roberson struct cpuset *parent; 481d7f687fcSJeff Roberson 482d7f687fcSJeff Roberson if (set->cs_id == CPUSET_INVALID) 483d7f687fcSJeff Roberson parent = set->cs_parent; 484d7f687fcSJeff Roberson else 485d7f687fcSJeff Roberson parent = set; 48673c40187SJeff Roberson if (!CPU_SUBSET(&parent->cs_mask, mask)) 487a03ee000SJeff Roberson return (EDEADLK); 488d7f687fcSJeff Roberson return (_cpuset_create(fset, parent, mask, CPUSET_INVALID)); 489d7f687fcSJeff Roberson } 490d7f687fcSJeff Roberson 491d7f687fcSJeff Roberson /* 492d7f687fcSJeff Roberson * Handle two cases for replacing the base set or mask of an entire process. 493d7f687fcSJeff Roberson * 494d7f687fcSJeff Roberson * 1) Set is non-null and mask is null. This reparents all anonymous sets 495d7f687fcSJeff Roberson * to the provided set and replaces all non-anonymous td_cpusets with the 496d7f687fcSJeff Roberson * provided set. 497d7f687fcSJeff Roberson * 2) Mask is non-null and set is null. This replaces or creates anonymous 498d7f687fcSJeff Roberson * sets for every thread with the existing base as a parent. 499d7f687fcSJeff Roberson * 500d7f687fcSJeff Roberson * This is overly complicated because we can't allocate while holding a 501d7f687fcSJeff Roberson * spinlock and spinlocks must be held while changing and examining thread 502d7f687fcSJeff Roberson * state. 503d7f687fcSJeff Roberson */ 504d7f687fcSJeff Roberson static int 505d7f687fcSJeff Roberson cpuset_setproc(pid_t pid, struct cpuset *set, cpuset_t *mask) 506d7f687fcSJeff Roberson { 507d7f687fcSJeff Roberson struct setlist freelist; 508d7f687fcSJeff Roberson struct setlist droplist; 50973c40187SJeff Roberson struct cpuset *tdset; 510d7f687fcSJeff Roberson struct cpuset *nset; 511d7f687fcSJeff Roberson struct thread *td; 512d7f687fcSJeff Roberson struct proc *p; 513d7f687fcSJeff Roberson int threads; 514d7f687fcSJeff Roberson int nfree; 515d7f687fcSJeff Roberson int error; 516d7f687fcSJeff Roberson /* 517d7f687fcSJeff Roberson * The algorithm requires two passes due to locking considerations. 518d7f687fcSJeff Roberson * 519d7f687fcSJeff Roberson * 1) Lookup the process and acquire the locks in the required order. 520d7f687fcSJeff Roberson * 2) If enough cpusets have not been allocated release the locks and 521d7f687fcSJeff Roberson * allocate them. Loop. 522d7f687fcSJeff Roberson */ 523d7f687fcSJeff Roberson LIST_INIT(&freelist); 524d7f687fcSJeff Roberson LIST_INIT(&droplist); 525d7f687fcSJeff Roberson nfree = 0; 526d7f687fcSJeff Roberson for (;;) { 527d7f687fcSJeff Roberson error = cpuset_which(CPU_WHICH_PID, pid, &p, &td, &nset); 528d7f687fcSJeff Roberson if (error) 529d7f687fcSJeff Roberson goto out; 530d7f687fcSJeff Roberson if (nfree >= p->p_numthreads) 531d7f687fcSJeff Roberson break; 532d7f687fcSJeff Roberson threads = p->p_numthreads; 533d7f687fcSJeff Roberson PROC_UNLOCK(p); 534d7f687fcSJeff Roberson for (; nfree < threads; nfree++) { 535d7f687fcSJeff Roberson nset = uma_zalloc(cpuset_zone, M_WAITOK); 536d7f687fcSJeff Roberson LIST_INSERT_HEAD(&freelist, nset, cs_link); 537d7f687fcSJeff Roberson } 538d7f687fcSJeff Roberson } 539d7f687fcSJeff Roberson PROC_LOCK_ASSERT(p, MA_OWNED); 540d7f687fcSJeff Roberson /* 541d7f687fcSJeff Roberson * Now that the appropriate locks are held and we have enough cpusets, 54273c40187SJeff Roberson * make sure the operation will succeed before applying changes. The 54373c40187SJeff Roberson * proc lock prevents td_cpuset from changing between calls. 544d7f687fcSJeff Roberson */ 545d7f687fcSJeff Roberson error = 0; 546d7f687fcSJeff Roberson FOREACH_THREAD_IN_PROC(p, td) { 54773c40187SJeff Roberson thread_lock(td); 54873c40187SJeff Roberson tdset = td->td_cpuset; 54973c40187SJeff Roberson /* 55073c40187SJeff Roberson * Verify that a new mask doesn't specify cpus outside of 55173c40187SJeff Roberson * the set the thread is a member of. 55273c40187SJeff Roberson */ 55373c40187SJeff Roberson if (mask) { 55473c40187SJeff Roberson if (tdset->cs_id == CPUSET_INVALID) 55573c40187SJeff Roberson tdset = tdset->cs_parent; 55673c40187SJeff Roberson if (!CPU_SUBSET(&tdset->cs_mask, mask)) 557a03ee000SJeff Roberson error = EDEADLK; 55873c40187SJeff Roberson /* 55973c40187SJeff Roberson * Verify that a new set won't leave an existing thread 56073c40187SJeff Roberson * mask without a cpu to run on. It can, however, restrict 56173c40187SJeff Roberson * the set. 56273c40187SJeff Roberson */ 56373c40187SJeff Roberson } else if (tdset->cs_id == CPUSET_INVALID) { 56473c40187SJeff Roberson if (!CPU_OVERLAP(&set->cs_mask, &tdset->cs_mask)) 565a03ee000SJeff Roberson error = EDEADLK; 56673c40187SJeff Roberson } 56773c40187SJeff Roberson thread_unlock(td); 56873c40187SJeff Roberson if (error) 56973c40187SJeff Roberson goto unlock_out; 57073c40187SJeff Roberson } 57173c40187SJeff Roberson /* 57273c40187SJeff Roberson * Replace each thread's cpuset while using deferred release. We 573374ae2a3SJeff Roberson * must do this because the thread lock must be held while operating 574374ae2a3SJeff Roberson * on the thread and this limits the type of operations allowed. 57573c40187SJeff Roberson */ 57673c40187SJeff Roberson FOREACH_THREAD_IN_PROC(p, td) { 577d7f687fcSJeff Roberson thread_lock(td); 578d7f687fcSJeff Roberson /* 579d7f687fcSJeff Roberson * If we presently have an anonymous set or are applying a 580d7f687fcSJeff Roberson * mask we must create an anonymous shadow set. That is 581d7f687fcSJeff Roberson * either parented to our existing base or the supplied set. 582d7f687fcSJeff Roberson * 583d7f687fcSJeff Roberson * If we have a base set with no anonymous shadow we simply 584d7f687fcSJeff Roberson * replace it outright. 585d7f687fcSJeff Roberson */ 586d7f687fcSJeff Roberson tdset = td->td_cpuset; 587d7f687fcSJeff Roberson if (tdset->cs_id == CPUSET_INVALID || mask) { 588d7f687fcSJeff Roberson nset = LIST_FIRST(&freelist); 589d7f687fcSJeff Roberson LIST_REMOVE(nset, cs_link); 590d7f687fcSJeff Roberson if (mask) 591d7f687fcSJeff Roberson error = cpuset_shadow(tdset, nset, mask); 592d7f687fcSJeff Roberson else 593d7f687fcSJeff Roberson error = _cpuset_create(nset, set, 594d7f687fcSJeff Roberson &tdset->cs_mask, CPUSET_INVALID); 595d7f687fcSJeff Roberson if (error) { 596d7f687fcSJeff Roberson LIST_INSERT_HEAD(&freelist, nset, cs_link); 597d7f687fcSJeff Roberson thread_unlock(td); 598d7f687fcSJeff Roberson break; 599d7f687fcSJeff Roberson } 600d7f687fcSJeff Roberson } else 601d7f687fcSJeff Roberson nset = cpuset_ref(set); 602d7f687fcSJeff Roberson cpuset_rel_defer(&droplist, tdset); 603d7f687fcSJeff Roberson td->td_cpuset = nset; 604d7f687fcSJeff Roberson sched_affinity(td); 605d7f687fcSJeff Roberson thread_unlock(td); 606d7f687fcSJeff Roberson } 60773c40187SJeff Roberson unlock_out: 608d7f687fcSJeff Roberson PROC_UNLOCK(p); 609d7f687fcSJeff Roberson out: 610d7f687fcSJeff Roberson while ((nset = LIST_FIRST(&droplist)) != NULL) 611d7f687fcSJeff Roberson cpuset_rel_complete(nset); 612d7f687fcSJeff Roberson while ((nset = LIST_FIRST(&freelist)) != NULL) { 613d7f687fcSJeff Roberson LIST_REMOVE(nset, cs_link); 614d7f687fcSJeff Roberson uma_zfree(cpuset_zone, nset); 615d7f687fcSJeff Roberson } 616d7f687fcSJeff Roberson return (error); 617d7f687fcSJeff Roberson } 618d7f687fcSJeff Roberson 619d7f687fcSJeff Roberson /* 620*71a19bdcSAttilio Rao * Calculate the ffs() of the cpuset. 621*71a19bdcSAttilio Rao */ 622*71a19bdcSAttilio Rao int 623*71a19bdcSAttilio Rao cpusetobj_ffs(const cpuset_t *set) 624*71a19bdcSAttilio Rao { 625*71a19bdcSAttilio Rao size_t i; 626*71a19bdcSAttilio Rao int cbit; 627*71a19bdcSAttilio Rao 628*71a19bdcSAttilio Rao cbit = 0; 629*71a19bdcSAttilio Rao for (i = 0; i < _NCPUWORDS; i++) { 630*71a19bdcSAttilio Rao if (set->__bits[i] != 0) { 631*71a19bdcSAttilio Rao cbit = ffsl(set->__bits[i]); 632*71a19bdcSAttilio Rao cbit += i * _NCPUBITS; 633*71a19bdcSAttilio Rao break; 634*71a19bdcSAttilio Rao } 635*71a19bdcSAttilio Rao } 636*71a19bdcSAttilio Rao return (cbit); 637*71a19bdcSAttilio Rao } 638*71a19bdcSAttilio Rao 639*71a19bdcSAttilio Rao /* 640*71a19bdcSAttilio Rao * Return a string representing a valid layout for a cpuset_t object. 641*71a19bdcSAttilio Rao * It expects an incoming buffer at least sized as CPUSETBUFSIZ. 642*71a19bdcSAttilio Rao */ 643*71a19bdcSAttilio Rao char * 644*71a19bdcSAttilio Rao cpusetobj_strprint(char *buf, const cpuset_t *set) 645*71a19bdcSAttilio Rao { 646*71a19bdcSAttilio Rao char *tbuf; 647*71a19bdcSAttilio Rao size_t i, bytesp, bufsiz; 648*71a19bdcSAttilio Rao 649*71a19bdcSAttilio Rao tbuf = buf; 650*71a19bdcSAttilio Rao bytesp = 0; 651*71a19bdcSAttilio Rao bufsiz = CPUSETBUFSIZ; 652*71a19bdcSAttilio Rao 653*71a19bdcSAttilio Rao for (i = 0; i < (_NCPUWORDS - 1); i++) { 654*71a19bdcSAttilio Rao bytesp = snprintf(tbuf, bufsiz, "%lx, ", set->__bits[i]); 655*71a19bdcSAttilio Rao bufsiz -= bytesp; 656*71a19bdcSAttilio Rao tbuf += bytesp; 657*71a19bdcSAttilio Rao } 658*71a19bdcSAttilio Rao snprintf(tbuf, bufsiz, "%lx", set->__bits[_NCPUWORDS - 1]); 659*71a19bdcSAttilio Rao return (buf); 660*71a19bdcSAttilio Rao } 661*71a19bdcSAttilio Rao 662*71a19bdcSAttilio Rao /* 663d7f687fcSJeff Roberson * Apply an anonymous mask to a single thread. 664d7f687fcSJeff Roberson */ 665a03ee000SJeff Roberson int 666d7f687fcSJeff Roberson cpuset_setthread(lwpid_t id, cpuset_t *mask) 667d7f687fcSJeff Roberson { 668d7f687fcSJeff Roberson struct cpuset *nset; 669d7f687fcSJeff Roberson struct cpuset *set; 670d7f687fcSJeff Roberson struct thread *td; 671d7f687fcSJeff Roberson struct proc *p; 672d7f687fcSJeff Roberson int error; 673d7f687fcSJeff Roberson 674d7f687fcSJeff Roberson nset = uma_zalloc(cpuset_zone, M_WAITOK); 6758bd75bddSJeff Roberson error = cpuset_which(CPU_WHICH_TID, id, &p, &td, &set); 676d7f687fcSJeff Roberson if (error) 677d7f687fcSJeff Roberson goto out; 678a03ee000SJeff Roberson set = NULL; 679d7f687fcSJeff Roberson thread_lock(td); 680a03ee000SJeff Roberson error = cpuset_shadow(td->td_cpuset, nset, mask); 681d7f687fcSJeff Roberson if (error == 0) { 682a03ee000SJeff Roberson set = td->td_cpuset; 683d7f687fcSJeff Roberson td->td_cpuset = nset; 684d7f687fcSJeff Roberson sched_affinity(td); 685d7f687fcSJeff Roberson nset = NULL; 686d7f687fcSJeff Roberson } 687d7f687fcSJeff Roberson thread_unlock(td); 688d7f687fcSJeff Roberson PROC_UNLOCK(p); 689a03ee000SJeff Roberson if (set) 690a03ee000SJeff Roberson cpuset_rel(set); 691d7f687fcSJeff Roberson out: 692d7f687fcSJeff Roberson if (nset) 693d7f687fcSJeff Roberson uma_zfree(cpuset_zone, nset); 694d7f687fcSJeff Roberson return (error); 695d7f687fcSJeff Roberson } 696d7f687fcSJeff Roberson 697d7f687fcSJeff Roberson /* 698d7f687fcSJeff Roberson * Creates the cpuset for thread0. We make two sets: 699d7f687fcSJeff Roberson * 700d7f687fcSJeff Roberson * 0 - The root set which should represent all valid processors in the 701d7f687fcSJeff Roberson * system. It is initially created with a mask of all processors 702d7f687fcSJeff Roberson * because we don't know what processors are valid until cpuset_init() 703d7f687fcSJeff Roberson * runs. This set is immutable. 704d7f687fcSJeff Roberson * 1 - The default set which all processes are a member of until changed. 705d7f687fcSJeff Roberson * This allows an administrator to move all threads off of given cpus to 706d7f687fcSJeff Roberson * dedicate them to high priority tasks or save power etc. 707d7f687fcSJeff Roberson */ 708d7f687fcSJeff Roberson struct cpuset * 709d7f687fcSJeff Roberson cpuset_thread0(void) 710d7f687fcSJeff Roberson { 711d7f687fcSJeff Roberson struct cpuset *set; 712d7f687fcSJeff Roberson int error; 713d7f687fcSJeff Roberson 714d7f687fcSJeff Roberson cpuset_zone = uma_zcreate("cpuset", sizeof(struct cpuset), NULL, NULL, 715d7f687fcSJeff Roberson NULL, NULL, UMA_ALIGN_PTR, 0); 716d7f687fcSJeff Roberson mtx_init(&cpuset_lock, "cpuset", NULL, MTX_SPIN | MTX_RECURSE); 717d7f687fcSJeff Roberson /* 718d7f687fcSJeff Roberson * Create the root system set for the whole machine. Doesn't use 719d7f687fcSJeff Roberson * cpuset_create() due to NULL parent. 720d7f687fcSJeff Roberson */ 721d7f687fcSJeff Roberson set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); 722d7f687fcSJeff Roberson set->cs_mask.__bits[0] = -1; 723d7f687fcSJeff Roberson LIST_INIT(&set->cs_children); 724d7f687fcSJeff Roberson LIST_INSERT_HEAD(&cpuset_ids, set, cs_link); 725d7f687fcSJeff Roberson set->cs_ref = 1; 726d7f687fcSJeff Roberson set->cs_flags = CPU_SET_ROOT; 727d7f687fcSJeff Roberson cpuset_zero = set; 728a03ee000SJeff Roberson cpuset_root = &set->cs_mask; 729d7f687fcSJeff Roberson /* 730d7f687fcSJeff Roberson * Now derive a default, modifiable set from that to give out. 731d7f687fcSJeff Roberson */ 732d7f687fcSJeff Roberson set = uma_zalloc(cpuset_zone, M_WAITOK); 733d7f687fcSJeff Roberson error = _cpuset_create(set, cpuset_zero, &cpuset_zero->cs_mask, 1); 734d7f687fcSJeff Roberson KASSERT(error == 0, ("Error creating default set: %d\n", error)); 735d7f687fcSJeff Roberson /* 736d7f687fcSJeff Roberson * Initialize the unit allocator. 0 and 1 are allocated above. 737d7f687fcSJeff Roberson */ 738d7f687fcSJeff Roberson cpuset_unr = new_unrhdr(2, INT_MAX, NULL); 739d7f687fcSJeff Roberson 740d7f687fcSJeff Roberson return (set); 741d7f687fcSJeff Roberson } 742d7f687fcSJeff Roberson 743d7f687fcSJeff Roberson /* 744413628a7SBjoern A. Zeeb * Create a cpuset, which would be cpuset_create() but 745413628a7SBjoern A. Zeeb * mark the new 'set' as root. 746413628a7SBjoern A. Zeeb * 74747479a8cSBjoern A. Zeeb * We are not going to reparent the td to it. Use cpuset_setproc_update_set() 74847479a8cSBjoern A. Zeeb * for that. 749413628a7SBjoern A. Zeeb * 750413628a7SBjoern A. Zeeb * In case of no error, returns the set in *setp locked with a reference. 751413628a7SBjoern A. Zeeb */ 752413628a7SBjoern A. Zeeb int 7530304c731SJamie Gritton cpuset_create_root(struct prison *pr, struct cpuset **setp) 754413628a7SBjoern A. Zeeb { 755413628a7SBjoern A. Zeeb struct cpuset *set; 756413628a7SBjoern A. Zeeb int error; 757413628a7SBjoern A. Zeeb 7580304c731SJamie Gritton KASSERT(pr != NULL, ("[%s:%d] invalid pr", __func__, __LINE__)); 759413628a7SBjoern A. Zeeb KASSERT(setp != NULL, ("[%s:%d] invalid setp", __func__, __LINE__)); 760413628a7SBjoern A. Zeeb 7610304c731SJamie Gritton error = cpuset_create(setp, pr->pr_cpuset, &pr->pr_cpuset->cs_mask); 762413628a7SBjoern A. Zeeb if (error) 763413628a7SBjoern A. Zeeb return (error); 764413628a7SBjoern A. Zeeb 765413628a7SBjoern A. Zeeb KASSERT(*setp != NULL, ("[%s:%d] cpuset_create returned invalid data", 766413628a7SBjoern A. Zeeb __func__, __LINE__)); 767413628a7SBjoern A. Zeeb 768413628a7SBjoern A. Zeeb /* Mark the set as root. */ 769413628a7SBjoern A. Zeeb set = *setp; 770413628a7SBjoern A. Zeeb set->cs_flags |= CPU_SET_ROOT; 771413628a7SBjoern A. Zeeb 772413628a7SBjoern A. Zeeb return (0); 773413628a7SBjoern A. Zeeb } 774413628a7SBjoern A. Zeeb 775413628a7SBjoern A. Zeeb int 776413628a7SBjoern A. Zeeb cpuset_setproc_update_set(struct proc *p, struct cpuset *set) 777413628a7SBjoern A. Zeeb { 778413628a7SBjoern A. Zeeb int error; 779413628a7SBjoern A. Zeeb 780413628a7SBjoern A. Zeeb KASSERT(p != NULL, ("[%s:%d] invalid proc", __func__, __LINE__)); 781413628a7SBjoern A. Zeeb KASSERT(set != NULL, ("[%s:%d] invalid set", __func__, __LINE__)); 782413628a7SBjoern A. Zeeb 783413628a7SBjoern A. Zeeb cpuset_ref(set); 784413628a7SBjoern A. Zeeb error = cpuset_setproc(p->p_pid, set, NULL); 785413628a7SBjoern A. Zeeb if (error) 786413628a7SBjoern A. Zeeb return (error); 787413628a7SBjoern A. Zeeb cpuset_rel(set); 788413628a7SBjoern A. Zeeb return (0); 789413628a7SBjoern A. Zeeb } 790413628a7SBjoern A. Zeeb 791413628a7SBjoern A. Zeeb /* 792d7f687fcSJeff Roberson * This is called once the final set of system cpus is known. Modifies 79393902625SJohn Baldwin * the root set and all children and mark the root read-only. 794d7f687fcSJeff Roberson */ 795d7f687fcSJeff Roberson static void 796d7f687fcSJeff Roberson cpuset_init(void *arg) 797d7f687fcSJeff Roberson { 798d7f687fcSJeff Roberson cpuset_t mask; 799d7f687fcSJeff Roberson 800d7f687fcSJeff Roberson #ifdef SMP 801*71a19bdcSAttilio Rao mask = all_cpus; 802d7f687fcSJeff Roberson #else 803*71a19bdcSAttilio Rao CPU_SETOF(0, &mask); 804d7f687fcSJeff Roberson #endif 805d7f687fcSJeff Roberson if (cpuset_modify(cpuset_zero, &mask)) 806d7f687fcSJeff Roberson panic("Can't set initial cpuset mask.\n"); 807d7f687fcSJeff Roberson cpuset_zero->cs_flags |= CPU_SET_RDONLY; 808d7f687fcSJeff Roberson } 809d7f687fcSJeff Roberson SYSINIT(cpuset, SI_SUB_SMP, SI_ORDER_ANY, cpuset_init, NULL); 810d7f687fcSJeff Roberson 811d7f687fcSJeff Roberson #ifndef _SYS_SYSPROTO_H_ 812d7f687fcSJeff Roberson struct cpuset_args { 813d7f687fcSJeff Roberson cpusetid_t *setid; 814d7f687fcSJeff Roberson }; 815d7f687fcSJeff Roberson #endif 816d7f687fcSJeff Roberson int 817d7f687fcSJeff Roberson cpuset(struct thread *td, struct cpuset_args *uap) 818d7f687fcSJeff Roberson { 819d7f687fcSJeff Roberson struct cpuset *root; 820d7f687fcSJeff Roberson struct cpuset *set; 821d7f687fcSJeff Roberson int error; 822d7f687fcSJeff Roberson 823d7f687fcSJeff Roberson thread_lock(td); 824a03ee000SJeff Roberson root = cpuset_refroot(td->td_cpuset); 825d7f687fcSJeff Roberson thread_unlock(td); 826d7f687fcSJeff Roberson error = cpuset_create(&set, root, &root->cs_mask); 827d7f687fcSJeff Roberson cpuset_rel(root); 828d7f687fcSJeff Roberson if (error) 829d7f687fcSJeff Roberson return (error); 830d7f687fcSJeff Roberson error = copyout(&set->cs_id, uap->setid, sizeof(set->cs_id)); 831a03ee000SJeff Roberson if (error == 0) 832a03ee000SJeff Roberson error = cpuset_setproc(-1, set, NULL); 833d7f687fcSJeff Roberson cpuset_rel(set); 834d7f687fcSJeff Roberson return (error); 835d7f687fcSJeff Roberson } 836d7f687fcSJeff Roberson 837d7f687fcSJeff Roberson #ifndef _SYS_SYSPROTO_H_ 838d7f687fcSJeff Roberson struct cpuset_setid_args { 839d7f687fcSJeff Roberson cpuwhich_t which; 840d7f687fcSJeff Roberson id_t id; 841d7f687fcSJeff Roberson cpusetid_t setid; 842d7f687fcSJeff Roberson }; 843d7f687fcSJeff Roberson #endif 844d7f687fcSJeff Roberson int 845d7f687fcSJeff Roberson cpuset_setid(struct thread *td, struct cpuset_setid_args *uap) 846d7f687fcSJeff Roberson { 847d7f687fcSJeff Roberson struct cpuset *set; 848d7f687fcSJeff Roberson int error; 849d7f687fcSJeff Roberson 850d7f687fcSJeff Roberson /* 851d7f687fcSJeff Roberson * Presently we only support per-process sets. 852d7f687fcSJeff Roberson */ 853d7f687fcSJeff Roberson if (uap->which != CPU_WHICH_PID) 854d7f687fcSJeff Roberson return (EINVAL); 855413628a7SBjoern A. Zeeb set = cpuset_lookup(uap->setid, td); 856d7f687fcSJeff Roberson if (set == NULL) 857d7f687fcSJeff Roberson return (ESRCH); 858d7f687fcSJeff Roberson error = cpuset_setproc(uap->id, set, NULL); 859d7f687fcSJeff Roberson cpuset_rel(set); 860d7f687fcSJeff Roberson return (error); 861d7f687fcSJeff Roberson } 862d7f687fcSJeff Roberson 863d7f687fcSJeff Roberson #ifndef _SYS_SYSPROTO_H_ 864d7f687fcSJeff Roberson struct cpuset_getid_args { 865d7f687fcSJeff Roberson cpulevel_t level; 866d7f687fcSJeff Roberson cpuwhich_t which; 867d7f687fcSJeff Roberson id_t id; 868d7f687fcSJeff Roberson cpusetid_t *setid; 869d7f687fcSJeff Roberson #endif 870d7f687fcSJeff Roberson int 871d7f687fcSJeff Roberson cpuset_getid(struct thread *td, struct cpuset_getid_args *uap) 872d7f687fcSJeff Roberson { 873d7f687fcSJeff Roberson struct cpuset *nset; 874d7f687fcSJeff Roberson struct cpuset *set; 875d7f687fcSJeff Roberson struct thread *ttd; 876d7f687fcSJeff Roberson struct proc *p; 877d7f687fcSJeff Roberson cpusetid_t id; 878d7f687fcSJeff Roberson int error; 879d7f687fcSJeff Roberson 880d7f687fcSJeff Roberson if (uap->level == CPU_LEVEL_WHICH && uap->which != CPU_WHICH_CPUSET) 881d7f687fcSJeff Roberson return (EINVAL); 882d7f687fcSJeff Roberson error = cpuset_which(uap->which, uap->id, &p, &ttd, &set); 883d7f687fcSJeff Roberson if (error) 884d7f687fcSJeff Roberson return (error); 885d7f687fcSJeff Roberson switch (uap->which) { 886d7f687fcSJeff Roberson case CPU_WHICH_TID: 887d7f687fcSJeff Roberson case CPU_WHICH_PID: 888d7f687fcSJeff Roberson thread_lock(ttd); 889a03ee000SJeff Roberson set = cpuset_refbase(ttd->td_cpuset); 890d7f687fcSJeff Roberson thread_unlock(ttd); 891d7f687fcSJeff Roberson PROC_UNLOCK(p); 892d7f687fcSJeff Roberson break; 893d7f687fcSJeff Roberson case CPU_WHICH_CPUSET: 894413628a7SBjoern A. Zeeb case CPU_WHICH_JAIL: 895d7f687fcSJeff Roberson break; 8969b33b154SJeff Roberson case CPU_WHICH_IRQ: 8979b33b154SJeff Roberson return (EINVAL); 898d7f687fcSJeff Roberson } 899d7f687fcSJeff Roberson switch (uap->level) { 900d7f687fcSJeff Roberson case CPU_LEVEL_ROOT: 901a03ee000SJeff Roberson nset = cpuset_refroot(set); 902d7f687fcSJeff Roberson cpuset_rel(set); 903d7f687fcSJeff Roberson set = nset; 904d7f687fcSJeff Roberson break; 905d7f687fcSJeff Roberson case CPU_LEVEL_CPUSET: 906d7f687fcSJeff Roberson break; 907d7f687fcSJeff Roberson case CPU_LEVEL_WHICH: 908d7f687fcSJeff Roberson break; 909d7f687fcSJeff Roberson } 910d7f687fcSJeff Roberson id = set->cs_id; 911d7f687fcSJeff Roberson cpuset_rel(set); 912d7f687fcSJeff Roberson if (error == 0) 913d7f687fcSJeff Roberson error = copyout(&id, uap->setid, sizeof(id)); 914d7f687fcSJeff Roberson 915d7f687fcSJeff Roberson return (error); 916d7f687fcSJeff Roberson } 917d7f687fcSJeff Roberson 918d7f687fcSJeff Roberson #ifndef _SYS_SYSPROTO_H_ 919d7f687fcSJeff Roberson struct cpuset_getaffinity_args { 920d7f687fcSJeff Roberson cpulevel_t level; 921d7f687fcSJeff Roberson cpuwhich_t which; 9227f64829aSRuslan Ermilov id_t id; 9237f64829aSRuslan Ermilov size_t cpusetsize; 9247f64829aSRuslan Ermilov cpuset_t *mask; 925d7f687fcSJeff Roberson }; 926d7f687fcSJeff Roberson #endif 927d7f687fcSJeff Roberson int 928d7f687fcSJeff Roberson cpuset_getaffinity(struct thread *td, struct cpuset_getaffinity_args *uap) 929d7f687fcSJeff Roberson { 930d7f687fcSJeff Roberson struct thread *ttd; 931d7f687fcSJeff Roberson struct cpuset *nset; 932d7f687fcSJeff Roberson struct cpuset *set; 933d7f687fcSJeff Roberson struct proc *p; 934d7f687fcSJeff Roberson cpuset_t *mask; 935d7f687fcSJeff Roberson int error; 9367f64829aSRuslan Ermilov size_t size; 937d7f687fcSJeff Roberson 93873c40187SJeff Roberson if (uap->cpusetsize < sizeof(cpuset_t) || 939887aedc6SKonstantin Belousov uap->cpusetsize > CPU_MAXSIZE / NBBY) 940d7f687fcSJeff Roberson return (ERANGE); 94173c40187SJeff Roberson size = uap->cpusetsize; 942d7f687fcSJeff Roberson mask = malloc(size, M_TEMP, M_WAITOK | M_ZERO); 943d7f687fcSJeff Roberson error = cpuset_which(uap->which, uap->id, &p, &ttd, &set); 944d7f687fcSJeff Roberson if (error) 945d7f687fcSJeff Roberson goto out; 946d7f687fcSJeff Roberson switch (uap->level) { 947d7f687fcSJeff Roberson case CPU_LEVEL_ROOT: 948d7f687fcSJeff Roberson case CPU_LEVEL_CPUSET: 949d7f687fcSJeff Roberson switch (uap->which) { 950d7f687fcSJeff Roberson case CPU_WHICH_TID: 951d7f687fcSJeff Roberson case CPU_WHICH_PID: 952d7f687fcSJeff Roberson thread_lock(ttd); 953d7f687fcSJeff Roberson set = cpuset_ref(ttd->td_cpuset); 954d7f687fcSJeff Roberson thread_unlock(ttd); 955d7f687fcSJeff Roberson break; 956d7f687fcSJeff Roberson case CPU_WHICH_CPUSET: 957413628a7SBjoern A. Zeeb case CPU_WHICH_JAIL: 958d7f687fcSJeff Roberson break; 9599b33b154SJeff Roberson case CPU_WHICH_IRQ: 9609b33b154SJeff Roberson error = EINVAL; 9619b33b154SJeff Roberson goto out; 962d7f687fcSJeff Roberson } 963d7f687fcSJeff Roberson if (uap->level == CPU_LEVEL_ROOT) 964a03ee000SJeff Roberson nset = cpuset_refroot(set); 965d7f687fcSJeff Roberson else 966a03ee000SJeff Roberson nset = cpuset_refbase(set); 967d7f687fcSJeff Roberson CPU_COPY(&nset->cs_mask, mask); 968d7f687fcSJeff Roberson cpuset_rel(nset); 969d7f687fcSJeff Roberson break; 970d7f687fcSJeff Roberson case CPU_LEVEL_WHICH: 971d7f687fcSJeff Roberson switch (uap->which) { 972d7f687fcSJeff Roberson case CPU_WHICH_TID: 973d7f687fcSJeff Roberson thread_lock(ttd); 974d7f687fcSJeff Roberson CPU_COPY(&ttd->td_cpuset->cs_mask, mask); 975d7f687fcSJeff Roberson thread_unlock(ttd); 976d7f687fcSJeff Roberson break; 977d7f687fcSJeff Roberson case CPU_WHICH_PID: 978d7f687fcSJeff Roberson FOREACH_THREAD_IN_PROC(p, ttd) { 979d7f687fcSJeff Roberson thread_lock(ttd); 980d7f687fcSJeff Roberson CPU_OR(mask, &ttd->td_cpuset->cs_mask); 981d7f687fcSJeff Roberson thread_unlock(ttd); 982d7f687fcSJeff Roberson } 983d7f687fcSJeff Roberson break; 984d7f687fcSJeff Roberson case CPU_WHICH_CPUSET: 985413628a7SBjoern A. Zeeb case CPU_WHICH_JAIL: 986d7f687fcSJeff Roberson CPU_COPY(&set->cs_mask, mask); 987d7f687fcSJeff Roberson break; 9889b33b154SJeff Roberson case CPU_WHICH_IRQ: 9899b33b154SJeff Roberson error = intr_getaffinity(uap->id, mask); 9909b33b154SJeff Roberson break; 991d7f687fcSJeff Roberson } 992d7f687fcSJeff Roberson break; 993d7f687fcSJeff Roberson default: 994d7f687fcSJeff Roberson error = EINVAL; 995d7f687fcSJeff Roberson break; 996d7f687fcSJeff Roberson } 997d7f687fcSJeff Roberson if (set) 998d7f687fcSJeff Roberson cpuset_rel(set); 999d7f687fcSJeff Roberson if (p) 1000d7f687fcSJeff Roberson PROC_UNLOCK(p); 1001d7f687fcSJeff Roberson if (error == 0) 1002d7f687fcSJeff Roberson error = copyout(mask, uap->mask, size); 1003d7f687fcSJeff Roberson out: 1004d7f687fcSJeff Roberson free(mask, M_TEMP); 1005d7f687fcSJeff Roberson return (error); 1006d7f687fcSJeff Roberson } 1007d7f687fcSJeff Roberson 1008d7f687fcSJeff Roberson #ifndef _SYS_SYSPROTO_H_ 1009d7f687fcSJeff Roberson struct cpuset_setaffinity_args { 1010d7f687fcSJeff Roberson cpulevel_t level; 1011d7f687fcSJeff Roberson cpuwhich_t which; 10127f64829aSRuslan Ermilov id_t id; 10137f64829aSRuslan Ermilov size_t cpusetsize; 10147f64829aSRuslan Ermilov const cpuset_t *mask; 1015d7f687fcSJeff Roberson }; 1016d7f687fcSJeff Roberson #endif 1017d7f687fcSJeff Roberson int 1018d7f687fcSJeff Roberson cpuset_setaffinity(struct thread *td, struct cpuset_setaffinity_args *uap) 1019d7f687fcSJeff Roberson { 1020d7f687fcSJeff Roberson struct cpuset *nset; 1021d7f687fcSJeff Roberson struct cpuset *set; 1022d7f687fcSJeff Roberson struct thread *ttd; 1023d7f687fcSJeff Roberson struct proc *p; 1024d7f687fcSJeff Roberson cpuset_t *mask; 1025d7f687fcSJeff Roberson int error; 1026d7f687fcSJeff Roberson 102773c40187SJeff Roberson if (uap->cpusetsize < sizeof(cpuset_t) || 1028887aedc6SKonstantin Belousov uap->cpusetsize > CPU_MAXSIZE / NBBY) 1029d7f687fcSJeff Roberson return (ERANGE); 103073c40187SJeff Roberson mask = malloc(uap->cpusetsize, M_TEMP, M_WAITOK | M_ZERO); 103173c40187SJeff Roberson error = copyin(uap->mask, mask, uap->cpusetsize); 1032d7f687fcSJeff Roberson if (error) 1033d7f687fcSJeff Roberson goto out; 103473c40187SJeff Roberson /* 103573c40187SJeff Roberson * Verify that no high bits are set. 103673c40187SJeff Roberson */ 103773c40187SJeff Roberson if (uap->cpusetsize > sizeof(cpuset_t)) { 103873c40187SJeff Roberson char *end; 103973c40187SJeff Roberson char *cp; 104073c40187SJeff Roberson 104173c40187SJeff Roberson end = cp = (char *)&mask->__bits; 104273c40187SJeff Roberson end += uap->cpusetsize; 104373c40187SJeff Roberson cp += sizeof(cpuset_t); 104473c40187SJeff Roberson while (cp != end) 104573c40187SJeff Roberson if (*cp++ != 0) { 104673c40187SJeff Roberson error = EINVAL; 104773c40187SJeff Roberson goto out; 104873c40187SJeff Roberson } 104973c40187SJeff Roberson 105073c40187SJeff Roberson } 1051d7f687fcSJeff Roberson switch (uap->level) { 1052d7f687fcSJeff Roberson case CPU_LEVEL_ROOT: 1053d7f687fcSJeff Roberson case CPU_LEVEL_CPUSET: 1054d7f687fcSJeff Roberson error = cpuset_which(uap->which, uap->id, &p, &ttd, &set); 1055d7f687fcSJeff Roberson if (error) 1056d7f687fcSJeff Roberson break; 1057d7f687fcSJeff Roberson switch (uap->which) { 1058d7f687fcSJeff Roberson case CPU_WHICH_TID: 1059d7f687fcSJeff Roberson case CPU_WHICH_PID: 1060d7f687fcSJeff Roberson thread_lock(ttd); 1061d7f687fcSJeff Roberson set = cpuset_ref(ttd->td_cpuset); 1062d7f687fcSJeff Roberson thread_unlock(ttd); 1063c6440f72SJeff Roberson PROC_UNLOCK(p); 1064d7f687fcSJeff Roberson break; 1065d7f687fcSJeff Roberson case CPU_WHICH_CPUSET: 1066413628a7SBjoern A. Zeeb case CPU_WHICH_JAIL: 1067d7f687fcSJeff Roberson break; 10689b33b154SJeff Roberson case CPU_WHICH_IRQ: 10699b33b154SJeff Roberson error = EINVAL; 10709b33b154SJeff Roberson goto out; 1071d7f687fcSJeff Roberson } 1072d7f687fcSJeff Roberson if (uap->level == CPU_LEVEL_ROOT) 1073a03ee000SJeff Roberson nset = cpuset_refroot(set); 1074d7f687fcSJeff Roberson else 1075a03ee000SJeff Roberson nset = cpuset_refbase(set); 1076d7f687fcSJeff Roberson error = cpuset_modify(nset, mask); 1077d7f687fcSJeff Roberson cpuset_rel(nset); 1078d7f687fcSJeff Roberson cpuset_rel(set); 1079d7f687fcSJeff Roberson break; 1080d7f687fcSJeff Roberson case CPU_LEVEL_WHICH: 1081d7f687fcSJeff Roberson switch (uap->which) { 1082d7f687fcSJeff Roberson case CPU_WHICH_TID: 1083d7f687fcSJeff Roberson error = cpuset_setthread(uap->id, mask); 1084d7f687fcSJeff Roberson break; 1085d7f687fcSJeff Roberson case CPU_WHICH_PID: 1086d7f687fcSJeff Roberson error = cpuset_setproc(uap->id, NULL, mask); 1087d7f687fcSJeff Roberson break; 1088d7f687fcSJeff Roberson case CPU_WHICH_CPUSET: 1089413628a7SBjoern A. Zeeb case CPU_WHICH_JAIL: 1090413628a7SBjoern A. Zeeb error = cpuset_which(uap->which, uap->id, &p, 1091d7f687fcSJeff Roberson &ttd, &set); 1092d7f687fcSJeff Roberson if (error == 0) { 1093d7f687fcSJeff Roberson error = cpuset_modify(set, mask); 1094d7f687fcSJeff Roberson cpuset_rel(set); 1095d7f687fcSJeff Roberson } 1096d7f687fcSJeff Roberson break; 10979b33b154SJeff Roberson case CPU_WHICH_IRQ: 10989b33b154SJeff Roberson error = intr_setaffinity(uap->id, mask); 10999b33b154SJeff Roberson break; 1100d7f687fcSJeff Roberson default: 1101d7f687fcSJeff Roberson error = EINVAL; 1102d7f687fcSJeff Roberson break; 1103d7f687fcSJeff Roberson } 1104d7f687fcSJeff Roberson break; 1105d7f687fcSJeff Roberson default: 1106d7f687fcSJeff Roberson error = EINVAL; 1107d7f687fcSJeff Roberson break; 1108d7f687fcSJeff Roberson } 1109d7f687fcSJeff Roberson out: 1110d7f687fcSJeff Roberson free(mask, M_TEMP); 1111d7f687fcSJeff Roberson return (error); 1112d7f687fcSJeff Roberson } 1113dea0ed66SBjoern A. Zeeb 1114dea0ed66SBjoern A. Zeeb #ifdef DDB 1115dea0ed66SBjoern A. Zeeb DB_SHOW_COMMAND(cpusets, db_show_cpusets) 1116dea0ed66SBjoern A. Zeeb { 1117dea0ed66SBjoern A. Zeeb struct cpuset *set; 1118dea0ed66SBjoern A. Zeeb int cpu, once; 1119dea0ed66SBjoern A. Zeeb 1120dea0ed66SBjoern A. Zeeb LIST_FOREACH(set, &cpuset_ids, cs_link) { 1121dea0ed66SBjoern A. Zeeb db_printf("set=%p id=%-6u ref=%-6d flags=0x%04x parent id=%d\n", 1122dea0ed66SBjoern A. Zeeb set, set->cs_id, set->cs_ref, set->cs_flags, 1123dea0ed66SBjoern A. Zeeb (set->cs_parent != NULL) ? set->cs_parent->cs_id : 0); 1124dea0ed66SBjoern A. Zeeb db_printf(" mask="); 1125dea0ed66SBjoern A. Zeeb for (once = 0, cpu = 0; cpu < CPU_SETSIZE; cpu++) { 1126dea0ed66SBjoern A. Zeeb if (CPU_ISSET(cpu, &set->cs_mask)) { 1127dea0ed66SBjoern A. Zeeb if (once == 0) { 1128dea0ed66SBjoern A. Zeeb db_printf("%d", cpu); 1129dea0ed66SBjoern A. Zeeb once = 1; 1130dea0ed66SBjoern A. Zeeb } else 1131dea0ed66SBjoern A. Zeeb db_printf(",%d", cpu); 1132dea0ed66SBjoern A. Zeeb } 1133dea0ed66SBjoern A. Zeeb } 1134dea0ed66SBjoern A. Zeeb db_printf("\n"); 1135dea0ed66SBjoern A. Zeeb if (db_pager_quit) 1136dea0ed66SBjoern A. Zeeb break; 1137dea0ed66SBjoern A. Zeeb } 1138dea0ed66SBjoern A. Zeeb } 1139dea0ed66SBjoern A. Zeeb #endif /* DDB */ 1140