Deleted Added
full compact
kern_cpuset.c (194707) kern_cpuset.c (198493)
1/*-
2 * Copyright (c) 2008, Jeffrey Roberson <jeff@freebsd.org>
3 * All rights reserved.
4 *
5 * Copyright (c) 2008 Nokia Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 15 unchanged lines hidden (view full) ---

24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2008, Jeffrey Roberson <jeff@freebsd.org>
3 * All rights reserved.
4 *
5 * Copyright (c) 2008 Nokia Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 15 unchanged lines hidden (view full) ---

24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/kern/kern_cpuset.c 194707 2009-06-23 14:39:21Z jamie $");
32__FBSDID("$FreeBSD: head/sys/kern/kern_cpuset.c 198493 2009-10-26 17:42:03Z jhb $");
33
34#include "opt_ddb.h"
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/sysproto.h>
39#include <sys/jail.h>
40#include <sys/kernel.h>

--- 33 unchanged lines hidden (view full) ---

74 * This set is usually a child of a 'root' set while the anonymous set may
75 * simply be referred to as a mask. In the syscall api these are referred to
76 * as the ROOT, CPUSET, and MASK levels where CPUSET is called 'base' here.
77 *
78 * Threads inherit their set from their creator whether it be anonymous or
79 * not. This means that anonymous sets are immutable because they may be
80 * shared. To modify an anonymous set a new set is created with the desired
81 * mask and the same parent as the existing anonymous set. This gives the
33
34#include "opt_ddb.h"
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/sysproto.h>
39#include <sys/jail.h>
40#include <sys/kernel.h>

--- 33 unchanged lines hidden (view full) ---

74 * This set is usually a child of a 'root' set while the anonymous set may
75 * simply be referred to as a mask. In the syscall api these are referred to
76 * as the ROOT, CPUSET, and MASK levels where CPUSET is called 'base' here.
77 *
78 * Threads inherit their set from their creator whether it be anonymous or
79 * not. This means that anonymous sets are immutable because they may be
80 * shared. To modify an anonymous set a new set is created with the desired
81 * mask and the same parent as the existing anonymous set. This gives the
82 * illusion of each thread having a private mask.A
82 * illusion of each thread having a private mask.
83 *
84 * Via the syscall apis a user may ask to retrieve or modify the root, base,
85 * or mask that is discovered via a pid, tid, or setid. Modifying a set
86 * modifies all numbered and anonymous child sets to comply with the new mask.
87 * Modifying a pid or tid's mask applies only to that tid but must still
88 * exist within the assigned parent set.
89 *
83 *
84 * Via the syscall apis a user may ask to retrieve or modify the root, base,
85 * or mask that is discovered via a pid, tid, or setid. Modifying a set
86 * modifies all numbered and anonymous child sets to comply with the new mask.
87 * Modifying a pid or tid's mask applies only to that tid but must still
88 * exist within the assigned parent set.
89 *
90 * A thread may not be assigned to a a group seperate from other threads in
90 * A thread may not be assigned to a a group separate from other threads in
91 * the process. This is to remove ambiguity when the setid is queried with
92 * a pid argument. There is no other technical limitation.
93 *
94 * This somewhat complex arrangement is intended to make it easy for
95 * applications to query available processors and bind their threads to
96 * specific processors while also allowing administrators to dynamically
97 * reprovision by changing sets which apply to groups of processes.
98 *
99 * A simple application should not concern itself with sets at all and
100 * rather apply masks to its own threads via CPU_WHICH_TID and a -1 id
91 * the process. This is to remove ambiguity when the setid is queried with
92 * a pid argument. There is no other technical limitation.
93 *
94 * This somewhat complex arrangement is intended to make it easy for
95 * applications to query available processors and bind their threads to
96 * specific processors while also allowing administrators to dynamically
97 * reprovision by changing sets which apply to groups of processes.
98 *
99 * A simple application should not concern itself with sets at all and
100 * rather apply masks to its own threads via CPU_WHICH_TID and a -1 id
101 * meaning 'curthread'. It may query availble cpus for that tid with a
101 * meaning 'curthread'. It may query available cpus for that tid with a
102 * getaffinity call using (CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1, ...).
103 */
104static uma_zone_t cpuset_zone;
105static struct mtx cpuset_lock;
106static struct setlist cpuset_ids;
107static struct unrhdr *cpuset_unr;
108static struct cpuset *cpuset_zero;
109

--- 38 unchanged lines hidden (view full) ---

148 if (set->cs_id == CPUSET_INVALID)
149 set = set->cs_parent;
150 cpuset_ref(set);
151
152 return (set);
153}
154
155/*
102 * getaffinity call using (CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1, ...).
103 */
104static uma_zone_t cpuset_zone;
105static struct mtx cpuset_lock;
106static struct setlist cpuset_ids;
107static struct unrhdr *cpuset_unr;
108static struct cpuset *cpuset_zero;
109

--- 38 unchanged lines hidden (view full) ---

148 if (set->cs_id == CPUSET_INVALID)
149 set = set->cs_parent;
150 cpuset_ref(set);
151
152 return (set);
153}
154
155/*
156 * Release a reference in a context where it is safe to allocte.
156 * Release a reference in a context where it is safe to allocate.
157 */
158void
159cpuset_rel(struct cpuset *set)
160{
161 cpusetid_t id;
162
163 if (refcount_release(&set->cs_ref) == 0)
164 return;

--- 582 unchanged lines hidden (view full) ---

747 if (error)
748 return (error);
749 cpuset_rel(set);
750 return (0);
751}
752
753/*
754 * This is called once the final set of system cpus is known. Modifies
157 */
158void
159cpuset_rel(struct cpuset *set)
160{
161 cpusetid_t id;
162
163 if (refcount_release(&set->cs_ref) == 0)
164 return;

--- 582 unchanged lines hidden (view full) ---

747 if (error)
748 return (error);
749 cpuset_rel(set);
750 return (0);
751}
752
753/*
754 * This is called once the final set of system cpus is known. Modifies
755 * the root set and all children and mark the root readonly.
755 * the root set and all children and mark the root read-only.
756 */
757static void
758cpuset_init(void *arg)
759{
760 cpuset_t mask;
761
762 CPU_ZERO(&mask);
763#ifdef SMP

--- 339 unchanged lines hidden ---
756 */
757static void
758cpuset_init(void *arg)
759{
760 cpuset_t mask;
761
762 CPU_ZERO(&mask);
763#ifdef SMP

--- 339 unchanged lines hidden ---