Lines Matching refs:set

74  * Each process belongs to an identified set, by default this is set 1.  Each
76 * named set. This creates an anonymous set which other threads and processes
79 * The named set is referred to herein as the 'base' set to avoid ambiguity.
80 * This set is usually a child of a 'root' set while the anonymous set may
84 * Threads inherit their set from their creator whether it be anonymous or
86 * shared. To modify an anonymous set a new set is created with the desired
87 * mask and the same parent as the existing anonymous set. This gives the
91 * or mask that is discovered via a pid, tid, or setid. Modifying a set
94 * exist within the assigned parent set.
127 cpuset_ref(struct cpuset *set)
130 refcount_acquire(&set->cs_ref);
131 return (set);
135 * Walks up the tree from 'set' to find the root. Returns the root
139 cpuset_refroot(struct cpuset *set)
142 for (; set->cs_parent != NULL; set = set->cs_parent)
143 if (set->cs_flags & CPU_SET_ROOT)
145 cpuset_ref(set);
147 return (set);
151 * Find the first non-anonymous set starting from 'set'. Returns this set
152 * referenced. May return the passed in set with an extra ref if it is
156 cpuset_refbase(struct cpuset *set)
159 if (set->cs_id == CPUSET_INVALID)
160 set = set->cs_parent;
161 cpuset_ref(set);
163 return (set);
170 cpuset_rel(struct cpuset *set)
174 if (refcount_release(&set->cs_ref) == 0)
177 LIST_REMOVE(set, cs_siblings);
178 id = set->cs_id;
180 LIST_REMOVE(set, cs_link);
182 cpuset_rel(set->cs_parent);
183 uma_zfree(cpuset_zone, set);
193 cpuset_rel_defer(struct setlist *head, struct cpuset *set)
196 if (refcount_release(&set->cs_ref) == 0)
199 LIST_REMOVE(set, cs_siblings);
200 if (set->cs_id != CPUSET_INVALID)
201 LIST_REMOVE(set, cs_link);
202 LIST_INSERT_HEAD(head, set, cs_link);
207 * Complete a deferred release. Removes the set from the list provided to
211 cpuset_rel_complete(struct cpuset *set)
213 LIST_REMOVE(set, cs_link);
214 cpuset_rel(set->cs_parent);
215 uma_zfree(cpuset_zone, set);
219 * Find a set based on an id. Returns it with a ref.
224 struct cpuset *set;
229 LIST_FOREACH(set, &cpuset_ids, cs_link)
230 if (set->cs_id == setid)
232 if (set)
233 cpuset_ref(set);
237 if (set != NULL && jailed(td->td_ucred)) {
241 for (tset = set; tset != NULL; tset = tset->cs_parent)
245 cpuset_rel(set);
246 set = NULL;
250 return (set);
254 * Create a set in the space provided in 'set' with the provided parameters.
255 * The set is returned with a single ref. May return EDEADLK if the set
259 _cpuset_create(struct cpuset *set, struct cpuset *parent, const cpuset_t *mask,
265 CPU_COPY(mask, &set->cs_mask);
266 LIST_INIT(&set->cs_children);
267 refcount_init(&set->cs_ref, 1);
268 set->cs_flags = 0;
270 CPU_AND(&set->cs_mask, &parent->cs_mask);
271 set->cs_id = id;
272 set->cs_parent = cpuset_ref(parent);
273 LIST_INSERT_HEAD(&parent->cs_children, set, cs_siblings);
274 if (set->cs_id != CPUSET_INVALID)
275 LIST_INSERT_HEAD(&cpuset_ids, set, cs_link);
282 * Create a new non-anonymous set with the requested parent and mask. May
289 struct cpuset *set;
296 *setp = set = uma_zalloc(cpuset_zone, M_WAITOK);
297 error = _cpuset_create(set, parent, mask, id);
301 uma_zfree(cpuset_zone, set);
308 * the tree of sets starting at 'set'. Checks for sets that would become
312 cpuset_testupdate(struct cpuset *set, cpuset_t *mask, int check_mask)
319 if (set->cs_flags & CPU_SET_RDONLY)
322 if (!CPU_OVERLAP(&set->cs_mask, mask))
324 CPU_COPY(&set->cs_mask, &newmask);
329 LIST_FOREACH(nset, &set->cs_children, cs_siblings)
339 cpuset_update(struct cpuset *set, cpuset_t *mask)
344 CPU_AND(&set->cs_mask, mask);
345 LIST_FOREACH(nset, &set->cs_children, cs_siblings)
346 cpuset_update(nset, &set->cs_mask);
352 * Modify the set 'set' to use a copy of the mask provided. Apply this new
357 cpuset_modify(struct cpuset *set, cpuset_t *mask)
372 set->cs_flags & CPU_SET_ROOT)
375 * Verify that we have access to this set of
378 root = set->cs_parent;
382 error = cpuset_testupdate(set, mask, 0);
385 CPU_COPY(mask, &set->cs_mask);
386 cpuset_update(set, mask);
399 * For WHICH_SET returns a valid set with a new reference.
402 * the base set of the current thread. May fail with ESRCH/EPERM.
408 struct cpuset *set;
415 *setp = set = NULL;
441 set = cpuset_refbase(curthread->td_cpuset);
444 set = cpuset_lookup(id, curthread);
445 if (set) {
446 *setp = set;
452 /* Find `set' for prison with given id. */
484 * Create an anonymous set with the provided mask in the space provided by
485 * 'fset'. If the passed in set is anonymous we use its parent otherwise
486 * the new set is a child of 'set'.
489 cpuset_shadow(struct cpuset *set, struct cpuset *fset, const cpuset_t *mask)
493 if (set->cs_id == CPUSET_INVALID)
494 parent = set->cs_parent;
496 parent = set;
503 * Handle two cases for replacing the base set or mask of an entire process.
506 * to the provided set and replaces all non-anonymous td_cpusets with the
507 * provided set.
508 * 2) Mask is non-null and set is null. This replaces or creates anonymous
516 cpuset_setproc(pid_t pid, struct cpuset *set, cpuset_t *mask)
563 * the set the thread is a member of.
571 * Verify that a new set won't leave an existing thread
573 * the set.
576 if (!CPU_OVERLAP(&set->cs_mask, &tdset->cs_mask))
591 * If we presently have an anonymous set or are applying a
592 * mask we must create an anonymous shadow set. That is
593 * either parented to our existing base or the supplied set.
595 * If we have a base set with no anonymous shadow we simply
605 error = _cpuset_create(nset, set,
613 nset = cpuset_ref(set);
636 cpusetobj_strprint(char *buf, const cpuset_t *set)
646 bytesp = snprintf(tbuf, bufsiz, "%lx,", set->__bits[i]);
650 snprintf(tbuf, bufsiz, "%lx", set->__bits[_NCPUWORDS - 1]);
659 cpusetobj_strscan(cpuset_t *set, const char *buf)
675 CPU_ZERO(set);
677 ret = sscanf(buf, "%lx,", &set->__bits[i]);
685 ret = sscanf(buf, "%lx", &set->__bits[nwords - 1]);
698 struct cpuset *set;
704 error = cpuset_which(CPU_WHICH_TID, id, &p, &td, &set);
707 set = NULL;
711 set = td->td_cpuset;
718 if (set)
719 cpuset_rel(set);
760 * roll back to default set. We're not using cpuset_shadow()
762 * if default set does not contain all CPUs.
774 * Current set is either default (1) or
775 * shadowed version of default set.
777 * Allocate new root set to be able to shadow it
791 /* Assume existing set was already allocated by previous call */
824 * 0 - The root set which should represent all valid processors in the
827 * runs. This set is immutable.
828 * 1 - The default set which all processes are a member of until changed.
835 struct cpuset *set;
843 * Create the root system set for the whole machine. Doesn't use
846 set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO);
847 CPU_FILL(&set->cs_mask);
848 LIST_INIT(&set->cs_children);
849 LIST_INSERT_HEAD(&cpuset_ids, set, cs_link);
850 set->cs_ref = 1;
851 set->cs_flags = CPU_SET_ROOT;
852 cpuset_zero = set;
853 cpuset_root = &set->cs_mask;
856 * Now derive a default, modifiable set from that to give out.
858 set = uma_zalloc(cpuset_zone, M_WAITOK);
859 error = _cpuset_create(set, cpuset_zero, &cpuset_zero->cs_mask, 1);
860 KASSERT(error == 0, ("Error creating default set: %d\n", error));
861 cpuset_default = set;
878 return (set);
883 * mark the new 'set' as root.
888 * In case of no error, returns the set in *setp locked with a reference.
893 struct cpuset *set;
906 /* Mark the set as root. */
907 set = *setp;
908 set->cs_flags |= CPU_SET_ROOT;
914 cpuset_setproc_update_set(struct proc *p, struct cpuset *set)
919 KASSERT(set != NULL, ("[%s:%d] invalid set", __func__, __LINE__));
921 cpuset_ref(set);
922 error = cpuset_setproc(p->p_pid, set, NULL);
925 cpuset_rel(set);
930 * This is called once the final set of system cpus is known. Modifies
931 * the root set and all children and mark the root read-only.
940 panic("Can't set initial cpuset mask.\n");
954 struct cpuset *set;
960 error = cpuset_create(&set, root, &root->cs_mask);
964 error = copyout(&set->cs_id, uap->setid, sizeof(set->cs_id));
966 error = cpuset_setproc(-1, set, NULL);
967 cpuset_rel(set);
989 struct cpuset *set;
997 set = cpuset_lookup(setid, td);
998 if (set == NULL)
1000 error = cpuset_setproc(id, set, NULL);
1001 cpuset_rel(set);
1026 struct cpuset *set;
1034 error = cpuset_which(which, id, &p, &ttd, &set);
1041 set = cpuset_refbase(ttd->td_cpuset);
1054 nset = cpuset_refroot(set);
1055 cpuset_rel(set);
1056 set = nset;
1063 tmpid = set->cs_id;
1064 cpuset_rel(set);
1094 struct cpuset *set;
1102 /* In Capability mode, you can only get your own CPU set. */
1113 error = cpuset_which(which, id, &p, &ttd, &set);
1123 set = cpuset_ref(ttd->td_cpuset);
1137 nset = cpuset_refroot(set);
1139 nset = cpuset_refbase(set);
1159 CPU_COPY(&set->cs_mask, mask);
1178 if (set)
1179 cpuset_rel(set);
1211 struct cpuset *set;
1219 /* In Capability mode, you can only set your own CPU set. */
1233 * Verify that no high bits are set.
1252 error = cpuset_which(which, id, &p, &ttd, &set);
1259 set = cpuset_ref(ttd->td_cpuset);
1274 nset = cpuset_refroot(set);
1276 nset = cpuset_refbase(set);
1279 cpuset_rel(set);
1291 error = cpuset_which(which, id, &p, &ttd, &set);
1293 error = cpuset_modify(set, mask);
1294 cpuset_rel(set);
1318 ddb_display_cpuset(const cpuset_t *set)
1323 if (CPU_ISSET(cpu, set)) {
1337 struct cpuset *set;
1339 LIST_FOREACH(set, &cpuset_ids, cs_link) {
1340 db_printf("set=%p id=%-6u ref=%-6d flags=0x%04x parent id=%d\n",
1341 set, set->cs_id, set->cs_ref, set->cs_flags,
1342 (set->cs_parent != NULL) ? set->cs_parent->cs_id : 0);
1344 ddb_display_cpuset(&set->cs_mask);